Skip to content

Commit 783ba64

Browse files
committed
[JITLink] Improve formatting for Edge, Block and Symbol debugging output.
1 parent 44664a5 commit 783ba64

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

llvm/lib/ExecutionEngine/JITLink/JITLink.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const char *getScopeName(Scope S) {
9393
raw_ostream &operator<<(raw_ostream &OS, const Block &B) {
9494
return OS << formatv("{0:x16}", B.getAddress()) << " -- "
9595
<< formatv("{0:x16}", B.getAddress() + B.getSize()) << ": "
96+
<< "size = " << formatv("{0:x}", B.getSize()) << ", "
9697
<< (B.isZeroFill() ? "zero-fill" : "content")
9798
<< ", align = " << B.getAlignment()
9899
<< ", align-ofs = " << B.getAlignmentOffset()
@@ -126,10 +127,10 @@ raw_ostream &operator<<(raw_ostream &OS, const Symbol &Sym) {
126127
break;
127128
}
128129
OS << (Sym.isLive() ? '+' : '-')
129-
<< ", size = " << formatv("{0:x8}", Sym.getSize())
130+
<< ", size = " << formatv("{0:x}", Sym.getSize())
130131
<< ", addr = " << formatv("{0:x16}", Sym.getAddress()) << " ("
131132
<< formatv("{0:x16}", Sym.getAddressable().getAddress()) << " + "
132-
<< formatv("{0:x8}", Sym.getOffset());
133+
<< formatv("{0:x}", Sym.getOffset());
133134
if (Sym.isDefined())
134135
OS << " " << Sym.getBlock().getSection().getName();
135136
OS << ")>";
@@ -139,8 +140,33 @@ raw_ostream &operator<<(raw_ostream &OS, const Symbol &Sym) {
139140
void printEdge(raw_ostream &OS, const Block &B, const Edge &E,
140141
StringRef EdgeKindName) {
141142
OS << "edge@" << formatv("{0:x16}", B.getAddress() + E.getOffset()) << ": "
142-
<< formatv("{0:x16}", B.getAddress()) << " + " << E.getOffset() << " -- "
143-
<< EdgeKindName << " -> " << E.getTarget() << " + " << E.getAddend();
143+
<< formatv("{0:x16}", B.getAddress()) << " + "
144+
<< formatv("{0:x}", E.getOffset()) << " -- " << EdgeKindName << " -> ";
145+
146+
auto &TargetSym = E.getTarget();
147+
if (TargetSym.hasName())
148+
OS << TargetSym.getName();
149+
else {
150+
auto &TargetBlock = TargetSym.getBlock();
151+
auto &TargetSec = TargetBlock.getSection();
152+
JITTargetAddress SecAddress = ~JITTargetAddress(0);
153+
for (auto *B : TargetSec.blocks())
154+
if (B->getAddress() < SecAddress)
155+
SecAddress = B->getAddress();
156+
157+
JITTargetAddress SecDelta = TargetSym.getAddress() - SecAddress;
158+
OS << formatv("{0:x16}", TargetSym.getAddress()) << " (section "
159+
<< TargetSec.getName();
160+
if (SecDelta)
161+
OS << " + " << formatv("{0:x}", SecDelta);
162+
OS << " / block " << formatv("{0:x16}", TargetBlock.getAddress());
163+
if (TargetSym.getOffset())
164+
OS << " + " << formatv("{0:x}", TargetSym.getOffset());
165+
OS << ")";
166+
}
167+
168+
if (E.getAddend() != 0)
169+
OS << " + " << E.getAddend();
144170
}
145171

146172
Section::~Section() {

0 commit comments

Comments
 (0)