On Wednesday, 13 January 2021 at 13:47:55 UTC, Roguish wrote:
On Wednesday, 13 January 2021 at 13:30:48 UTC, Roguish wrote:
Anything else I need to know when debugging on Linux, without
an IDE?
One specific question I have is: what's the difference between
-g and -debug and -d-debug?
Also, what does it mean to "always emit a stackframe" (compiler
option -gs) ?
-g : generate dwarf info, the debug info, the most important
-debug : compiles the debug statements, e.g debug logging. not so
important, this
is a conditional compilation feature.
-gs : always emit a prelude/prologue. but dmd pretty much
always do that even
when not required (sigh).
You really mostly only requires -g. Then you have to learn gdb.
A few basis to get started, a session for a segfault is often like
$ gdb ./myapp
$ run
and when it crashes, note the source position, additionally
$ bt
$ p somevar
$ p some.more.complex.expression
may already give interesting infos. If not, during a second
session you will rather put breakpoints to see what happens
before the access violation and step from that breakpoint to the
code that accesses unowned memory.
$ gdb ./myapp
$ break <somefile>.d <linenum>
$ run
and then step by step, each time it pauses you inspect the
interesting stuff.
Note that I may be wrong on the syntax of the commands as I
always use an IDE GUI.