GCC -g 与 -g3 GDB 标志:有什么区别? [英] GCC -g vs -g3 GDB Flag: What is the Difference?
问题描述
在使用 gcc 或 Clang 编译 C 源代码时,我总是使用 -g
标志为 gdb 生成调试信息.
gcc -g -o helloworld helloworld.c
我注意到有些人推荐-g3
.-g
和 -g3
标志之间有什么区别?-g
和-ggdb
还有区别吗?
来自 文档:
<块引用>-g
以操作系统的本机格式(stabs、COFF、XCOFF 或 DWARF 2)生成调试信息.GDB 可以使用它调试信息.在大多数使用 stabs 格式的系统上,-g允许使用只有 GDB 可以使用的额外调试信息;这额外的信息使调试在 GDB 中工作得更好,但可能使其他调试器崩溃或拒绝读取程序.如果你想要确定是否生成额外信息,请使用-gstabs+、-gstabs、-gxcoff+、-gxcoff 或 -gvms(见下文).
...
<块引用>
-ggdb
生成供 GDB 使用的调试信息.这意味着使用最具表现力的可用格式(DWARF 2、stabs 或本机格式,如果这些都不支持),包括 GDB 扩展,如果完全有可能.
<块引用>
-gvms级别
请求调试信息,也使用 level 来指定多少信息.默认级别为 2.级别 0 不生成调试信息.因此,-g0 否定 -g.
....
第 3 级包括额外信息,例如所有宏定义出现在节目中.一些调试器支持宏扩展你使用 -g3.
When compiling C source code with either gcc or Clang, I always use the -g
flag to generate debugging information for 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
?
From the docs:
-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).
...
-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.
-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.
....
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3.
这篇关于GCC -g 与 -g3 GDB 标志:有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!