Skip to content

Commit 23f1ba3

Browse files
Reapply "[NFC][DebugInfo][DWARF] Create new low-level dwarf library (#… (#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
1 parent a4be46e commit 23f1ba3

File tree

57 files changed

+893
-801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+893
-801
lines changed

bolt/include/bolt/Core/DIEBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
#include "llvm/CodeGen/DIE.h"
2121
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
2222
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
23-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
2423
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
24+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2525
#include "llvm/Support/Allocator.h"
2626

2727
#include <list>

bolt/lib/Core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(LLVM_LINK_COMPONENTS
22
DebugInfoDWARF
3+
DebugInfoDWARFLowLevel
34
Demangle
45
MC
56
MCDisassembler

bolt/lib/Core/DIEBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
#include "llvm/CodeGen/DIE.h"
1515
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
1616
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
17-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1817
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
1918
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
2019
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
2120
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
21+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2222
#include "llvm/Support/Casting.h"
2323
#include "llvm/Support/Debug.h"
2424
#include "llvm/Support/ErrorHandling.h"

bolt/lib/Core/DebugNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include "bolt/Core/DebugNames.h"
1010
#include "bolt/Core/BinaryContext.h"
11-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1211
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
12+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1313
#include "llvm/Support/EndianStream.h"
1414
#include "llvm/Support/LEB128.h"
1515
#include <cstdint>

bolt/lib/Rewrite/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
set(LLVM_LINK_COMPONENTS
22
Core
33
DebugInfoDWARF
4+
DebugInfoDWARFLowLevel
45
JITLink
56
MC
67
Object

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
2525
#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h"
2626
#include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h"
27-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
2827
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
2928
#include "llvm/DebugInfo/DWARF/DWARFTypeUnit.h"
3029
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
30+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
3131
#include "llvm/MC/MCAsmBackend.h"
3232
#include "llvm/MC/MCAssembler.h"
3333
#include "llvm/MC/MCObjectWriter.h"

compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ $LINK $LIBCXX_ARCHIVE_DIR/libc++.a \
174174
$LLVM_BUILD/lib/libLLVMObject.a \
175175
$LLVM_BUILD/lib/libLLVMBinaryFormat.a \
176176
$LLVM_BUILD/lib/libLLVMDebugInfoDWARF.a \
177+
$LLVM_BUILD/lib/libLLVMDebugInfoDWARFLowLevel.a \
177178
$LLVM_BUILD/lib/libLLVMDebugInfoGSYM.a \
178179
$LLVM_BUILD/lib/libLLVMSupport.a \
179180
$LLVM_BUILD/lib/libLLVMDebugInfoPDB.a \

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#include "lldb/Target/StackID.h"
3737
#include "lldb/Target/Target.h"
3838
#include "lldb/Target/Thread.h"
39-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
39+
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
40+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
4041

4142
using namespace lldb;
4243
using namespace lldb_private;
@@ -81,7 +82,7 @@ void DWARFExpression::DumpLocation(Stream *s, lldb::DescriptionLevel level,
8182
llvm::DIDumpOptions DumpOpts;
8283
DumpOpts.GetNameForDWARFReg = GetRegName;
8384
llvm::DWARFExpression E(m_data.GetAsLLVM(), m_data.GetAddressByteSize());
84-
llvm::DWARFExpressionPrinter::print(&E, s->AsRawOstream(), DumpOpts, nullptr);
85+
llvm::printDwarfExpression(&E, s->AsRawOstream(), DumpOpts, nullptr);
8586
}
8687

8788
RegisterKind DWARFExpression::GetRegisterKind() const { return m_reg_kind; }

lldb/source/Symbol/UnwindPlan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#include "lldb/Utility/Log.h"
1818
#include "llvm/ADT/STLExtras.h"
1919
#include "llvm/DebugInfo/DIContext.h"
20-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
20+
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
21+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2122
#include <optional>
2223

2324
using namespace lldb;
@@ -89,8 +90,7 @@ static void DumpDWARFExpr(Stream &s, llvm::ArrayRef<uint8_t> expr, Thread *threa
8990
order_and_width->second);
9091
llvm::DWARFExpression E(data, order_and_width->second,
9192
llvm::dwarf::DWARF32);
92-
llvm::DWARFExpressionPrinter::print(&E, s.AsRawOstream(),
93-
llvm::DIDumpOptions(), nullptr);
93+
printDwarfExpression(&E, s.AsRawOstream(), llvm::DIDumpOptions(), nullptr);
9494
} else
9595
s.PutCString("dwarf-expr");
9696
}

lldb/unittests/Symbol/PostfixExpressionTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
#include "lldb/Utility/StreamString.h"
1212
#include "llvm/ADT/StringExtras.h"
1313
#include "llvm/DebugInfo/DIContext.h"
14-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
14+
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
15+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1516
#include "llvm/Support/FormatVariadic.h"
1617
#include "llvm/Support/raw_ostream.h"
1718
#include "gmock/gmock.h"
@@ -160,7 +161,7 @@ static std::string ParseAndGenerateDWARF(llvm::StringRef expr) {
160161
std::string result;
161162
llvm::raw_string_ostream os(result);
162163
llvm::DWARFExpression E(extractor, addr_size, llvm::dwarf::DWARF32);
163-
llvm::DWARFExpressionPrinter::print(&E, os, llvm::DIDumpOptions(), nullptr);
164+
llvm::printDwarfExpression(&E, os, llvm::DIDumpOptions(), nullptr);
164165
return result;
165166
}
166167

lldb/unittests/SymbolFile/NativePDB/PdbFPOProgramToDWARFExpressionTests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
#include "lldb/Utility/StreamBuffer.h"
1717
#include "lldb/Utility/StreamString.h"
1818
#include "llvm/DebugInfo/DIContext.h"
19-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
19+
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
20+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2021

2122
using namespace lldb;
2223
using namespace lldb_private;
@@ -40,7 +41,7 @@ CheckValidProgramTranslation(llvm::StringRef fpo_program,
4041
std::string result;
4142
llvm::raw_string_ostream os(result);
4243
llvm::DWARFExpression E(extractor, /*AddressSize=*/4, llvm::dwarf::DWARF32);
43-
llvm::DWARFExpressionPrinter::print(&E, os, llvm::DIDumpOptions(), nullptr);
44+
llvm::printDwarfExpression(&E, os, llvm::DIDumpOptions(), nullptr);
4445

4546
// actual check
4647
ASSERT_EQ(expected_dwarf_expression, result);

llvm/include/llvm/DWARFLinker/AddressesMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "llvm/ADT/AddressRanges.h"
1313
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
1414
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
15-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1615
#include "llvm/DebugInfo/DWARF/DWARFUnit.h"
16+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1717
#include <cstdint>
1818

1919
namespace llvm {

llvm/include/llvm/DWARFLinker/Classic/DWARFLinker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
2121
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
2222
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
23-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
23+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2424
#include "llvm/Support/Compiler.h"
2525
#include <map>
2626

llvm/include/llvm/DWARFLinker/DWARFLinkerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "llvm/DebugInfo/DWARF/DWARFDebugLine.h"
1717
#include "llvm/DebugInfo/DWARF/DWARFDebugRangeList.h"
1818
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
19-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
19+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2020
#include "llvm/Support/Compiler.h"
2121
#include <map>
2222
namespace llvm {

llvm/include/llvm/DebugInfo/DWARF/DWARFCFIPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H
1010
#define LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H
1111

12-
#include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h"
12+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
1313
#include "llvm/Support/Compiler.h"
1414

1515
namespace llvm {

llvm/include/llvm/DebugInfo/DWARF/DWARFDataExtractor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
#define LLVM_DEBUGINFO_DWARF_DWARFDATAEXTRACTOR_H
1111

1212
#include "llvm/BinaryFormat/Dwarf.h"
13-
#include "llvm/DebugInfo/DWARF/DWARFDataExtractorSimple.h"
1413
#include "llvm/DebugInfo/DWARF/DWARFObject.h"
1514
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
1615
#include "llvm/DebugInfo/DWARF/DWARFSection.h"
16+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFDataExtractorSimple.h"
1717
#include "llvm/Support/Compiler.h"
1818

1919
namespace llvm {

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/SmallString.h"
1414
#include "llvm/ADT/iterator.h"
15-
#include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h"
16-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
15+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
16+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1717
#include "llvm/Support/Compiler.h"
1818
#include "llvm/Support/Error.h"
1919
#include "llvm/TargetParser/Triple.h"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===--- DWARFExpressionPRinter.h - DWARF Expression Printing ---*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_DEBUGINFO_DWARF_DWARFEXPRESSIONPRINTER_H
10+
#define LLVM_DEBUGINFO_DWARF_DWARFEXPRESSIONPRINTER_H
11+
12+
#include "llvm/ADT/StringRef.h"
13+
#include "llvm/ADT/iterator.h"
14+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
15+
#include "llvm/Support/Compiler.h"
16+
17+
namespace llvm {
18+
19+
// This functionality is separated from the main data structure so that nothing
20+
// in DWARFExpression.cpp needs build-time dependencies on DWARFUnit or other
21+
// higher-level Dwarf structures. This approach creates better layering and
22+
// allows DWARFExpression to be used from code which can't have dependencies on
23+
// those higher-level structures.
24+
25+
class DWARFUnit;
26+
struct DIDumpOptions;
27+
class raw_ostream;
28+
29+
/// Print a Dwarf expression/
30+
/// \param E to be printed
31+
/// \param OS to this stream
32+
/// \param GetNameForDWARFReg callback to return dwarf register name
33+
LLVM_ABI void printDwarfExpression(const DWARFExpression *E, raw_ostream &OS,
34+
DIDumpOptions DumpOpts, DWARFUnit *U,
35+
bool IsEH = false);
36+
37+
/// Print the expression in a format intended to be compact and useful to a
38+
/// user, but not perfectly unambiguous, or capable of representing every
39+
/// valid DWARF expression. Returns true if the expression was sucessfully
40+
/// printed.
41+
///
42+
/// \param E to be printed
43+
/// \param OS to this stream
44+
/// \param GetNameForDWARFReg callback to return dwarf register name
45+
///
46+
/// \returns true if the expression was successfully printed
47+
LLVM_ABI bool printDwarfExpressionCompact(
48+
const DWARFExpression *E, raw_ostream &OS,
49+
std::function<StringRef(uint64_t RegNum, bool IsEH)> GetNameForDWARFReg =
50+
nullptr);
51+
52+
/// Pretty print a register opcode and operands.
53+
/// \param U within the context of this Dwarf unit, if any.
54+
/// \param OS to this stream
55+
/// \param DumpOpts with these options
56+
/// \param Opcode to print
57+
/// \param Operands to the opcode
58+
///
59+
/// returns true if the Op was successfully printed
60+
LLVM_ABI bool prettyPrintRegisterOp(DWARFUnit *U, raw_ostream &OS,
61+
DIDumpOptions DumpOpts, uint8_t Opcode,
62+
ArrayRef<uint64_t> Operands);
63+
64+
} // end namespace llvm
65+
66+
#endif // LLVM_DEBUGINFO_DWARF_DWARFEXPRESSIONPRINTER_H

llvm/include/llvm/DebugInfo/DWARF/DWARFVerifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
1515
#include "llvm/DebugInfo/DWARF/DWARFAddressRange.h"
1616
#include "llvm/DebugInfo/DWARF/DWARFDie.h"
17-
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
1817
#include "llvm/DebugInfo/DWARF/DWARFUnitIndex.h"
18+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1919
#include "llvm/Support/Compiler.h"
2020
#include <cstdint>
2121
#include <map>

0 commit comments

Comments
 (0)