This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
Re: c++/1141: cannot print local variables in (some) constructor functions
- From: Daniel Jacobowitz <drow at mvista dot com>
- To: nobody at sources dot redhat dot com
- Cc: gdb-prs at sources dot redhat dot com,
- Date: 13 Mar 2003 17:18:01 -0000
- Subject: Re: c++/1141: cannot print local variables in (some) constructor functions
- Reply-to: Daniel Jacobowitz <drow at mvista dot com>
The following reply was made to PR c++/1141; it has been noted by GNATS.
From: Daniel Jacobowitz <drow at mvista dot com>
To: germain at cs dot utah dot edu
Cc: gdb-gnats at sources dot redhat dot com, gcc-bugs at gcc dot gnu dot org
Subject: Re: c++/1141: cannot print local variables in (some) constructor functions
Date: Thu, 13 Mar 2003 12:12:16 -0500
On Thu, Mar 13, 2003 at 04:42:00PM -0000, germain at cs dot utah dot edu wrote:
>
> >Number: 1141
> >Category: c++
> >Synopsis: cannot print local variables in (some) constructor functions
> >Confidential: no
> >Severity: serious
> >Priority: high
> >Responsible: unassigned
> >State: open
> >Class: change-request
> >Submitter-Id: net
> >Arrival-Date: Thu Mar 13 16:48:00 UTC 2003
> >Closed-Date:
> >Last-Modified:
> >Originator: germain at cs dot utah dot edu
> >Release: gdb 5.3 (gcc 3.2.(1 or 2))
> >Organization:
> >Environment:
> Linux juggler 2.4.18-17.7.xsmp #1 SMP Tue Oct 8 12:37:04 EDT 2002 i686 unknown
> >Description:
> I'm having a problem with the gdb (5.3) debugger being able to
> tell me the value of local variables in a class function.
> I'm compiling with g++ 3.2.1.
>
> Here is the code:
>
> class ABC
> {
> public:
> ABC(double x);
> ABC(int x)
> {
> int temp = x;
> x_ = temp;
> }
> int x_;
> };
>
> ABC::ABC(double x)
> {
> double temp = x;
> x_ = temp;
> }
>
> int main(int argc, char* argv[])
> {
> ABC abc(1.0);
> ABC def(1);
> }
>
>
>
> % g++ -g test.cpp -o test
>
>
> the problem is that when i step into the constructor taking a double,
> I cannot print the temp variable ("No symbol "temp" in current
> context." When i step into the int (inlined) constructor, I can print
> the temp variable.
>
>
> (gdb) break main
> (gdb) run
> Starting program: /home/germain/PETE/jim
> Breakpoint 1, main (argc=1, argv=0xbffff514) at test.cpp:24
> (gdb) s
> ABC (this=0xbffff4a4, x=1) at test.cpp:18
> (gdb) p temp
> No symbol "temp" in current context.
> (gdb) fin
> Run till exit from #0 ABC (this=0xbffff4a4, x=1) at test.cpp:18
> main (argc=1, argv=0xbffff514) at test.cpp:25
> (gdb) s
> ABC (this=0xbffff4a0, x=1) at test.cpp:10
> (gdb) p temp
> $1 = 1072693248
> (gdb)
>
> I do not think this is a case of the compiler optimizing the
> variable away, (no optimization flags are used...) and if it
> is, then it shouldn't be (IMO).
>
> any help would be appreciated
Thanks for the great bug report. Unfortunately, this is a GCC bug
rather than a GDB bug. Here's the affected debug info. First, for one
copy of the constructor:
<1><f3>: Abbrev Number: 20 (DW_TAG_subprogram)
DW_AT_sibling : <129>
DW_AT_abstract_origin: <c2>
DW_AT_low_pc : 0x80483d0 134513616
DW_AT_high_pc : 0x8048401 134513665
DW_AT_frame_base : 1 byte block: 55 (DW_OP_reg5; )
<2><106>: Abbrev Number: 21 (DW_TAG_formal_parameter)
DW_AT_abstract_origin: <cd>
DW_AT_location : 2 byte block: 91 8 (DW_OP_fbreg: 8; )
<2><10e>: Abbrev Number: 21 (DW_TAG_formal_parameter)
DW_AT_abstract_origin: <d7>
DW_AT_location : 2 byte block: 91 78 (DW_OP_fbreg: -8; )
<2><116>: Abbrev Number: 22 (DW_TAG_lexical_block)
DW_AT_low_pc : 0x80483dc 134513628
DW_AT_high_pc : 0x8048401 134513665
<3><11f>: Abbrev Number: 23 (DW_TAG_variable)
DW_AT_abstract_origin: <e1>
DW_AT_location : 2 byte block: 91 70 (DW_OP_fbreg: -16; )
Then for the other, the one you're actually using:
<1><129>: Abbrev Number: 20 (DW_TAG_subprogram)
DW_AT_sibling : <15c>
DW_AT_abstract_origin: <c2>
DW_AT_low_pc : 0x8048402 134513666
DW_AT_high_pc : 0x8048433 134513715
DW_AT_frame_base : 1 byte block: 55 (DW_OP_reg5; )
<2><13c>: Abbrev Number: 21 (DW_TAG_formal_parameter)
DW_AT_abstract_origin: <cd>
DW_AT_location : 2 byte block: 91 8 (DW_OP_fbreg: 8; )
<2><144>: Abbrev Number: 21 (DW_TAG_formal_parameter)
DW_AT_abstract_origin: <d7>
DW_AT_location : 2 byte block: 91 78 (DW_OP_fbreg: -8; )
<2><14c>: Abbrev Number: 22 (DW_TAG_lexical_block)
DW_AT_low_pc : 0x804840e 134513678
DW_AT_high_pc : 0x8048433 134513715
<3><155>: Abbrev Number: 24 (DW_TAG_variable)
DW_AT_abstract_origin: <e1>
Note that the last DW_TAG_variable is missing a DW_AT_location.
Without that GDB can't find the variable. I've reproduced this in both
GCC 3.2 and GCC 3.4; someone on the GCC side will have to look at it.
--
Daniel Jacobowitz
MontaVista Software Debian GNU/Linux Developer