求助:GCC编译选项加上
发布网友
发布时间:2022-04-26 21:30
我来回答
共2个回答
懂视网
时间:2022-04-30 13:09
帖子,以及相关手册上的内容进行解释说明。
Debugging-Options of GCC 手册说明
-g Produce debugging information in the operating system‘s native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information.
-g 选项可以产生符合操作系统本地格式的调试信息(stabs、COFF、XCOFF ,或者 DWARF 2)。GDB 可以基于这里调试信息进行工作。
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 格式的系统中,-g 选项会使能额外的、只有 GDB 能用的调试信息;这种额外信息能够令 GDB 更好的进行调试,但可能使得其他调试器发生崩溃,或者拒绝对可执行程序进行解析。如果你想要针对是否额外信息进行控制,可以使用 -gstabs+, -gstabs, -gxcoff+, -gxcoff, 或 -gvms 等选项。
GCC allows you to use -g with -O. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values are already at hand; some statements may execute in different places because they have been moved out of loops.
GCC 允许你同时使用 -g 和 -O 选项。代码在优化后可能会产生令人惊奇的结果:一些你声明的变量可能已经不存在了;控制流可能走到了你未曾想象到的位置;一些语句可能不会被执行,因为其计算结果是常量,或者其结果早已经被获得;一些语句可能在不同的地方被执行,因为其被移出了当前循环。
Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.
无论怎样,针对优化后的输出进行调试还是可能的。这也就是带 bug 的优化器仍旧被使用的背后原因。
The following options are useful when GCC is generated with the capability for more than one debugging format.
-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.
-ggdb 产生 GDB 所需的调试信息。这意味着将会使用可用的、最具表达力的格式(DWARF 2 、stabs ,或者在前两者不支持情况下的其他本地格式),如果可能的话还会包含 GDB 扩展信息。
-gstabs+
Produce debugging information in stabs format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program.
产生 stabs 格式的调试信息(如果支持的话),并且会使用只有 GNU 调试器(GDB)才理解的 GNU 扩展。这些扩展的使用可能会导致其他调试器崩溃或者拒绝读取编译出来的可执行程序。
-gstabs
Produce debugging information in stabs format (if that is supported), without GDB extensions. This is the format used by DBX on most BSD systems. On MIPS, Alpha and System V Release 4 systems this option produces stabs debugging output that is not understood by DBX or SDB. On System V Release 4 systems this option requires the GNU assembler.
产生 stabs 格式的调试信息(如果支持的话),其中不包含 GDB 扩展。用于 DBX 调试器。
-gxcoff
Produce debugging information in XCOFF format (if that is supported). This is the format used by the DBX debugger on IBM RS/6000 systems.
产生 XCOFF 格式的调试信息(如果支持的话),用于 DBX 调试器。
-gxcoff+
Produce debugging information in XCOFF format (if that is supported), using GNU extensions understood only by the GNU debugger (GDB). The use of these extensions is likely to make other debuggers crash or refuse to read the program, and may cause assemblers other than the GNU assembler (GAS) to fail with an error.
产生 XCOFF 格式的调试信息(如果支持的话),并且会使用只有 GNU 调试器(GDB)才理解的 GNU 扩展。这些扩展的使用可能会导致其他调试器崩溃或者拒绝读取编译出来的可执行程序,并且可能造成除 GNU 汇编器(GAS)以外的其他汇编器的执行失败。
-gvms
Produce debugging information in Alpha/VMS debug format (if that is supported). This is the format used by DEBUG on Alpha/VMS systems.
产生 Alpha/VMS 格式的调试信息(如果支持的话)。
Re: difference between -g, -ggdb and -ggdb3 邮件列表说明
I was wondering what the difference between -g, -ggdb and -ggdb3 as option for gcc?
-g produces debugging information in the OS1s 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).
It is *possible* (I‘ve heard) that the -ggdb can produce debugging information that can confuse other debuggers if you are not using gdb.
only use gdb, so I cannot confirm or refute that rumor.
So...
If you use gdb, use -ggdb (same as -ggdb2), or -ggdb1 (to help reduce the
debug footprint), or -ggdb3 (for additional debugging info).
If you do not use gdb...
Use -g and keep in mind that gdb works with the OS‘s native format too.
I use -g even though I use gdb exclusively when I use gcc/g++.
I could use -ggdb ... but I forget to type those extra three characters.
One thing is that "-g" is portable (e.g. in Makefiles destined to be executed on non-GNU platforms). I had a portability issue regarding -g vs. -ggdb on an AIX machine recently, that‘s why I bring it up.
No idea on what -ggdb adds in usability, though.
【原创】GCC选项-g和-ggdb的区别
标签:
热心网友
时间:2022-04-30 10:17
Debug选项:
在 gcc编译源代码时指定-g选项可以产生带有调试信息的目标代码,gcc可以为多个不同平台上帝不同调试器提供调试信息,默认gcc产生的调试信息是为 gdb使用的,可以使用-gformat 指定要生成的调试信息的格式以提供给其他平台的其他调试器使用.常用的格式有
-ggdb:生成gdb专 用的调试信息,使用最适合的格式(DWARF 2,stabs等)会有一些gdb专用的扩展,可能造成其他调试器无法运行.
-gstabs:使用 stabs格式,不包含gdb扩展,stabs常用于BSD系统的DBX调试器.
-gcoff:产生COFF格式的调试信息,常用于System V下的SDB调试器;
-gxcoff:产生XCOFF格式的调试信息,用于IBM的RS/6000下的DBX调试器;
-gdwarf- 2:产生DWARF version2 的格式的调试信息,常用于IRIXX6上的DBX调试器.GCC会使用DWARF version3的一些特性.
可 以指定调试信息的等级:在指定的调试格式后面加上等级:
如: -ggdb2 等,0代表不产生调试信息.在使用-gdwarf-2时因为最早的格式为-gdwarf2会造成混乱,所以要额外使用一个-glevel来指定调试信息的 等级,其他格式选项也可以另外指定等级.
gcc可以使用-p选项指定生成信息以供porf使用.