Skip to content

Revert "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… #145959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

Sterling-Augustine
Copy link
Contributor

…145081)"

This reverts commit cbf781f.

Breaks a couple of buildbots.

@llvmbot
Copy link
Member

llvmbot commented Jun 26, 2025

@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-bolt
@llvm/pr-subscribers-llvm-binary-utilities

@llvm/pr-subscribers-lldb

Author: None (Sterling-Augustine)

Changes

…145081)"

This reverts commit cbf781f.

Breaks a couple of buildbots.


Patch is 96.13 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/145959.diff

54 Files Affected:

  • (modified) bolt/include/bolt/Core/DIEBuilder.h (+1-1)
  • (modified) bolt/lib/Core/CMakeLists.txt (-1)
  • (modified) bolt/lib/Core/DIEBuilder.cpp (+1-1)
  • (modified) bolt/lib/Core/DebugNames.cpp (+1-1)
  • (modified) bolt/lib/Rewrite/CMakeLists.txt (-1)
  • (modified) bolt/lib/Rewrite/DWARFRewriter.cpp (+1-1)
  • (modified) lldb/source/Expression/DWARFExpression.cpp (+2-3)
  • (modified) lldb/source/Symbol/UnwindPlan.cpp (+3-3)
  • (modified) lldb/unittests/Symbol/PostfixExpressionTest.cpp (+2-3)
  • (modified) lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp (+2-3)
  • (modified) llvm/include/llvm/DWARFLinker/AddressesMap.h (+1-1)
  • (modified) llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h (+1-1)
  • (modified) llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h (+1-1)
  • (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h (+1-1)
  • (renamed) llvm/include/llvm/DebugInfo/DWARF/DWARFCFIProgram.h (+4-146)
  • (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h (+1-1)
  • (renamed) llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h ()
  • (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h (+2-2)
  • (renamed) llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h (+62-1)
  • (removed) llvm/include/llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h (-66)
  • (modified) llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h (+1-1)
  • (modified) llvm/lib/CodeGen/AsmPrinter/CMakeLists.txt (-1)
  • (modified) llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp (+1-1)
  • (modified) llvm/lib/DWARFLinker/Classic/CMakeLists.txt (-1)
  • (modified) llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp (+1-1)
  • (modified) llvm/lib/DWARFLinker/Classic/DWARFLinkerCompileUnit.cpp (+1-1)
  • (modified) llvm/lib/DebugInfo/DWARF/CMakeLists.txt (+2-4)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFCFIPrinter.cpp (+3-3)
  • (renamed) llvm/lib/DebugInfo/DWARF/DWARFCFIProgram.cpp (+146-2)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp (+3-4)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp (+2-3)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFDie.cpp (+2-3)
  • (added) llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp (+538)
  • (removed) llvm/lib/DebugInfo/DWARF/DWARFExpressionPrinter.cpp (-311)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp (+1-1)
  • (modified) llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp (+1-1)
  • (removed) llvm/lib/DebugInfo/DWARF/LowLevel/CMakeLists.txt (-14)
  • (removed) llvm/lib/DebugInfo/DWARF/LowLevel/DWARFExpression.cpp (-253)
  • (modified) llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp (+3-3)
  • (modified) llvm/lib/ProfileData/CMakeLists.txt (-1)
  • (modified) llvm/lib/ProfileData/InstrProfCorrelator.cpp (+1-1)
  • (modified) llvm/tools/dsymutil/CMakeLists.txt (-1)
  • (modified) llvm/tools/dsymutil/DwarfLinkerForBinary.cpp (+1-1)
  • (modified) llvm/tools/llvm-dwarfdump/CMakeLists.txt (-1)
  • (modified) llvm/tools/llvm-dwarfdump/Statistics.cpp (+1-1)
  • (modified) llvm/tools/llvm-dwarfutil/CMakeLists.txt (-1)
  • (modified) llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp (+1-1)
  • (modified) llvm/tools/llvm-objdump/CMakeLists.txt (-1)
  • (modified) llvm/tools/llvm-objdump/SourcePrinter.cpp (+2-3)
  • (modified) llvm/unittests/DebugInfo/DWARF/CMakeLists.txt (-1)
  • (modified) llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp (+2-3)
  • (modified) llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp (+1-1)
  • (modified) utils/bazel/llvm-project-overlay/bolt/BUILD.bazel (-2)
  • (modified) utils/bazel/llvm-project-overlay/llvm/BUILD.bazel (-24)
diff --git a/bolt/include/bolt/Core/DIEBuilder.h b/bolt/include/bolt/Core/DIEBuilder.h
index e4a4fc6b2f258..32e455ad3030a 100644
--- a/bolt/include/bolt/Core/DIEBuilder.h
+++ b/bolt/include/bolt/Core/DIEBuilder.h
@@ -20,8 +20,8 @@
 #include "llvm/CodeGen/DIE.h"
 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
 #include "llvm/Support/Allocator.h"
 
 #include <list>
diff --git a/bolt/lib/Core/CMakeLists.txt b/bolt/lib/Core/CMakeLists.txt
index fc72dc023c590..8c1f5d0bb37b5 100644
--- a/bolt/lib/Core/CMakeLists.txt
+++ b/bolt/lib/Core/CMakeLists.txt
@@ -1,6 +1,5 @@
 set(LLVM_LINK_COMPONENTS
   DebugInfoDWARF
-  DebugInfoDWARFLowLevel
   Demangle
   MC
   MCDisassembler
diff --git a/bolt/lib/Core/DIEBuilder.cpp b/bolt/lib/Core/DIEBuilder.cpp
index b041dc5ea1cce..d36dbb3459249 100644
--- a/bolt/lib/Core/DIEBuilder.cpp
+++ b/bolt/lib/Core/DIEBuilder.cpp
@@ -14,11 +14,11 @@
 #include "llvm/CodeGen/DIE.h"
 #include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
 #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/ErrorHandling.h"
diff --git a/bolt/lib/Core/DebugNames.cpp b/bolt/lib/Core/DebugNames.cpp
index a9d98a6ba879b..aa1c8f3d42d4b 100644
--- a/bolt/lib/Core/DebugNames.cpp
+++ b/bolt/lib/Core/DebugNames.cpp
@@ -8,8 +8,8 @@
 
 #include "bolt/Core/DebugNames.h"
 #include "bolt/Core/BinaryContext.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
 #include "llvm/Support/EndianStream.h"
 #include "llvm/Support/LEB128.h"
 #include <cstdint>
diff --git a/bolt/lib/Rewrite/CMakeLists.txt b/bolt/lib/Rewrite/CMakeLists.txt
index 775036063dd5a..c83cf36982167 100644
--- a/bolt/lib/Rewrite/CMakeLists.txt
+++ b/bolt/lib/Rewrite/CMakeLists.txt
@@ -1,7 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   Core
   DebugInfoDWARF
-  DebugInfoDWARFLowLevel
   JITLink
   MC
   Object
diff --git a/bolt/lib/Rewrite/DWARFRewriter.cpp b/bolt/lib/Rewrite/DWARFRewriter.cpp
index 0c1a1bac6c72e..9c9bdefe08429 100644
--- a/bolt/lib/Rewrite/DWARFRewriter.cpp
+++ b/bolt/lib/Rewrite/DWARFRewriter.cpp
@@ -24,10 +24,10 @@
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
 #include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
 #include "llvm/MC/MCAsmBackend.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCObjectWriter.h"
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index 2df27513a0b3f..661324338e801 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -36,8 +36,7 @@
 #include "lldb/Target/StackID.h"
 #include "lldb/Target/Target.h"
 #include "lldb/Target/Thread.h"
-#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -82,7 +81,7 @@ void DWARFExpression::DumpLocation(Stream *s, lldb::DescriptionLevel level,
   llvm::DIDumpOptions DumpOpts;
   DumpOpts.GetNameForDWARFReg = GetRegName;
   llvm::DWARFExpression E(m_data.GetAsLLVM(), m_data.GetAddressByteSize());
-  llvm::printDwarfExpression(&E, s->AsRawOstream(), DumpOpts, nullptr);
+  llvm::DWARFExpressionPrinter::print(&E, s->AsRawOstream(), DumpOpts, nullptr);
 }
 
 RegisterKind DWARFExpression::GetRegisterKind() const { return m_reg_kind; }
diff --git a/lldb/source/Symbol/UnwindPlan.cpp b/lldb/source/Symbol/UnwindPlan.cpp
index 9245e52732061..e9ac6b6cde295 100644
--- a/lldb/source/Symbol/UnwindPlan.cpp
+++ b/lldb/source/Symbol/UnwindPlan.cpp
@@ -17,8 +17,7 @@
 #include "lldb/Utility/Log.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/DebugInfo/DIContext.h"
-#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include <optional>
 
 using namespace lldb;
@@ -90,7 +89,8 @@ static void DumpDWARFExpr(Stream &s, llvm::ArrayRef<uint8_t> expr, Thread *threa
                              order_and_width->second);
     llvm::DWARFExpression E(data, order_and_width->second,
                             llvm::dwarf::DWARF32);
-    printDwarfExpression(&E, s.AsRawOstream(), llvm::DIDumpOptions(), nullptr);
+    llvm::DWARFExpressionPrinter::print(&E, s.AsRawOstream(),
+                                        llvm::DIDumpOptions(), nullptr);
   } else
     s.PutCString("dwarf-expr");
 }
diff --git a/lldb/unittests/Symbol/PostfixExpressionTest.cpp b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
index f60b5d2c389ed..1e437da5133d9 100644
--- a/lldb/unittests/Symbol/PostfixExpressionTest.cpp
+++ b/lldb/unittests/Symbol/PostfixExpressionTest.cpp
@@ -11,8 +11,7 @@
 #include "lldb/Utility/StreamString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/DebugInfo/DIContext.h"
-#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/raw_ostream.h"
 #include "gmock/gmock.h"
@@ -161,7 +160,7 @@ static std::string ParseAndGenerateDWARF(llvm::StringRef expr) {
   std::string result;
   llvm::raw_string_ostream os(result);
   llvm::DWARFExpression E(extractor, addr_size, llvm::dwarf::DWARF32);
-  llvm::printDwarfExpression(&E, os, llvm::DIDumpOptions(), nullptr);
+  llvm::DWARFExpressionPrinter::print(&E, os, llvm::DIDumpOptions(), nullptr);
   return result;
 }
 
diff --git a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
index c60688ef22939..d746e04f8a9fc 100644
--- a/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
+++ b/lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp
@@ -16,8 +16,7 @@
 #include "lldb/Utility/StreamBuffer.h"
 #include "lldb/Utility/StreamString.h"
 #include "llvm/DebugInfo/DIContext.h"
-#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 
 using namespace lldb;
 using namespace lldb_private;
@@ -41,7 +40,7 @@ CheckValidProgramTranslation(llvm::StringRef fpo_program,
   std::string result;
   llvm::raw_string_ostream os(result);
   llvm::DWARFExpression E(extractor, /*AddressSize=*/4, llvm::dwarf::DWARF32);
-  llvm::printDwarfExpression(&E, os, llvm::DIDumpOptions(), nullptr);
+  llvm::DWARFExpressionPrinter::print(&E, os, llvm::DIDumpOptions(), nullptr);
 
   // actual check
   ASSERT_EQ(expected_dwarf_expression, result);
diff --git a/llvm/include/llvm/DWARFLinker/AddressesMap.h b/llvm/include/llvm/DWARFLinker/AddressesMap.h
index e2215c70dc34e..a232aafadc5ce 100644
--- a/llvm/include/llvm/DWARFLinker/AddressesMap.h
+++ b/llvm/include/llvm/DWARFLinker/AddressesMap.h
@@ -12,8 +12,8 @@
 #include "llvm/ADT/AddressRanges.h"
 #include "llvm/DebugInfo/DWARF/DWARFContext.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/DebugInfo/DWARF/DWARFUnit.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
 #include <cstdint>
 
 namespace llvm {
diff --git a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
index 5b9535380aebf..b12d96812108e 100644
--- a/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
+++ b/llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h
@@ -20,7 +20,7 @@
 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/Compiler.h"
 #include <map>
 
diff --git a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
index 99aeb0df076e6..17a18c4b029f4 100644
--- a/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
+++ b/llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h
@@ -16,7 +16,7 @@
 #include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
 #include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
 #include "llvm/DebugInfo/DWARF/DWARFDie.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/Compiler.h"
 #include <map>
 namespace llvm {
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h
index 7d4bf8d923097..4723f00a4d241 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h
@@ -9,7 +9,7 @@
 #ifndef LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H
 #define LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H
 
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
+#include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
diff --git a/llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIProgram.h
similarity index 50%
rename from llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h
rename to llvm/include/llvm/DebugInfo/DWARF/DWARFCFIProgram.h
index bdad0b5ad7a5a..1d89ac3578c10 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFCFIProgram.h
@@ -12,8 +12,8 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFDataExtractorSimple.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/Triple.h"
@@ -78,150 +78,8 @@ class CFIProgram {
   /// starting at *Offset and ending at EndOffset. *Offset is updated
   /// to EndOffset upon successful parsing, or indicates the offset
   /// where a problem occurred in case an error is returned.
-  template <typename T>
-  LLVM_ABI Error parse(DWARFDataExtractorBase<T> &Data, uint64_t *Offset,
-                       uint64_t EndOffset) {
-    // See DWARF standard v3, section 7.23
-    const uint8_t DWARF_CFI_PRIMARY_OPCODE_MASK = 0xc0;
-    const uint8_t DWARF_CFI_PRIMARY_OPERAND_MASK = 0x3f;
-
-    DataExtractor::Cursor C(*Offset);
-    while (C && C.tell() < EndOffset) {
-      uint8_t Opcode = Data.getRelocatedValue(C, 1);
-      if (!C)
-        break;
-
-      // Some instructions have a primary opcode encoded in the top bits.
-      if (uint8_t Primary = Opcode & DWARF_CFI_PRIMARY_OPCODE_MASK) {
-        // If it's a primary opcode, the first operand is encoded in the
-        // bottom bits of the opcode itself.
-        uint64_t Op1 = Opcode & DWARF_CFI_PRIMARY_OPERAND_MASK;
-        switch (Primary) {
-        case DW_CFA_advance_loc:
-        case DW_CFA_restore:
-          addInstruction(Primary, Op1);
-          break;
-        case DW_CFA_offset:
-          addInstruction(Primary, Op1, Data.getULEB128(C));
-          break;
-        default:
-          llvm_unreachable("invalid primary CFI opcode");
-        }
-        continue;
-      }
-
-      // Extended opcode - its value is Opcode itself.
-      switch (Opcode) {
-      default:
-        return createStringError(errc::illegal_byte_sequence,
-                                 "invalid extended CFI opcode 0x%" PRIx8,
-                                 Opcode);
-      case DW_CFA_nop:
-      case DW_CFA_remember_state:
-      case DW_CFA_restore_state:
-      case DW_CFA_GNU_window_save:
-      case DW_CFA_AARCH64_negate_ra_state_with_pc:
-        // No operands
-        addInstruction(Opcode);
-        break;
-      case DW_CFA_set_loc:
-        // Operands: Address
-        addInstruction(Opcode, Data.getRelocatedAddress(C));
-        break;
-      case DW_CFA_advance_loc1:
-        // Operands: 1-byte delta
-        addInstruction(Opcode, Data.getRelocatedValue(C, 1));
-        break;
-      case DW_CFA_advance_loc2:
-        // Operands: 2-byte delta
-        addInstruction(Opcode, Data.getRelocatedValue(C, 2));
-        break;
-      case DW_CFA_advance_loc4:
-        // Operands: 4-byte delta
-        addInstruction(Opcode, Data.getRelocatedValue(C, 4));
-        break;
-      case DW_CFA_restore_extended:
-      case DW_CFA_undefined:
-      case DW_CFA_same_value:
-      case DW_CFA_def_cfa_register:
-      case DW_CFA_def_cfa_offset:
-      case DW_CFA_GNU_args_size:
-        // Operands: ULEB128
-        addInstruction(Opcode, Data.getULEB128(C));
-        break;
-      case DW_CFA_def_cfa_offset_sf:
-        // Operands: SLEB128
-        addInstruction(Opcode, Data.getSLEB128(C));
-        break;
-      case DW_CFA_LLVM_def_aspace_cfa:
-      case DW_CFA_LLVM_def_aspace_cfa_sf: {
-        auto RegNum = Data.getULEB128(C);
-        auto CfaOffset = Opcode == DW_CFA_LLVM_def_aspace_cfa
-                             ? Data.getULEB128(C)
-                             : Data.getSLEB128(C);
-        auto AddressSpace = Data.getULEB128(C);
-        addInstruction(Opcode, RegNum, CfaOffset, AddressSpace);
-        break;
-      }
-      case DW_CFA_offset_extended:
-      case DW_CFA_register:
-      case DW_CFA_def_cfa:
-      case DW_CFA_val_offset: {
-        // Operands: ULEB128, ULEB128
-        // Note: We can not embed getULEB128 directly into function
-        // argument list. getULEB128 changes Offset and order of evaluation
-        // for arguments is unspecified.
-        uint64_t op1 = Data.getULEB128(C);
-        uint64_t op2 = Data.getULEB128(C);
-        addInstruction(Opcode, op1, op2);
-        break;
-      }
-      case DW_CFA_offset_extended_sf:
-      case DW_CFA_def_cfa_sf:
-      case DW_CFA_val_offset_sf: {
-        // Operands: ULEB128, SLEB128
-        // Note: see comment for the previous case
-        uint64_t op1 = Data.getULEB128(C);
-        uint64_t op2 = (uint64_t)Data.getSLEB128(C);
-        addInstruction(Opcode, op1, op2);
-        break;
-      }
-      case DW_CFA_def_cfa_expression: {
-        uint64_t ExprLength = Data.getULEB128(C);
-        addInstruction(Opcode, 0);
-        StringRef Expression = Data.getBytes(C, ExprLength);
-
-        DataExtractor Extractor(Expression, Data.isLittleEndian(),
-                                Data.getAddressSize());
-        // Note. We do not pass the DWARF format to DWARFExpression, because
-        // DW_OP_call_ref, the only operation which depends on the format, is
-        // prohibited in call frame instructions, see sec. 6.4.2 in DWARFv5.
-        Instructions.back().Expression =
-            DWARFExpression(Extractor, Data.getAddressSize());
-        break;
-      }
-      case DW_CFA_expression:
-      case DW_CFA_val_expression: {
-        uint64_t RegNum = Data.getULEB128(C);
-        addInstruction(Opcode, RegNum, 0);
-
-        uint64_t BlockLength = Data.getULEB128(C);
-        StringRef Expression = Data.getBytes(C, BlockLength);
-        DataExtractor Extractor(Expression, Data.isLittleEndian(),
-                                Data.getAddressSize());
-        // Note. We do not pass the DWARF format to DWARFExpression, because
-        // DW_OP_call_ref, the only operation which depends on the format, is
-        // prohibited in call frame instructions, see sec. 6.4.2 in DWARFv5.
-        Instructions.back().Expression =
-            DWARFExpression(Extractor, Data.getAddressSize());
-        break;
-      }
-      }
-    }
-
-    *Offset = C.tell();
-    return C.takeError();
-  }
+  LLVM_ABI Error parse(DWARFDataExtractor Data, uint64_t *Offset,
+                       uint64_t EndOffset);
 
   void addInstruction(const Instruction &I) { Instructions.push_back(I); }
 
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
index def291046c7db..005ccd208cdda 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h
@@ -10,10 +10,10 @@
 #define LLVM_DEBUGINFO_DWARF_DWARFDATAEXTRACTOR_H
 
 #include "llvm/BinaryFormat/Dwarf.h"
+#include "llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h"
 #include "llvm/DebugInfo/DWARF/DWARFObject.h"
 #include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
 #include "llvm/DebugInfo/DWARF/DWARFSection.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFDataExtractorSimple.h"
 #include "llvm/Support/Compiler.h"
 
 namespace llvm {
diff --git a/llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFDataExtractorSimple.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h
similarity index 100%
rename from llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFDataExtractorSimple.h
rename to llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
index e0d60f605964f..3b367009a379d 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
@@ -12,8 +12,8 @@
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/iterator.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
-#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
+#include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h"
+#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Error.h"
 #include "llvm/TargetParser/Triple.h"
diff --git a/llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
similarity index 67%
rename from llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h
rename to llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
index 06840b20f9690..ea414278c35d6 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
@@ -65,7 +65,7 @@ class DWARFExpression {
 
     /// Description of the encoding of one expression Op.
     struct Description {
-      DwarfVersion Version;     ///< Dwarf version where the Op was introduced.
+      DwarfVersion Version; ///< Dwarf version where the Op was introduced.
       SmallVector<Encoding> Op; ///< Encoding for Op operands.
 
       template <typename... Ts>
@@ -77,6 +77,7 @@ class DWARFExpression {
 
   private:
     friend class DWARFExpression::iterator;
+    friend class DWARFExpressionPrinter;
     friend class DWARFVerifier;
 
     uint8_t Opcode; ///< The Op Opcode, DW_OP_<something>.
@@ -155,6 +156,7 @@ class DWARFExpression {
 
   StringRef getData() const { return Data.getData(); }
 
+  friend class DWARFExpressionPrinter;
   friend class DWARFVerifier;
 
 private:
@@ -168,6 +170,65 @@ inline bool operator==(const DWARFExpression::iterator &LHS,
   return LHS.Expr == RHS.Expr && LHS.Offset == RHS.Offset;
 }
 
+// This functionality is separated from the main data structure so that nothing
+// in DWARFExpression.cpp needs build-time dependencies on DWARFUnit or other
+// higher-level Dwarf structures. This approach creates better layering and
+// allows DWARFExpression to be used from code which can't have dependencies on
+// those higher-level structures.
+
+class DWARFUnit;
+struct DIDumpOptions;
+class raw_o...
[truncated]

@Sterling-Augustine Sterling-Augustine merged commit 5d03e7a into llvm:main Jun 26, 2025
12 of 15 checks passed
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp bolt/include/bolt/Core/DIEBuilder.h bolt/lib/Core/DIEBuilder.cpp bolt/lib/Core/DebugNames.cpp bolt/lib/Rewrite/DWARFRewriter.cpp lldb/source/Expression/DWARFExpression.cpp lldb/source/Symbol/UnwindPlan.cpp lldb/unittests/Symbol/PostfixExpressionTest.cpp lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp llvm/include/llvm/DWARFLinker/AddressesMap.h llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp llvm/lib/DWARFLinker/Classic/DWARFLinker.cpp llvm/lib/DWARFLinker/Classic/DWARFLinkerCompileUnit.cpp llvm/lib/DebugInfo/DWARF/DWARFCFIPrinter.cpp llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp llvm/lib/DebugInfo/DWARF/DWARFDebugLoc.cpp llvm/lib/DebugInfo/DWARF/DWARFDie.cpp llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp llvm/lib/DebugInfo/DWARF/DWARFVerifier.cpp llvm/lib/DebugInfo/LogicalView/Readers/LVDWARFReader.cpp llvm/lib/ProfileData/InstrProfCorrelator.cpp llvm/tools/dsymutil/DwarfLinkerForBinary.cpp llvm/tools/llvm-dwarfdump/Statistics.cpp llvm/tools/llvm-dwarfutil/DebugInfoLinker.cpp llvm/tools/llvm-objdump/SourcePrinter.cpp llvm/unittests/DebugInfo/DWARF/DWARFExpressionCompactPrinterTest.cpp llvm/unittests/DebugInfo/DWARF/DWARFExpressionCopyBytesTest.cpp llvm/include/llvm/DebugInfo/DWARF/DWARFCFIProgram.h llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h llvm/lib/DebugInfo/DWARF/DWARFCFIProgram.cpp
View the diff from clang-format here.
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
index ea414278c..ec8fb97c1 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFExpression.h
@@ -65,7 +65,7 @@ public:
 
     /// Description of the encoding of one expression Op.
     struct Description {
-      DwarfVersion Version; ///< Dwarf version where the Op was introduced.
+      DwarfVersion Version;     ///< Dwarf version where the Op was introduced.
       SmallVector<Encoding> Op; ///< Encoding for Op operands.
 
       template <typename... Ts>
diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 8255e013a..5203b25f2 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -214,8 +214,8 @@ bool DWARFExpression::Operation::extract(DataExtractor Data,
         Operands[Operand] = Data.getULEB128(&Offset);
         break;
       case 3: // global as uint32
-         Operands[Operand] = Data.getU32(&Offset);
-         break;
+        Operands[Operand] = Data.getU32(&Offset);
+        break;
       default:
         return false; // Unknown Wasm location
       }
@@ -354,7 +354,8 @@ bool DWARFExpressionPrinter::printOp(const DWARFExpression::Operation *Op,
       case 4:
         OS << format(" 0x%" PRIx64, Op->Operands[Operand]);
         break;
-      default: assert(false);
+      default:
+        assert(false);
       }
     } else if (Size == DWARFExpression::Operation::SizeBlock) {
       uint64_t Offset = Op->Operands[Operand];

@dwblaikie
Copy link
Collaborator

FYI: per https://llvm.org/docs/CodeReview.html#code-review-workflow - please don't commit a PR without approval, once it's sent for review. If the intent wasn't to precommit review the PR, it should be created with the skip-precommit-approval tag.

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 26, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve2-vla running on linaro-g4-02 while building bolt,lldb,llvm,utils at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/198/builds/5640

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'SanitizerCommon-ubsan-aarch64-Linux :: Posix/create_thread_loop.cpp' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/./bin/clang  --driver-mode=g++ -gline-tables-only -fsanitize=undefined   -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta  -funwind-tables  -I/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/llvm/compiler-rt/test -ldl -O3 -pthread /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-aarch64-Linux/Posix/Output/create_thread_loop.cpp.tmp &&  /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-aarch64-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000 # RUN: at line 3
+ /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/./bin/clang --driver-mode=g++ -gline-tables-only -fsanitize=undefined -Wthread-safety -Wthread-safety-reference -Wthread-safety-beta -funwind-tables -I/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/llvm/compiler-rt/test -ldl -O3 -pthread /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp -o /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-aarch64-Linux/Posix/Output/create_thread_loop.cpp.tmp
+ /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-aarch64-Linux/Posix/Output/create_thread_loop.cpp.tmp 1000
UndefinedBehaviorSanitizer:DEADLYSIGNAL
==108455==ERROR: UndefinedBehaviorSanitizer: SEGV on unknown address 0xf9f4cd80f1e8 (pc 0xf9f4d24ce460 bp 0xffffe466c130 sp 0xffffe466c130 T108455)
==108455==The signal is caused by a READ memory access.
    #0 0xf9f4d24ce460 in pthread_detach nptl/pthread_detach.c:48:29
    #1 0xaaec89a6f0b0 in main /home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/llvm/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp:23:7
    #2 0xf9f4d24773f8 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
    #3 0xf9f4d24774c8 in __libc_start_main csu/../csu/libc-start.c:392:3
    #4 0xaaec89a44dec in _start (/home/tcwg-buildbot/worker/clang-aarch64-sve2-vla/stage1/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/ubsan-aarch64-Linux/Posix/Output/create_thread_loop.cpp.tmp+0x4dec)

==108455==Register values:
 x0 = 0x0000000000000000   x1 = 0x0000f9f4cd80f0e0   x2 = 0x0000f9f4cd80f508   x3 = 0x0000000000000008  
 x4 = 0x0000f9f4cd80f1b0   x5 = 0x0000f9f4cd80f8a0   x6 = 0x0000f9f4cd80f1b0   x7 = 0x0000f9f4cd000000  
 x8 = 0x0000000000000087   x9 = 0xffffffffffffffe0  x10 = 0x0000f9f4d24cd2e4  x11 = 0x00000000003d0f00  
x12 = 0x0000f9f4cd80f0e0  x13 = 0x0000f9f4d25f3450  x14 = 0x0000000000000140  x15 = 0x0000aaecbd5970a0  
x16 = 0x0000000000000001  x17 = 0x0000f9f4d24ce430  x18 = 0x0000000000000000  x19 = 0x0000f9f4cd80f0e0  
x20 = 0x0000aaec89a6f11c  x21 = 0x0000aaec89a935c0  x22 = 0x0000f9f4d2a24040  x23 = 0x0000aaec89a6f024  
x24 = 0x0000f9f4d25ea000  x25 = 0x0000000000000000  x26 = 0x0000ffffe466c310  x27 = 0x0000aaec89a935c0  
x28 = 0x0000000000000000   fp = 0x0000ffffe466c130   lr = 0x0000f9f4d24ce45c   sp = 0x0000ffffe466c130  
UndefinedBehaviorSanitizer can not provide additional info.
SUMMARY: UndefinedBehaviorSanitizer: SEGV nptl/pthread_detach.c:48:29 in pthread_detach
==108455==ABORTING

--

********************


Sterling-Augustine added a commit that referenced this pull request Jun 27, 2025
…#… (#145959) (#146112)

Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#…
(#145959)
    
This reapplies cbf781f, with fixes for
the shared-library build and the unconventional sanitizer-runtime build.

Original Description:

This is the culmination of a series of changes described in [1].
    
Although somewhat large by line count, it is almost entirely mechanical,
creating a new library in DebugInfo/DWARF/LowLevel. This new library has
very minimal dependencies, allowing it to be used from more places than
the normal DebugInfo/DWARF library--in particular from MC.
    
1.
https://discourse.llvm.org/t/rfc-debuginfo-dwarf-refactor-into-to-lower-and-higher-level-libraries/86665/2
searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Jun 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bazel "Peripheral" support tier build system: utils/bazel BOLT debuginfo lldb llvm:binary-utilities llvm:codegen PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants