GCC -g vs - GDB标志:区别是什么?

时间:2020-12-27 16:40:11

When compiling C source code with either gcc or Clang, I always use the -g flag to generate debugging information for gdb.

在用gcc或Clang编译C源代码时,我总是使用-g标志来生成gdb的调试信息。

gcc -g -o helloworld helloworld.c

海湾合作委员会。

I noticed that some people recommend -g3 instead. What is the difference between the -g and -g3 flags? Also is there a difference between -g and -ggdb?

我注意到有些人推荐-g3。g和-g3标志的区别是什么?g和-ggdb之间也有区别吗?

2 个解决方案

#1


65  

From the docs:

从文档:

-g

- g

Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information. On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but probably makes other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below).

在操作系统的本机格式(stabs, COFF, XCOFF,或DWARF 2)中生成调试信息。GDB可以使用此调试信息。在大多数使用stabs格式的系统中,-g支持使用只有GDB才能使用的额外调试信息;这些额外的信息使调试工作在GDB中更好,但可能会使其他调试器崩溃或拒绝读取程序。如果您想要控制是否生成额外的信息,请使用-gstabs+、-gstabs、-gxcoff+、-gxcoff或-gvms(参见下面)。

...


-ggdb

- ggdb

Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible.

生成用于GDB的调试信息。这意味着使用最具表现力的格式(如果不支持的话,可以使用DWARF 2、stabs或本机格式),包括如果可能的话,包括GDB扩展。


-gvmslevel

-gvmslevel

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.

请求调试信息,并使用级别来指定信息的数量。默认的级别是2。0级不产生任何调试信息。因此,g0否定- g。

....

....

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

第3级包含额外的信息,例如程序中所有的宏定义。一些调试器在使用-g3时支持宏扩展。

#2


8  

tl;dr: To answer your specific question, -g3 "includes extra information such as macro definitions. Some debuggers support macro expansion when you use -g3", while -g does not.

要回答你的具体问题,-g3“包括一些额外的信息,如宏观定义。一些调试器支持在使用-g3时进行宏扩展,而-g则不支持。

The broader answer is that gcc supports four levels of debug information, from -g0 (debug information disabled) through -g3 (maximum debug information).

更广泛的答案是gcc支持4个级别的调试信息,从-g0(调试信息禁用)到-g3(最大调试信息)。

Specifying -g is equivalent to -g2. Curiously, the gcc docs say little about what information -g/-g2 includes or excludes.

指定-g等于-g2。奇怪的是,gcc的文档很少提到什么信息-g/-g2包含或排除。

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.

请求调试信息,并使用级别来指定信息的数量。默认的级别是2。0级不产生任何调试信息。因此,g0否定- 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.

第1级生成的信息非常少,足以在您不打算调试的程序的部分中进行回溯。这包括函数和外部变量的描述,以及行号表,但是没有关于局部变量的信息。

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

第3级包含额外的信息,例如程序中所有的宏定义。一些调试器在使用-g3时支持宏扩展。

#1


65  

From the docs:

从文档:

-g

- g

Produce debugging information in the operating system's native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information. On most systems that use stabs format, -g enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but probably makes other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below).

在操作系统的本机格式(stabs, COFF, XCOFF,或DWARF 2)中生成调试信息。GDB可以使用此调试信息。在大多数使用stabs格式的系统中,-g支持使用只有GDB才能使用的额外调试信息;这些额外的信息使调试工作在GDB中更好,但可能会使其他调试器崩溃或拒绝读取程序。如果您想要控制是否生成额外的信息,请使用-gstabs+、-gstabs、-gxcoff+、-gxcoff或-gvms(参见下面)。

...


-ggdb

- ggdb

Produce debugging information for use by GDB. This means to use the most expressive format available (DWARF 2, stabs, or the native format if neither of those are supported), including GDB extensions if at all possible.

生成用于GDB的调试信息。这意味着使用最具表现力的格式(如果不支持的话,可以使用DWARF 2、stabs或本机格式),包括如果可能的话,包括GDB扩展。


-gvmslevel

-gvmslevel

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.

请求调试信息,并使用级别来指定信息的数量。默认的级别是2。0级不产生任何调试信息。因此,g0否定- g。

....

....

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

第3级包含额外的信息,例如程序中所有的宏定义。一些调试器在使用-g3时支持宏扩展。

#2


8  

tl;dr: To answer your specific question, -g3 "includes extra information such as macro definitions. Some debuggers support macro expansion when you use -g3", while -g does not.

要回答你的具体问题,-g3“包括一些额外的信息,如宏观定义。一些调试器支持在使用-g3时进行宏扩展,而-g则不支持。

The broader answer is that gcc supports four levels of debug information, from -g0 (debug information disabled) through -g3 (maximum debug information).

更广泛的答案是gcc支持4个级别的调试信息,从-g0(调试信息禁用)到-g3(最大调试信息)。

Specifying -g is equivalent to -g2. Curiously, the gcc docs say little about what information -g/-g2 includes or excludes.

指定-g等于-g2。奇怪的是,gcc的文档很少提到什么信息-g/-g2包含或排除。

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.

请求调试信息,并使用级别来指定信息的数量。默认的级别是2。0级不产生任何调试信息。因此,g0否定- 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.

第1级生成的信息非常少,足以在您不打算调试的程序的部分中进行回溯。这包括函数和外部变量的描述,以及行号表,但是没有关于局部变量的信息。

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

第3级包含额外的信息,例如程序中所有的宏定义。一些调试器在使用-g3时支持宏扩展。