-
Notifications
You must be signed in to change notification settings - Fork 15k
[NFC] Extract Printing portions of DWARFCFIProgram to new files #143762
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
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| //===- DWARFCFIPrinter.h ----------------------------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H | ||
| #define LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H | ||
|
|
||
| #include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h" | ||
|
|
||
| namespace llvm { | ||
|
|
||
| struct DIDumpOptions; | ||
|
|
||
| namespace dwarf { | ||
|
|
||
| // This class is separate from CFIProgram to decouple CFIPrograms from the | ||
| // enclosing DWARF dies and type units, which allows using them in lower-level | ||
| // places without build dependencies. | ||
|
|
||
| class CFIPrinter { | ||
| public: | ||
| static void print(const CFIProgram &P, raw_ostream &OS, | ||
| DIDumpOptions DumpOpts, unsigned IndentLevel, | ||
| std::optional<uint64_t> Address); | ||
|
|
||
| static void printOperand(raw_ostream &OS, DIDumpOptions DumpOpts, | ||
| const CFIProgram &P, | ||
| const CFIProgram::Instruction &Instr, | ||
| unsigned OperandIdx, uint64_t Operand, | ||
| std::optional<uint64_t> &Address); | ||
| }; | ||
|
|
||
| } // end namespace dwarf | ||
|
|
||
| } // end namespace llvm | ||
|
|
||
| #endif // LLVM_DEBUGINFO_DWARF_DWARFCFIPRINTER_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| //===- DWARFCFIPrinter.cpp - Print the cfi-portions of .debug_frame -------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "llvm/DebugInfo/DWARF/DWARFCFIPrinter.h" | ||
| #include "llvm/DebugInfo/DIContext.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFCFIProgram.h" | ||
| #include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h" | ||
| #include "llvm/Support/Compiler.h" | ||
| #include "llvm/Support/DataExtractor.h" | ||
| #include "llvm/Support/Errc.h" | ||
| #include "llvm/Support/ErrorHandling.h" | ||
| #include "llvm/Support/Format.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
| #include <cassert> | ||
| #include <cinttypes> | ||
| #include <cstdint> | ||
| #include <optional> | ||
|
|
||
| using namespace llvm; | ||
| using namespace dwarf; | ||
|
|
||
| void CFIPrinter::print(const CFIProgram &P, raw_ostream &OS, | ||
| DIDumpOptions DumpOpts, unsigned IndentLevel, | ||
| std::optional<uint64_t> Address) { | ||
| for (const auto &Instr : P) { | ||
| uint8_t Opcode = Instr.Opcode; | ||
| OS.indent(2 * IndentLevel); | ||
| OS << P.callFrameString(Opcode) << ":"; | ||
| for (size_t i = 0; i < Instr.Ops.size(); ++i) | ||
| printOperand(OS, DumpOpts, P, Instr, i, Instr.Ops[i], Address); | ||
| OS << '\n'; | ||
| } | ||
| } | ||
|
|
||
| static void printRegister(raw_ostream &OS, DIDumpOptions DumpOpts, | ||
| unsigned RegNum) { | ||
| if (DumpOpts.GetNameForDWARFReg) { | ||
| auto RegName = DumpOpts.GetNameForDWARFReg(RegNum, DumpOpts.IsEH); | ||
| if (!RegName.empty()) { | ||
| OS << RegName; | ||
| return; | ||
| } | ||
| } | ||
| OS << "reg" << RegNum; | ||
| } | ||
|
|
||
| /// Print \p Opcode's operand number \p OperandIdx which has value \p Operand. | ||
| void CFIPrinter::printOperand(raw_ostream &OS, DIDumpOptions DumpOpts, | ||
| const CFIProgram &P, | ||
| const CFIProgram::Instruction &Instr, | ||
| unsigned OperandIdx, uint64_t Operand, | ||
| std::optional<uint64_t> &Address) { | ||
| assert(OperandIdx < CFIProgram::MaxOperands); | ||
| uint8_t Opcode = Instr.Opcode; | ||
| CFIProgram::OperandType Type = P.getOperandTypes()[Opcode][OperandIdx]; | ||
|
|
||
| switch (Type) { | ||
| case CFIProgram::OT_Unset: { | ||
| OS << " Unsupported " << (OperandIdx ? "second" : "first") << " operand to"; | ||
| auto OpcodeName = P.callFrameString(Opcode); | ||
| if (!OpcodeName.empty()) | ||
| OS << " " << OpcodeName; | ||
| else | ||
| OS << format(" Opcode %x", Opcode); | ||
| break; | ||
| } | ||
| case CFIProgram::OT_None: | ||
| break; | ||
| case CFIProgram::OT_Address: | ||
| OS << format(" %" PRIx64, Operand); | ||
| Address = Operand; | ||
| break; | ||
| case CFIProgram::OT_Offset: | ||
| // The offsets are all encoded in a unsigned form, but in practice | ||
| // consumers use them signed. It's most certainly legacy due to | ||
| // the lack of signed variants in the first Dwarf standards. | ||
| OS << format(" %+" PRId64, int64_t(Operand)); | ||
| break; | ||
| case CFIProgram::OT_FactoredCodeOffset: // Always Unsigned | ||
| if (P.CodeAlignmentFactor) | ||
| OS << format(" %" PRId64, Operand * P.CodeAlignmentFactor); | ||
| else | ||
| OS << format(" %" PRId64 "*code_alignment_factor", Operand); | ||
| if (Address && P.CodeAlignmentFactor) { | ||
| *Address += Operand * P.CodeAlignmentFactor; | ||
| OS << format(" to 0x%" PRIx64, *Address); | ||
| } | ||
| break; | ||
| case CFIProgram::OT_SignedFactDataOffset: | ||
| if (P.DataAlignmentFactor) | ||
| OS << format(" %" PRId64, int64_t(Operand) * P.DataAlignmentFactor); | ||
| else | ||
| OS << format(" %" PRId64 "*data_alignment_factor", int64_t(Operand)); | ||
| break; | ||
| case CFIProgram::OT_UnsignedFactDataOffset: | ||
| if (P.DataAlignmentFactor) | ||
| OS << format(" %" PRId64, Operand * P.DataAlignmentFactor); | ||
| else | ||
| OS << format(" %" PRId64 "*data_alignment_factor", Operand); | ||
| break; | ||
| case CFIProgram::OT_Register: | ||
| OS << ' '; | ||
| printRegister(OS, DumpOpts, Operand); | ||
| break; | ||
| case CFIProgram::OT_AddressSpace: | ||
| OS << format(" in addrspace%" PRId64, Operand); | ||
| break; | ||
| case CFIProgram::OT_Expression: | ||
| assert(Instr.Expression && "missing DWARFExpression object"); | ||
| OS << " "; | ||
| DWARFExpressionPrinter::print(&Instr.Expression.value(), OS, DumpOpts, | ||
| nullptr); | ||
| break; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.