Bug 14999 - Clang debug info crashes GDB when trying to collect local variables in a trace
Summary: Clang debug info crashes GDB when trying to collect local variables in a trace
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 7.5
: P2 normal
Target Milestone: 7.6
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-07 01:50 UTC by David Blaikie
Modified: 2013-01-18 18:37 UTC (History)
1 user (show)

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


Attachments
x86 assembly for trace.c from Clang (1.64 KB, application/octet-stream)
2013-01-07 19:36 UTC, David Blaikie
Details
x86 assembly for trace.c from Clang with frame pointers (1.61 KB, application/octet-stream)
2013-01-08 03:16 UTC, David Blaikie
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Blaikie 2013-01-07 01:50:34 UTC
Using Clang ToT (I believe this would easily reproduce with the recently released 3.2 as well, perhaps with older versions too) to compile the following program:

  int func(int p) {
    int x = p + 3;
    return x;
  }

  int main() { return func(3); }

Then loading that into GDB (7.5) & executing the following:

  trace 3
  actions
  collect x
  end

At the "collect" point (reproduces when using "collect q" instead) GDB has the following error:

  ../../gdb-7.5.x/gdb/tracepoint.c:665: internal-error: expression has min height < 0
  A problem internal to GDB has been detected,
  further debugging may prove unreliable.

It'd be nice if GDB didn't fail. Beyond that, there's nothing in Clang's debug info that seems unreasonable for this, but evidently there's /some/ difference between GCC 4.7 and Clang's output here because GCC's output works just fine. Perhaps the location information is broken in some way. (advice on that would be appreciated, though not required - this bug is merely about the internal error)
Comment 1 Tom Tromey 2013-01-07 15:32:17 UTC
Could you attach the executable?
That would help.
Comment 2 David Blaikie 2013-01-07 19:36:14 UTC
Created attachment 6799 [details]
x86 assembly for trace.c from Clang

x86 assembly for trace.c, you can use gcc to assemble this if you like (ie: Clang is not required):

gcc-4.7 trace.s && gdb a.out < script

(where script is the commands mentioned in the initial bug description)
Comment 3 Tom Tromey 2013-01-07 20:29:29 UTC
The bug is that we don't require_rvalue after computing the
frame base.
Testing a patch.
Comment 4 David Blaikie 2013-01-08 03:16:11 UTC
Created attachment 6801 [details]
x86 assembly for trace.c from Clang with frame pointers

Since you mentioned something about frames, that reminded me that Clang does tend to be a bit conservative about frame pointers - so I thought I should mention/demonstrate (in case it's relevant) that this bug does still reproduce when I force Clang to emit frame pointers.
Comment 5 Tom Tromey 2013-01-08 04:26:54 UTC
(In reply to comment #4)
> Created attachment 6801 [details]
> x86 assembly for trace.c from Clang with frame pointers
> 
> Since you mentioned something about frames, that reminded me that Clang does
> tend to be a bit conservative about frame pointers - so I thought I should
> mention/demonstrate (in case it's relevant) that this bug does still reproduce
> when I force Clang to emit frame pointers.

It isn't about frame pointers but about the DW_AT_frame_base.
GCC usually uses DW_OP_call_frame_cfa.
clang is emitting

    <41>   DW_AT_frame_base  : 1 byte block: 56 	(DW_OP_reg6 (rbp))

The DWARF->AX translator was mishandling this -- just an oversight there.
I have a patch, and it works; I just need to turn the .s into
a test case.
Comment 6 Sourceware Commits 2013-01-18 18:32:42 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	tromey@sourceware.org	2013-01-18 18:32:35

Modified files:
	gdb            : ChangeLog dwarf2loc.c 
	gdb/testsuite  : ChangeLog 
Added files:
	gdb/testsuite/gdb.dwarf2: trace-crash.S trace-crash.exp 

Log message:
	PR c++/14999:
	* dwarf2loc.c (dwarf2_compile_expr_to_ax) <DW_OP_fbreg>:
	Call require_rvalue.
	gdb/testsuite
	* gdb.dwarf2/trace-crash.s: New file.
	* gdb.dwarf2/trace-crash.exp: New file.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/ChangeLog.diff?cvsroot=src&r1=1.15035&r2=1.15036
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/dwarf2loc.c.diff?cvsroot=src&r1=1.160&r2=1.161
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/ChangeLog.diff?cvsroot=src&r1=1.3518&r2=1.3519
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.dwarf2/trace-crash.S.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/gdb/testsuite/gdb.dwarf2/trace-crash.exp.diff?cvsroot=src&r1=NONE&r2=1.1
Comment 7 Tom Tromey 2013-01-18 18:37:33 UTC
Fix checked in.