GCC debug option documentation is not that comprehensive. So trying to compile a binary with different options -g
, -g1
, -g2
, -g3
I got the following result.
When compiling with -g
and -g2
binary has the same 13KB
in size.
When compiling with -g1
the binary ended up in 9.3KB
in size
When compiling with -g3
the binary has 73KB
in size
So is -g
equivalent to -g2
? But the level 2 is not even explained in the documentation. Here is what the docs say (no level 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.
Or am I missing something?
CodePudding user response:
So is
-g
equivalent to-g2
?
Yes.
But the level 2 is not even explained in the documentation. [...] Or am I missing something?
You are missing something. You have overlooked the sentence immediately preceding your quotation:
The default level is 2.
This means that -g2
means the same thing as -g
. (And -ggdb2
means the same thing as -ggdb
, etc.) This serves in part as a reference for each of the -g*2
options to the docs of the corresponding unnumbered -g*
options, where you will find the relevant documentation. In particular, the documentation for -g2
is the documentation for -g
, which appears first in the section.