public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* DWARF for extern variable
@ 2021-08-23 21:17 Indu Bhagat
  2021-08-24  7:55 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Indu Bhagat @ 2021-08-23 21:17 UTC (permalink / raw)
  To: gcc-patches

Hello,

What is the expected DWARF for extern variable in the following cases? I 
am seeing that the DWARF generated is different with gcc8.4.1 vs gcc-trunk.

Testcase 1
----------
extern const char a[];

int foo()
{
   return a != 0;
}

Testcase 1 Behavior
---------------------
- gcc-trunk has _no_ DWARF for variable a.
- gcc8.4.1 generates following DW_TAG_variable for extern variable a. 
But does not designate it as a non-defining decl (IIUC, 
DW_AT_specification is used for such cases?).

<..>
  <1><31>: Abbrev Number: 2 (DW_TAG_array_type)
     <32>   DW_AT_type        : <0x48>
     <36>   DW_AT_sibling     : <0x3c>
  <2><3a>: Abbrev Number: 3 (DW_TAG_subrange_type)
  <2><3b>: Abbrev Number: 0
  <1><3c>: Abbrev Number: 4 (DW_TAG_const_type)
     <3d>   DW_AT_type        : <0x31>
  <1><41>: Abbrev Number: 5 (DW_TAG_base_type)
     <42>   DW_AT_byte_size   : 1
     <43>   DW_AT_encoding    : 6        (signed char)
     <44>   DW_AT_name        : (indirect string, offset: 0x1df6): char
  <1><48>: Abbrev Number: 4 (DW_TAG_const_type)
     <49>   DW_AT_type        : <0x41>
  <1><4d>: Abbrev Number: 6 (DW_TAG_variable)
     <4e>   DW_AT_name        : a
     <50>   DW_AT_decl_file   : 1
     <51>   DW_AT_decl_line   : 1
     <52>   DW_AT_decl_column : 19
     <53>   DW_AT_type        : <0x3c>
     <57>   DW_AT_external    : 1
     <57>   DW_AT_declaration : 1
<..>

-----------------------------------------------------------

Testcase 2
----------
extern const char a[];
const char a[] = "testme";

Testcase 2 Behavior
--------------------
- Both gcc-trunk and gcc8.4.1 generate two DW_TAG_variable DIEs (the 
defining decl holds the reference to the non-defining decl via 
DW_AT_specification)
- But gcc8.4.1 does not generate any DWARF for the type of the defining 
decl (const char[7]) but gcc-trunk does.

## DWARF for testcase 2 with gcc-trunk is as follows:
<...>
  <1><22>: Abbrev Number: 2 (DW_TAG_array_type)
     <23>   DW_AT_type        : <0x39>
     <27>   DW_AT_sibling     : <0x2d>
  <2><2b>: Abbrev Number: 5 (DW_TAG_subrange_type)
  <2><2c>: Abbrev Number: 0
  <1><2d>: Abbrev Number: 1 (DW_TAG_const_type)
     <2e>   DW_AT_type        : <0x22>
  <1><32>: Abbrev Number: 3 (DW_TAG_base_type)
     <33>   DW_AT_byte_size   : 1
     <34>   DW_AT_encoding    : 6        (signed char)
     <35>   DW_AT_name        : (indirect string, offset: 0x2035): char
  <1><39>: Abbrev Number: 1 (DW_TAG_const_type)
     <3a>   DW_AT_type        : <0x32>
  <1><3e>: Abbrev Number: 6 (DW_TAG_variable)
     <3f>   DW_AT_name        : a
     <41>   DW_AT_decl_file   : 1
     <42>   DW_AT_decl_line   : 1
     <43>   DW_AT_decl_column : 19
     <44>   DW_AT_type        : <0x2d>
     <48>   DW_AT_external    : 1
     <48>   DW_AT_declaration : 1
  <1><48>: Abbrev Number: 2 (DW_TAG_array_type)
     <49>   DW_AT_type        : <0x39>
     <4d>   DW_AT_sibling     : <0x58>
  <2><51>: Abbrev Number: 7 (DW_TAG_subrange_type)
     <52>   DW_AT_type        : <0x5d>
     <56>   DW_AT_upper_bound : 6
  <2><57>: Abbrev Number: 0
  <1><58>: Abbrev Number: 1 (DW_TAG_const_type)
     <59>   DW_AT_type        : <0x48>
  <1><5d>: Abbrev Number: 3 (DW_TAG_base_type)
     <5e>   DW_AT_byte_size   : 8
     <5f>   DW_AT_encoding    : 7        (unsigned)
     <60>   DW_AT_name        : (indirect string, offset: 0x2023): long 
unsigned int
  <1><64>: Abbrev Number: 8 (DW_TAG_variable)
     <65>   DW_AT_specification: <0x3e>
     <69>   DW_AT_decl_line   : 2
     <6a>   DW_AT_decl_column : 12
     <6b>   DW_AT_type        : <0x58>
     <6f>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0 
(DW_OP_addr: 0)
  <1><79>: Abbrev Number: 0

## DWARF for testcase 2 with gcc8.4.1 is as follows:
  <1><21>: Abbrev Number: 2 (DW_TAG_array_type)
     <22>   DW_AT_type        : <0x38>
     <26>   DW_AT_sibling     : <0x2c>
  <2><2a>: Abbrev Number: 3 (DW_TAG_subrange_type)
  <2><2b>: Abbrev Number: 0
  <1><2c>: Abbrev Number: 4 (DW_TAG_const_type)
     <2d>   DW_AT_type        : <0x21>
  <1><31>: Abbrev Number: 5 (DW_TAG_base_type)
     <32>   DW_AT_byte_size   : 1
     <33>   DW_AT_encoding    : 6        (signed char)
     <34>   DW_AT_name        : (indirect string, offset: 0x1e04): char
  <1><38>: Abbrev Number: 4 (DW_TAG_const_type)
     <39>   DW_AT_type        : <0x31>
  <1><3d>: Abbrev Number: 6 (DW_TAG_variable)
     <3e>   DW_AT_name        : a
     <40>   DW_AT_decl_file   : 1
     <41>   DW_AT_decl_line   : 1
     <42>   DW_AT_decl_column : 19
     <43>   DW_AT_type        : <0x2c>
     <47>   DW_AT_external    : 1
     <47>   DW_AT_declaration : 1
  <1><47>: Abbrev Number: 5 (DW_TAG_base_type)
     <48>   DW_AT_byte_size   : 8
     <49>   DW_AT_encoding    : 7        (unsigned)
     <4a>   DW_AT_name        : (indirect string, offset: 0x1df2): long 
unsigned int
  <1><4e>: Abbrev Number: 7 (DW_TAG_variable)
     <4f>   DW_AT_specification: <0x3d>
     <53>   DW_AT_decl_line   : 2
     <54>   DW_AT_decl_column : 12
     <55>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0 
(DW_OP_addr: 0)
  <1><5f>: Abbrev Number: 0

Thanks
Indu

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

* Re: DWARF for extern variable
  2021-08-23 21:17 DWARF for extern variable Indu Bhagat
@ 2021-08-24  7:55 ` Richard Biener
  2021-09-01 17:25   ` Indu Bhagat
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2021-08-24  7:55 UTC (permalink / raw)
  To: Indu Bhagat; +Cc: gcc-patches

On Mon, Aug 23, 2021 at 11:18 PM Indu Bhagat via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hello,
>
> What is the expected DWARF for extern variable in the following cases? I
> am seeing that the DWARF generated is different with gcc8.4.1 vs gcc-trunk.
>
> Testcase 1
> ----------
> extern const char a[];
>
> int foo()
> {
>    return a != 0;
> }
>
> Testcase 1 Behavior
> ---------------------
> - gcc-trunk has _no_ DWARF for variable a.

Use -fno-eliminate-unused-debug-symbols (the comparison is folded away
very early it seems).  Then we get similar DWARF as with GCC 8.

> - gcc8.4.1 generates following DW_TAG_variable for extern variable a.
> But does not designate it as a non-defining decl (IIUC,
> DW_AT_specification is used for such cases?).

It has DW_AT_declaration.

>
> <..>
>   <1><31>: Abbrev Number: 2 (DW_TAG_array_type)
>      <32>   DW_AT_type        : <0x48>
>      <36>   DW_AT_sibling     : <0x3c>
>   <2><3a>: Abbrev Number: 3 (DW_TAG_subrange_type)
>   <2><3b>: Abbrev Number: 0
>   <1><3c>: Abbrev Number: 4 (DW_TAG_const_type)
>      <3d>   DW_AT_type        : <0x31>
>   <1><41>: Abbrev Number: 5 (DW_TAG_base_type)
>      <42>   DW_AT_byte_size   : 1
>      <43>   DW_AT_encoding    : 6        (signed char)
>      <44>   DW_AT_name        : (indirect string, offset: 0x1df6): char
>   <1><48>: Abbrev Number: 4 (DW_TAG_const_type)
>      <49>   DW_AT_type        : <0x41>
>   <1><4d>: Abbrev Number: 6 (DW_TAG_variable)
>      <4e>   DW_AT_name        : a
>      <50>   DW_AT_decl_file   : 1
>      <51>   DW_AT_decl_line   : 1
>      <52>   DW_AT_decl_column : 19
>      <53>   DW_AT_type        : <0x3c>
>      <57>   DW_AT_external    : 1
>      <57>   DW_AT_declaration : 1
> <..>
>
> -----------------------------------------------------------
>
> Testcase 2
> ----------
> extern const char a[];
> const char a[] = "testme";
>
> Testcase 2 Behavior
> --------------------
> - Both gcc-trunk and gcc8.4.1 generate two DW_TAG_variable DIEs (the
> defining decl holds the reference to the non-defining decl via
> DW_AT_specification)
> - But gcc8.4.1 does not generate any DWARF for the type of the defining
> decl (const char[7]) but gcc-trunk does.
>
> ## DWARF for testcase 2 with gcc-trunk is as follows:
> <...>
>   <1><22>: Abbrev Number: 2 (DW_TAG_array_type)
>      <23>   DW_AT_type        : <0x39>
>      <27>   DW_AT_sibling     : <0x2d>
>   <2><2b>: Abbrev Number: 5 (DW_TAG_subrange_type)
>   <2><2c>: Abbrev Number: 0
>   <1><2d>: Abbrev Number: 1 (DW_TAG_const_type)
>      <2e>   DW_AT_type        : <0x22>
>   <1><32>: Abbrev Number: 3 (DW_TAG_base_type)
>      <33>   DW_AT_byte_size   : 1
>      <34>   DW_AT_encoding    : 6        (signed char)
>      <35>   DW_AT_name        : (indirect string, offset: 0x2035): char
>   <1><39>: Abbrev Number: 1 (DW_TAG_const_type)
>      <3a>   DW_AT_type        : <0x32>
>   <1><3e>: Abbrev Number: 6 (DW_TAG_variable)
>      <3f>   DW_AT_name        : a
>      <41>   DW_AT_decl_file   : 1
>      <42>   DW_AT_decl_line   : 1
>      <43>   DW_AT_decl_column : 19
>      <44>   DW_AT_type        : <0x2d>
>      <48>   DW_AT_external    : 1
>      <48>   DW_AT_declaration : 1
>   <1><48>: Abbrev Number: 2 (DW_TAG_array_type)
>      <49>   DW_AT_type        : <0x39>
>      <4d>   DW_AT_sibling     : <0x58>
>   <2><51>: Abbrev Number: 7 (DW_TAG_subrange_type)
>      <52>   DW_AT_type        : <0x5d>
>      <56>   DW_AT_upper_bound : 6
>   <2><57>: Abbrev Number: 0
>   <1><58>: Abbrev Number: 1 (DW_TAG_const_type)
>      <59>   DW_AT_type        : <0x48>
>   <1><5d>: Abbrev Number: 3 (DW_TAG_base_type)
>      <5e>   DW_AT_byte_size   : 8
>      <5f>   DW_AT_encoding    : 7        (unsigned)
>      <60>   DW_AT_name        : (indirect string, offset: 0x2023): long
> unsigned int
>   <1><64>: Abbrev Number: 8 (DW_TAG_variable)
>      <65>   DW_AT_specification: <0x3e>
>      <69>   DW_AT_decl_line   : 2
>      <6a>   DW_AT_decl_column : 12
>      <6b>   DW_AT_type        : <0x58>

I suppose having both a DW_AT_specification and a DW_AT_type
is somewhat at odds.  It's likely because the definition specifies
the size of the array while the specification does not.  Not sure
what should be best done here.

Richard.

>      <6f>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
> (DW_OP_addr: 0)
>   <1><79>: Abbrev Number: 0
>
> ## DWARF for testcase 2 with gcc8.4.1 is as follows:
>   <1><21>: Abbrev Number: 2 (DW_TAG_array_type)
>      <22>   DW_AT_type        : <0x38>
>      <26>   DW_AT_sibling     : <0x2c>
>   <2><2a>: Abbrev Number: 3 (DW_TAG_subrange_type)
>   <2><2b>: Abbrev Number: 0
>   <1><2c>: Abbrev Number: 4 (DW_TAG_const_type)
>      <2d>   DW_AT_type        : <0x21>
>   <1><31>: Abbrev Number: 5 (DW_TAG_base_type)
>      <32>   DW_AT_byte_size   : 1
>      <33>   DW_AT_encoding    : 6        (signed char)
>      <34>   DW_AT_name        : (indirect string, offset: 0x1e04): char
>   <1><38>: Abbrev Number: 4 (DW_TAG_const_type)
>      <39>   DW_AT_type        : <0x31>
>   <1><3d>: Abbrev Number: 6 (DW_TAG_variable)
>      <3e>   DW_AT_name        : a
>      <40>   DW_AT_decl_file   : 1
>      <41>   DW_AT_decl_line   : 1
>      <42>   DW_AT_decl_column : 19
>      <43>   DW_AT_type        : <0x2c>
>      <47>   DW_AT_external    : 1
>      <47>   DW_AT_declaration : 1
>   <1><47>: Abbrev Number: 5 (DW_TAG_base_type)
>      <48>   DW_AT_byte_size   : 8
>      <49>   DW_AT_encoding    : 7        (unsigned)
>      <4a>   DW_AT_name        : (indirect string, offset: 0x1df2): long
> unsigned int
>   <1><4e>: Abbrev Number: 7 (DW_TAG_variable)
>      <4f>   DW_AT_specification: <0x3d>
>      <53>   DW_AT_decl_line   : 2
>      <54>   DW_AT_decl_column : 12
>      <55>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
> (DW_OP_addr: 0)
>   <1><5f>: Abbrev Number: 0
>
> Thanks
> Indu

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

* Re: DWARF for extern variable
  2021-08-24  7:55 ` Richard Biener
@ 2021-09-01 17:25   ` Indu Bhagat
  2021-09-02  7:32     ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Indu Bhagat @ 2021-09-01 17:25 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches

On 8/24/21 12:55 AM, Richard Biener wrote:
> On Mon, Aug 23, 2021 at 11:18 PM Indu Bhagat via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
>>
>> Hello,
>>
>> What is the expected DWARF for extern variable in the following cases? I
>> am seeing that the DWARF generated is different with gcc8.4.1 vs gcc-trunk.
>>
>>
>> Testcase 2
>> ----------
>> extern const char a[];
>> const char a[] = "testme";
>>
>> Testcase 2 Behavior
>> --------------------
>> - Both gcc-trunk and gcc8.4.1 generate two DW_TAG_variable DIEs (the
>> defining decl holds the reference to the non-defining decl via
>> DW_AT_specification)
>> - But gcc8.4.1 does not generate any DWARF for the type of the defining
>> decl (const char[7]) but gcc-trunk does.
>>
>> ## DWARF for testcase 2 with gcc-trunk is as follows:
>> <...>
>>    <1><22>: Abbrev Number: 2 (DW_TAG_array_type)
>>       <23>   DW_AT_type        : <0x39>
>>       <27>   DW_AT_sibling     : <0x2d>
>>    <2><2b>: Abbrev Number: 5 (DW_TAG_subrange_type)
>>    <2><2c>: Abbrev Number: 0
>>    <1><2d>: Abbrev Number: 1 (DW_TAG_const_type)
>>       <2e>   DW_AT_type        : <0x22>
>>    <1><32>: Abbrev Number: 3 (DW_TAG_base_type)
>>       <33>   DW_AT_byte_size   : 1
>>       <34>   DW_AT_encoding    : 6        (signed char)
>>       <35>   DW_AT_name        : (indirect string, offset: 0x2035): char
>>    <1><39>: Abbrev Number: 1 (DW_TAG_const_type)
>>       <3a>   DW_AT_type        : <0x32>
>>    <1><3e>: Abbrev Number: 6 (DW_TAG_variable)
>>       <3f>   DW_AT_name        : a
>>       <41>   DW_AT_decl_file   : 1
>>       <42>   DW_AT_decl_line   : 1
>>       <43>   DW_AT_decl_column : 19
>>       <44>   DW_AT_type        : <0x2d>
>>       <48>   DW_AT_external    : 1
>>       <48>   DW_AT_declaration : 1
>>    <1><48>: Abbrev Number: 2 (DW_TAG_array_type)
>>       <49>   DW_AT_type        : <0x39>
>>       <4d>   DW_AT_sibling     : <0x58>
>>    <2><51>: Abbrev Number: 7 (DW_TAG_subrange_type)
>>       <52>   DW_AT_type        : <0x5d>
>>       <56>   DW_AT_upper_bound : 6
>>    <2><57>: Abbrev Number: 0
>>    <1><58>: Abbrev Number: 1 (DW_TAG_const_type)
>>       <59>   DW_AT_type        : <0x48>
>>    <1><5d>: Abbrev Number: 3 (DW_TAG_base_type)
>>       <5e>   DW_AT_byte_size   : 8
>>       <5f>   DW_AT_encoding    : 7        (unsigned)
>>       <60>   DW_AT_name        : (indirect string, offset: 0x2023): long
>> unsigned int
>>    <1><64>: Abbrev Number: 8 (DW_TAG_variable)
>>       <65>   DW_AT_specification: <0x3e>
>>       <69>   DW_AT_decl_line   : 2
>>       <6a>   DW_AT_decl_column : 12
>>       <6b>   DW_AT_type        : <0x58>
> 
> I suppose having both a DW_AT_specification and a DW_AT_type
> is somewhat at odds.  It's likely because the definition specifies
> the size of the array while the specification does not.  Not sure
> what should be best done here.
> 
> Richard.

Hmm..I thought the generated DWARF by gcc-trunk for testcase 2 is 
coherent and specifies the information in alignment with the source : 
DW_AT_type of the defining declaration correctly specifies the type to 
be const char[7] while the DW_AT_specification pointing to the 
non-defining decl (and with type const char[] with no size info).

The DWARF generated by gcc-8.4.1, however, does seem to be missing 
information though. It should have the information for the defining decl 
and hence, the size info. i.e., DW_AT_type pointing to a array with 
DW_TAG_subrange_type with attribute DW_AT_upper_bound = 6 like above. 
Isn't it ?

Indu

> 
>>       <6f>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
>> (DW_OP_addr: 0)
>>    <1><79>: Abbrev Number: 0
>>
>> ## DWARF for testcase 2 with gcc8.4.1 is as follows:
>>    <1><21>: Abbrev Number: 2 (DW_TAG_array_type)
>>       <22>   DW_AT_type        : <0x38>
>>       <26>   DW_AT_sibling     : <0x2c>
>>    <2><2a>: Abbrev Number: 3 (DW_TAG_subrange_type)
>>    <2><2b>: Abbrev Number: 0
>>    <1><2c>: Abbrev Number: 4 (DW_TAG_const_type)
>>       <2d>   DW_AT_type        : <0x21>
>>    <1><31>: Abbrev Number: 5 (DW_TAG_base_type)
>>       <32>   DW_AT_byte_size   : 1
>>       <33>   DW_AT_encoding    : 6        (signed char)
>>       <34>   DW_AT_name        : (indirect string, offset: 0x1e04): char
>>    <1><38>: Abbrev Number: 4 (DW_TAG_const_type)
>>       <39>   DW_AT_type        : <0x31>
>>    <1><3d>: Abbrev Number: 6 (DW_TAG_variable)
>>       <3e>   DW_AT_name        : a
>>       <40>   DW_AT_decl_file   : 1
>>       <41>   DW_AT_decl_line   : 1
>>       <42>   DW_AT_decl_column : 19
>>       <43>   DW_AT_type        : <0x2c>
>>       <47>   DW_AT_external    : 1
>>       <47>   DW_AT_declaration : 1
>>    <1><47>: Abbrev Number: 5 (DW_TAG_base_type)
>>       <48>   DW_AT_byte_size   : 8
>>       <49>   DW_AT_encoding    : 7        (unsigned)
>>       <4a>   DW_AT_name        : (indirect string, offset: 0x1df2): long
>> unsigned int
>>    <1><4e>: Abbrev Number: 7 (DW_TAG_variable)
>>       <4f>   DW_AT_specification: <0x3d>
>>       <53>   DW_AT_decl_line   : 2
>>       <54>   DW_AT_decl_column : 12
>>       <55>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
>> (DW_OP_addr: 0)
>>    <1><5f>: Abbrev Number: 0
>>
>> Thanks
>> Indu


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

* Re: DWARF for extern variable
  2021-09-01 17:25   ` Indu Bhagat
@ 2021-09-02  7:32     ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2021-09-02  7:32 UTC (permalink / raw)
  To: Indu Bhagat; +Cc: gcc-patches

On Wed, Sep 1, 2021 at 7:25 PM Indu Bhagat <indu.bhagat@oracle.com> wrote:
>
> On 8/24/21 12:55 AM, Richard Biener wrote:
> > On Mon, Aug 23, 2021 at 11:18 PM Indu Bhagat via Gcc-patches
> > <gcc-patches@gcc.gnu.org> wrote:
> >>
> >> Hello,
> >>
> >> What is the expected DWARF for extern variable in the following cases? I
> >> am seeing that the DWARF generated is different with gcc8.4.1 vs gcc-trunk.
> >>
> >>
> >> Testcase 2
> >> ----------
> >> extern const char a[];
> >> const char a[] = "testme";
> >>
> >> Testcase 2 Behavior
> >> --------------------
> >> - Both gcc-trunk and gcc8.4.1 generate two DW_TAG_variable DIEs (the
> >> defining decl holds the reference to the non-defining decl via
> >> DW_AT_specification)
> >> - But gcc8.4.1 does not generate any DWARF for the type of the defining
> >> decl (const char[7]) but gcc-trunk does.
> >>
> >> ## DWARF for testcase 2 with gcc-trunk is as follows:
> >> <...>
> >>    <1><22>: Abbrev Number: 2 (DW_TAG_array_type)
> >>       <23>   DW_AT_type        : <0x39>
> >>       <27>   DW_AT_sibling     : <0x2d>
> >>    <2><2b>: Abbrev Number: 5 (DW_TAG_subrange_type)
> >>    <2><2c>: Abbrev Number: 0
> >>    <1><2d>: Abbrev Number: 1 (DW_TAG_const_type)
> >>       <2e>   DW_AT_type        : <0x22>
> >>    <1><32>: Abbrev Number: 3 (DW_TAG_base_type)
> >>       <33>   DW_AT_byte_size   : 1
> >>       <34>   DW_AT_encoding    : 6        (signed char)
> >>       <35>   DW_AT_name        : (indirect string, offset: 0x2035): char
> >>    <1><39>: Abbrev Number: 1 (DW_TAG_const_type)
> >>       <3a>   DW_AT_type        : <0x32>
> >>    <1><3e>: Abbrev Number: 6 (DW_TAG_variable)
> >>       <3f>   DW_AT_name        : a
> >>       <41>   DW_AT_decl_file   : 1
> >>       <42>   DW_AT_decl_line   : 1
> >>       <43>   DW_AT_decl_column : 19
> >>       <44>   DW_AT_type        : <0x2d>
> >>       <48>   DW_AT_external    : 1
> >>       <48>   DW_AT_declaration : 1
> >>    <1><48>: Abbrev Number: 2 (DW_TAG_array_type)
> >>       <49>   DW_AT_type        : <0x39>
> >>       <4d>   DW_AT_sibling     : <0x58>
> >>    <2><51>: Abbrev Number: 7 (DW_TAG_subrange_type)
> >>       <52>   DW_AT_type        : <0x5d>
> >>       <56>   DW_AT_upper_bound : 6
> >>    <2><57>: Abbrev Number: 0
> >>    <1><58>: Abbrev Number: 1 (DW_TAG_const_type)
> >>       <59>   DW_AT_type        : <0x48>
> >>    <1><5d>: Abbrev Number: 3 (DW_TAG_base_type)
> >>       <5e>   DW_AT_byte_size   : 8
> >>       <5f>   DW_AT_encoding    : 7        (unsigned)
> >>       <60>   DW_AT_name        : (indirect string, offset: 0x2023): long
> >> unsigned int
> >>    <1><64>: Abbrev Number: 8 (DW_TAG_variable)
> >>       <65>   DW_AT_specification: <0x3e>
> >>       <69>   DW_AT_decl_line   : 2
> >>       <6a>   DW_AT_decl_column : 12
> >>       <6b>   DW_AT_type        : <0x58>
> >
> > I suppose having both a DW_AT_specification and a DW_AT_type
> > is somewhat at odds.  It's likely because the definition specifies
> > the size of the array while the specification does not.  Not sure
> > what should be best done here.
> >
> > Richard.
>
> Hmm..I thought the generated DWARF by gcc-trunk for testcase 2 is
> coherent and specifies the information in alignment with the source :
> DW_AT_type of the defining declaration correctly specifies the type to
> be const char[7] while the DW_AT_specification pointing to the
> non-defining decl (and with type const char[] with no size info).
>
> The DWARF generated by gcc-8.4.1, however, does seem to be missing
> information though. It should have the information for the defining decl
> and hence, the size info. i.e., DW_AT_type pointing to a array with
> DW_TAG_subrange_type with attribute DW_AT_upper_bound = 6 like above.
> Isn't it ?

Yes.

> Indu
>
> >
> >>       <6f>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
> >> (DW_OP_addr: 0)
> >>    <1><79>: Abbrev Number: 0
> >>
> >> ## DWARF for testcase 2 with gcc8.4.1 is as follows:
> >>    <1><21>: Abbrev Number: 2 (DW_TAG_array_type)
> >>       <22>   DW_AT_type        : <0x38>
> >>       <26>   DW_AT_sibling     : <0x2c>
> >>    <2><2a>: Abbrev Number: 3 (DW_TAG_subrange_type)
> >>    <2><2b>: Abbrev Number: 0
> >>    <1><2c>: Abbrev Number: 4 (DW_TAG_const_type)
> >>       <2d>   DW_AT_type        : <0x21>
> >>    <1><31>: Abbrev Number: 5 (DW_TAG_base_type)
> >>       <32>   DW_AT_byte_size   : 1
> >>       <33>   DW_AT_encoding    : 6        (signed char)
> >>       <34>   DW_AT_name        : (indirect string, offset: 0x1e04): char
> >>    <1><38>: Abbrev Number: 4 (DW_TAG_const_type)
> >>       <39>   DW_AT_type        : <0x31>
> >>    <1><3d>: Abbrev Number: 6 (DW_TAG_variable)
> >>       <3e>   DW_AT_name        : a
> >>       <40>   DW_AT_decl_file   : 1
> >>       <41>   DW_AT_decl_line   : 1
> >>       <42>   DW_AT_decl_column : 19
> >>       <43>   DW_AT_type        : <0x2c>
> >>       <47>   DW_AT_external    : 1
> >>       <47>   DW_AT_declaration : 1
> >>    <1><47>: Abbrev Number: 5 (DW_TAG_base_type)
> >>       <48>   DW_AT_byte_size   : 8
> >>       <49>   DW_AT_encoding    : 7        (unsigned)
> >>       <4a>   DW_AT_name        : (indirect string, offset: 0x1df2): long
> >> unsigned int
> >>    <1><4e>: Abbrev Number: 7 (DW_TAG_variable)
> >>       <4f>   DW_AT_specification: <0x3d>
> >>       <53>   DW_AT_decl_line   : 2
> >>       <54>   DW_AT_decl_column : 12
> >>       <55>   DW_AT_location    : 9 byte block: 3 0 0 0 0 0 0 0 0
> >> (DW_OP_addr: 0)
> >>    <1><5f>: Abbrev Number: 0
> >>
> >> Thanks
> >> Indu
>

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

end of thread, other threads:[~2021-09-02  7:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-23 21:17 DWARF for extern variable Indu Bhagat
2021-08-24  7:55 ` Richard Biener
2021-09-01 17:25   ` Indu Bhagat
2021-09-02  7:32     ` Richard Biener

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).