14

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

ArielBH
  • 1,991
  • 3
  • 22
  • 38

3 Answers3

24

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)

maxkoryukov
  • 4,205
  • 5
  • 33
  • 54
dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
7

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.

wallyk
  • 56,922
  • 16
  • 83
  • 148
4

The full example would be:

CFLAGS =-g

all: program.o
    gcc -o program program.o

The CFLAGS here is applied to both the compiler and the linker.

Arik
  • 1,257
  • 9
  • 13
  • 1
    That's not true. In your example `-g` is only applied in the compile step. This is because compilation happens through an implicit rule of make that creates `program.o` from `program.c` (without `program.c` ever being mentioned explicitly in the makefile. The implicit rule uses `CFLAGS`. However, the explicit rule for the linking step is executed as shown - thus `-g` is *not* applied while linking (AFAIK it does not have to with gcc anyway). – stefanct Dec 20 '19 at 14:00