Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate Debug symbols with Makefile for C? [Linux]

I'm trying to use GDB and KDEvelop to debug a console app under Knoppix VM. KDevelop and GDB don't break at my breakpoints. I suspect it's because they don't have debug symbols.

If I'm correct how do I need to change my Makefile to create those. Maybe the problem is somewhere else?

Regards, Ariel

like image 914
ArielBH Avatar asked Dec 20 '09 23:12

ArielBH


People also ask

How do I debug with makefile?

To use it, just set the list of variables to print on the command line, and include the debug target: $ make V="USERNAME SHELL" debug makefile:2: USERNAME = Owner makefile:2: SHELL = /bin/sh.exe make: debug is up to date. Now you can print variables by simply listing them on the command line.

Can we debug makefile?

Unfortunately, there is no such thing as a makefile debugger to examine how a particular rule is being evaluated or a variable expanded. Instead, most debugging is performed with simple print state- ments and by inspection of the makefile.

How do I add debug symbols in GDB?

To add additional symbols you might use add-symbol-file . The add-symbol-file command reads additional symbol table information from the file filename. You would use this command when filename has been dynamically loaded (by some other means) into the program that is running.

What are debug symbols in Linux?

A debug symbol is a special kind of symbol that attaches additional information to the symbol table of an object file, such as a shared library or an executable.


2 Answers

Include -g in the flags sent to the compiler and linker. The default variables for this are CFLAGS and LDFLAGS respectively.

The second step: exclude -s from flags (-s means strip)

like image 170
dmckee --- ex-moderator kitten Avatar answered Oct 14 '22 10:10

dmckee --- ex-moderator kitten


If you are able to see source and set the breakpoint, then you probably have debugging symbols established. However, the usual sequence is:

gcc -g -o (outputname) (source files...)
gdb outputname

Give more specifics about what you are doing and what messages you see and we can be more specific.

like image 43
wallyk Avatar answered Oct 14 '22 09:10

wallyk