[英]Is -g the same as -g2 for gcc and clang?
GCC debug option documentation is not that comprehensive. GCC 调试选项文档并不全面。 So trying to compile a binary with different options -g
, -g1
, -g2
, -g3
I got the following result.因此,尝试使用不同的选项-g
、 -g1
、 -g2
、 -g3
编译二进制文件,我得到了以下结果。
When compiling with -g
and -g2
binary has the same 13KB
in size.使用-g
和-g2
编译时,二进制文件大小相同,均为13KB
。
When compiling with -g1
the binary ended up in 9.3KB
in size使用-g1
编译时,二进制文件的大小为9.3KB
When compiling with -g3
the binary has 73KB
in size使用-g3
编译时,二进制文件大小为73KB
So is -g
equivalent to -g2
?那么-g
是否等同于-g2
? But the level 2 is not even explained in the documentation.但是文档中甚至没有解释级别 2。 Here is what the docs say (no level 2):这是文档所说的(没有 2 级):
Level 0 produces no debug information at all. 0 级根本不产生调试信息。 Thus, -g0 negates -g.因此,-g0 否定 -g。
Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug.级别 1 产生的信息最少,足以在您不打算调试的程序部分中进行回溯。 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.第 3 级包括额外信息,例如程序中存在的所有宏定义。 Some debuggers support macro expansion when you use -g3.当您使用 -g3 时,某些调试器支持宏扩展。
Or am I missing something?还是我错过了什么?
So is
-g
equivalent to-g2
?那么-g
是否等同于-g2
?
Yes.是的。
But the level 2 is not even explained in the documentation.但是文档中甚至没有解释级别 2。 [...] Or am I missing something? [...] 还是我错过了什么?
You are missing something.你错过了一些东西。 You have overlooked the sentence immediately preceding your quotation:您忽略了引用之前的句子:
The default level is 2.默认级别为 2。
This means that -g2
means the same thing as -g
.这意味着-g2
的含义与-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. (并且-ggdb2
与-ggdb
等的含义相同。)这部分地作为每个-g*2
选项对相应未编号-g*
选项的文档的参考,您可以在其中找到相关文档. In particular, the documentation for -g2
is the documentation for -g
, which appears first in the section.特别是, -g2
的文档是-g
的文档,它首先出现在本节中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.