This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix DW_AT_frame_base with -fdwarf2-cfi-asm


On Tue, Jun 2, 2009 at 7:31 AM, Paul Pluzhnikov <ppluzhnikov@google.com> wrote:

> Gcc built with that change (@148069) and tested with GDB CVS Head is
> back to 523 unexpected failures. I'll try to figure out why that
> number is still so high.

I believe majority of the failures are explained by incorrect DW_AT_location
for local pointer variables. Test case:

--- cut ---
struct foo { int x; int y; };

int main()
{
  int *px;
  int x;

  struct foo *pfoo;
  struct foo foo_struct;

  px = &x;
  *px = 42;

  pfoo = &foo_struct;
  pfoo->x = 24;
  pfoo->y = 25;

  return 0;
}
--- cut ---

This compiles into (annotated):

t.o:     file format elf64-x86-64

Disassembly of section .text:

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   48 8d 45 e4             lea    -0x1c(%rbp),%rax   # &x == %rbp-28
   8:   48 89 45 f8             mov    %rax,-0x8(%rbp)    # &px == %rbp-8
   c:   48 8b 45 f8             mov    -0x8(%rbp),%rax
  10:   c7 00 2a 00 00 00       movl   $0x2a,(%rax)
  16:   48 8d 45 d0             lea    -0x30(%rbp),%rax   #
&foo_struct = %rbp-48
  1a:   48 89 45 f0             mov    %rax,-0x10(%rbp)   # &pfoo == %rbp-16
  1e:   48 8b 45 f0             mov    -0x10(%rbp),%rax
  22:   c7 00 18 00 00 00       movl   $0x18,(%rax)
  28:   48 8b 45 f0             mov    -0x10(%rbp),%rax
  2c:   c7 40 04 19 00 00 00    movl   $0x19,0x4(%rax)
  33:   b8 00 00 00 00          mov    $0x0,%eax
  38:   c9                      leaveq
  39:   c3                      retq

But readelf says:

Contents of the .debug_loc section:

    Offset   Begin    End      Expression
    00000000 00000000 00000001 (DW_OP_breg7: 8)
    00000000 00000001 00000004 (DW_OP_breg7: 16)
    00000000 00000004 00000039 (DW_OP_breg6: 16)
    00000000 00000039 0000003a (DW_OP_breg7: 8)
    00000000 <End of list>

And

 <2><7d>: Abbrev Number: 6 (DW_TAG_variable)
    <7e>   DW_AT_name        : px
    <81>   DW_AT_decl_file   : 1
    <82>   DW_AT_decl_line   : 5
    <83>   DW_AT_type        : <0xb3>
    <87>   DW_AT_location    : 2 byte block: 91 58      (DW_OP_fbreg: -40)
 <2><8a>: Abbrev Number: 6 (DW_TAG_variable)
    <8b>   DW_AT_name        : x
    <8d>   DW_AT_decl_file   : 1
    <8e>   DW_AT_decl_line   : 6
    <8f>   DW_AT_type        : <0x52>
    <93>   DW_AT_location    : 2 byte block: 91 54      (DW_OP_fbreg: -44)
 <2><96>: Abbrev Number: 7 (DW_TAG_variable)
    <97>   DW_AT_name        : (indirect string, offset: 0x34): pfoo
    <9b>   DW_AT_decl_file   : 1
    <9c>   DW_AT_decl_line   : 8
    <9d>   DW_AT_type        : <0xb9>
    <a1>   DW_AT_location    : 2 byte block: 91 48      (DW_OP_fbreg: -56)
 <2><a4>: Abbrev Number: 7 (DW_TAG_variable)
    <a5>   DW_AT_name        : (indirect string, offset: 0x0): foo_struct
    <a9>   DW_AT_decl_file   : 1
    <aa>   DW_AT_decl_line   : 9
    <ab>   DW_AT_type        : <0x2d>
    <af>   DW_AT_location    : 2 byte block: 91 40      (DW_OP_fbreg: -64)


So addresses of 'x' and 'foo_struct' are correct, but addresses of 'px'
and 'pfoo' are way off.

This is a regression from gcc-4.4.0; no clue when it was introduced.

Thanks,
-- 
Paul Pluzhnikov


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]