[PATCH] D103131: support debug info for alias variable
David Blaikie via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 12 10:55:31 PDT 2021
dblaikie added a comment.
In D103131#2814595 <https://reviews.llvm.org/D103131#2814595>, @kamleshbhalui wrote:
> In D103131#2814015 <https://reviews.llvm.org/D103131#2814015>, @dblaikie wrote:
>
>> In D103131#2811969 <https://reviews.llvm.org/D103131#2811969>, @kamleshbhalui wrote:
>>
>>> In D103131#2811220 <https://reviews.llvm.org/D103131#2811220>, @dblaikie wrote:
>>>
>>>> Any idea if the GDB test suite covers this functionality? I'd hope so, but maybe it doesn't.
>>>>
>>>> But yeah, at the moment I don't have any great reason to avoid the imported declaration form - so happy to go with that.
>>>
>>> Hi David,
>>>
>>> with imported declaration patch and with current patch(in review or say gcc way) this case works ok(we can print type and value of newname)
>>> $cat test.c
>>> int oldname = 1;
>>> extern int newname attribute((alias("oldname")));
>>>
>>> but when we make newname static it works with current patch(in review or say gcc way) but it does not work with imported decl patch(https://reviews.llvm.org/D103131?id=347883).
>>>
>>> Should we go with gcc way or am I missing something?
>>> note: used gdb debugger.
>>
>> An ideas what's happening when `newname` is static? Is the DWARF any different/interesting there? (since the DWARF for imported decl seems like it would have nothing to do with the linkange of the alias - since it doesn't refer to the actual alias in the object file, etc)
>
> There not much different apart from extern has external attribute.
> **case 1) when `newname` is static**
>
> .debug_info contents:
> 0x00000000: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000076)
>
> 0x0000000b: DW_TAG_compile_unit
> DW_AT_producer ("clang version 13.0.0 (git at github.com:llvm/llvm-project.git 4cd7169f5517167ef456e82c6dcae669bde6c725)")
> DW_AT_language (DW_LANG_C99)
> DW_AT_name ("test.c")
> DW_AT_stmt_list (0x00000000)
> DW_AT_comp_dir ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin")
> DW_AT_low_pc (0x0000000000000000)
> DW_AT_high_pc (0x0000000000000008)
>
> 0x0000002a: DW_TAG_variable
> DW_AT_name ("oldname")
> DW_AT_type (0x0000003f "int")
> DW_AT_external (true)
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (1)
> DW_AT_location (DW_OP_addr 0x0)
>
> 0x0000003f: DW_TAG_base_type
> DW_AT_name ("int")
> DW_AT_encoding (DW_ATE_signed)
> DW_AT_byte_size (0x04)
>
> 0x00000046: DW_TAG_variable
> DW_AT_name ("newname")
> DW_AT_type (0x0000003f "int")
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (2)
> DW_AT_declaration (true)
>
> 0x00000051: DW_TAG_imported_declaration
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (2)
> DW_AT_import (0x00000046)
> DW_AT_name ("newname")
>
> 0x0000005c: DW_TAG_subprogram
> DW_AT_low_pc (0x0000000000000000)
> DW_AT_high_pc (0x0000000000000008)
> DW_AT_frame_base (DW_OP_reg6 RBP)
> DW_AT_name ("main")
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (3)
> DW_AT_type (0x0000003f "int")
> DW_AT_external (true)
>
> 0x00000075: NULL
>
> **case 2) when `newname` is extern**
>
> .debug_info contents:
> 0x00000000: Compile Unit: length = 0x00000072, format = DWARF32, version = 0x0004, abbr_offset = 0x0000, addr_size = 0x08 (next unit at 0x00000076)
>
> 0x0000000b: DW_TAG_compile_unit
> DW_AT_producer ("clang version 13.0.0 (git at github.com:llvm/llvm-project.git 4cd7169f5517167ef456e82c6dcae669bde6c725)")
> DW_AT_language (DW_LANG_C99)
> DW_AT_name ("test.c")
> DW_AT_stmt_list (0x00000000)
> DW_AT_comp_dir ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin")
> DW_AT_low_pc (0x0000000000000000)
> DW_AT_high_pc (0x0000000000000008)
>
> 0x0000002a: DW_TAG_variable
> DW_AT_name ("oldname")
> DW_AT_type (0x0000003f "int")
> DW_AT_external (true)
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (1)
> DW_AT_location (DW_OP_addr 0x0)
>
> 0x0000003f: DW_TAG_base_type
> DW_AT_name ("int")
> DW_AT_encoding (DW_ATE_signed)
> DW_AT_byte_size (0x04)
>
> 0x00000046: DW_TAG_variable
> DW_AT_name ("newname")
> DW_AT_type (0x0000003f "int")
> DW_AT_external (true)
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (2)
> DW_AT_declaration (true)
>
> 0x00000051: DW_TAG_imported_declaration
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (2)
> DW_AT_import (0x00000046)
> DW_AT_name ("newname")
>
> 0x0000005c: DW_TAG_subprogram
> DW_AT_low_pc (0x0000000000000000)
> DW_AT_high_pc (0x0000000000000008)
> DW_AT_frame_base (DW_OP_reg6 RBP)
> DW_AT_name ("main")
> DW_AT_decl_file ("/folk/kkumar/tcllvm/llvm-build-lldb-rel/bin/test.c")
> DW_AT_decl_line (3)
> DW_AT_type (0x0000003f "int")
> DW_AT_external (true)
>
> 0x00000075: NULL
This debug info looks confusing - it looks like it's using /both/ strategies. There's a `DW_TAG_variable` for `oldname` then a `DW_TAG_variable` declaration for `newname` then a `DW_TAG_imported_declaration` for `newname` from `newname`. I don't think that's a solution we'd want - either we have just the two `DW_TAG_variable`s, or we have the `oldname` `DW_TAG_variable` and a `DW_TAG_imported_declaration` that imports that `oldname` variable as `newname`, right?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103131/new/
https://reviews.llvm.org/D103131
More information about the cfe-commits
mailing list