[llvm] r337544 - [DebugInfo] Generate .debug_names section when it makes sense

Pavel Labath via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 20 05:59:06 PDT 2018


Author: labath
Date: Fri Jul 20 05:59:05 2018
New Revision: 337544

URL: http://llvm.org/viewvc/llvm-project?rev=337544&view=rev
Log:
[DebugInfo] Generate .debug_names section when it makes sense

Summary:
This patch makes us generate the debug_names section in response to some
user-facing commands (previously it was only generated if explicitly
selected via the -accel-tables option).

My goal was to make this work for DWARF>=5 (as it's an official part of
that standard), and also, as an extension, for DWARF<5 if one is
explicitly tuning for lldb as a debugger (because it brings a large
performance improvement there).

This is slightly complicated by the fact that the debug_names tables are
incompatible with the DWARF v4 type units (they assume that the type
units are in the debug_info section), and unfortunately, right now we
generate DWARF v4-style type units even for -gdwarf-5. For this reason,
I disable all accelerator tables if the user requested type unit
generation. I do this even for apple tables, as they have the same
problem (in fact generating type units for apple targets makes us crash
even before we get around to emitting the accelerator tables).

Reviewers: JDevlieghere, aprantl, dblaikie, echristo, probinson

Subscribers: llvm-commits

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

Added:
    llvm/trunk/test/DebugInfo/X86/accel-tables-dwarf5.ll
Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
    llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/trunk/test/DebugInfo/X86/accel-tables.ll
    llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp?rev=337544&r1=337543&r2=337544&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.cpp Fri Jul 20 05:59:05 2018
@@ -94,6 +94,11 @@ static cl::opt<bool> GenerateARangeSecti
                                            cl::desc("Generate dwarf aranges"),
                                            cl::init(false));
 
+static cl::opt<bool>
+    GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
+                           cl::desc("Generate DWARF4 type units."),
+                           cl::init(false));
+
 static cl::opt<bool> SplitDwarfCrossCuReferences(
     "split-dwarf-cross-cu-references", cl::Hidden,
     cl::desc("Enable cross-cu references in DWO files"), cl::init(false));
@@ -284,6 +289,29 @@ void DbgVariable::addMMIEntry(const DbgV
          "conflicting locations for variable");
 }
 
+static AccelTableKind computeAccelTableKind(unsigned DwarfVersion,
+                                            bool GenerateTypeUnits,
+                                            DebuggerKind Tuning,
+                                            const Triple &TT) {
+  // Honor an explicit request.
+  if (AccelTables != AccelTableKind::Default)
+    return AccelTables;
+
+  // Accelerator tables with type units are currently not supported.
+  if (GenerateTypeUnits)
+    return AccelTableKind::None;
+
+  // Accelerator tables get emitted if targetting DWARF v5 or LLDB.  DWARF v5
+  // always implies debug_names. For lower standard versions we use apple
+  // accelerator tables on apple platforms and debug_names elsewhere.
+  if (DwarfVersion >= 5)
+    return AccelTableKind::Dwarf;
+  if (Tuning == DebuggerKind::LLDB)
+    return TT.isOSBinFormatMachO() ? AccelTableKind::Apple
+                                   : AccelTableKind::Dwarf;
+  return AccelTableKind::None;
+}
+
 DwarfDebug::DwarfDebug(AsmPrinter *A, Module *M)
     : DebugHandlerBase(A), DebugLocs(A->OutStreamer->isVerboseAsm()),
       InfoHolder(A, "info_string", DIEValueAllocator),
@@ -302,16 +330,6 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
   else
     DebuggerTuning = DebuggerKind::GDB;
 
-  // Turn on accelerator tables by default, if tuning for LLDB and the target is
-  // supported.
-  if (AccelTables == AccelTableKind::Default) {
-    if (tuneForLLDB() && A->TM.getTargetTriple().isOSBinFormatMachO())
-      TheAccelTableKind = AccelTableKind::Apple;
-    else
-      TheAccelTableKind = AccelTableKind::None;
-  } else
-    TheAccelTableKind = AccelTables;
-
   if (DwarfInlinedStrings == Default)
     UseInlineStrings = TT.isNVPTX();
   else
@@ -346,6 +364,11 @@ DwarfDebug::DwarfDebug(AsmPrinter *A, Mo
   else
     UseSectionsAsReferences = DwarfSectionsAsReferences == Enable;
 
+  GenerateTypeUnits = GenerateDwarfTypeUnits;
+
+  TheAccelTableKind = computeAccelTableKind(
+      DwarfVersion, GenerateTypeUnits, DebuggerTuning, A->TM.getTargetTriple());
+
   // Work around a GDB bug. GDB doesn't support the standard opcode;
   // SCE doesn't support GNU's; LLDB prefers the standard opcode, which
   // is defined as of DWARF 3.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h?rev=337544&r1=337543&r2=337544&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfDebug.h Fri Jul 20 05:59:05 2018
@@ -279,6 +279,9 @@ class DwarfDebug : public DebugHandlerBa
   ///Allow emission of the .debug_loc section.
   bool UseLocSection = true;
 
+  /// Generate DWARF v4 type units.
+  bool GenerateTypeUnits;
+
   /// DWARF5 Experimental Options
   /// @{
   AccelTableKind TheAccelTableKind;
@@ -546,6 +549,9 @@ public:
   /// Returns whether .debug_loc section should be emitted.
   bool useLocSection() const { return UseLocSection; }
 
+  /// Returns whether to generate DWARF v4 type units.
+  bool generateTypeUnits() const { return GenerateTypeUnits; }
+
   // Experimental DWARF5 features.
 
   /// Returns what kind (if any) of accelerator tables to emit.

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp?rev=337544&r1=337543&r2=337544&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DwarfUnit.cpp Fri Jul 20 05:59:05 2018
@@ -47,11 +47,6 @@ using namespace llvm;
 
 #define DEBUG_TYPE "dwarfdebug"
 
-static cl::opt<bool>
-GenerateDwarfTypeUnits("generate-type-units", cl::Hidden,
-                       cl::desc("Generate DWARF4 type units."),
-                       cl::init(false));
-
 DIEDwarfExpression::DIEDwarfExpression(const AsmPrinter &AP, DwarfUnit &DU,
                                        DIELoc &DIE)
     : DwarfExpression(AP.getDwarfVersion()), AP(AP), DU(DU),
@@ -185,7 +180,7 @@ bool DwarfUnit::isShareableAcrossCUs(con
     return false;
   return (isa<DIType>(D) ||
           (isa<DISubprogram>(D) && !cast<DISubprogram>(D)->isDefinition())) &&
-         !GenerateDwarfTypeUnits;
+         !DD->generateTypeUnits();
 }
 
 DIE *DwarfUnit::getDIE(const DINode *D) const {
@@ -768,7 +763,7 @@ DIE *DwarfUnit::getOrCreateTypeDIE(const
   else if (auto *STy = dyn_cast<DISubroutineType>(Ty))
     constructTypeDIE(TyDIE, STy);
   else if (auto *CTy = dyn_cast<DICompositeType>(Ty)) {
-    if (GenerateDwarfTypeUnits && !Ty->isForwardDecl())
+    if (DD->generateTypeUnits() && !Ty->isForwardDecl())
       if (MDString *TypeId = CTy->getRawIdentifier()) {
         DD->addDwarfTypeUnitType(getCU(), TypeId->getString(), TyDIE, CTy);
         // Skip updating the accelerator tables since this is not the full type.

Added: llvm/trunk/test/DebugInfo/X86/accel-tables-dwarf5.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/accel-tables-dwarf5.ll?rev=337544&view=auto
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/accel-tables-dwarf5.ll (added)
+++ llvm/trunk/test/DebugInfo/X86/accel-tables-dwarf5.ll Fri Jul 20 05:59:05 2018
@@ -0,0 +1,46 @@
+; Verify the emission of accelerator tables for the DWARF v5 case.
+
+; debug_names should be emitted regardless of the target and debugger tuning
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj -debugger-tune=gdb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -debugger-tune=lldb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+
+; But not if also type units are enabled.
+; TODO: This is the case because we currently don't generate DWARF v5-compatible
+; type units. Change this once DWARF v5 type units are implemented.
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -generate-type-units -debugger-tune=lldb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+; RUN: llc -mtriple=x86_64-apple-darwin12 -generate-type-units -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+
+; NONE-NOT: apple_names
+; NONE-NOT: debug_names
+
+; DEBUG_NAMES-NOT: apple_names
+; DEBUG_NAMES: debug_names
+; DEBUG_NAMES-NOT: apple_names
+
+
+ at x = common dso_local global i32 0, align 4, !dbg !0
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!8, !9, !10}
+!llvm.ident = !{!11}
+
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
+!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !6, line: 1, type: !7, isLocal: false, isDefinition: true)
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 337260) (llvm/trunk 337262)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "-", directory: "/tmp", checksumkind: CSK_MD5, checksum: "06c25fe0c80b8959051a62f8f034710a")
+!4 = !{}
+!5 = !{!0}
+!6 = !DIFile(filename: "<stdin>", directory: "/tmp", checksumkind: CSK_MD5, checksum: "06c25fe0c80b8959051a62f8f034710a")
+!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!8 = !{i32 2, !"Dwarf Version", i32 5}
+!9 = !{i32 2, !"Debug Info Version", i32 3}
+!10 = !{i32 1, !"wchar_size", i32 4}
+!11 = !{!"clang version 7.0.0 (trunk 337260) (llvm/trunk 337262)"}

Modified: llvm/trunk/test/DebugInfo/X86/accel-tables.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/accel-tables.ll?rev=337544&r1=337543&r2=337544&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/accel-tables.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/accel-tables.ll Fri Jul 20 05:59:05 2018
@@ -1,16 +1,34 @@
-; Verify the emission of accelerator tables for various targets.
+; Verify the emission of accelerator tables for various targets for the DWARF<=4 case
 
-; Darwin has the tables unless we specifically tune for gdb
-; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj < %s | llvm-readobj -sections - | FileCheck --check-prefix=CHECK1 %s
-; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj -debugger-tune=gdb < %s | llvm-readobj -sections - | FileCheck --check-prefix=CHECK2 %s
-
-; Linux does not have the tables even if we explicitly tune for lldb
-; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj < %s | llvm-readobj -sections - | FileCheck --check-prefix=CHECK2 %s
-; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -debugger-tune=lldb < %s | llvm-readobj -sections - | FileCheck --check-prefix=CHECK2 %s
-
-; CHECK1: apple_names
-
-; CHECK2-NOT: apple_names
+; Darwin has the apple tables unless we specifically tune for gdb
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=APPLE %s
+; RUN: llc -mtriple=x86_64-apple-darwin12 -filetype=obj -debugger-tune=gdb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+
+; Linux does has debug_names tables only if we explicitly tune for lldb
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -debugger-tune=lldb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=DEBUG_NAMES %s
+
+; Neither target has accelerator tables if type units are enabled, as DWARF v4
+; type units are not compatible with accelerator tables.
+; RUN: llc -mtriple=x86_64-pc-linux -filetype=obj -generate-type-units -debugger-tune=lldb < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+; RUN: llc -mtriple=x86_64-apple-darwin12 -generate-type-units -filetype=obj < %s \
+; RUN:   | llvm-readobj -sections - | FileCheck --check-prefix=NONE %s
+
+; APPLE-NOT: debug_names
+; APPLE: apple_names
+; APPLE-NOT: debug_names
+
+; NONE-NOT: apple_names
+; NONE-NOT: debug_names
+
+; DEBUG_NAMES-NOT: apple_names
+; DEBUG_NAMES: debug_names
+; DEBUG_NAMES-NOT: apple_names
 
 @var = thread_local global i32 0, align 4, !dbg !0
 

Modified: llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll?rev=337544&r1=337543&r2=337544&view=diff
==============================================================================
--- llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll (original)
+++ llvm/trunk/test/DebugInfo/X86/string-offsets-table.ll Fri Jul 20 05:59:05 2018
@@ -81,6 +81,8 @@
 ; SPLIT:      .debug_str contents:
 ; SPLIT-NEXT: 0x00000000:{{.*}}
 ; SPLIT-NEXT: 0x[[STRING2SPLIT:[0-9a-f]*]]{{.*}}
+; SPLIT-NEXT: 0x[[STRING3SPLIT:[0-9a-f]*]]{{.*}}
+; SPLIT-NEXT: 0x[[STRING4SPLIT:[0-9a-f]*]]{{.*}}
 ;
 ; Extract the string offsets referenced in the .dwo file by the split unit.
 ; SPLIT:      .debug_str.dwo contents:
@@ -91,9 +93,11 @@
 ; Check the string offsets sections in both the main and the .dwo files and
 ; verify that the extracted string offsets are referenced correctly.
 ; SPLIT:      .debug_str_offsets contents:
-; SPLIT-NEXT: 0x00000000: Contribution size = 12, Format = DWARF32, Version = 5
+; SPLIT-NEXT: 0x00000000: Contribution size = 20, Format = DWARF32, Version = 5
 ; SPLIT-NEXT: 0x00000008: 00000000{{.*}}
 ; SPLIT-NEXT: 0x0000000c: [[STRING2SPLIT]]
+; SPLIT-NEXT: 0x00000010: [[STRING3SPLIT]]
+; SPLIT-NEXT: 0x00000014: [[STRING4SPLIT]]
 ; SPLIT:      .debug_str_offsets.dwo contents:
 ; SPLIT-NEXT: 0x00000000: Contribution size = 36, Format = DWARF32, Version = 5
 ; SPLIT-NEXT: 0x00000008: 00000000{{.*}}




More information about the llvm-commits mailing list