https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94875

            Bug ID: 94875
           Summary: -fdebug-types-section drops DW_AT_object_pointer
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

Consider the test-case consisting of gdb.cp/derivation.cc and
gdb.cp/derivation2.cc (
https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=gdb/testsuite/gdb.cp/derivation.cc;hb=HEAD
and
https://sourceware.org/git/?p=binutils-gdb.git;a=blob_plain;f=gdb/testsuite/gdb.cp/derivation2.cc;hb=HEAD
).

Without -fdebug-types-section:
...
$ g++ derivation.cc derivation2.cc -g
...
we have:
...
 <0><d2>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <d8>   DW_AT_name        : derivation.cc
 <1><161>: Abbrev Number: 11 (DW_TAG_class_type)
    <162>   DW_AT_name        : A
    <164>   DW_AT_byte_size   : 8
    <165>   DW_AT_decl_file   : 1
    <166>   DW_AT_decl_line   : 33
    <167>   DW_AT_sibling     : <0x1df>
 <2><16b>: Abbrev Number: 12 (DW_TAG_typedef)
    <16c>   DW_AT_name        : value_type
    <170>   DW_AT_decl_file   : 1
    <171>   DW_AT_decl_line   : 35
    <172>   DW_AT_type        : <0x14a>
    <176>   DW_AT_accessibility: 1      (public)
 <2><1a6>: Abbrev Number: 15 (DW_TAG_subprogram)
    <1a7>   DW_AT_external    : 1
    <1a7>   DW_AT_name        : afoo
    <1ab>   DW_AT_decl_file   : 1
    <1ac>   DW_AT_decl_line   : 44
    <1ad>   DW_AT_linkage_name: _ZN1A4afooEv
    <1b1>   DW_AT_type        : <0x16b>
    <1b5>   DW_AT_accessibility: 1      (public)
    <1b6>   DW_AT_declaration : 1
    <1b6>   DW_AT_object_pointer: <0x1be>
    <1ba>   DW_AT_sibling     : <0x1c4>
 <3><1be>: Abbrev Number: 7 (DW_TAG_formal_parameter)
    <1bf>   DW_AT_type        : <0x1df>
    <1c3>   DW_AT_artificial  : 1
 <1><d15>: Abbrev Number: 48 (DW_TAG_subprogram)
    <d16>   DW_AT_specification: <0x1a6>
    <d1a>   DW_AT_decl_line   : 198
    <d1b>   DW_AT_object_pointer: <0xd39>
    <d1f>   DW_AT_low_pc      : 0x400640
    <d27>   DW_AT_high_pc     : 0xf
    <d2f>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
    <d31>   DW_AT_object_pointer: <0xd39>
    <d35>   DW_AT_GNU_all_call_sites: 1
    <d35>   DW_AT_sibling     : <0xd46>
 <2><d39>: Abbrev Number: 47 (DW_TAG_formal_parameter)
    <d3a>   DW_AT_name        :  this
    <d3e>   DW_AT_type        : <0x1e5>
    <d42>   DW_AT_artificial  : 1
    <d42>   DW_AT_location    : 2 byte block: 91 68     (DW_OP_fbreg: -24)
...

OTOH with -fdebug-types-section:
...
$ g++ derivation.cc derivation2.cc -g -fdebug-types-section
...
we have:
...
.debug_info:
 <0><d2>: Abbrev Number: 41 (DW_TAG_compile_unit)
    <d8>   DW_AT_name        : derivation.cc
 <1><13e>: Abbrev Number: 45 (DW_TAG_class_type)
    <13f>   DW_AT_name        : A
    <141>   DW_AT_signature   : <0xccc>
    <145>   DW_AT_declaration : 1
    <145>   DW_AT_sibling     : <0x174>
 <2><153>: Abbrev Number: 47 (DW_TAG_subprogram)
    <154>   DW_AT_external    : 1
    <154>   DW_AT_name        : afoo
    <158>   DW_AT_decl_file   : 1
    <159>   DW_AT_decl_line   : 44
    <15a>   DW_AT_linkage_name: _ZN1A4afooEv
    <15e>   DW_AT_type        : <0xcdb>
    <162>   DW_AT_accessibility: 1      (public)
    <163>   DW_AT_declaration : 1
 <1><8fd>: Abbrev Number: 68 (DW_TAG_subprogram)
    <8fe>   DW_AT_specification: <0x153>
    <902>   DW_AT_decl_line   : 198
    <903>   DW_AT_object_pointer: <0x921>
    <907>   DW_AT_low_pc      : 0x400640
    <90f>   DW_AT_high_pc     : 0xf
    <917>   DW_AT_frame_base  : 1 byte block: 9c        (DW_OP_call_frame_cfa)
    <919>   DW_AT_object_pointer: <0x921>
    <91d>   DW_AT_GNU_all_call_sites: 1
    <91d>   DW_AT_sibling     : <0x92e>
 <2><921>: Abbrev Number: 67 (DW_TAG_formal_parameter)
    <922>   DW_AT_name        : (indirect string, offset: 0x63c): this
    <926>   DW_AT_type        : <0x17a>
    <92a>   DW_AT_artificial  : 1
    <92a>   DW_AT_location    : 2 byte block: 91 68     (DW_OP_fbreg: -24)
 <1><ccc>: Abbrev Number: 27 (DW_TAG_class_type)
    <ccd>   DW_AT_name        : A
    <ccf>   DW_AT_signature   : signature: 0xbb06cf12bfa5e351
    <cd7>   DW_AT_declaration : 1
    <cd7>   DW_AT_sibling     : <0xce8>
 <2><cdb>: Abbrev Number: 28 (DW_TAG_typedef)
    <cdc>   DW_AT_name        : (indirect string, offset: 0x515): value_type
    <ce0>   DW_AT_decl_file   : 1
    <ce1>   DW_AT_decl_line   : 35
    <ce2>   DW_AT_type        : <0xce8>
    <ce6>   DW_AT_accessibility: 1      (public)

.debug_types:
  Compilation Unit @ offset 0x94b:
   Signature:     0xbb06cf12bfa5e351
   Type Offset:   0x25 (0x94b + 0x25 == 0x970)
 <0><962>: Abbrev Number: 1 (DW_TAG_type_unit)
 <1><970>: Abbrev Number: 25 (DW_TAG_class_type)
    <971>   DW_AT_name        : A
    <973>   DW_AT_byte_size   : 8
    <974>   DW_AT_decl_file   : 1
    <975>   DW_AT_decl_line   : 33
    <976>   DW_AT_sibling     : <0x9ee>
 <2><97a>: Abbrev Number: 28 (DW_TAG_typedef)
    <97b>   DW_AT_name        : (indirect string, offset: 0x515): value_type
    <97f>   DW_AT_decl_file   : 1
    <980>   DW_AT_decl_line   : 35
    <981>   DW_AT_type        : <0x9ee>
    <985>   DW_AT_accessibility: 1      (public)
 <2><9b5>: Abbrev Number: 32 (DW_TAG_subprogram)
    <9b6>   DW_AT_external    : 1
    <9b6>   DW_AT_name        : (indirect string, offset: 0x26e): afoo
    <9ba>   DW_AT_decl_file   : 1
    <9bb>   DW_AT_decl_line   : 44
    <9bc>   DW_AT_linkage_name: (indirect string, offset: 0x37e): _ZN1A4afooEv
    <9c0>   DW_AT_type        : <0x97a>
    <9c4>   DW_AT_accessibility: 1      (public)
    <9c5>   DW_AT_declaration : 1
    <9c5>   DW_AT_object_pointer: <0x9cd>
    <9c9>   DW_AT_sibling     : <0x9d3>
 <3><9cd>: Abbrev Number: 6 (DW_TAG_formal_parameter)
    <9ce>   DW_AT_type        : <0x9f5> 
    <9d2>   DW_AT_artificial  : 1
...

The curious thing is that DIE 0x153 has no DW_AT_object_pointer.

Gdb normally ignores DIE 0x153, but I just tested a gdb fix that doesn't ignore
it (to fix another problem in gdb related to -fdebug-types-section,
https://sourceware.org/bugzilla/show_bug.cgi?id=25898) and got:
...
$ gdb -batch a.out \
    -ex "ptype A::value_type" \
    -ex "break marker1" \
    -ex r \
    -ex up \
    -ex "ptype/r a_instance"
type = int
Breakpoint 1 at 0x400723: file derivation.cc, line 271.

Breakpoint 1, marker1 () at derivation.cc:271
271     }
#1  0x00000000004007ae in main () at derivation.cc:287
287         marker1(); // marker1-returns-here
type = class A {
  public:
    A::value_type a;
    A::value_type aa;

    static A(void);
    static A::value_type afoo(void);
    static A::value_type foo(void);

    typedef int value_type;
}
...

GDB now prints afoo as static, because of the missing DW_AT_object_pointer.

Reply via email to