gcc -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.

-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 will probably make 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 were already
at hand; some statements may execute in different places because
they were moved out of loops.


Nevertheless it proves possible to debug optimized output. This
makes it reasonable to use the optimizer for programs that might
have bugs.



电子邮件地址不会被公开。 必填项已用*标注