[llvm] c8ae089 - [llvm-dwarfdump] dump link to the immediate parent.

Alexey Lapshin via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 03:14:22 PST 2021


Author: Alexey Lapshin
Date: 2021-11-09T14:14:06+03:00
New Revision: c8ae08987db2db5ff26a094b963e126e90a922dc

URL: https://github.com/llvm/llvm-project/commit/c8ae08987db2db5ff26a094b963e126e90a922dc
DIFF: https://github.com/llvm/llvm-project/commit/c8ae08987db2db5ff26a094b963e126e90a922dc.diff

LOG: [llvm-dwarfdump] dump link to the immediate parent.

It is often useful to know which die is the parent of the current die.
This patch adds information about parent offset into the dump:

0x0000000b: DW_TAG_compile_unit
              DW_AT_producer    ("by_hand")

0x00000014:   DW_TAG_base_type (0x0000000b)  <<<<<<<<<<<<<<
                DW_AT_name      ("int")

Now it is easy to see which die is the parent of the current die.
This patch makes that behaviour to be default.
We can make it to be opt-in if neccessary.

This functionality differs from already existed "--show-parents"
in that sence that parent information is shown for all dies and
only link to the immediate parent is shown.

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

Added: 
    llvm/test/tools/llvm-dwarfdump/X86/tag-parent-offset.yaml

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
    llvm/test/tools/llvm-dwarfdump/X86/verbose.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
index b24894c43c3a2..7caf678e8ad1c 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
@@ -1080,9 +1080,13 @@ void DWARFDie::dump(raw_ostream &OS, unsigned Indent,
       if (AbbrevDecl) {
         WithColor(OS, HighlightColor::Tag).get().indent(Indent)
             << formatv("{0}", getTag());
-        if (DumpOpts.Verbose)
+        if (DumpOpts.Verbose) {
           OS << format(" [%u] %c", abbrCode,
                        AbbrevDecl->hasChildren() ? '*' : ' ');
+          if (Optional<uint32_t> ParentIdx = Die->getParentIdx())
+            OS << format(" (0x%8.8" PRIx64 ")",
+                         U->getDIEAtIndex(*ParentIdx).getOffset());
+        }
         OS << '\n';
 
         // Dump all data in the DIE for the attributes.

diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/tag-parent-offset.yaml b/llvm/test/tools/llvm-dwarfdump/X86/tag-parent-offset.yaml
new file mode 100644
index 0000000000000..b2516cd4e729b
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/X86/tag-parent-offset.yaml
@@ -0,0 +1,49 @@
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-dwarfdump -v -a %t.o | FileCheck %s
+
+## This test checks that llvm-dwarfdump prints link
+## to the parent of the current die:
+
+## DW_TAG_base_type [3] (0x00000014) <<<<<
+
+# CHECK: .o: file format
+# CHECK: 0x0000000b: DW_TAG_compile_unit
+# CHECK: 0x00000014:   DW_TAG_namespace [2] * (0x0000000b)
+# CHECK: DW_TAG_base_type [3] (0x00000014)
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+  Machine: EM_X86_64
+DWARF:
+  debug_abbrev:
+    - Table:
+      - Tag:      DW_TAG_compile_unit
+        Children: DW_CHILDREN_yes
+        Attributes:
+          - Attribute: DW_AT_producer
+            Form:      DW_FORM_string
+      - Tag:      DW_TAG_namespace
+        Children: DW_CHILDREN_yes
+        Attributes:
+          - Attribute: DW_AT_name
+            Form:      DW_FORM_string
+      - Tag:      DW_TAG_base_type
+        Children: DW_CHILDREN_no
+        Attributes:
+          - Attribute: DW_AT_name
+            Form:      DW_FORM_string
+  debug_info:
+    - Version: 4
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - CStr: by_hand
+        - AbbrCode: 2
+          Values:
+            - CStr: name 
+        - AbbrCode: 3
+          Values:
+            - CStr: int

diff  --git a/llvm/test/tools/llvm-dwarfdump/X86/verbose.test b/llvm/test/tools/llvm-dwarfdump/X86/verbose.test
index 253e9fae1e519..c2fde6b873232 100644
--- a/llvm/test/tools/llvm-dwarfdump/X86/verbose.test
+++ b/llvm/test/tools/llvm-dwarfdump/X86/verbose.test
@@ -7,9 +7,9 @@
 #       CHECK:.debug_info contents:
 #       CHECK:0x0000000b: DW_TAG_compile_unit [1] *
 #       CHECK:              DW_AT_name [DW_FORM_strp]	( .debug_str[0x{{.*}}] = "brief.c")
-#       CHECK:0x0000002a:   DW_TAG_subprogram [2]  
+#       CHECK:0x0000002a:   DW_TAG_subprogram [2]   (0x0000000b)
 #       CHECK:                DW_AT_name [DW_FORM_strp]	( .debug_str[0x{{.*}}] = "main")
-#       CHECK:0x00000043:   DW_TAG_base_type [3]  
+#       CHECK:0x00000043:   DW_TAG_base_type [3]   (0x0000000b)
 #  CHECK-NEXT:                DW_AT_name [DW_FORM_strp]	( .debug_str[0x{{.*}}] = "int")
 
 #       CHECK:.debug_line contents:


        


More information about the llvm-commits mailing list