Bug 13568 - GDB can trigger a SIGBUS putting a breakpoint on a source line removed by linker garbage collection
Summary: GDB can trigger a SIGBUS putting a breakpoint on a source line removed by lin...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: breakpoints (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 7.5
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-06 15:59 UTC by Nick Clifton
Modified: 2012-01-30 20:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Executable to demonstrate the problem (4.22 KB, application/octet-stream)
2012-01-26 09:56 UTC, Nick Clifton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Clifton 2012-01-06 15:59:34 UTC
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
Comment 1 Nick Clifton 2012-01-06 17:22:07 UTC
FYI I have created a Binutils PR for this issue as well:

http://sourceware.org/bugzilla/show_bug.cgi?id=13569
Comment 2 Tom Tromey 2012-01-25 17:44:35 UTC
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
Comment 3 Nick Clifton 2012-01-26 09:56:29 UTC
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)
Comment 4 Tom Tromey 2012-01-26 14:56:10 UTC
Thanks.
Comment 5 Tom Tromey 2012-01-26 15:27:59 UTC
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
Comment 6 Sourceware Commits 2012-01-30 20:10:40 UTC
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
Comment 7 Tom Tromey 2012-01-30 20:12:33 UTC
Fixed.