public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/11627] New: No access to automatic variables in constructors and destructors
@ 2010-05-24 13:47 thor at math dot tu-berlin dot de
  2010-05-24 14:58 ` [Bug c++/11627] " tromey at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: thor at math dot tu-berlin dot de @ 2010-05-24 13:47 UTC (permalink / raw)
  To: gdb-prs

gdb cannot access automatic ("local") variables in C++ constructors and
destructors. To reproduce, enter the following program:

class A {
  //
  int var;
public:
  A(int value);
  ~A(void);
  //
  int getVar()
  {
    return var;
  }
};

A::A(int value)
{
  int tmp = value;

  while(tmp & 1) {
    tmp += value;
    tmp >>= 1;
    value >>= 1;
  }

  var = value;
}

A::~A(void)
{
  int tmp = var;

  while(tmp > 0) {
    tmp--;
  }
}

int main(int argc,char **argv)
{
  int i;

  A a(42);

  return a.getVar();
}

compile with -O0 -ggdb3 with g++ 4.3.2 and start debugging with gdb. Set a
breakpoint at main, step into A::A. "print tmp" will only give you

No symbol "tmp" in current context.

which is clearly incorrect. Continue stepping through the program. When entering
the destructor, try the same again. Again "tmp" is not accessible.

Note that this is not because the compiler optimized the variable out, this can
be checked on the generated assembly source.

-- 
           Summary: No access to automatic variables in constructors and
                    destructors
           Product: gdb
           Version: 7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at sourceware dot org
        ReportedBy: thor at math dot tu-berlin dot de
                CC: gdb-prs at sourceware dot org
 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://sourceware.org/bugzilla/show_bug.cgi?id=11627

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/11627] No access to automatic variables in constructors and destructors
  2010-05-24 13:47 [Bug c++/11627] New: No access to automatic variables in constructors and destructors thor at math dot tu-berlin dot de
@ 2010-05-24 14:58 ` tromey at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: tromey at redhat dot com @ 2010-05-24 14:58 UTC (permalink / raw)
  To: gdb-prs


------- Additional Comments From tromey at redhat dot com  2010-05-24 14:58 -------
I think this is actually a compiler bug.
It works for me with gcc 4.4.1 and gdb 7.1.

See:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39961
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27574

You can verify using "readelf -wi" or some other dwarf dumper.
Search for tmp in the output.  I see:

 <3><e5>: Abbrev Number: 17 (DW_TAG_variable)
    <e6>   DW_AT_name        : tmp      
    <ea>   DW_AT_decl_file   : 1        
    <eb>   DW_AT_decl_line   : 16       
    <ec>   DW_AT_type        : <0x8f>   


*** This bug has been marked as a duplicate of 8246 ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |DUPLICATE


http://sourceware.org/bugzilla/show_bug.cgi?id=11627

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-24 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-24 13:47 [Bug c++/11627] New: No access to automatic variables in constructors and destructors thor at math dot tu-berlin dot de
2010-05-24 14:58 ` [Bug c++/11627] " tromey at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).