Skip to content

Commit 937ff61

Browse files
committed
format
1 parent 5b6bb00 commit 937ff61

File tree

1 file changed

+66
-60
lines changed

1 file changed

+66
-60
lines changed

llvm/tools/llvm-readobj/ELFDumper.cpp

Lines changed: 66 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ enum class FunctionKind : uint64_t {
203203

204204
// Per-function call graph information.
205205
template <typename AddrType> struct FunctionCallgraphInfoImpl {
206-
uint64_t FormatVersionNumber;
206+
uint64_t FormatVersionNumber;
207207
FunctionKind Kind;
208-
uint64_t FunctionTypeId; // Only if Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID
208+
uint64_t
209+
FunctionTypeId; // Only if Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID
209210
DenseMap<AddrType, uint64_t> IndirectCallsites;
210211
SmallSet<AddrType, 4> DirectCallees;
211212
};
@@ -466,11 +467,12 @@ template <typename ELFT> class ELFDumper : public ObjDumper {
466467
// Callgraph - Main data structure to maintain per function callgraph
467468
// information.
468469
MapVector<typename ELFT::uint, FunctionCallgraphInfo> FuncCGInfo;
469-
470-
// // Callgraph - 64 bit type id mapped to entry PC addresses of functions which
470+
471+
// // Callgraph - 64 bit type id mapped to entry PC addresses of functions
472+
// which
471473
// // are of the given type id.
472474
// MapVector<uint64_t, SmallVector<typename ELFT::uint>> TypeIdToIndirTargets;
473-
475+
474476
// Callgraph - Read callgraph section and process its contents to populate
475477
// Callgraph related data structures which will be used to dump callgraph
476478
// info. Returns false if there is no .callgraph section in the input file.
@@ -5433,7 +5435,7 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54335435
Data.getUnsigned(&Offset, sizeof(CallSitePc), &CGSectionErr);
54345436
if (CGSectionErr)
54355437
PrintMalformedError(CGSectionErr, Twine::utohexstr(FuncAddr),
5436-
"indirect callsite PC");
5438+
"indirect callsite PC");
54375439
CGInfo.IndirectCallsites.try_emplace(CallSitePc, TypeId);
54385440
}
54395441

@@ -5468,15 +5470,15 @@ template <class ELFT> bool ELFDumper<ELFT>::processCallGraphSection() {
54685470
}
54695471

54705472
static StringRef GetFuntionKindString(FunctionKind Kind) {
5471-
switch(Kind) {
5472-
case FunctionKind::NOT_INDIRECT_TARGET:
5473-
return "NOT_INDIRECT_TARGET";
5474-
case FunctionKind::INDIRECT_TARGET_UNKNOWN_TID:
5475-
return "INDIRECT_TARGET_UNKNOWN_TID";
5476-
case FunctionKind::INDIRECT_TARGET_KNOWN_TID:
5477-
return "INDIRECT_TARGET_KNOWN_TID";
5478-
case FunctionKind::NOT_LISTED:
5479-
return "NOT_LISTED";
5473+
switch (Kind) {
5474+
case FunctionKind::NOT_INDIRECT_TARGET:
5475+
return "NOT_INDIRECT_TARGET";
5476+
case FunctionKind::INDIRECT_TARGET_UNKNOWN_TID:
5477+
return "INDIRECT_TARGET_UNKNOWN_TID";
5478+
case FunctionKind::INDIRECT_TARGET_KNOWN_TID:
5479+
return "INDIRECT_TARGET_KNOWN_TID";
5480+
case FunctionKind::NOT_LISTED:
5481+
return "NOT_LISTED";
54805482
}
54815483
llvm_unreachable("Unknown FunctionKind.");
54825484
}
@@ -5485,34 +5487,35 @@ template <class ELFT> void GNUELFDumper<ELFT>::printCallGraphInfo() {
54855487
if (!this->processCallGraphSection())
54865488
return;
54875489
using FunctionCallgraphInfo =
5488-
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
5490+
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
54895491
for (const auto &El : this->FuncCGInfo) {
5490-
typename ELFT::uint FuncEntryPc = El.first;
5491-
FunctionCallgraphInfo CGInfo = El.second;
5492-
OS << "Function PC:: " << format("%lx", FuncEntryPc); // TODO: Print function name
5493-
OS << "\nFormatVersionNumber:: " << CGInfo.FormatVersionNumber;
5494-
OS << "\nFunction Kind:: " << GetFuntionKindString(CGInfo.Kind);
5495-
if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
5496-
OS << "\nFunction Type ID:: " << CGInfo.FunctionTypeId;
5497-
OS << "\nIndirect callee count:: " << CGInfo.IndirectCallsites.size();
5498-
if(CGInfo.IndirectCallsites.size() > 0) {
5499-
OS << "\n{";
5500-
for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
5501-
OS << "\ncallsite: " << format("%lx", IndirCallSitePc);
5502-
OS << "\ncalleeTypeId: " << format("%lx", TypeId);
5503-
}
5504-
OS << "\n}";
5492+
typename ELFT::uint FuncEntryPc = El.first;
5493+
FunctionCallgraphInfo CGInfo = El.second;
5494+
OS << "Function PC:: "
5495+
<< format("%lx", FuncEntryPc); // TODO: Print function name
5496+
OS << "\nFormatVersionNumber:: " << CGInfo.FormatVersionNumber;
5497+
OS << "\nFunction Kind:: " << GetFuntionKindString(CGInfo.Kind);
5498+
if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
5499+
OS << "\nFunction Type ID:: " << CGInfo.FunctionTypeId;
5500+
OS << "\nIndirect callee count:: " << CGInfo.IndirectCallsites.size();
5501+
if (CGInfo.IndirectCallsites.size() > 0) {
5502+
OS << "\n{";
5503+
for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
5504+
OS << "\ncallsite: " << format("%lx", IndirCallSitePc);
5505+
OS << "\ncalleeTypeId: " << format("%lx", TypeId);
55055506
}
5506-
OS << "\nDirect callee count:: " << CGInfo.DirectCallees.size();
5507-
if(CGInfo.DirectCallees.size() > 0) {
5508-
OS << "\n{";
5509-
for (auto CalleePC : CGInfo.DirectCallees) {
5510-
OS << "\n" << format("%lx", CalleePC);
5511-
}
5512-
OS << "\n}";
5507+
OS << "\n}";
5508+
}
5509+
OS << "\nDirect callee count:: " << CGInfo.DirectCallees.size();
5510+
if (CGInfo.DirectCallees.size() > 0) {
5511+
OS << "\n{";
5512+
for (auto CalleePC : CGInfo.DirectCallees) {
5513+
OS << "\n" << format("%lx", CalleePC);
55135514
}
5514-
OS << "\n";
5515-
}
5515+
OS << "\n}";
5516+
}
5517+
OS << "\n";
5518+
}
55165519
}
55175520

55185521
template <class ELFT>
@@ -8353,28 +8356,31 @@ template <class ELFT> void LLVMELFDumper<ELFT>::printCallGraphInfo() {
83538356
DictScope D(this->W, "callgraph_info");
83548357

83558358
using FunctionCallgraphInfo =
8356-
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
8359+
::FunctionCallgraphInfoImpl<typename ELFT::uint>;
83578360
for (const auto &El : this->FuncCGInfo) {
8358-
typename ELFT::uint FuncEntryPc = El.first;
8359-
FunctionCallgraphInfo CGInfo = El.second;
8360-
std::string FuncPCStr = std::to_string(FuncEntryPc);
8361-
DictScope FuncScope(this->W, FuncPCStr); // TODO: Print function name
8362-
this->W.printNumber("FormatVersionNumber", CGInfo.FormatVersionNumber);
8363-
this->W.printNumber("Kind", (uint64_t)CGInfo.Kind); // TODO: Print Function Kind String GetFuntionKindString(El.second.Kind);
8364-
if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
8365-
this->W.printNumber("TypeId", CGInfo.FunctionTypeId);
8366-
this->W.printNumber("NumIndirectCallSites", CGInfo.IndirectCallsites.size());
8367-
if(CGInfo.IndirectCallsites.size() > 0) {
8368-
ListScope ICT(this->W, "indirect_call_sites");
8369-
for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
8370-
DictScope IDC(this->W);
8371-
this->W.printHex("callsite", IndirCallSitePc);
8372-
this->W.printHex("type_id", TypeId);
8373-
}
8361+
typename ELFT::uint FuncEntryPc = El.first;
8362+
FunctionCallgraphInfo CGInfo = El.second;
8363+
std::string FuncPCStr = std::to_string(FuncEntryPc);
8364+
DictScope FuncScope(this->W, FuncPCStr); // TODO: Print function name
8365+
this->W.printNumber("FormatVersionNumber", CGInfo.FormatVersionNumber);
8366+
this->W.printNumber(
8367+
"Kind", (uint64_t)CGInfo.Kind); // TODO: Print Function Kind String
8368+
// GetFuntionKindString(El.second.Kind);
8369+
if (CGInfo.Kind == FunctionKind::INDIRECT_TARGET_KNOWN_TID)
8370+
this->W.printNumber("TypeId", CGInfo.FunctionTypeId);
8371+
this->W.printNumber("NumIndirectCallSites",
8372+
CGInfo.IndirectCallsites.size());
8373+
if (CGInfo.IndirectCallsites.size() > 0) {
8374+
ListScope ICT(this->W, "indirect_call_sites");
8375+
for (auto &[IndirCallSitePc, TypeId] : CGInfo.IndirectCallsites) {
8376+
DictScope IDC(this->W);
8377+
this->W.printHex("callsite", IndirCallSitePc);
8378+
this->W.printHex("type_id", TypeId);
83748379
}
8375-
this->W.printNumber("NumDirectCallSites", CGInfo.DirectCallees.size());
8376-
if(CGInfo.DirectCallees.size() > 0)
8377-
this->W.printHexList("direct_callees", CGInfo.DirectCallees);
8380+
}
8381+
this->W.printNumber("NumDirectCallSites", CGInfo.DirectCallees.size());
8382+
if (CGInfo.DirectCallees.size() > 0)
8383+
this->W.printHexList("direct_callees", CGInfo.DirectCallees);
83788384
}
83798385
}
83808386

0 commit comments

Comments
 (0)