If GDB is asked to place a breakpoint on a line of source code that has been removed from the executable via linker garbage collection it can trigger a SIGBUS fault. Vis: % cat a.c int main() { return 0; } int fun () { return 0; } % gcc -g3 -ffunction-sections -Wl.--gc-sections a.c % gdb -nw a.out (gdb) break a.c:6 Bus error (core dumped) This problem can be reproduced using the current (2012-01-06) GDB mainline sources. Note however that it needs a 4.6 or earlier version of GCC as the compiler. Newer GCCs create a .debug_loc section in the executable which appears to avoid this problem. The underlying issue is that the linker has not removed the redundant entries from the .debug_line section, and hence this is a binutils bug. On the other hand it would be nice if GDB did not generate a SIGBUS when presented with bogus debug information. Detection of this problem originated from a thread in the binutils mailing list that starts here: http://sourceware.org/ml/binutils/2012-01/msg00047.html
FYI I have created a Binutils PR for this issue as well: http://sourceware.org/bugzilla/show_bug.cgi?id=13569
I couldn't reproduce with gcc 4.5 and CVS head gdb; see appended transcript. If it still fails for you, could you attach an executable? That might help. barimba. gcc --version gcc (GCC) 4.5.1 20100430 (prerelease) [gcc-4_5-branch revision 158946] Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. barimba. gcc -g3 -ffunction-sections -Wl,--gc-sections a.c -o prbarimba. ~/gnu/baseline-gdb/build/gdb/gdb -nw ./pr GNU gdb (GDB) 7.4.50.20120125-cvs Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-unknown-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/tromey/gnu/PRS/gdb13568/pr...done. (gdb) b a.c:6 No line 6 in file "a.c". Make breakpoint pending on future shared library load? (y or [n]) n
Created attachment 6177 [details] Executable to demonstrate the problem % gdb -nw a.bad GNU gdb (GDB) 7.4.50.20120126-cvs Copyright (C) 2012 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /media/Devo/current/i686-pc-linux-gnu/tests/a.bad...done. (gdb) break a.c:6 Bus error (core dumped)
Thanks.
The bug is that there is a recursive include in the .debug_macro section. This causes gdb to overrun the stack. I'm testing a fix. Contents of the .debug_macro section: Offset: 0x0 Version: 4 Offset size: 4 Offset into .debug_line: 0x0 DW_MACRO_GNU_transparent_include - offset : 0x0 DW_MACRO_GNU_start_file - lineno: 0 filenum: 1 filename: a.c DW_MACRO_GNU_end_file
CVSROOT: /cvs/src Module name: src Changes by: tromey@sourceware.org 2012-01-30 20:10:33 Modified files: gdb : ChangeLog dwarf2read.c Log message: PR breakpoints/13568: * dwarf2read.c (dwarf_decode_macro_bytes): Add 'include_hash' argument. Check for recursive includes. (dwarf_decode_macros): Create an include hash. Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.13789&r2=1.13790 http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2read.c.diff?cvsroot=src&r1=1.610&r2=1.611
Fixed.