namhyung / uftrace

Function graph tracer for C/C++/Rust/Python
https://uftrace.github.io/slide/
GNU General Public License v2.0
3.02k stars 443 forks source link

Discussion of DEBUG=1 Debugging-Options #1504

Open paranlee opened 2 years ago

paranlee commented 2 years ago

I was curious about the debug options at compile time, so I looked into the gnu documentation.

-g produces debugging information in the OS¹s native format (stabs, COFF, XCOFF, or DWARF 2).

-ggdb produces debugging information specifically intended for gdb.

-ggdb3 produces extra debugging information, for example: including macro definitions.

-ggdb by itself without specifying the level defaults to -ggdb2 (i.e., gdb for level 2).

Re: difference between -g, -ggdb and -ggdb3

Request debugging information and also use level to specify how much information. The default level is 2.

Level 0 produces no debug information at all. Thus, -g0 negates -g.

Level 1 produces minimal information, enough for making backtraces in parts of the program that you don’t plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables.

Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.

If you use multiple -g options, with or without level numbers, the last such option is the one that is effective.

-gdwarf does not accept a concatenated debug level, to avoid confusion with -gdwarf-level. Instead use an additional -glevel option to change the debug level for DWARF.


If we turn on the debugging option, wouldn't it be convenient to debug with level 3?

[`Makefile`](https://github.com/namhyung/uftrace/blob/master/Makefile)

ifeq ($(DEBUG), 1) COMMON_CFLAGS += -O0 -g -DDEBUG_MODE=1 else COMMON_CFLAGS += -O2 -g -DDEBUG_MODE=0 endif

namhyung commented 2 years ago

No objection from me, but could you please verify if clang also supports -g3?