cdebugging

when are debug symbols included


In which phase of compilation process are the debug symbols actually generated.

If I compile a object file with -g option, than does it makes imperative that whatever object file may be built into (shared lib, static lib, executable), the output will always have debug symbols in it ? if don't specify the -g during linking, will the output binary will have debug symbols or not ?


Solution

    1. Every relocatable object file has a symbol table in .symtab section, which includes the information about functions and global variables that are defined and referenced in the program. However, unlike the symbol table insider a compiler, the .symtab symbol table does not contain entries for local variables.
    2. -g enables use of extra debugging information, e.g. line number. As David pointed out, the default behavior depends on compiler and platforms.
    3. You can refer to this page for more detail.