Re: [PING][PATCH PR gdb/18071] TLS variables can't be resolved on aarch64-linux-gnu

Wei-min Pan
2018-01-18T00:18:11Z

On 1/17/2018 12:55 AM, Yao Qi wrote:
> On Wed, Jan 17, 2018 at 1:05 AM, Weimin Pan <weimin.pan@oracle.com> wrote:
>> dwarf2_physname() does call dw2_linkage_name(). But since the class member,
>> i.e. another_thread_local, does not contain either DW_AT_linkage_name or
>> DW_AT_MIPS_linkage_name attribute, its canonicalized name gets returned.
>>
> dwarf2_physname is called twice with the parameter NAME is
> "another_thread_local".
> The first is about DW_TAG_member and the second is about DW_TAG_variable.
>
> <2><37>: Abbrev Number: 3 (DW_TAG_member)
> <38> DW_AT_name : (indirect string, offset: 0x6e):
> another_thread_local
> <3c> DW_AT_decl_file : 1
> <3d> DW_AT_decl_line : 3
> <3e> DW_AT_type : <0x44>
> <42> DW_AT_external : 1
> <42> DW_AT_accessibility: 1 (public)
> <43> DW_AT_declaration : 1
> ....
> <1><68>: Abbrev Number: 6 (DW_TAG_variable)
> <69> DW_AT_specification: <0x37>
> <6d> DW_AT_decl_line : 6
> <6e> DW_AT_linkage_name: (indirect string, offset: 0x0):
> _ZN1K20another_thread_localE
>
> The second one matters, not the first one. If I set this breakpoint,
> it will hit twice,
>
> (gdb) b dwarf2_physname if strcmp (name, "another_thread_local") == 0
>
> in the 2nd breakpoint hit, you can see dwarf2_physname is called by
> new_symbol_full,
>
> (gdb) bt 5
> #0 dwarf2_physname (name=0x60d0000096fe "another_thread_local",
> die=0x621000156ce0, cu=0x612000018340)
> at gdb/dwarf2read.c:11183
> #1 0x00000000008f20a9 in new_symbol_full (die=0x621000156ce0,
> type=0x0, cu=0x612000018340, space=0x0)
> at gdb/dwarf2read.c:21416
> #2 0x00000000008c80a6 in read_variable (die=0x621000156ce0,
> cu=0x612000018340) at gdb/dwarf2read.c:14439
>
> it returns "K::another_thread_local", and use it to set symbol name.
> That symbol
> is used in lookup_minimal_symbol_and_objfile (SYMBOL_LINKAGE_NAME (sym))
> later when you type command "info address K::another_thread_local".

Yes, the 2nd breakpoint hit in dwarf2_physname() was to handle
the DW_TAG_variable die for another_thread_local. The function
did fetch the correct mangled name from dw2_linkage_name() and
set it in local variable "mangled". Problem is "mangled" got
demangled with gdb_demangle(), for the purpose of suppressing
C++ template function's return type which I don't quite follow,
and the demangled name gets returned.