Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc: what's the difference between "-g" and "-ggdb"?

I am working under linux, it seems to me that the effect of "-g" and "-ggdb" are no much difference. I only find using "-ggdb" will generate binary several bytes bigger.

So what's the core difference that gdb should have one "-g" option and another "-ggdb" option?

like image 982
Hind Forsum Avatar asked Mar 10 '23 20:03

Hind Forsum


2 Answers

The compiled program should be stored at some where, for the debuggers (GDB here) to look into it and follow.

This is technically called as "Debugging data format".

Some universaslly accepted debugging data formats are (there are some more):

COFF - Common Object File Format - on UNIX like systems.

PE/COFF - Portable Executable - pretty famous on windows, usually dotnet uses it.

DWARF - popular on UNIX like systems.

etc..

The GDB options you asked in your question are related to generating these debugging data formats.

Based on documenation the funcdamental difference is: option "g" provides the debugging data in particular system's native format. option "-ggdb" is bit rich and expensive. provides the debugging data in most expressive format available.

like image 179
Pavan Chandaka Avatar answered Mar 15 '23 23:03

Pavan Chandaka


I recommend you to read this documentation, and this topic.

like image 43
Lucas Avatar answered Mar 16 '23 00:03

Lucas