I have a variable declared in a c++ file like this:
namespace {
VelocityLongitudinal vel_lgt;
}
The corresponding dwarf info is
<1><5e08b>: Abbrev Number: 317 (DW_TAG_namespace)
<5e08d> DW_AT_sibling : <0x5e09e>
<2><5e091>: Abbrev Number: 193 (DW_TAG_variable)
<5e093> DW_AT_name : (indirect string, offset: 0xa5582): vel_lgt
<5e097> DW_AT_decl_file : 2
<5e098> DW_AT_decl_line : 19
<5e099> DW_AT_type : <0x5bed3>
<5e09d> DW_AT_declaration : 1
<2><5e09d>: Abbrev Number: 0
We see that there is no DW_AT_linkage_name and no DW_AT_location
In the symbol table (readelf -s) I find. The address, 21a0a0, matches the address gdb reports (print &'(anonymous namespace)::vel_lgt')
42: 0000000000000000 0 FILE LOCAL DEFAULT ABS vehiclemotionstate_server
43: 000000000021a0a0 24 OBJECT LOCAL DEFAULT 2 _ZN12_GLOBAL__N_17vel_lgt
How does gdb find that? vehiclemotionstate_serve.cpp is the name of the file in which the variable is declared. It seems unlikely that gdb would search for entries with matching last characters in the symbol table entries for a certain cpp file. And if so, how would it distinguish between two different declarations of the same name in files with the same name?