Skip to content

Commit

Permalink
[BOLT][NFC] Extract a function for dump MCInst (#67225)
Browse files Browse the repository at this point in the history
In GDB debugging, obtaining the assembly representation of MCInst is
more intuitive.
  • Loading branch information
llongint committed Nov 21, 2023
1 parent 7f740be commit f3e54f2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,9 @@ class BinaryContext {
/// Return true if the function should be emitted to the output file.
bool shouldEmit(const BinaryFunction &Function) const;

/// Dump the assembly representation of MCInst to debug output.
void dump(const MCInst &Inst) const;

/// Print the string name for a CFI operation.
static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);

Expand Down
9 changes: 9 additions & 0 deletions bolt/lib/Core/BinaryContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
return HasRelocations || Function.isSimple();
}

void BinaryContext::dump(const MCInst &Inst) const {
if (LLVM_UNLIKELY(!InstPrinter)) {
dbgs() << "Cannot dump for InstPrinter is not initialized.\n";
return;
}
InstPrinter->printInst(&Inst, 0, "", *STI, dbgs());
dbgs() << "\n";
}

void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
uint32_t Operation = Inst.getOperation();
switch (Operation) {
Expand Down
10 changes: 4 additions & 6 deletions bolt/lib/Passes/ValidateInternalCalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,16 @@ bool ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
LLVM_DEBUG({
dbgs() << "Detected out-of-range PIC reference in " << Function
<< "\nReturn address load: ";
BC.InstPrinter->printInst(TargetInst, 0, "", *BC.STI, dbgs());
dbgs() << "\nUse: ";
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
dbgs() << "\n";
BC.dump(*TargetInst);
dbgs() << "Use: ";
BC.dump(Use);
Function.dump();
});
return false;
}
LLVM_DEBUG({
dbgs() << "Validated access: ";
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
dbgs() << "\n";
BC.dump(Use);
});
}
if (!UseDetected) {
Expand Down

0 comments on commit f3e54f2

Please sign in to comment.