Skip to content

Commit 4042154

Browse files
author
Amirhossein Pashaeehir
committed
Move the printing logic of UnwindTable to UnwindTablePrinter
1 parent 1ed0df2 commit 4042154

File tree

7 files changed

+263
-188
lines changed

7 files changed

+263
-188
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//===- DWARFUnwindTablePrinter.h --------------------------------*- 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_DWARFUNWINDTABLEPRINTER_H
10+
#define LLVM_DEBUGINFO_DWARF_DWARFUNWINDTABLEPRINTER_H
11+
12+
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFUnwindTable.h"
13+
#include "llvm/Support/Compiler.h"
14+
15+
namespace llvm {
16+
17+
struct DIDumpOptions;
18+
19+
namespace dwarf {
20+
21+
/// Print an unwind location expression as text and use the register information
22+
/// if some is provided.
23+
///
24+
/// \param R the unwind location to print.
25+
///
26+
/// \param OS the stream to use for output.
27+
///
28+
/// \param MRI register information that helps emit register names insteead
29+
/// of raw register numbers.
30+
///
31+
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
32+
/// instead of from .debug_frame. This is needed for register number
33+
/// conversion because some register numbers differ between the two sections
34+
/// for certain architectures like x86.
35+
LLVM_ABI void printUnwindLocation(const UnwindLocation &R, raw_ostream &OS,
36+
DIDumpOptions DumpOpts);
37+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindLocation &R);
38+
39+
/// Print all registers + locations that are currently defined in a register
40+
/// locations.
41+
///
42+
/// \param RL the register locations to print.
43+
///
44+
/// \param OS the stream to use for output.
45+
///
46+
/// \param MRI register information that helps emit register names insteead
47+
/// of raw register numbers.
48+
///
49+
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
50+
/// instead of from .debug_frame. This is needed for register number
51+
/// conversion because some register numbers differ between the two sections
52+
/// for certain architectures like x86.
53+
LLVM_ABI void printRegisterLocations(const RegisterLocations &RL,
54+
raw_ostream &OS, DIDumpOptions DumpOpts);
55+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RegisterLocations &RL);
56+
57+
/// Print an UnwindRow to the stream.
58+
///
59+
/// \param Row the UnwindRow to print.
60+
///
61+
/// \param OS the stream to use for output.
62+
///
63+
/// \param MRI register information that helps emit register names insteead
64+
/// of raw register numbers.
65+
///
66+
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
67+
/// instead of from .debug_frame. This is needed for register number
68+
/// conversion because some register numbers differ between the two sections
69+
/// for certain architectures like x86.
70+
///
71+
/// \param IndentLevel specify the indent level as an integer. The UnwindRow
72+
/// will be output to the stream preceded by 2 * IndentLevel number of spaces.
73+
LLVM_ABI void printUnwindRow(const UnwindRow &Row, raw_ostream &OS,
74+
DIDumpOptions DumpOpts, unsigned IndentLevel = 0);
75+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindRow &Row);
76+
77+
/// Print a UnwindTable to the stream.
78+
///
79+
/// \param Rows the UnwindTable to print.
80+
///
81+
/// \param OS the stream to use for output.
82+
///
83+
/// \param MRI register information that helps emit register names instead
84+
/// of raw register numbers.
85+
///
86+
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
87+
/// instead of from .debug_frame. This is needed for register number
88+
/// conversion because some register numbers differ between the two sections
89+
/// for certain architectures like x86.
90+
///
91+
/// \param IndentLevel specify the indent level as an integer. The UnwindRow
92+
/// will be output to the stream preceded by 2 * IndentLevel number of spaces.
93+
LLVM_ABI void printUnwindTable(const UnwindTable &Rows, raw_ostream &OS,
94+
DIDumpOptions DumpOpts,
95+
unsigned IndentLevel = 0);
96+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindTable &Rows);
97+
98+
} // end namespace dwarf
99+
100+
} // end namespace llvm
101+
102+
#endif // LLVM_DEBUGINFO_DWARF_DWARFUNWINDTABLEPRINTER_H

llvm/include/llvm/DebugInfo/DWARF/LowLevel/DWARFUnwindTable.h

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_DEBUGINFO_DWARF_DWARFUNWINDTABLE_H
1010
#define LLVM_DEBUGINFO_DWARF_DWARFUNWINDTABLE_H
1111

12+
#include "llvm/ADT/SmallVector.h"
1213
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
1314
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
1415
#include "llvm/Support/Compiler.h"
@@ -122,6 +123,11 @@ class UnwindLocation {
122123
Location getLocation() const { return Kind; }
123124
uint32_t getRegister() const { return RegNum; }
124125
int32_t getOffset() const { return Offset; }
126+
bool hasAddressSpace() const {
127+
if(AddrSpace)
128+
return true;
129+
return false;
130+
}
125131
uint32_t getAddressSpace() const {
126132
assert(Kind == RegPlusOffset && AddrSpace);
127133
return *AddrSpace;
@@ -145,25 +151,10 @@ class UnwindLocation {
145151
std::optional<DWARFExpression> getDWARFExpressionBytes() const {
146152
return Expr;
147153
}
148-
/// Dump a location expression as text and use the register information if
149-
/// some is provided.
150-
///
151-
/// \param OS the stream to use for output.
152-
///
153-
/// \param MRI register information that helps emit register names insteead
154-
/// of raw register numbers.
155-
///
156-
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
157-
/// instead of from .debug_frame. This is needed for register number
158-
/// conversion because some register numbers differ between the two sections
159-
/// for certain architectures like x86.
160-
LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const;
161154

162155
LLVM_ABI bool operator==(const UnwindLocation &RHS) const;
163156
};
164157

165-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindLocation &R);
166-
167158
/// A class that can track all registers with locations in a UnwindRow object.
168159
///
169160
/// Register locations use a map where the key is the register number and the
@@ -189,6 +180,13 @@ class RegisterLocations {
189180
return Pos->second;
190181
}
191182

183+
SmallVector<uint32_t, 4> getRegisters() const {
184+
SmallVector<uint32_t, 4> Registers;
185+
for(auto &&[Register, _]: Locations)
186+
Registers.push_back(Register);
187+
return Registers;
188+
}
189+
192190
/// Set the location for the register in \a RegNum to \a Location.
193191
///
194192
/// \param RegNum the register number to set the location for.
@@ -204,19 +202,6 @@ class RegisterLocations {
204202
/// \param RegNum the register number to remove the location for.
205203
void removeRegisterLocation(uint32_t RegNum) { Locations.erase(RegNum); }
206204

207-
/// Dump all registers + locations that are currently defined in this object.
208-
///
209-
/// \param OS the stream to use for output.
210-
///
211-
/// \param MRI register information that helps emit register names insteead
212-
/// of raw register numbers.
213-
///
214-
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
215-
/// instead of from .debug_frame. This is needed for register number
216-
/// conversion because some register numbers differ between the two sections
217-
/// for certain architectures like x86.
218-
LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts) const;
219-
220205
/// Returns true if we have any register locations in this object.
221206
bool hasLocations() const { return !Locations.empty(); }
222207

@@ -227,8 +212,6 @@ class RegisterLocations {
227212
}
228213
};
229214

230-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const RegisterLocations &RL);
231-
232215
/// A class that represents a single row in the unwind table that is decoded by
233216
/// parsing the DWARF Call Frame Information opcodes.
234217
///
@@ -281,27 +264,8 @@ class UnwindRow {
281264
const UnwindLocation &getCFAValue() const { return CFAValue; }
282265
RegisterLocations &getRegisterLocations() { return RegLocs; }
283266
const RegisterLocations &getRegisterLocations() const { return RegLocs; }
284-
285-
/// Dump the UnwindRow to the stream.
286-
///
287-
/// \param OS the stream to use for output.
288-
///
289-
/// \param MRI register information that helps emit register names insteead
290-
/// of raw register numbers.
291-
///
292-
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
293-
/// instead of from .debug_frame. This is needed for register number
294-
/// conversion because some register numbers differ between the two sections
295-
/// for certain architectures like x86.
296-
///
297-
/// \param IndentLevel specify the indent level as an integer. The UnwindRow
298-
/// will be output to the stream preceded by 2 * IndentLevel number of spaces.
299-
LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts,
300-
unsigned IndentLevel = 0) const;
301267
};
302268

303-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindRow &Row);
304-
305269
/// A class that contains all UnwindRow objects for an FDE or a single unwind
306270
/// row for a CIE. To unwind an address the rows, which are sorted by start
307271
/// address, can be searched to find the UnwindRow with the lowest starting
@@ -325,23 +289,6 @@ class UnwindTable {
325289
return Rows[Index];
326290
}
327291

328-
/// Dump the UnwindTable to the stream.
329-
///
330-
/// \param OS the stream to use for output.
331-
///
332-
/// \param MRI register information that helps emit register names instead
333-
/// of raw register numbers.
334-
///
335-
/// \param IsEH true if the DWARF Call Frame Information is from .eh_frame
336-
/// instead of from .debug_frame. This is needed for register number
337-
/// conversion because some register numbers differ between the two sections
338-
/// for certain architectures like x86.
339-
///
340-
/// \param IndentLevel specify the indent level as an integer. The UnwindRow
341-
/// will be output to the stream preceded by 2 * IndentLevel number of spaces.
342-
LLVM_ABI void dump(raw_ostream &OS, DIDumpOptions DumpOpts,
343-
unsigned IndentLevel = 0) const;
344-
345292
private:
346293
RowContainer Rows;
347294
};
@@ -367,8 +314,6 @@ LLVM_ABI Expected<UnwindTable::RowContainer>
367314
parseRows(const CFIProgram &CFIP, UnwindRow &CurrRow,
368315
const RegisterLocations *InitialLocs);
369316

370-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const UnwindTable &Rows);
371-
372317
} // end namespace dwarf
373318

374319
} // end namespace llvm

llvm/lib/DebugInfo/DWARF/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ add_llvm_component_library(LLVMDebugInfoDWARF
2828
DWARFTypeUnit.cpp
2929
DWARFUnitIndex.cpp
3030
DWARFUnit.cpp
31+
DWARFUnwindTablePrinter.cpp
3132
DWARFVerifier.cpp
3233

3334
ADDITIONAL_HEADER_DIRS

llvm/lib/DebugInfo/DWARF/DWARFDebugFrame.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/DebugInfo/DWARF/DWARFCFIPrinter.h"
1616
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
1717
#include "llvm/DebugInfo/DWARF/DWARFExpressionPrinter.h"
18+
#include "llvm/DebugInfo/DWARF/DWARFUnwindTablePrinter.h"
1819
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFCFIProgram.h"
1920
#include "llvm/DebugInfo/DWARF/LowLevel/DWARFExpression.h"
2021
#include "llvm/Support/Compiler.h"
@@ -136,7 +137,7 @@ void CIE::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
136137
OS << "\n";
137138

138139
if (Expected<UnwindTable> RowsOrErr = createUnwindTable(this))
139-
RowsOrErr->dump(OS, DumpOpts, 1);
140+
printUnwindTable(*RowsOrErr, OS, DumpOpts, 1);
140141
else {
141142
DumpOpts.RecoverableErrorHandler(joinErrors(
142143
createStringError(errc::invalid_argument,
@@ -164,7 +165,7 @@ void FDE::dump(raw_ostream &OS, DIDumpOptions DumpOpts) const {
164165
OS << "\n";
165166

166167
if (Expected<UnwindTable> RowsOrErr = createUnwindTable(this))
167-
RowsOrErr->dump(OS, DumpOpts, 1);
168+
printUnwindTable(*RowsOrErr, OS, DumpOpts, 1);
168169
else {
169170
DumpOpts.RecoverableErrorHandler(joinErrors(
170171
createStringError(errc::invalid_argument,

0 commit comments

Comments
 (0)