Skip to content

Commit f3e54f2

Browse files
authored
[BOLT][NFC] Extract a function for dump MCInst (#67225)
In GDB debugging, obtaining the assembly representation of MCInst is more intuitive.
1 parent 7f740be commit f3e54f2

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,9 @@ class BinaryContext {
12901290
/// Return true if the function should be emitted to the output file.
12911291
bool shouldEmit(const BinaryFunction &Function) const;
12921292

1293+
/// Dump the assembly representation of MCInst to debug output.
1294+
void dump(const MCInst &Inst) const;
1295+
12931296
/// Print the string name for a CFI operation.
12941297
static void printCFI(raw_ostream &OS, const MCCFIInstruction &Inst);
12951298

bolt/lib/Core/BinaryContext.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,6 +1738,15 @@ bool BinaryContext::shouldEmit(const BinaryFunction &Function) const {
17381738
return HasRelocations || Function.isSimple();
17391739
}
17401740

1741+
void BinaryContext::dump(const MCInst &Inst) const {
1742+
if (LLVM_UNLIKELY(!InstPrinter)) {
1743+
dbgs() << "Cannot dump for InstPrinter is not initialized.\n";
1744+
return;
1745+
}
1746+
InstPrinter->printInst(&Inst, 0, "", *STI, dbgs());
1747+
dbgs() << "\n";
1748+
}
1749+
17411750
void BinaryContext::printCFI(raw_ostream &OS, const MCCFIInstruction &Inst) {
17421751
uint32_t Operation = Inst.getOperation();
17431752
switch (Operation) {

bolt/lib/Passes/ValidateInternalCalls.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,16 @@ bool ValidateInternalCalls::analyzeFunction(BinaryFunction &Function) const {
281281
LLVM_DEBUG({
282282
dbgs() << "Detected out-of-range PIC reference in " << Function
283283
<< "\nReturn address load: ";
284-
BC.InstPrinter->printInst(TargetInst, 0, "", *BC.STI, dbgs());
285-
dbgs() << "\nUse: ";
286-
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
287-
dbgs() << "\n";
284+
BC.dump(*TargetInst);
285+
dbgs() << "Use: ";
286+
BC.dump(Use);
288287
Function.dump();
289288
});
290289
return false;
291290
}
292291
LLVM_DEBUG({
293292
dbgs() << "Validated access: ";
294-
BC.InstPrinter->printInst(&Use, 0, "", *BC.STI, dbgs());
295-
dbgs() << "\n";
293+
BC.dump(Use);
296294
});
297295
}
298296
if (!UseDetected) {

0 commit comments

Comments
 (0)