Вопрос

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.

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top