5

Alright I just can't get gdb to work despite trying quite a few solutions.

My makefile does cc -g _________ and produces myfilesys

>gdb myfilesys
(gdb) break my_linked_list.c:90
No symbol table is loaded, use the "file" command...
(gdb) file myfilesys
Reading symbols from /home/jsexton/Work/cs492/hw3/myfilesys...(no 
debugging symbols found)...done.
(gdb) break my_linked_list.c:90
No symbol table is loaded, use the "file" command...

Can anyone see the problem? My program is broken into like 30 .c files, so I really do need to use the file:[line number] thing.

3
  • Can you show the complete command line? Did you compile files into .o before linking?
    – Henry Hu
    Commented Apr 21, 2014 at 22:56
  • At the command line, type file myfilesys. This will print the filetype. Prints a good bit of information, make sure it says 'not stripped'. Feel free to add the output to your question.
    – esorton
    Commented Apr 21, 2014 at 22:56
  • 1
    When it says ...(no debugging symbols found)... when loading in your file, it means it. Check to make sure your makefile is really doing cc -g -c compilation of each .c file, not just the last one to make your myfilesys. If all your sources are in one directory, you can do cc -g *.c -o myfilesys.
    – jxh
    Commented Apr 21, 2014 at 23:07

1 Answer 1

4

Although you claim to have compiled with cc -g on your executable myfilesys, GDB does not see any, as evidenced in your attempt to use GDB's file command:

(gdb) file myfilesys
Reading symbols from /.../myfilesys...(no debugging symbols found)...done.

Taking you at your word that you have actually used cc -g for compiling myfilesys, this means that you have either stripped the symbols from your binaries (I find this unlikely, but I mention the possibility), or none of your object files have debug symbols. Assuming the latter, you need to apply the cc -g -c compilation to each individual source file. Then, each of the resulting object files will have debugging symbols, and the resulting executable will also have debugging symbols (so long as you do not strip them out after linking).

With standard makefiles such as gmake, this can usually be easily accomplished by augmenting the CFLAGS variable with -g. Below is a complete makefile that illustrates this with three source files:

CFLAGS=-g

myfilesys: a.o b.o c.o
        $(CC) $^ -o $@

GCC already has implicit rules that know how to create a .o file from the corresponding .c file. However, you can alter the command line arguments passed to the compiler by changing the CFLAGS variable. Pre-processing directives and include directories are usually passed in by augmenting the CPPFLAGS variable (C++ specific flags are read from CXXFLAGS, but CPPFLAGS options are passed to both the C and C++ compilers).

We need to define an explicit rule for creating the executable myfilesys (the $(CC) rule is indented with a tab character, a makefile requirement). After typing make, the executable will have symbols, and GDB will not report missing symbols in your executable (it may report about missing symbols from any libraries that you use):

(gdb) file myfilesys
Reading symbols from /.../myfilesys...done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.