[Bug debug/39485] New: -O0 -g still puts whole object to a register

jan dot kratochvil at redhat dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 17 23:33:00 GMT 2009


A regression from 4.3 for GNU C++ 4.4.0 20090317 (experimental)
-PASS: gdb.cp/classes.exp: calling method for small class
+XFAIL: gdb.cp/classes.exp: calling method for small class (PRMS 2972)
-------------------------------------------------------------------------------
Breakpoint 1, main () at small.C:36
36        return v.x + 5;       /* break-here */
(gdb) p v.method()
Address requested for identifier "v" which is in register $rbx
-------------------------------------------------------------------------------
from gcc-4.3:
(gdb) p v.method()
$1 = 82
-------------------------------------------------------------------------------
/* from gdb.cp/classes.cc */

/* Try to get the compiler to allocate a class in a register.  */
class small {
 public:
  int x;
  int method ();
};

int
small::method ()
{
  return x + 5;
}

void marker_reg1 () {}

int
main ()
{
  /* We don't call any methods for v, so gcc version cygnus-2.3.3-930220
     might put this variable in a register.  This is a lose, though, because
     it means that GDB can't call any methods for that variable.  */
  register small v;

  int i;

  /* Perform a computation sufficiently complicated that optimizing compilers
     won't optimized out the variable.  If some compiler constant-folds this
     whole loop, maybe using a parameter to this function here would help.  */
  v.x = 0;
  for (i = 0; i < 13; ++i)
    v.x += i;
  --v.x; /* v.x is now 77 */
  marker_reg1 ();
  return v.x + 5;       /* break-here */
}
-------------------------------------------------------------------------------
    < c>   DW_AT_producer    : (indirect string, offset: 0x19): GNU C++ 4.4.0
20090317 (experimental)
 <3><ed>: Abbrev Number: 14 (DW_TAG_variable)
    <ee>   DW_AT_name        : v
    <f2>   DW_AT_type        : <0x2d>
    <f6>   DW_AT_location    : 1 byte block: 53         (DW_OP_reg3)

Formerly the class was left in memory:
    < c>   DW_AT_producer    : (indirect string, offset: 0x31): GNU C++ 4.3.2
20081105 (Red Hat 4.3.2-7)
 <2><dc>: Abbrev Number: 13 (DW_TAG_variable)
    <dd>   DW_AT_name        : v        
    <e1>   DW_AT_type        : <0x2d>   
    <e5>   DW_AT_location    : 2 byte block: 76 6c      (DW_OP_breg6: -20)

Moreover small::method() expects the object to be in memory so GDB cannot just
pass it in the %ebx register as is:
    < c>   DW_AT_producer    : (indirect string, offset: 0x19): GNU C++ 4.4.0
20090317 (experimental)
 <2><45>: Abbrev Number: 4 (DW_TAG_subprogram)
    <46>   DW_AT_external    : 1
    <47>   DW_AT_name        : (indirect string, offset: 0xc): method
    <51>   DW_AT_type        : <0x5e>
    <55>   DW_AT_declaration : 1
 <3><56>: Abbrev Number: 5 (DW_TAG_formal_parameter)
    <57>   DW_AT_type        : <0x65>
    <5b>   DW_AT_artificial  : 1
 <1><6b>: Abbrev Number: 8 (DW_TAG_subprogram)
    <6c>   DW_AT_specification: <0x45>
    <81>   DW_AT_frame_base  : 0x0      (location list)
 <2><89>: Abbrev Number: 9 (DW_TAG_formal_parameter)
    <8a>   DW_AT_name        : (indirect string, offset: 0x52): this
    <8e>   DW_AT_type        : <0x97>
    <92>   DW_AT_artificial  : 1
    <93>   DW_AT_location    : 2 byte block: 91 68      (DW_OP_fbreg: -24)

GDB could probably use a (trivial=memcpy in this case) copy constructor (+later
destructor) from %ebx to a memory location.


-- 
           Summary: -O0 -g still puts whole object to a register
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: debug
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jan dot kratochvil at redhat dot com
GCC target triplet: x86_64-unknown-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39485



More information about the Gcc-bugs mailing list