Skip to content

Commit d015578

Browse files
authored
[llvm-gsymutil] Fix dumping of call sites for merged functions (#119759)
Currently, when dumping the contents of a GSYM there are three issues: - Callsite information is not displayed for merged functions - this is because of a bug in `CallSiteInfoLoader::buildFunctionMap` where when enumerating through `Func.MergedFunctions` - we enumerate by value instead of by reference. - There is no variable indent for printing callsite info - meaning that when printing callsites for merged functions, the indent will be different than the other info of the merged function. To address this we add configurable indent for printing callsite info - Callsite info is printed right after merged function info. Meaning that if the merged function also has call site information, the parent's callsite info will appear right after the merged function's callsite info - leading to confusion. To address this we print the callsite info first, then the merged functions info. This change addresses all the above 3 issues. Example of old vs new: <img width="1074" alt="image" src="https://github.com/user-attachments/assets/d039ad69-fa79-4abb-9816-eda9cc2eda53" />
1 parent 9bf7930 commit d015578

File tree

4 files changed

+1523
-7
lines changed

4 files changed

+1523
-7
lines changed

llvm/include/llvm/DebugInfo/GSYM/GsymReader.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ class GsymReader {
199199
/// \param OS The output stream to dump to.
200200
///
201201
/// \param CSIC The CallSiteInfoCollection object to dump.
202-
void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC);
202+
///
203+
/// \param Indent The indentation as number of spaces. Used when dumping as an
204+
/// item from within MergedFunctionsInfo.
205+
void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
206+
uint32_t Indent = 0);
203207

204208
/// Dump a LineTable object.
205209
///

llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ StringMap<FunctionInfo *> CallSiteInfoLoader::buildFunctionMap() {
181181
StringMap<FunctionInfo *> FuncMap;
182182
for (auto &Func : Funcs) {
183183
FuncMap.try_emplace(GCreator.getString(Func.Name), &Func);
184-
if (auto MFuncs = Func.MergedFunctions)
184+
if (auto &MFuncs = Func.MergedFunctions)
185185
for (auto &MFunc : MFuncs->MergedFunctions)
186186
FuncMap.try_emplace(GCreator.getString(MFunc.Name), &MFunc);
187187
}

llvm/lib/DebugInfo/GSYM/GsymReader.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,13 @@ void GsymReader::dump(raw_ostream &OS, const FunctionInfo &FI,
406406
if (FI.Inline)
407407
dump(OS, *FI.Inline, Indent);
408408

409+
if (FI.CallSites)
410+
dump(OS, *FI.CallSites, Indent);
411+
409412
if (FI.MergedFunctions) {
410413
assert(Indent == 0 && "MergedFunctionsInfo should only exist at top level");
411414
dump(OS, *FI.MergedFunctions);
412415
}
413-
414-
if (FI.CallSites)
415-
dump(OS, *FI.CallSites);
416416
}
417417

418418
void GsymReader::dump(raw_ostream &OS, const MergedFunctionsInfo &MFI) {
@@ -454,10 +454,13 @@ void GsymReader::dump(raw_ostream &OS, const CallSiteInfo &CSI) {
454454
}
455455
}
456456

457-
void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC) {
457+
void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
458+
uint32_t Indent) {
459+
OS.indent(Indent);
458460
OS << "CallSites (by relative return offset):\n";
459461
for (const auto &CS : CSIC.CallSites) {
460-
OS.indent(2);
462+
OS.indent(Indent);
463+
OS << " ";
461464
dump(OS, CS);
462465
OS << "\n";
463466
}

0 commit comments

Comments
 (0)