Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging with gdb on a program with no optimization but still there is no symbol in the current context for local variables

People also ask

What are debugging symbols in GDB?

A Debugging Symbol Table maps instructions in the compiled binary program to their corresponding variable, function, or line in the source code. This mapping could be something like: Program instruction ⇒ item name, item type, original file, line number defined.

What compiler option is needed to enable debugging for a program using GDB?

Basic Usage. All program to be debugged in gdb must be compiled by gcc with the option "-g" turning on.

How does GDB debugger works?

How GDB Debugs? GDB allows you to do things like run the program up to a certain point then stop and print out the values of certain variables at that point, or step through the program one line at a time and print out the values of each variable after executing each line. GDB uses a simple command line interface.


As noted in the release notes for GCC 4.8 (i.e. current trunk):

DWARF4 is now the default when generating DWARF debug information. When -g is used on a platform that uses DWARF debugging information, GCC will now default to -gdwarf-4 -fno-debug-types-section. GDB 7.5, Valgrind 3.8.0 and elfutils 0.154 debug information consumers support DWARF4 by default. Before GCC 4.8 the default version used was DWARF2. To make GCC 4.8 generate an older DWARF version use -g together with -gdwarf-2 or -gdwarf-3. The default for Darwin and VxWorks is still -gdwarf-2 -gstrict-dwarf.

So you need to use GDB 7.5 or compile with -g -gdwarf-2


No, even with --quiet it works for me. Maybe there's something wrong with your setup.

~/tmp $ g++ -Wall tmp.cpp -o tmp -O0 -ggdb3
~/tmp $ gdb --quiet --args ./tmp string
Reading symbols from /xxxxxxxx/tmp...done.
(gdb) b 12
Breakpoint 1 at 0x400c95: file tmp.cpp, line 12.
(gdb) run
Starting program: /xxxxxxxx/tmp string
Breakpoint 1, main (argc=2, argv=0x7fffffffdc58) at tmp.cpp:12
12        std::reverse(str.begin(), str.end());
(gdb) print str
$1 = "string"
(gdb) info locals
str = "string"
(gdb)