Skip to content

Commit 13771da

Browse files
committed
Address other review comments
1 parent a8fd5df commit 13771da

File tree

4 files changed

+57
-33
lines changed

4 files changed

+57
-33
lines changed

llvm/docs/CommandGuide/llvm-objdump.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,36 @@ OPTIONS
291291

292292
Target triple to disassemble for, see ``--version`` for available targets.
293293

294+
.. option:: --visualize-jumps=<modes>
295+
296+
Display a control-flow graph which shows the targets of branch instructions to the left of disasembly. ``modes`` is a comma-separated list of options, which configure the character set and used to print the graph.
297+
298+
If ``modes`` is omitted, the default is ``unicode,auto``
299+
300+
.. option:: off
301+
302+
Disable control-flow graph
303+
304+
.. option:: ascii
305+
306+
Render control-flow graph using ASCII characters
307+
308+
.. option:: unicode
309+
310+
Render control-flow graph using unicode box-drawing characters
311+
312+
.. option:: nocolor
313+
314+
Render control-flow graph without using colors
315+
316+
.. option:: auto
317+
318+
Render control-flow graph using colors if supported by the terminal
319+
320+
.. option:: color
321+
322+
Render control-flow graph using colors
323+
294324
.. option:: -w, --wide
295325

296326
Ignored for compatibility with GNU objdump.

llvm/tools/llvm-objdump/SourcePrinter.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,19 @@ const char *LiveVariablePrinter::getLineChar(LineChar C) const {
211211
bool IsASCII = DbgVariables == DVASCII;
212212
switch (C) {
213213
case LineChar::RangeStart:
214-
return IsASCII ? "^" : (const char *)u8"\u2548";
214+
return IsASCII ? "^" : u8"\u2548";
215215
case LineChar::RangeMid:
216-
return IsASCII ? "|" : (const char *)u8"\u2503";
216+
return IsASCII ? "|" : u8"\u2503";
217217
case LineChar::RangeEnd:
218-
return IsASCII ? "v" : (const char *)u8"\u253b";
218+
return IsASCII ? "v" : u8"\u253b";
219219
case LineChar::LabelVert:
220-
return IsASCII ? "|" : (const char *)u8"\u2502";
220+
return IsASCII ? "|" : u8"\u2502";
221221
case LineChar::LabelCornerNew:
222-
return IsASCII ? "/" : (const char *)u8"\u250c";
222+
return IsASCII ? "/" : u8"\u250c";
223223
case LineChar::LabelCornerActive:
224-
return IsASCII ? "|" : (const char *)u8"\u2520";
224+
return IsASCII ? "|" : u8"\u2520";
225225
case LineChar::LabelHoriz:
226-
return IsASCII ? "-" : (const char *)u8"\u2500";
226+
return IsASCII ? "-" : u8"\u2500";
227227
}
228228
llvm_unreachable("Unhandled LineChar enum");
229229
}
@@ -516,6 +516,15 @@ const raw_ostream::Colors LineColors[] = {
516516
raw_ostream::CYAN,
517517
};
518518

519+
raw_ostream::Colors ControlFlowPrinter::PickColor() {
520+
if (!OutputMode.color_enabled())
521+
return raw_ostream::RESET;
522+
auto Ret = LineColors[NextColorIdx];
523+
NextColorIdx =
524+
(NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
525+
return Ret;
526+
}
527+
519528
void ControlFlowPrinter::addEdge(uint64_t From, uint64_t To) {
520529
auto It = Targets.find(To);
521530
if (It == Targets.end())
@@ -551,32 +560,24 @@ void ControlFlowPrinter::finalise() {
551560
T->Column = Column;
552561
MaxColumn = std::max(MaxColumn, Column);
553562

554-
#if 1
555-
LLVM_DEBUG(
556-
dbgs() << "Target: 0x" << Twine::utohexstr(T->Target) << " (" << T->Length()
557-
<< ") Column " << Column << ":\n";
558-
for (auto Source : T->Sources)
559-
dbgs() << " Source: 0x" << Twine::utohexstr(Source) << "\n";
560-
);
561-
#endif
562563
}
563564

564565
setControlFlowColumnWidth(MaxColumn * 2 + 4);
565566
}
566567

567568
const char *ControlFlowPrinter::getLineChar(LineChar C) const {
568-
bool IsASCII = OutputMode.Chars == VisualizeJumpsMode::ASCII;
569+
bool IsASCII = !OutputMode.unicode_enabled();
569570
switch (C) {
570571
case LineChar::Horiz:
571-
return IsASCII ? "-" : (const char *)u8"\u2500";
572+
return IsASCII ? "-" : u8"\u2500";
572573
case LineChar::Vert:
573-
return IsASCII ? "|" : (const char *)u8"\u2502";
574+
return IsASCII ? "|" : u8"\u2502";
574575
case LineChar::TopCorner:
575-
return IsASCII ? "/" : (const char *)u8"\u256d";
576+
return IsASCII ? "/" : u8"\u256d";
576577
case LineChar::BottomCorner:
577-
return IsASCII ? "\\" : (const char *)u8"\u2570";
578+
return IsASCII ? "\\" : u8"\u2570";
578579
case LineChar::Tee:
579-
return IsASCII ? "+" : (const char *)u8"\u251c";
580+
return IsASCII ? "+" : u8"\u251c";
580581
case LineChar::Arrow:
581582
return ">";
582583
}

llvm/tools/llvm-objdump/SourcePrinter.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct VisualizeJumpsMode {
184184

185185
bool enabled() const { return Chars != Off; }
186186
bool color_enabled() const { return enabled() && Colors != BlackAndWhite; }
187+
bool unicode_enabled() const { return Chars == Unicode; }
187188

188189
void ResolveAutoColor(raw_ostream &OS) {
189190
if (Colors == Auto)
@@ -246,14 +247,7 @@ class ControlFlowPrinter {
246247
const MCSubtargetInfo &STI;
247248

248249
int NextColorIdx;
249-
raw_ostream::Colors PickColor() {
250-
if ((OutputMode & VisualizeJumpsMode::ColorMask) ==
251-
VisualizeJumpsMode::Off)
252-
return raw_ostream::RESET;
253-
auto Ret = LineColors[NextColorIdx];
254-
NextColorIdx = (NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
255-
return Ret;
256-
}
250+
raw_ostream::Colors PickColor();
257251

258252
int getIndentLevel() const { return 10; }
259253

llvm/tools/llvm-objdump/llvm-objdump.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,8 @@ unsigned objdump::GetColumnIndent(MCSubtargetInfo const &STI,
514514
// Special case for assembly string: the assembly printer uses tabs, so we
515515
// need to ensure we start the instruction on a tab stop (multiple of 8).
516516
Indent = alignTo(Indent, 8);
517-
if (Col == DisassemblyColumn::Assembly) {
517+
if (Col == DisassemblyColumn::Assembly)
518518
return Indent;
519-
}
520519

521520
// Assembly width can be configured with --debug-vars-indent=
522521
// FIXME this variable name is confusing.
@@ -1376,8 +1375,8 @@ collectLocalBranchTargets(ArrayRef<uint8_t> Bytes, MCInstrAnalysis *MIA,
13761375
End += SectionAddr;
13771376
uint64_t Index = Start;
13781377

1379-
std::vector<RelocationRef>::const_iterator RelCur = Relocs.begin();
1380-
std::vector<RelocationRef>::const_iterator RelEnd = Relocs.end();
1378+
auto RelCur = Relocs.begin();
1379+
auto RelEnd = Relocs.end();
13811380

13821381
while (Index < End) {
13831382
// Disassemble a real instruction and record function-local branch labels.

0 commit comments

Comments
 (0)