The difference between "original" gcc option-G and-GGDB

Source: Internet
Author: User
Tags dbx



Many people are not sure what the difference between the GCC compile option-G and-ggdb is, which is explained in terms of a post on StackOverflow and the contents of the relevant manual.

Debugging-options of GCCManual Description

- Gproduce debugging information in the operating system ' s native format (stabs, COFF, XCOFF, or DWARF 2). GDB can work with this debugging information.
the- g option produces debug information that conforms to the operating system's local format (stabs, COFF, XCOFF, or DWARF 2). GDB can work based on the debugging information here.
On The most systems the use stabs format,-G enables use of extra debugging information, the 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).
in most systems that use the stabs format, the-G option enables additional debugging information that only GDB can use, and this extra information can make GDB better debug, but may cause other debuggers to crash or refuse to parse the executable. If you want to control whether additional information is available, you can use-gstabs+,-gstabs,-gxcoff+,-gxcoff, or-gvms options.

GCC allows you to use-g with-o. The shortcuts taken by optimized code could occasionally produce surprising results:some variables you declared could not Exi St at all; Flow of control may briefly move where do not expect it; Some statements may is executed because they compute constant results or their values is already at hand; Some statements may execute in different places because they has been moved out of loops.
GCC allows you to use the-G and-o options at the same time. The code may produce surprising results after optimization: Some of the variables you declare may no longer exist; The control flow may go to a place you have never imagined; some statements may not be executed because the result is a constant, or the result is already obtained; some statements may be executed in different places. Because it was moved out of the current loop.

Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might has bugs.
In any case, it is possible to debug the optimized output. This is why the optimizer with Bugs is still being used.

The following options are useful when GCC is generated with the capability for more than one debugging format.


-ggdbproduce 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 is Suppo rted), including GDB extensions if at all possible.
-ggdb produces the debug information required by GDB. This means that the available, most expressive formats (DWARF 2, stabs, or other local formats that are not supported in the first two cases) will be used and, if possible, include GDB extension information.


-gstabs+
Produce debugging information in stabs format (if-is-supported), using GNU extensions understood only by the GNU Debu Gger (GDB). The use of these extensions are likely to make other debuggers crash or refuse to read the program.
generates debug information in the stabs format (if supported) and uses only the GNU debugger (GDB) to understandGNU extension. The use of these extensions may cause other debuggers to crash or refuse to read compiled executable programs.

-gstabs
produce debugging information in stabs format (if-is supported), without GDB extensions. This is the format used by DBX in most BSD systems. On MIPS, Alpha and System V Release 4 Systems The This option produces stabs debugging output the is isn't understood by DBX or SDB. On System V Release 4 Systems This option requires the GNU assembler.
generates debug information (if supported) in the stabs format, which does not include GDB extensions. For the DBX debugger.


-gxcoff
Produce debugging information in XCOFF format (if, is supported). This is the format used by the DBX debugger on IBM rs/6000 systems.
generate debug information in XCOFF format (if supported)for the DBX debugger.

-gxcoff+
produce debugging information in XCOFF format (if-is-supported), using GNU extensions understood by the GNU Debugger (GDB). The use of these extensions are likely to make other debuggers crash or refuse to read the program, and may cause assembler s other than the GNU assembler-to-fail with an error.
generate debug information in XCOFF format (if supported), and will use only the GNU debugger (GDB) to understandGNU extension. The use of these extensions may cause other debuggers to crash or refuse to read compiled executable programs, and may result in the addition of the GNU Assembler (gas)other than the execution of the assembler failed.

-gvms
produce debugging information in Alpha/vms Debug format (if it is supported). This is the format used by DEBUG on ALPHA/VMS systems.
generate debug information in ALPHA/VMS format (if supported) .



re:difference between-g,-ggdb and-ggdb3 Mailing list description

I was wondering what is 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-Level 2).

It's *possible* (I ' ve heard) that THE-GGDB can produce debugging information that canconfuse other debuggers if you is not using GDB.
Only the use of 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 don't use gdb ...
Use-g and keep in mind, the gdb works with the OS ' s native format too.

I use-g even though I use GDB exclusively if 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-be-executed on NON-GNU platforms). I had a portability issue regarding-g vs.-ggdb on the AIX machine recently, that's why I bring it up.
No idea on what-ggdb adds in usability, though.




The difference between "original" gcc option-G and-GGDB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.