[PATCH] D40156: Fix recursive attribute fetching in DWARFDie

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 16:11:08 PST 2017


0x31a1e561: TAG_compile_unit [1] *
             AT_producer( "GNU C++ 5.x 20161206 ..." )
             AT_language( DW_LANG_C_plus_plus )
             AT_name( "/home/engshare/third-party2/glog/0.3.2_fb/src/glog-0.3.2/src/vlog_is_on.cc" )
             AT_comp_dir( "/home/engshare/third-party2/glog/0.3.2_fb/src/glog-0.3.2" )
             AT_ranges( 0x04b59e20
                [0x0000000002c7c2d0 - 0x0000000002c7c9a5)
                [0x00000000005e4e90 - 0x00000000005e4ed7)
                [0x0000000002c7b870 - 0x0000000002c7b89a)
                [0x000000000056c380 - 0x000000000056c426)
                [0x0000000002c7c9c0 - 0x0000000002c7c9ea)
                [0x000000000056c430 - 0x000000000056c5cb)
                 End )
             AT_low_pc( 0x0000000000000000 )
             AT_stmt_list( 0x02b87914 )

> On Nov 16, 2017, at 4:09 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> Do you happen to have minimized source & a specific GCC version (unless it's just ubiquitous to all/many GCC versions)?
> 
> On Thu, Nov 16, 2017 at 4:06 PM Greg Clayton <clayborg at gmail.com <mailto:clayborg at gmail.com>> wrote:
> Don't ask me. I just have a GCC generated file that does this.
> 
>> On Nov 16, 2017, at 4:05 PM, David Blaikie <dblaikie at gmail.com <mailto:dblaikie at gmail.com>> wrote:
>> 
>> I don't quite follow - why would there be two levels of abstract origin? (X -abstract_origin-> Y -abstract_origin-> Z) rather than having X refer to Z as its abstract_origin directly?
>> 
>> On Thu, Nov 16, 2017 at 4:01 PM Greg Clayton via Phabricator <reviews at reviews.llvm.org <mailto:reviews at reviews.llvm.org>> wrote:
>> clayborg created this revision.
>> Herald added a subscriber: JDevlieghere.
>> 
>> The previous implementation would only look 1 DW_AT_specification or DW_AT_abstract_origin deep. This means DWARFDie::getName() would fail in certain cases. I ran into such a case while creating a tool that used the LLVM DWARF parser to generate a symbolication format so I have seen this in the wild.
>> 
>> 
>> Repository:
>>   rL LLVM
>> 
>> https://reviews.llvm.org/D40156 <https://reviews.llvm.org/D40156>
>> 
>> Files:
>>   lib/DebugInfo/DWARF/DWARFDie.cpp
>>   unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>> 
>> 
>> Index: unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>> ===================================================================
>> --- unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>> +++ unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>> @@ -1287,12 +1287,16 @@
>>      auto CUDie = CU.getUnitDIE();
>>      auto FuncSpecDie = CUDie.addChild(DW_TAG_subprogram);
>>      auto FuncAbsDie = CUDie.addChild(DW_TAG_subprogram);
>> +    // Put the linkage name in a second abstract origin DIE to ensure we
>> +    // recurse through more than just one DIE when looking for attributes.
>> +    auto FuncAbsDie2 = CUDie.addChild(DW_TAG_subprogram);
>>      auto FuncDie = CUDie.addChild(DW_TAG_subprogram);
>>      auto VarAbsDie = CUDie.addChild(DW_TAG_variable);
>>      auto VarDie = CUDie.addChild(DW_TAG_variable);
>>      FuncSpecDie.addAttribute(DW_AT_name, DW_FORM_strp, SpecDieName);
>> -    FuncAbsDie.addAttribute(DW_AT_linkage_name, DW_FORM_strp, SpecLinkageName);
>> +    FuncAbsDie2.addAttribute(DW_AT_linkage_name, DW_FORM_strp, SpecLinkageName);
>>      FuncAbsDie.addAttribute(DW_AT_specification, DW_FORM_ref4, FuncSpecDie);
>> +    FuncAbsDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, FuncAbsDie2);
>>      FuncDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, FuncAbsDie);
>>      VarAbsDie.addAttribute(DW_AT_name, DW_FORM_strp, AbsDieName);
>>      VarDie.addAttribute(DW_AT_abstract_origin, DW_FORM_ref4, VarAbsDie);
>> @@ -1314,7 +1318,8 @@
>> 
>>    auto FuncSpecDie = CUDie.getFirstChild();
>>    auto FuncAbsDie = FuncSpecDie.getSibling();
>> -  auto FuncDie = FuncAbsDie.getSibling();
>> +  auto FuncAbsDie2 = FuncAbsDie.getSibling();
>> +  auto FuncDie = FuncAbsDie2.getSibling();
>>    auto VarAbsDie = FuncDie.getSibling();
>>    auto VarDie = VarAbsDie.getSibling();
>> 
>> Index: lib/DebugInfo/DWARF/DWARFDie.cpp
>> ===================================================================
>> --- lib/DebugInfo/DWARF/DWARFDie.cpp
>> +++ lib/DebugInfo/DWARF/DWARFDie.cpp
>> @@ -298,17 +298,16 @@
>>  DWARFDie::findRecursively(ArrayRef<dwarf::Attribute> Attrs) const {
>>    if (!isValid())
>>      return None;
>> -  auto Die = *this;
>> -  if (auto Value = Die.find(Attrs))
>> +  if (auto Value = find(Attrs))
>>      return Value;
>> -  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_abstract_origin))
>> -    Die = D;
>> -  if (auto Value = Die.find(Attrs))
>> -    return Value;
>> -  if (auto D = Die.getAttributeValueAsReferencedDie(DW_AT_specification))
>> -    Die = D;
>> -  if (auto Value = Die.find(Attrs))
>> -    return Value;
>> +  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_abstract_origin)) {
>> +    if (auto Value = Die.findRecursively(Attrs))
>> +      return Value;
>> +  }
>> +  if (auto Die = getAttributeValueAsReferencedDie(DW_AT_specification)) {
>> +    if (auto Value = Die.findRecursively(Attrs))
>> +      return Value;
>> +  }
>>    return None;
>>  }
>> 
>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171116/fb6fdc8f/attachment.html>


More information about the llvm-commits mailing list