[llvm] r337933 - dwarfgen: Add support for generating the debug_str_offsets section, take 2

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 25 09:31:02 PDT 2018


Thanks for the heads-up Alex. I have a feeling I know what is the
issue here (different handling of inter-section references in dwarf on
mac vs. other platforms), but I'll have to think about what is the
correct fix here. I'll revert the patch in the mean time.
On Wed, 25 Jul 2018 at 17:25, Alex L <arphaman at gmail.com> wrote:
>
> Hi Pavel,
>
> This commit has caused two test failures in our darwin CI:
>
> http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental/51228/consoleFull
>
> Here are the failures:
>
> FAIL: LLVM-Unit :: DebugInfo/DWARF/./DebugInfoDWARFTests/DWARFDebugInfo.TestDWARF32Version5Addr4AllForms (1294 of 39800)
> ******************** TEST 'LLVM-Unit :: DebugInfo/DWARF/./DebugInfoDWARFTests/DWARFDebugInfo.TestDWARF32Version5Addr4AllForms' FAILED ********************
> Note: Google Test filter = DWARFDebugInfo.TestDWARF32Version5Addr4AllForms
> [==========] Running 1 test from 1 test case.
> [----------] Global test environment set-up.
> [----------] 1 test from DWARFDebugInfo
> [ RUN      ] DWARFDebugInfo.TestDWARF32Version5Addr4AllForms
> /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp:312: Failure
> Value of: (bool)ExtractedStrxValue
>   Actual: false
> Expected: true
> warning: DWARF compile unit extends beyond its bounds cu 0x00000000 at 0x000000c0
> error: parsing a range list table: section is not large enough to contain a .debug_rnglists table length at offset 0x0
> Assertion failed: (Storage.hasVal), function getPointer, file /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/include/llvm/ADT/Optional.h, line 176.
> 0  DebugInfoDWARFTests      0x0000000110101698 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
> 1  DebugInfoDWARFTests      0x0000000110100627 llvm::sys::RunSignalHandlers() + 39
> 2  DebugInfoDWARFTests      0x0000000110101c92 SignalHandler(int) + 258
> 3  libsystem_platform.dylib 0x00007fff615b7f5a _sigtramp + 26
> 4  libsystem_platform.dylib 0x76616c73646c6975 _sigtramp + 51440181
> 5  libsystem_c.dylib        0x00007fff613551ae abort + 127
> 6  libsystem_c.dylib        0x00007fff6131d1ac basename_r + 0
> 7  DebugInfoDWARFTests      0x000000010f149edc void (anonymous namespace)::TestAllForms<(unsigned short)5, unsigned int, unsigned int>() + 19916
> 8  DebugInfoDWARFTests      0x0000000110108f90 testing::Test::Run() + 528
> 9  DebugInfoDWARFTests      0x0000000110109fe0 testing::TestInfo::Run() + 576
> 10 DebugInfoDWARFTests      0x000000011010a7f7 testing::TestCase::Run() + 471
> 11 DebugInfoDWARFTests      0x00000001101121b7 testing::internal::UnitTestImpl::RunAllTests() + 1143
> 12 DebugInfoDWARFTests      0x0000000110111d15 testing::UnitTest::Run() + 229
> 13 DebugInfoDWARFTests      0x000000011010269f main + 111
> 14 libdyld.dylib            0x00007fff612a9015 start + 1
> 15 libdyld.dylib            0x0000000000000002 start + 2664787950
>
> ********************
> FAIL: LLVM-Unit :: DebugInfo/DWARF/./DebugInfoDWARFTests/DWARFDebugInfo.TestDWARF32Version5Addr8AllForms (1295 of 39800)
> ******************** TEST 'LLVM-Unit :: DebugInfo/DWARF/./DebugInfoDWARFTests/DWARFDebugInfo.TestDWARF32Version5Addr8AllForms' FAILED ********************
> Note: Google Test filter = DWARFDebugInfo.TestDWARF32Version5Addr8AllForms
> [==========] Running 1 test from 1 test case.
> [----------] Global test environment set-up.
> [----------] 1 test from DWARFDebugInfo
> [ RUN      ] DWARFDebugInfo.TestDWARF32Version5Addr8AllForms
> /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp:312: Failure
> Value of: (bool)ExtractedStrxValue
>   Actual: false
> Expected: true
> warning: DWARF compile unit extends beyond its bounds cu 0x00000000 at 0x000000c8
> error: parsing a range list table: section is not large enough to contain a .debug_rnglists table length at offset 0x0
> Assertion failed: (Storage.hasVal), function getPointer, file /Users/buildslave/jenkins/workspace/clang-stage1-cmake-RA-incremental/llvm/include/llvm/ADT/Optional.h, line 176.
> 0  DebugInfoDWARFTests      0x000000010412e698 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
> 1  DebugInfoDWARFTests      0x000000010412d627 llvm::sys::RunSignalHandlers() + 39
> 2  DebugInfoDWARFTests      0x000000010412ec92 SignalHandler(int) + 258
> 3  libsystem_platform.dylib 0x00007fff615b7f5a _sigtramp + 26
> 4  libsystem_platform.dylib 0x76616c73646c6975 _sigtramp + 51440181
> 5  libsystem_c.dylib        0x00007fff613551ae abort + 127
> 6  libsystem_c.dylib        0x00007fff6131d1ac basename_r + 0
> 7  DebugInfoDWARFTests      0x000000010317bd3d void (anonymous namespace)::TestAllForms<(unsigned short)5, unsigned long long, unsigned int>() + 19917
> 8  DebugInfoDWARFTests      0x0000000104135f90 testing::Test::Run() + 528
> 9  DebugInfoDWARFTests      0x0000000104136fe0 testing::TestInfo::Run() + 576
> 10 DebugInfoDWARFTests      0x00000001041377f7 testing::TestCase::Run() + 471
> 11 DebugInfoDWARFTests      0x000000010413f1b7 testing::internal::UnitTestImpl::RunAllTests() + 1143
> 12 DebugInfoDWARFTests      0x000000010413ed15 testing::UnitTest::Run() + 229
> 13 DebugInfoDWARFTests      0x000000010412f69f main + 111
> 14 libdyld.dylib            0x00007fff612a9015 start + 1
> 15 libdyld.dylib            0x0000000000000002 start + 2664787950
>
> ********************
>
>
> Do you mind taking a look?
> Let me know if you need assistance for testing/verifying fixes on Darwin.
>
> Cheers,
> Alex
>
> On 25 July 2018 at 08:33, Pavel Labath via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: labath
>> Date: Wed Jul 25 08:33:32 2018
>> New Revision: 337933
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=337933&view=rev
>> Log:
>> dwarfgen: Add support for generating the debug_str_offsets section, take 2
>>
>> This recommits r337910 after fixing an "ambiguous call to addAttribute"
>> error with some compilers (gcc circa 4.9 and MSVC). It seems that these
>> compilers will consider a "false -> pointer" conversion during overload
>> resolution. This creates ambiguity because one I added an overload which
>> takes a MCExpr * as an argument.
>>
>> I fix this by making the new overload take MCExpr&, which avoids the
>> conversion. It also documents the fact that we expect a valid MCExpr
>> object.
>>
>> Original commit message follows:
>>
>> The motivation for this is D49493, where we'd like to test details of
>> debug_str_offsets behavior which is difficult to trigger from a
>> traditional test.
>>
>> This adds the plubming necessary for dwarfgen to generate this section.
>> The more interesting changes are:
>> - I've moved emitStringOffsetsTableHeader function from DwarfFile to
>>   DwarfStringPool, so I can generate the section header more easily from
>>   the unit test.
>> - added a new addAttribute overload taking an MCExpr*. This is used to
>>   generate the DW_AT_str_offsets_base, which links a compile unit to the
>>   offset table.
>>
>> I've also added a basic test for reading and writing DW_form_strx forms.
>>
>> Reviewers: dblaikie, JDevlieghere, probinson
>>
>> Subscribers: llvm-commits, aprantl
>>
>> Differential Revision: https://reviews.llvm.org/D49670
>>
>> Modified:
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
>>     llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
>>     llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>>     llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
>>     llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Wed Jul 25 08:33:32 2018
>> @@ -1506,8 +1506,9 @@ void DwarfDebug::emitAbbreviations() {
>>
>>  void DwarfDebug::emitStringOffsetsTableHeader() {
>>    DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
>> -  Holder.emitStringOffsetsTableHeader(
>> -      Asm->getObjFileLowering().getDwarfStrOffSection());
>> +  Holder.getStringPool().emitStringOffsetsTableHeader(
>> +      *Asm, Asm->getObjFileLowering().getDwarfStrOffSection(),
>> +      Holder.getStringOffsetsStartSym());
>>  }
>>
>>  template <typename AccelTableT>
>> @@ -2292,8 +2293,9 @@ void DwarfDebug::emitDebugLineDWO() {
>>
>>  void DwarfDebug::emitStringOffsetsTableHeaderDWO() {
>>    assert(useSplitDwarf() && "No split dwarf?");
>> -  InfoHolder.emitStringOffsetsTableHeader(
>> -      Asm->getObjFileLowering().getDwarfStrOffDWOSection());
>> +  InfoHolder.getStringPool().emitStringOffsetsTableHeader(
>> +      *Asm, Asm->getObjFileLowering().getDwarfStrOffDWOSection(),
>> +      InfoHolder.getStringOffsetsStartSym());
>>  }
>>
>>  // Emit the .debug_str.dwo section for separated dwarf. This contains the
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.cpp Wed Jul 25 08:33:32 2018
>> @@ -28,26 +28,6 @@ void DwarfFile::addUnit(std::unique_ptr<
>>    CUs.push_back(std::move(U));
>>  }
>>
>> -void DwarfFile::emitStringOffsetsTableHeader(MCSection *Section) {
>> -  if (StrPool.empty())
>> -    return;
>> -  Asm->OutStreamer->SwitchSection(Section);
>> -  unsigned EntrySize = 4;
>> -  // FIXME: DWARF64
>> -  // We are emitting the header for a contribution to the string offsets
>> -  // table. The header consists of an entry with the contribution's
>> -  // size (not including the size of the length field), the DWARF version and
>> -  // 2 bytes of padding.
>> -  Asm->emitInt32(StrPool.size() * EntrySize + 4);
>> -  Asm->emitInt16(Asm->getDwarfVersion());
>> -  Asm->emitInt16(0);
>> -  // Define the symbol that marks the start of the contribution. It is
>> -  // referenced by most unit headers via DW_AT_str_offsets_base.
>> -  // Split units do not use the attribute.
>> -  if (StringOffsetsStartSym)
>> -    Asm->OutStreamer->EmitLabel(StringOffsetsStartSym);
>> -}
>> -
>>  // Emit the various dwarf units to the unit section USection with
>>  // the abbreviations going into ASection.
>>  void DwarfFile::emitUnits(bool UseOffsets) {
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfFile.h Wed Jul 25 08:33:32 2018
>> @@ -91,9 +91,6 @@ public:
>>    /// Add a unit to the list of CUs.
>>    void addUnit(std::unique_ptr<DwarfCompileUnit> U);
>>
>> -  /// Emit the string table offsets header.
>> -  void emitStringOffsetsTableHeader(MCSection *Section);
>> -
>>    /// Emit all of the units to the section listed with the given
>>    /// abbreviation section.
>>    void emitUnits(bool UseOffsets);
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.cpp Wed Jul 25 08:33:32 2018
>> @@ -39,6 +39,28 @@ DwarfStringPool::EntryRef DwarfStringPoo
>>    return EntryRef(*I.first);
>>  }
>>
>> +void DwarfStringPool::emitStringOffsetsTableHeader(AsmPrinter &Asm,
>> +                                                   MCSection *Section,
>> +                                                   MCSymbol *StartSym) {
>> +  if (empty())
>> +    return;
>> +  Asm.OutStreamer->SwitchSection(Section);
>> +  unsigned EntrySize = 4;
>> +  // FIXME: DWARF64
>> +  // We are emitting the header for a contribution to the string offsets
>> +  // table. The header consists of an entry with the contribution's
>> +  // size (not including the size of the length field), the DWARF version and
>> +  // 2 bytes of padding.
>> +  Asm.emitInt32(size() * EntrySize + 4);
>> +  Asm.emitInt16(Asm.getDwarfVersion());
>> +  Asm.emitInt16(0);
>> +  // Define the symbol that marks the start of the contribution. It is
>> +  // referenced by most unit headers via DW_AT_str_offsets_base.
>> +  // Split units do not use the attribute.
>> +  if (StartSym)
>> +    Asm.OutStreamer->EmitLabel(StartSym);
>> +}
>> +
>>  void DwarfStringPool::emit(AsmPrinter &Asm, MCSection *StrSection,
>>                             MCSection *OffsetSection, bool UseRelativeOffsets) {
>>    if (Pool.empty())
>>
>> Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h (original)
>> +++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfStringPool.h Wed Jul 25 08:33:32 2018
>> @@ -19,6 +19,7 @@ namespace llvm {
>>
>>  class AsmPrinter;
>>  class MCSection;
>> +class MCSymbol;
>>
>>  // Collection of strings for this unit and assorted symbols.
>>  // A String->Symbol mapping of strings used by indirect
>> @@ -36,6 +37,9 @@ public:
>>
>>    DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
>>
>> +  void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection,
>> +                                    MCSymbol *StartSym);
>> +
>>    void emit(AsmPrinter &Asm, MCSection *StrSection,
>>              MCSection *OffsetSection = nullptr,
>>              bool UseRelativeOffsets = false);
>>
>> Modified: llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp (original)
>> +++ llvm/trunk/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp Wed Jul 25 08:33:32 2018
>> @@ -67,12 +67,23 @@ void TestAllForms() {
>>    const uint32_t Dwarf32Values[] = {1, 2, 3, 4, 5, 6, 7, 8};
>>    const char *StringValue = "Hello";
>>    const char *StrpValue = "World";
>> +  const char *StrxValue = "Indexed";
>> +  const char *Strx1Value = "Indexed1";
>> +  const char *Strx2Value = "Indexed2";
>> +  const char *Strx3Value = "Indexed3";
>> +  const char *Strx4Value = "Indexed4";
>>
>>    auto ExpectedDG = dwarfgen::Generator::create(Triple, Version);
>>    ASSERT_THAT_EXPECTED(ExpectedDG, Succeeded());
>>    dwarfgen::Generator *DG = ExpectedDG.get().get();
>>    dwarfgen::CompileUnit &CU = DG->addCompileUnit();
>>    dwarfgen::DIE CUDie = CU.getUnitDIE();
>> +
>> +  if (Version >= 5)
>> +    CUDie.addAttribute(dwarf::DW_AT_str_offsets_base, dwarf::DW_FORM_sec_offset,
>> +                       *MCSymbolRefExpr::create(DG->getStringOffsetsStartSym(),
>> +                                                *DG->getMCContext()));
>> +
>>    uint16_t Attr = DW_AT_lo_user;
>>
>>    //----------------------------------------------------------------------
>> @@ -122,6 +133,19 @@ void TestAllForms() {
>>    const auto Attr_DW_FORM_string = static_cast<dwarf::Attribute>(Attr++);
>>    CUDie.addAttribute(Attr_DW_FORM_string, DW_FORM_string, StringValue);
>>
>> +  const auto Attr_DW_FORM_strx = static_cast<dwarf::Attribute>(Attr++);
>> +  const auto Attr_DW_FORM_strx1 = static_cast<dwarf::Attribute>(Attr++);
>> +  const auto Attr_DW_FORM_strx2 = static_cast<dwarf::Attribute>(Attr++);
>> +  const auto Attr_DW_FORM_strx3 = static_cast<dwarf::Attribute>(Attr++);
>> +  const auto Attr_DW_FORM_strx4 = static_cast<dwarf::Attribute>(Attr++);
>> +  if (Version >= 5) {
>> +    CUDie.addAttribute(Attr_DW_FORM_strx, DW_FORM_strx, StrxValue);
>> +    CUDie.addAttribute(Attr_DW_FORM_strx1, DW_FORM_strx1, Strx1Value);
>> +    CUDie.addAttribute(Attr_DW_FORM_strx2, DW_FORM_strx2, Strx2Value);
>> +    CUDie.addAttribute(Attr_DW_FORM_strx3, DW_FORM_strx3, Strx3Value);
>> +    CUDie.addAttribute(Attr_DW_FORM_strx4, DW_FORM_strx4, Strx4Value);
>> +  }
>> +
>>    const auto Attr_DW_FORM_strp = static_cast<dwarf::Attribute>(Attr++);
>>    CUDie.addAttribute(Attr_DW_FORM_strp, DW_FORM_strp, StrpValue);
>>
>> @@ -281,11 +305,33 @@ void TestAllForms() {
>>    //----------------------------------------------------------------------
>>    auto ExtractedStringValue = toString(DieDG.find(Attr_DW_FORM_string));
>>    EXPECT_TRUE((bool)ExtractedStringValue);
>> -  EXPECT_TRUE(strcmp(StringValue, *ExtractedStringValue) == 0);
>> +  EXPECT_STREQ(StringValue, *ExtractedStringValue);
>> +
>> +  if (Version >= 5) {
>> +    auto ExtractedStrxValue = toString(DieDG.find(Attr_DW_FORM_strx));
>> +    EXPECT_TRUE((bool)ExtractedStrxValue);
>> +    EXPECT_STREQ(StrxValue, *ExtractedStrxValue);
>> +
>> +    auto ExtractedStrx1Value = toString(DieDG.find(Attr_DW_FORM_strx1));
>> +    EXPECT_TRUE((bool)ExtractedStrx1Value);
>> +    EXPECT_STREQ(Strx1Value, *ExtractedStrx1Value);
>> +
>> +    auto ExtractedStrx2Value = toString(DieDG.find(Attr_DW_FORM_strx2));
>> +    EXPECT_TRUE((bool)ExtractedStrx2Value);
>> +    EXPECT_STREQ(Strx2Value, *ExtractedStrx2Value);
>> +
>> +    auto ExtractedStrx3Value = toString(DieDG.find(Attr_DW_FORM_strx3));
>> +    EXPECT_TRUE((bool)ExtractedStrx3Value);
>> +    EXPECT_STREQ(Strx3Value, *ExtractedStrx3Value);
>> +
>> +    auto ExtractedStrx4Value = toString(DieDG.find(Attr_DW_FORM_strx4));
>> +    EXPECT_TRUE((bool)ExtractedStrx4Value);
>> +    EXPECT_STREQ(Strx4Value, *ExtractedStrx4Value);
>> +  }
>>
>>    auto ExtractedStrpValue = toString(DieDG.find(Attr_DW_FORM_strp));
>>    EXPECT_TRUE((bool)ExtractedStrpValue);
>> -  EXPECT_TRUE(strcmp(StrpValue, *ExtractedStrpValue) == 0);
>> +  EXPECT_STREQ(StrpValue, *ExtractedStrpValue);
>>
>>    //----------------------------------------------------------------------
>>    // Test reference forms
>>
>> Modified: llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp (original)
>> +++ llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp Wed Jul 25 08:33:32 2018
>> @@ -54,16 +54,36 @@ void dwarfgen::DIE::addAttribute(uint16_
>>  }
>>
>>  void dwarfgen::DIE::addAttribute(uint16_t A, dwarf::Form Form,
>> +                                 const MCExpr &Expr) {
>> +  auto &DG = CU->getGenerator();
>> +  Die->addValue(DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,
>> +                DIEExpr(&Expr));
>> +}
>> +
>> +void dwarfgen::DIE::addAttribute(uint16_t A, dwarf::Form Form,
>>                                   StringRef String) {
>>    auto &DG = CU->getGenerator();
>> -  if (Form == DW_FORM_string) {
>> +  switch (Form) {
>> +  case DW_FORM_string:
>>      Die->addValue(DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,
>>                    new (DG.getAllocator())
>>                        DIEInlineString(String, DG.getAllocator()));
>> -  } else {
>> +    break;
>> +
>> +  case DW_FORM_strp:
>> +  case DW_FORM_GNU_str_index:
>> +  case DW_FORM_strx:
>> +  case DW_FORM_strx1:
>> +  case DW_FORM_strx2:
>> +  case DW_FORM_strx3:
>> +  case DW_FORM_strx4:
>>      Die->addValue(
>>          DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,
>>          DIEString(DG.getStringPool().getEntry(*DG.getAsmPrinter(), String)));
>> +    break;
>> +
>> +  default:
>> +    llvm_unreachable("Unhandled form!");
>>    }
>>  }
>>
>> @@ -427,6 +447,7 @@ llvm::Error dwarfgen::Generator::init(Tr
>>    Asm->setDwarfVersion(Version);
>>
>>    StringPool = llvm::make_unique<DwarfStringPool>(Allocator, *Asm, StringRef());
>> +  StringOffsetsStartSym = Asm->createTempSymbol("str_offsets_base");
>>
>>    return Error::success();
>>  }
>> @@ -448,7 +469,12 @@ StringRef dwarfgen::Generator::generate(
>>      CU->setLength(CUOffset - 4);
>>    }
>>    Abbreviations.Emit(Asm.get(), MOFI->getDwarfAbbrevSection());
>> -  StringPool->emit(*Asm, MOFI->getDwarfStrSection());
>> +
>> +  StringPool->emitStringOffsetsTableHeader(*Asm, MOFI->getDwarfStrOffSection(),
>> +                                           StringOffsetsStartSym);
>> +  StringPool->emit(*Asm, MOFI->getDwarfStrSection(),
>> +                   MOFI->getDwarfStrOffSection());
>> +
>>    MS->SwitchSection(MOFI->getDwarfInfoSection());
>>    for (auto &CU : CompileUnits) {
>>      uint16_t Version = CU->getVersion();
>>
>> Modified: llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h?rev=337933&r1=337932&r2=337933&view=diff
>> ==============================================================================
>> --- llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h (original)
>> +++ llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.h Wed Jul 25 08:33:32 2018
>> @@ -89,6 +89,14 @@ public:
>>    /// \param U the unsigned integer to encode.
>>    void addAttribute(uint16_t Attr, dwarf::Form Form, uint64_t U);
>>
>> +  /// Add an attribute value to be encoded as a DIEExpr
>> +  ///
>> +  /// \param Attr a dwarf::Attribute enumeration value or any uint16_t that
>> +  /// represents a user defined DWARF attribute.
>> +  /// \param Form the dwarf::Form to use when encoding the attribute.
>> +  /// \param Expr the MC expression used to compute the value
>> +  void addAttribute(uint16_t Attr, dwarf::Form Form, const MCExpr &Expr);
>> +
>>    /// Add an attribute value to be encoded as a DIEString or DIEInlinedString.
>>    ///
>>    /// \param Attr a dwarf::Attribute enumeration value or any uint16_t that
>> @@ -242,6 +250,8 @@ class Generator {
>>    std::vector<std::unique_ptr<LineTable>> LineTables;
>>    DIEAbbrevSet Abbreviations;
>>
>> +  MCSymbol *StringOffsetsStartSym;
>> +
>>    SmallString<4096> FileBytes;
>>    /// The stream we use to generate the DWARF into as an ELF file.
>>    std::unique_ptr<raw_svector_ostream> Stream;
>> @@ -293,6 +303,7 @@ public:
>>    MCContext *getMCContext() const { return MC.get(); }
>>    DIEAbbrevSet &getAbbrevSet() { return Abbreviations; }
>>    DwarfStringPool &getStringPool() { return *StringPool; }
>> +  MCSymbol *getStringOffsetsStartSym() const { return StringOffsetsStartSym; }
>>
>>    /// Save the generated DWARF file to disk.
>>    ///
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>


More information about the llvm-commits mailing list