문제

I am using eclipse CDT in Ubuntu OS and have created a C project with external static library(libtomcrypt) linked to it. It runs and gives the output correctly, but I want to know definition of the library functions, the call hierarchy of the functions and their implementation.

So turned on debugging mode and started looking into execution steps line by line using "step into" button and it works with the functions that I defined in main() (i.e., step into works for test_function() in this example) but step into is not working for the library functions that I'm calling(register_hash(&sha256_desc) & find_hash("sha256") functions in this example).

It just skips the the line without stepping into and moves onto next line. Please help me solve this problem.

   int main()
    {
    /* some code initialization */

            double sha_elapsed;

                /* register hashes .... */
                if ((err=register_hash(&sha256_desc)) == -1) {
                    printf("Error registering MD5.\n");
                    return -1;
                }

                /* get hash index */
                indx = find_hash("sha256");
                if (indx == -1) {
                    printf("Invalid hash name!\n");
                    return -1;
                }
            printf("something");
            test_function() {
                //code for the function
            }
       //remaining code
}//end of main()
도움이 되었습니까?

해결책

In order to debug your code, debugger will need some information (eg, which line of code corresponds to this object code, in a executable).

To make this information available, you need to specifically instruct your compiler (with -g option in gcc & g++).

Suppose you have a library, which you compile using makefile (as in your case). You need to look in the makefile of library, for flags used for compilation. As in,

CC=g++
CFLAGS=-c -Wall

And then, you add -g option in flags:

CFLAGS=-c -Wall -g

(Incase, your makefile doesn't use CFLAGS, you need to look for lines where compilation takes place and add -g option to all those lines, manually).

Then make your library. Now, you can compile you test programs like this:

gcc -I/home/xxx/Documents/libtomcrypt-1.17/src/headers -c -g Tomcrypt_SHA-256_Bmark.c jg_timing.c -ltomcrypt
gcc -I/home/xxx/Documents/libtomcrypt-1.17/src/headers Tomcrypt_SHA-256_Bmark.o jg_timing.o -o executable -ltomcrypt 

EDIT: Also note that '-g' option should be included during compilation, and not during linking (as you did ).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top