mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-14 11:39:35 +00:00
[BOLT][NFC] Move printDebugInfo out of BC::printInstruction
Simplify `BinaryContext::printInstruction`. Reviewed By: ayermolo Differential Revision: https://reviews.llvm.org/D127561
This commit is contained in:
parent
a838043f38
commit
7dee646b28
@ -239,7 +239,7 @@ public:
|
||||
Optional<DWARFUnit *> getDWOCU(uint64_t DWOId);
|
||||
|
||||
/// Returns DWOContext if it exists.
|
||||
DWARFContext *getDWOContext();
|
||||
DWARFContext *getDWOContext() const;
|
||||
|
||||
/// Get Number of DWOCUs in a map.
|
||||
uint32_t getNumDWOCUs() { return DWOCUs.size(); }
|
||||
|
@ -1411,7 +1411,7 @@ Optional<DWARFUnit *> BinaryContext::getDWOCU(uint64_t DWOId) {
|
||||
return Iter->second;
|
||||
}
|
||||
|
||||
DWARFContext *BinaryContext::getDWOContext() {
|
||||
DWARFContext *BinaryContext::getDWOContext() const {
|
||||
if (DWOCUs.empty())
|
||||
return nullptr;
|
||||
return &DWOCUs.begin()->second->getContext();
|
||||
@ -1673,6 +1673,36 @@ bool BinaryContext::isMarker(const SymbolRef &Symbol) const {
|
||||
return getMarkerType(Symbol) != MarkerSymType::NONE;
|
||||
}
|
||||
|
||||
static void printDebugInfo(raw_ostream &OS, const MCInst &Instruction,
|
||||
const BinaryFunction *Function,
|
||||
DWARFContext *DwCtx) {
|
||||
DebugLineTableRowRef RowRef =
|
||||
DebugLineTableRowRef::fromSMLoc(Instruction.getLoc());
|
||||
if (RowRef == DebugLineTableRowRef::NULL_ROW)
|
||||
return;
|
||||
|
||||
const DWARFDebugLine::LineTable *LineTable;
|
||||
if (Function && Function->getDWARFUnit() &&
|
||||
Function->getDWARFUnit()->getOffset() == RowRef.DwCompileUnitIndex) {
|
||||
LineTable = Function->getDWARFLineTable();
|
||||
} else {
|
||||
LineTable = DwCtx->getLineTableForUnit(
|
||||
DwCtx->getCompileUnitForOffset(RowRef.DwCompileUnitIndex));
|
||||
}
|
||||
assert(LineTable && "line table expected for instruction with debug info");
|
||||
|
||||
const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
|
||||
StringRef FileName = "";
|
||||
if (Optional<const char *> FName =
|
||||
dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
|
||||
FileName = *FName;
|
||||
OS << " # debug line " << FileName << ":" << Row.Line;
|
||||
if (Row.Column)
|
||||
OS << ":" << Row.Column;
|
||||
if (Row.Discriminator)
|
||||
OS << " discriminator:" << Row.Discriminator;
|
||||
}
|
||||
|
||||
void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
|
||||
uint64_t Offset,
|
||||
const BinaryFunction *Function,
|
||||
@ -1720,33 +1750,8 @@ void BinaryContext::printInstruction(raw_ostream &OS, const MCInst &Instruction,
|
||||
|
||||
MIB->printAnnotations(Instruction, OS);
|
||||
|
||||
if (opts::PrintDebugInfo) {
|
||||
DebugLineTableRowRef RowRef =
|
||||
DebugLineTableRowRef::fromSMLoc(Instruction.getLoc());
|
||||
if (RowRef != DebugLineTableRowRef::NULL_ROW) {
|
||||
const DWARFDebugLine::LineTable *LineTable;
|
||||
if (Function && Function->getDWARFUnit() &&
|
||||
Function->getDWARFUnit()->getOffset() == RowRef.DwCompileUnitIndex) {
|
||||
LineTable = Function->getDWARFLineTable();
|
||||
} else {
|
||||
LineTable = DwCtx->getLineTableForUnit(
|
||||
DwCtx->getCompileUnitForOffset(RowRef.DwCompileUnitIndex));
|
||||
}
|
||||
assert(LineTable &&
|
||||
"line table expected for instruction with debug info");
|
||||
|
||||
const DWARFDebugLine::Row &Row = LineTable->Rows[RowRef.RowIndex - 1];
|
||||
StringRef FileName = "";
|
||||
if (Optional<const char *> FName =
|
||||
dwarf::toString(LineTable->Prologue.FileNames[Row.File - 1].Name))
|
||||
FileName = *FName;
|
||||
OS << " # debug line " << FileName << ":" << Row.Line;
|
||||
if (Row.Column)
|
||||
OS << ":" << Row.Column;
|
||||
if (Row.Discriminator)
|
||||
OS << " discriminator:" << Row.Discriminator;
|
||||
}
|
||||
}
|
||||
if (opts::PrintDebugInfo)
|
||||
printDebugInfo(OS, Instruction, Function, DwCtx.get());
|
||||
|
||||
if ((opts::PrintRelocations || PrintRelocations) && Function) {
|
||||
const uint64_t Size = computeCodeSize(&Instruction, &Instruction + 1);
|
||||
|
Loading…
Reference in New Issue
Block a user