DebugInfo: llvm-dwarfdump support for gnu_pubnames section
authorDavid Blaikie <dblaikie@gmail.com>
Thu, 19 Sep 2013 23:01:29 +0000 (23:01 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Thu, 19 Sep 2013 23:01:29 +0000 (23:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191050 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/DebugInfo/DIContext.h
include/llvm/Support/Dwarf.h
lib/CodeGen/AsmPrinter/DwarfDebug.cpp
lib/DebugInfo/DWARFContext.cpp
lib/DebugInfo/DWARFContext.h
test/DebugInfo/X86/gnu-public-names.ll

index 4bb7c774389a62ecf3da86a7aaa6546c9dbd2e02..ab0fca58ecd47e946c53fd489f2a3779d46c736d 100644 (file)
@@ -109,6 +109,7 @@ enum DIDumpType {
   DIDT_Loc,
   DIDT_Ranges,
   DIDT_Pubnames,
+  DIDT_GnuPubnames,
   DIDT_Str,
   DIDT_StrDwo,
   DIDT_StrOffsetsDwo
index 30f268c6519a01e21083193fc89cb97681adb252..7b87c6a90d0346d33af1c8fbb4514fee1fbaf993 100644 (file)
@@ -821,19 +821,18 @@ StringRef GDBIndexEntryLinkageString(GDBIndexEntryLinkage Linkage);
 /// offset of the cu within the debug_info section stored in those 24 bits.
 struct PubIndexEntryDescriptor {
   GDBIndexEntryKind Kind;
-  GDBIndexEntryLinkage Static;
-  PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Static)
-      : Kind(Kind), Static(Static) {}
+  GDBIndexEntryLinkage Linkage;
+  PubIndexEntryDescriptor(GDBIndexEntryKind Kind, GDBIndexEntryLinkage Linkage)
+      : Kind(Kind), Linkage(Linkage) {}
   /* implicit */ PubIndexEntryDescriptor(GDBIndexEntryKind Kind)
-      : Kind(Kind), Static(GIEL_EXTERNAL) {}
+      : Kind(Kind), Linkage(GIEL_EXTERNAL) {}
   explicit PubIndexEntryDescriptor(uint8_t Value)
       : Kind(static_cast<GDBIndexEntryKind>((Value & KIND_MASK) >>
                                             KIND_OFFSET)),
-        Static(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
-                                                 LINKAGE_OFFSET)) {}
-  uint8_t toBits() {
-    return Kind << KIND_OFFSET | Static << LINKAGE_OFFSET;
-  }
+        Linkage(static_cast<GDBIndexEntryLinkage>((Value & LINKAGE_MASK) >>
+                                                  LINKAGE_OFFSET)) {}
+  uint8_t toBits() { return Kind << KIND_OFFSET | Linkage << LINKAGE_OFFSET; }
+
 private:
   enum {
     KIND_OFFSET = 4,
index a5b5905f3b1a393dce9615331620154f2171cd98..a8ebf45e6e95c3d73c6ca98556b1f849fd772a1c 100644 (file)
@@ -2404,7 +2404,7 @@ void DwarfDebug::emitDebugPubNames(bool GnuStyle) {
         dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheCU, Entity);
         Asm->OutStreamer.AddComment(
             "Kind: " + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " +
-            dwarf::GDBIndexEntryLinkageString(Desc.Static));
+            dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
         Asm->EmitInt8(Desc.toBits());
       }
 
@@ -2466,7 +2466,7 @@ void DwarfDebug::emitDebugPubTypes(bool GnuStyle) {
         dwarf::PubIndexEntryDescriptor Desc = computeIndexValue(TheCU, Entity);
         Asm->OutStreamer.AddComment(
             "Kind: " + dwarf::GDBIndexEntryKindString(Desc.Kind) + ", " +
-            dwarf::GDBIndexEntryLinkageString(Desc.Static));
+            dwarf::GDBIndexEntryLinkageString(Desc.Linkage));
         Asm->EmitInt8(Desc.toBits());
       }
 
index baf2bb5b577289b656aa8d6b1017433ee53a26d3..c87855e530b83169cf57e3cf75ac124a3dceeaa3 100644 (file)
@@ -120,6 +120,27 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) {
     }
   }
 
+  if (DumpType == DIDT_All || DumpType == DIDT_GnuPubnames) {
+    OS << "\n.debug_gnu_pubnames contents:\n";
+    DataExtractor pubNames(getGnuPubNamesSection(), isLittleEndian(), 0);
+    offset = 0;
+    OS << "Length:                " << pubNames.getU32(&offset) << "\n";
+    OS << "Version:               " << pubNames.getU16(&offset) << "\n";
+    OS << "Offset in .debug_info: " << pubNames.getU32(&offset) << "\n";
+    OS << "Size:                  " << pubNames.getU32(&offset) << "\n";
+    OS << "Offset     Linkage  Kind    Name\n";
+    while (offset < getGnuPubNamesSection().size()) {
+      uint32_t dieRef = pubNames.getU32(&offset);
+      if (dieRef == 0)
+        break;
+      PubIndexEntryDescriptor desc(pubNames.getU8(&offset));
+      OS << format("0x%8.8x ", dieRef)
+         << format("%-8s", dwarf::GDBIndexEntryLinkageString(desc.Linkage))
+         << ' ' << dwarf::GDBIndexEntryKindString(desc.Kind) << ' '
+         << pubNames.getCStr(&offset) << "\n";
+    }
+  }
+
   if (DumpType == DIDT_All || DumpType == DIDT_AbbrevDwo) {
     const DWARFDebugAbbrev *D = getDebugAbbrevDWO();
     if (D) {
@@ -566,6 +587,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) :
         .Case("debug_str", &StringSection)
         .Case("debug_ranges", &RangeSection)
         .Case("debug_pubnames", &PubNamesSection)
+        .Case("debug_gnu_pubnames", &GnuPubNamesSection)
         .Case("debug_info.dwo", &InfoDWOSection)
         .Case("debug_abbrev.dwo", &AbbrevDWOSection)
         .Case("debug_str.dwo", &StringDWOSection)
index c491b4ca492b633e1c9faf3a197e46033076787f..e4b640e4c90fb0b5a9802800605308c4f55ed1e4 100644 (file)
@@ -125,6 +125,7 @@ public:
   virtual StringRef getStringSection() = 0;
   virtual StringRef getRangeSection() = 0;
   virtual StringRef getPubNamesSection() = 0;
+  virtual StringRef getGnuPubNamesSection() = 0;
 
   // Sections for DWARF5 split dwarf proposal.
   virtual StringRef getInfoDWOSection() = 0;
@@ -166,6 +167,7 @@ class DWARFContextInMemory : public DWARFContext {
   StringRef StringSection;
   StringRef RangeSection;
   StringRef PubNamesSection;
+  StringRef GnuPubNamesSection;
 
   // Sections for DWARF5 split dwarf proposal.
   RelocAddrMap InfoDWORelocMap;
@@ -195,6 +197,7 @@ public:
   virtual StringRef getStringSection() { return StringSection; }
   virtual StringRef getRangeSection() { return RangeSection; }
   virtual StringRef getPubNamesSection() { return PubNamesSection; }
+  virtual StringRef getGnuPubNamesSection() { return GnuPubNamesSection; }
 
   // Sections for DWARF5 split dwarf proposal.
   virtual StringRef getInfoDWOSection() { return InfoDWOSection; }
index 19dd5b571261c936dfcede69eb39345bc6035517..9d4e6b609aefa1fd34691dd6716bbcbbc9c55418 100644 (file)
@@ -1,4 +1,5 @@
-; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections -o - %s | FileCheck %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections < %s | FileCheck -check-prefix=ASM %s
+; RUN: llc -mtriple=x86_64-pc-linux-gnu -generate-gnu-dwarf-pub-sections -filetype=obj < %s | llvm-dwarfdump - | FileCheck %s
 ; ModuleID = 'dwarf-public-names.cpp'
 ;
 ; Generated from:
 ; }
 
 
-; CHECK: .byte   32                      # Kind: VARIABLE, EXTERNAL
-; CHECK-NEXT: .asciz   "global_namespace_variable" # External Name
-; CHECK: .byte   48                      # Kind: FUNCTION, EXTERNAL
-; CHECK-NEXT: .asciz   "global_namespace_function" # External Name
-; CHECK: .byte   176                     # Kind: FUNCTION, STATIC
-; CHECK-NEXT: .asciz   "static_member_function" # External Name
-; CHECK: .byte   32                      # Kind: VARIABLE, EXTERNAL
-; CHECK-NEXT: .asciz   "global_variable"      # External Name
-; CHECK: .byte   48                      # Kind: FUNCTION, EXTERNAL
-; CHECK-NEXT: .asciz   "global_function"      # External Name
-; CHECK: .byte   176                     # Kind: FUNCTION, STATIC
-; CHECK-NEXT: .asciz   "member_function"      # External Name
+; ASM: .byte   32                      # Kind: VARIABLE, EXTERNAL
+
+; CHECK: .debug_gnu_pubnames contents:
+; CHECK-NEXT: Length:   167
+; CHECK-NEXT: Version:  2
+; CHECK-NEXT: Offset in .debug_info: 0
+; CHECK-NEXT: Size:     317
+; CHECK-NEXT: Offset     Linkage  Kind     Name
+; CHECK-DAG:  0x00000094 EXTERNAL VARIABLE global_namespace_variable
+; CHECK-DAG:  0x000000a3 EXTERNAL FUNCTION global_namespace_function
+; CHECK-DAG:  0x000000e8 STATIC   FUNCTION static_member_function
+; CHECK-DAG:  0x0000007c EXTERNAL VARIABLE global_variable
+; CHECK-DAG:  0x000000ff EXTERNAL FUNCTION global_function
+; CHECK-DAG:  0x000000be STATIC   FUNCTION member_function
 
 %struct.C = type { i8 }