2

I'm trying to debug my first program in D compiled using

dmd -debug hello.d

but when I run the executable through GDB-7.6 it doesn't seem to know where to find the source code and decode the format of the stack trace (and its name-demangling).

Is GDB-debugging DMD-generated executables not yet supported or have I missed something?

Nordlöw
  • 11,838
  • 10
  • 52
  • 99

1 Answers1

8

The -debug flag means that debug code is enabled, which is not the same as having debug symbols. The flag you are looking for is -g or -gc.

See http://dlang.org/dmd-linux.html#switches for more info on the compiler flags.

Nordlöw
  • 11,838
  • 10
  • 52
  • 99
John_C
  • 788
  • 5
  • 17
  • 1
    Ok. So i added the flag `-gc` but it still doesn't work. It now errors with `warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000`. Command `break main` fails but pressing Ctrl-C during execution seems to get gdb into a usable state. – Nordlöw Jul 01 '13 at 00:21
  • I'm running GDB through Emacs and the format of the stack-frames seems to confuse Emacs aswell. I can't click on them to change stack frame. Variable view seems to work at least when I press Ctrl-C. – Nordlöw Jul 01 '13 at 00:27
  • 1
    Just to check the simple things: "dmd -gc hello.d" produces an executable called "hello". "gdb ./hello" (straight from terminal, let's leave emacs out for now) should produce no errors, except maybe asking for some more debug libraries to be installed. "run" should then run the program, as usual in gdb. – John_C Jul 01 '13 at 09:22
  • To get this configured with DUB, we can add: ` "dflags": [ "-m64", "-g", "-gc" ] ` to dub.json – Arun Mar 09 '17 at 07:03