Bug 81267 - Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void"
Summary: Missing DW_AT_type in DW_TAG_typedef of "typedef of typedef of void"
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: debug (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-debug
Depends on:
Blocks:
 
Reported: 2017-06-30 15:16 UTC by Pedro Alves
Modified: 2017-07-03 07:34 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pedro Alves 2017-06-30 15:16:53 UTC
I'm writing a GDB testcase that exercises the "whatis" command.  If passed a type name, that command strips one, and only one, level of typedef from the type.  The test exposed missing target type info in the case of "typedef of typedef of void".

I.e., with:

~~~
typedef void void_typedef1;
typedef void_typedef1 void_typedef2;

void_typedef1 *void_typedef1_ptr; // just to be sure the types are emitted.
void_typedef2 *void_typedef2_ptr; // ditto.
~~~

We get:

 <1><21>: Abbrev Number: 2 (DW_TAG_typedef)
    <22>   DW_AT_name        : (indirect string, offset: 0x1bf): void_typedef1
    <26>   DW_AT_decl_file   : 1
    <27>   DW_AT_decl_line   : 1
 <1><28>: Abbrev Number: 2 (DW_TAG_typedef)
    <29>   DW_AT_name        : (indirect string, offset: 0x1cd): void_typedef2
    <2d>   DW_AT_decl_file   : 1
    <2e>   DW_AT_decl_line   : 2

Notice that "void_typedef2" has no DW_AT_type pointing to "void_typedef1".
Seeing this, GDB assumes that "void_typedef2" is a direct typedef to "void":

 (gdb) whatis void_typedef1
 type = void
 (gdb) whatis void_typedef2
 type = void

The correct output in the second case above would have been:

 (gdb) whatis void_typedef2
 type = void_typedef1

... which is what I get if I compile the testcase with clang instead of gcc.  

clang (3.7) outputs:

 <1><44>: Abbrev Number: 4 (DW_TAG_typedef)
    <45>   DW_AT_name        : (indirect string, offset: 0x5e): void_typedef1
    <49>   DW_AT_decl_file   : 1
    <4a>   DW_AT_decl_line   : 1
...
 <1><65>: Abbrev Number: 5 (DW_TAG_typedef)
    <66>   DW_AT_type        : <0x44>
    <6a>   DW_AT_name        : (indirect string, offset: 0x7e): void_typedef2
    <6e>   DW_AT_decl_file   : 1
    <6f>   DW_AT_decl_line   : 2

I.e., it only "optimizes out" DW_AT_type when the typedef is a direct typedef to void.