[llvm] [obj2yaml] Add support for ELF .debug_info and .debug_abbrev (PR #91193)

Andrew Savonichev via llvm-commits llvm-commits at lists.llvm.org
Tue May 7 02:18:57 PDT 2024


https://github.com/asavonic updated https://github.com/llvm/llvm-project/pull/91193

>From d41616a156ae3f4da7d9c7256f3be2c0f470c56b Mon Sep 17 00:00:00 2001
From: Andrew Savonichev <andrew.savonichev at gmail.com>
Date: Mon, 22 Apr 2024 13:08:48 +0900
Subject: [PATCH] [obj2yaml] Add support for ELF .debug_info and .debug_abbrev

Support for these DWARF sections was already in obj2yaml for MachO,
but not enabled for ELF.
---
 llvm/test/MC/AsmParser/directive_file-3.s     |   3 +-
 .../obj2yaml/ELF/DWARF/debug-info-abbrev.yaml | 121 ++++++++++++++++++
 llvm/tools/obj2yaml/elf2yaml.cpp              |   4 +
 3 files changed, 127 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/tools/obj2yaml/ELF/DWARF/debug-info-abbrev.yaml

diff --git a/llvm/test/MC/AsmParser/directive_file-3.s b/llvm/test/MC/AsmParser/directive_file-3.s
index c3bdaede27058..530d937150754 100644
--- a/llvm/test/MC/AsmParser/directive_file-3.s
+++ b/llvm/test/MC/AsmParser/directive_file-3.s
@@ -18,7 +18,8 @@ f1:
 
 // CHECK-DEBUG:  Sections:
 // CHECK-DEBUG:  - Name:            .text
-// CHECK-DEBUG:  - Name:            .debug_info
 // CHECK-DEBUG:  - Name:            .rel.debug_info
 // CHECK-DEBUG:    Info:            .debug_info
 // CHECK-DEBUG:  Symbols:
+// CHECK-DEBUG:  DWARF:
+// CHECK-DEBUG:    debug_info:
diff --git a/llvm/test/tools/obj2yaml/ELF/DWARF/debug-info-abbrev.yaml b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-info-abbrev.yaml
new file mode 100644
index 0000000000000..fda6c5a640049
--- /dev/null
+++ b/llvm/test/tools/obj2yaml/ELF/DWARF/debug-info-abbrev.yaml
@@ -0,0 +1,121 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+
+# CHECK:  debug_abbrev:
+# CHECK:    - ID:              0
+# CHECK:      Table:
+# CHECK:        - Code:            0x1
+# CHECK:          Tag:             DW_TAG_compile_unit
+# CHECK:          Children:        DW_CHILDREN_no
+# CHECK:          Attributes:
+# CHECK:            - Attribute:       DW_AT_low_pc
+# CHECK:              Form:            DW_FORM_addr
+# CHECK:    - ID:              1
+# CHECK:      Table:
+# CHECK:        - Code:            0x1
+# CHECK:          Tag:             DW_TAG_compile_unit
+# CHECK:          Children:        DW_CHILDREN_no
+# CHECK:          Attributes:
+# CHECK:            - Attribute:       DW_AT_low_pc
+# CHECK:              Form:            DW_FORM_data4
+# CHECK:    - ID:              2
+# CHECK:      Table:
+# CHECK:        - Code:            0x1
+# CHECK:          Tag:             DW_TAG_compile_unit
+# CHECK:          Children:        DW_CHILDREN_no
+# CHECK:          Attributes:
+# CHECK:            - Attribute:       DW_AT_low_pc
+# CHECK:              Form:            DW_FORM_udata
+#
+# CHECK:  debug_info:
+# CHECK:    - Length:          0xC
+# CHECK:      Version:         4
+# CHECK:      AbbrevTableID:   1
+# CHECK:      AbbrOffset:      0x8
+# CHECK:      AddrSize:        8
+# CHECK:      Entries:
+# CHECK:        - AbbrCode:        0x1
+# CHECK:          Values:
+# CHECK:            - Value:           0x1234
+# CHECK:    - Length:          0xC
+# CHECK:      Version:         4
+# CHECK:      AbbrevTableID:   1
+# CHECK:      AbbrOffset:      0x8
+# CHECK:      AddrSize:        8
+# CHECK:      Entries:
+# CHECK:        - AbbrCode:        0x1
+# CHECK:          Values:
+# CHECK:            - Value:           0x4321
+# CHECK:    - Length:          0x10
+# CHECK:      Version:         4
+# CHECK:      AbbrevTableID:   0
+# CHECK:      AbbrOffset:      0x0
+# CHECK:      AddrSize:        8
+# CHECK:      Entries:
+# CHECK:        - AbbrCode:        0x1
+# CHECK:          Values:
+# CHECK:            - Value:           0x5678
+# CHECK:    - Length:          0xB
+# CHECK:      Version:         4
+# CHECK:      AbbrevTableID:   2
+# CHECK:      AbbrOffset:      0x10
+# CHECK:      AddrSize:        8
+# CHECK:      Entries:
+# CHECK:        - AbbrCode:        0x1
+# CHECK:          Values:
+# CHECK:            - Value:           0x8765
+
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:    ELFDATA2LSB
+  Type:    ET_EXEC
+DWARF:
+  debug_abbrev:
+    - Table:
+        - Code:     1
+          Tag:      DW_TAG_compile_unit
+          Children: DW_CHILDREN_no
+          Attributes:
+            - Attribute: DW_AT_low_pc
+              Form:      DW_FORM_addr
+    - ID: 2
+      Table:
+        - Code:     1
+          Tag:      DW_TAG_compile_unit
+          Children: DW_CHILDREN_no
+          Attributes:
+            - Attribute: DW_AT_low_pc
+              Form:      DW_FORM_data4
+    - ID: 1
+      Table:
+        - Code:     1
+          Tag:      DW_TAG_compile_unit
+          Children: DW_CHILDREN_no
+          Attributes:
+            - Attribute: DW_AT_low_pc
+              Form:      DW_FORM_udata
+  debug_info:
+    - Version:       4
+      AbbrevTableID: 2
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - Value: 0x1234
+    - Version:       4
+      AbbrevTableID: 2
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - Value: 0x4321
+    - Version:       4
+      AbbrevTableID: 0
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - Value: 0x5678
+    - Version:       4
+      AbbrevTableID: 1
+      Entries:
+        - AbbrCode: 1
+          Values:
+            - Value: 0x8765
diff --git a/llvm/tools/obj2yaml/elf2yaml.cpp b/llvm/tools/obj2yaml/elf2yaml.cpp
index 6b9af906736c3..8222f0cc4a36d 100644
--- a/llvm/tools/obj2yaml/elf2yaml.cpp
+++ b/llvm/tools/obj2yaml/elf2yaml.cpp
@@ -536,6 +536,10 @@ std::optional<DWARFYAML::Data> ELFDumper<ELFT>::dumpDWARFSections(
         Err = dumpDebugRanges(*DWARFCtx, DWARF);
       else if (RawSec->Name == ".debug_addr")
         Err = dumpDebugAddr(*DWARFCtx, DWARF);
+      else if (RawSec->Name == ".debug_abbrev")
+        Err = dumpDebugAbbrev(*DWARFCtx, DWARF);
+      else if (RawSec->Name == ".debug_info")
+        dumpDebugInfo(*DWARFCtx, DWARF);
       else
         continue;
 



More information about the llvm-commits mailing list