Here is the minimal test case exhibiting my trouble:
$ cat bug.cc #include <iostream> class c { public: c (); }; c::c () { int i = 42; std::cout << i << std::endl; } int main (int argc, char** argv) { c* C = new c; } I compile it with the following command: $ g++ -g -O0 bug.cc With g++ 3.* or 4.0.*, everything's fine: (gdb) start Breakpoint 1 at 0x4008d8: file /home/toomas/bug.cc, line 14. warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7fff193fd000 main (argc=1, argv=0x7fff19283c78) at /home/toomas/bug.cc:14 14 c* C = new c; (gdb) s c (this=0x602010) at /home/toomas/bug.cc:7 7 int i = 42; (gdb) s 8 std::cout << i << std::endl; (gdb) p i $1 = 42 (gdb) info locals i = 42 But with version 4.1.0 and above, I cannot inspect local symbols in c::c(): (gdb) start Breakpoint 1 at 0x4008d8: file /home/toomas/bug.cc, line 14. warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff13fd000 main (argc=1, argv=0x7ffff1261c58) at /home/toomas/bug.cc:14 14 c* C = new c; (gdb) s c (this=0x602010) at /home/toomas/bug.cc:7 7 int i = 42; (gdb) s 8 std::cout << i << std::endl; (gdb) p i No symbol "i" in current context. (gdb) info locals No locals. At the same time, there is nothing wrong with the local symbols of main(). Experimenting with sources co'd from SVN (trunk), I found out that the last revision that behaves correctly is -r96653. There was one change in -r96654: 2005-03-18 Jan Hubicka <[EMAIL PROTECTED]> * cgraph.c (cgraph_remove_node): Avoid loop in code deciding whether function body should be released; do not proactively release function bodies in non-unit-at-a-time mode. Here I turned out to have arrived at the seat of the end of my wits. Output of `objdump -lSd' was exactly the same in both cases, but there were many differences in the `.debug_info' section. This seems not to be a hardware- or distribution-specific issue, because I have the same situation on two Debian systems and on a hand-crafted system, with both AMD64 and Pentium 4 hardware. (All of them GNU/Linux.) Thanks in advance, Toomas. Environment: System: Linux toomas 2.6.23.1 #1 SMP Sun Nov 4 13:54:34 EET 2007 x86_64 GNU/Linux host: x86_64-unknown-linux-gnu build: x86_64-unknown-linux-gnu target: x86_64-unknown-linux-gnu configured with: /INCOMING/misc/gcc-96654/configure --disable-multilib --disable-bootstrap --enable-languages=c,c++ How-To-Repeat: cat > bug.cc << EOF #include <iostream> class c { public: c (); }; c::c () { int i = 42; std::cout << i << std::endl; } int main (int argc, char** argv) { c* C = new c; } EOF g++ -g -O0 bug.cc { echo start; echo s; echo s; echo info locals; } | gdb --batch -x - ./a.out -- Summary: trouble debugging C++ programs: info locals => No locals. Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: toomas at rosin dot pri dot ee GCC build triplet: x86_64-unknown-linux-gnu GCC host triplet: x86_64-unknown-linux-gnu GCC target triplet: x86_64-unknown-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34767