OSDN Git Service

[CodeGen/Dwarf] Make debug_names compatible with split-dwarf
authorPavel Labath <labath@google.com>
Wed, 18 Apr 2018 12:11:59 +0000 (12:11 +0000)
committerPavel Labath <labath@google.com>
Wed, 18 Apr 2018 12:11:59 +0000 (12:11 +0000)
Summary:
Previously we crashed for the combination of the two features because we
tried to reference the dwo CU from the main object file. The fix
consists of two items:
- reference the skeleton CU from the name index (the consumer is
  expected to use the skeleton CU to find the real data).
- use the main object file string pool for the strings in the index

Reviewers: JDevlieghere, aprantl, dblaikie

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D45566

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330249 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/AsmPrinter/AccelTable.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/CodeGen/AsmPrinter/DwarfDebug.h
test/DebugInfo/Generic/debug-names-one-cu.ll

index 1107e02..a1ae137 100644 (file)
@@ -416,7 +416,9 @@ void Dwarf5AccelTableEmitter::emitCUList() const {
   for (const auto &CU : enumerate(CompUnits)) {
     assert(CU.index() == CU.value()->getUniqueID());
     Asm->OutStreamer->AddComment("Compilation unit " + Twine(CU.index()));
-    Asm->emitDwarfSymbolReference(CU.value()->getLabelBegin());
+    const DwarfCompileUnit *MainCU =
+        DD.useSplitDwarf() ? CU.value()->getSkeleton() : CU.value().get();
+    Asm->emitDwarfSymbolReference(MainCU->getLabelBegin());
   }
 }
 
index 177a094..a8e36ec 100644 (file)
@@ -2267,6 +2267,13 @@ void DwarfDebug::addDwarfTypeUnitType(DwarfCompileUnit &CU,
   CU.addDIETypeSignature(RefDie, Signature);
 }
 
+void DwarfDebug::addAccelDebugName(StringRef Name, const DIE &Die) {
+  assert(getAccelTableKind() == AccelTableKind::Dwarf);
+
+  DwarfFile &Holder = useSplitDwarf() ? SkeletonHolder : InfoHolder;
+  AccelDebugNames.addName(Holder.getStringPool().getEntry(*Asm, Name), Die);
+}
+
 // Accelerator table mutators - add each name along with its companion
 // DIE to the proper table while ensuring that the name that we're going
 // to reference is in the string table. We do this since the names we
@@ -2277,8 +2284,7 @@ void DwarfDebug::addAccelName(StringRef Name, const DIE &Die) {
     AccelNames.addName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
     break;
   case AccelTableKind::Dwarf:
-    AccelDebugNames.addName(InfoHolder.getStringPool().getEntry(*Asm, Name),
-                            Die);
+    addAccelDebugName(Name, Die);
     break;
   case AccelTableKind::None:
     return;
@@ -2300,8 +2306,7 @@ void DwarfDebug::addAccelNamespace(StringRef Name, const DIE &Die) {
                            &Die);
     break;
   case AccelTableKind::Dwarf:
-    AccelDebugNames.addName(InfoHolder.getStringPool().getEntry(*Asm, Name),
-                            Die);
+    addAccelDebugName(Name, Die);
     break;
   case AccelTableKind::None:
     return;
@@ -2316,8 +2321,7 @@ void DwarfDebug::addAccelType(StringRef Name, const DIE &Die, char Flags) {
     AccelTypes.addName(InfoHolder.getStringPool().getEntry(*Asm, Name), &Die);
     break;
   case AccelTableKind::Dwarf:
-    AccelDebugNames.addName(InfoHolder.getStringPool().getEntry(*Asm, Name),
-                            Die);
+    addAccelDebugName(Name, Die);
     break;
   case AccelTableKind::None:
     return;
index bd248fd..f01d680 100644 (file)
@@ -339,6 +339,10 @@ class DwarfDebug : public DebugHandlerBase {
   /// Construct a DIE for this abstract scope.
   void constructAbstractSubprogramScopeDIE(DwarfCompileUnit &SrcCU, LexicalScope *Scope);
 
+  /// Helper function to add a name to the .debug_names table, using the
+  /// appropriate string pool.
+  void addAccelDebugName(StringRef Name, const DIE &Die);
+
   void finishVariableDefinitions();
 
   void finishSubprogramDefinitions();
index 69ea641..d9b9c8f 100644 (file)
@@ -3,6 +3,10 @@
 ; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
 ; RUN: llvm-dwarfdump -debug-names -verify %t | FileCheck --check-prefix=VERIFY %s
 
+; Now try the same with split dwarf.
+; RUN: %llc_dwarf -split-dwarf-file=foo.dwo -accel-tables=Dwarf -filetype=obj -o %t < %s
+; RUN: llvm-dwarfdump -debug-names %t | FileCheck %s
+
 ; Check the header
 ; CHECK: CU count: 1
 ; CHECK: Local TU count: 0