0

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()
annunarcist
  • 1,637
  • 3
  • 20
  • 42
  • Related: [why can't step into a function](http://stackoverflow.com/questions/10167484/why-cant-step-into-a-function-in-gdb). – mohit Jun 14 '13 at 16:52
  • what does it mean by "standard library with debugging information"?? Can you please elaborate? In my case I'm linking tomcrypt library, but not any standard C library. – annunarcist Jun 14 '13 at 19:22
  • does it have to do anything with .d files?? – annunarcist Jun 14 '13 at 21:00
  • Do you've the source code of the library? If yes, recompile it with debug info. – mohit Jun 14 '13 at 21:15
  • yes I do have the source code of the library, i am unable to understand the part-recompile with debug info. When I compiled it using the makefile provided by the API, it created the following library files : libtomcrypt.so.0.0.117.debug, libtomcrypt.so.0.debug, libtomcrypt.so.debug, libtomcrypt.a And I have set the path of these libraries and included the library libtomcrypt.a in eclipse(excluding lib prefix and .a extension). Do i need to change the library included?? – annunarcist Jun 17 '13 at 15:44
  • should I compile with -g ?? – annunarcist Jun 17 '13 at 16:01
  • Yes. Also look [Compiling for debugging](http://www.delorie.com/gnu/docs/gdb/gdb_17.html). – mohit Jun 17 '13 at 17:25
  • It also gives the output as: Reading symbols from /home/anvesh/workspace/Tomcrypt_SHA-256_Bmark/src/executable...(no debugging symbols found)...done. (gdb) (gdb) .... – annunarcist Jun 18 '13 at 03:37
  • Can you give the exact command you used to compile your library? Also post your Makefile. Also state which compiler you're using. – mohit Jun 18 '13 at 06:30
  • i'm using gcc compiler, i gave the following commands in the order(in terminal) for compiling the library: ./configure;make;sudo make install and used the generated library file for debugging my test file. – annunarcist Jun 18 '13 at 22:04
  • And compiled my test file using the following commands:gcc -I/home/xxx/Documents/libtomcrypt-1.17/src/headers -c Tomcrypt_SHA-256_Bmark.c jg_timing.c -ltomcrypt;where, Tomcrypt_SHA-256_Bmark.c is my test file and jg_timing.c is a dependancy file & tomcrypt is the library file that i'm including (which i got from executing above comment);then i linked the object files & used -g option to generate executable with debug info (correct me if wrong) using the following command : gcc -I/home/xxx/Documents/libtomcrypt-1.17/src/headers -g Tomcrypt_SHA-256_Bmark.o jg_timing.o -o executable -ltomcrypt – annunarcist Jun 18 '13 at 22:11
  • when i executed the executable as:gdb executable,it gave the output as: Reading symbols from /home/anvesh/workspace/Tomcrypt_SHA-256_Bmark/src/executable...(no debugging symbols found)...done. (gdb) (gdb) – annunarcist Jun 18 '13 at 22:12
  • so i'm not using any makefile for executing my test file in terminal or is it that you need makefile of the library? – annunarcist Jun 18 '13 at 22:20

1 Answers1

1

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 ).

mohit
  • 5,696
  • 3
  • 24
  • 37
  • that solved the problem!! and just to know more about modes of -g option. My library makefile already has -g3 option(maximum debugging) included in CFLAGS, but after including -g option only, this thing got fixed and a library file with debugging options is generated. Is it any version compatibility issue? or -g3 is not the appropriate option for debugging?? thanks for your help!! – annunarcist Jun 19 '13 at 16:29
  • `-g3` should be fine. I think the problem was that you included `-g` during linking, except that it should be done during compilation. `-g3` means extra debugging information also get stored, which should work perfectly with all debuggers. – mohit Jun 20 '13 at 06:28