Skip to content

Commit 1b86857

Browse files
committed
Clean up callgraph output
1 parent 937ff61 commit 1b86857

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
466466

467467
// Callgraph - Main data structure to maintain per function callgraph
468468
// information.
469-
MapVector<typename ELFT::uint, FunctionCallgraphInfo> FuncCGInfo;
469+
MapVector<typename ELFT::uint, FunctionCallgraphInfo> FuncCGInfos;
470470

471471
// // Callgraph - 64 bit type id mapped to entry PC addresses of functions
472472
// which
@@ -5381,7 +5381,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
53815381
reportError(std::move(CGSectionErr),
53825382
"While reading call graph info function entry PC");
53835383

5384-
if (FuncCGInfo.find(FuncAddr) != FuncCGInfo.end()) {
5384+
if (FuncCGInfos.find(FuncAddr) != FuncCGInfos.end()) {
53855385
Error DuplicatePcErr =
53865386
createError("for function PC: 0x" + Twine::utohexstr(FuncAddr));
53875387
reportError(std::move(DuplicatePcErr), "Duplicate call graph entry");
@@ -5444,7 +5444,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54445444
if (CGSectionErr)
54455445
PrintMalformedError(CGSectionErr, Twine::utohexstr(FuncAddr),
54465446
"number of direct callsites");
5447-
// Read direct call sites and populate FuncCGInfo.
5447+
// Read direct call sites and populate FuncCGInfos.
54485448
for (uint64_t I = 0; I < NumDirectCallees; ++I) {
54495449
typename ELFT::uint Callee =
54505450
Data.getUnsigned(&Offset, sizeof(Callee), &CGSectionErr);
@@ -5453,7 +5453,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54535453
"direct callee PC");
54545454
CGInfo.DirectCallees.insert(Callee);
54555455
}
5456-
FuncCGInfo[FuncAddr] = CGInfo;
5456+
FuncCGInfos[FuncAddr] = CGInfo;
54575457
}
54585458

54595459
if (NotListedCount)
@@ -5464,7 +5464,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54645464
std::to_string(UnknownCount) + " indirect targets.");
54655465

54665466
// Sort function info by function PC.
5467-
llvm::sort(FuncCGInfo,
5467+
llvm::sort(FuncCGInfos,
54685468
[](const auto &A, const auto &B) { return A.first < B.first; });
54695469
return true;
54705470
}
@@ -5486,32 +5486,41 @@ static StringRef GetFuntionKindString(FunctionKind Kind) {
54865486
template <class ELFT> void GNUELFDumper<ELFT>::printCallGraphInfo() {
54875487
if (!this->processCallGraphSection())
54885488
return;
5489+
if (this->FuncCGInfos.size() == 0)
5490+
return;
54895491
using FunctionCallgraphInfo =
54905492
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
5491-
for (const auto &El : this->FuncCGInfo) {
5493+
OS << "Call graph information:: \n";
5494+
for (const auto &El : this->FuncCGInfos) {
54925495
typename ELFT::uint FuncEntryPc = El.first;
54935496
FunctionCallgraphInfo CGInfo = El.second;
5494-
OS << "Function PC:: "
5497+
OS << "\nFunction PC:: 0x"
54955498
<< format("%lx", FuncEntryPc); // TODO: Print function name
54965499
OS << "\nFormatVersionNumber:: " << CGInfo.FormatVersionNumber;
54975500
OS << "\nFunction Kind:: " << GetFuntionKindString(CGInfo.Kind);
54985501
if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
5499-
OS << "\nFunction Type ID:: " << CGInfo.FunctionTypeId;
5502+
OS << "\nFunction Type ID:: 0x" << format("%lx", CGInfo.FunctionTypeId);
55005503
OS << "\nIndirect callee count:: " << CGInfo.IndirectCallsites.size();
55015504
if (CGInfo.IndirectCallsites.size() > 0) {
5502-
OS << "\n{";
5505+
OS << "\n{";
55035506
for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
5504-
OS << "\ncallsite: " << format("%lx", IndirCallSitePc);
5505-
OS << "\ncalleeTypeId: " << format("%lx", TypeId);
5506-
}
5507+
OS << "\n";
5508+
OS.PadToColumn(2);
5509+
OS << "callsite: 0x" << format("%lx", IndirCallSitePc);
5510+
OS << "\n";
5511+
OS.PadToColumn(2);
5512+
OS << "calleeTypeId: 0x" << format("%lx", TypeId);
5513+
}
55075514
OS << "\n}";
55085515
}
55095516
OS << "\nDirect callee count:: " << CGInfo.DirectCallees.size();
55105517
if (CGInfo.DirectCallees.size() > 0) {
55115518
OS << "\n{";
55125519
for (auto CalleePC : CGInfo.DirectCallees) {
5513-
OS << "\n" << format("%lx", CalleePC);
5514-
}
5520+
OS << "\n";
5521+
OS.PadToColumn(2);
5522+
OS << "0x" << format("%lx", CalleePC);
5523+
}
55155524
OS << "\n}";
55165525
}
55175526
OS << "\n";
@@ -8357,7 +8366,7 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCallGraphInfo() {
83578366

83588367
using FunctionCallgraphInfo =
83598368
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
8360-
for (const auto &El : this->FuncCGInfo) {
8369+
for (const auto &El : this->FuncCGInfos) {
83618370
typename ELFT::uint FuncEntryPc = El.first;
83628371
FunctionCallgraphInfo CGInfo = El.second;
83638372
std::string FuncPCStr = std::to_string(FuncEntryPc);

0 commit comments

Comments
 (0)