Skip to content

Commit

Permalink
[llvm-gsymutil] Fix dumping of call sites for merged functions (#119759)
Browse files Browse the repository at this point in the history
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"
/>
  • Loading branch information
alx32 authored Dec 13, 2024
1 parent 9bf7930 commit d015578
Show file tree
Hide file tree
Showing 4 changed files with 1,523 additions and 7 deletions.
6 changes: 5 additions & 1 deletion llvm/include/llvm/DebugInfo/GSYM/GsymReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,11 @@ class GsymReader {
/// \param OS The output stream to dump to.
///
/// \param CSIC The CallSiteInfoCollection object to dump.
void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC);
///
/// \param Indent The indentation as number of spaces. Used when dumping as an
/// item from within MergedFunctionsInfo.
void dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
uint32_t Indent = 0);

/// Dump a LineTable object.
///
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/DebugInfo/GSYM/CallSiteInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ StringMap<FunctionInfo *> CallSiteInfoLoader::buildFunctionMap() {
StringMap<FunctionInfo *> FuncMap;
for (auto &Func : Funcs) {
FuncMap.try_emplace(GCreator.getString(Func.Name), &Func);
if (auto MFuncs = Func.MergedFunctions)
if (auto &MFuncs = Func.MergedFunctions)
for (auto &MFunc : MFuncs->MergedFunctions)
FuncMap.try_emplace(GCreator.getString(MFunc.Name), &MFunc);
}
Expand Down
13 changes: 8 additions & 5 deletions llvm/lib/DebugInfo/GSYM/GsymReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,13 +406,13 @@ void GsymReader::dump(raw_ostream &OS, const FunctionInfo &FI,
if (FI.Inline)
dump(OS, *FI.Inline, Indent);

if (FI.CallSites)
dump(OS, *FI.CallSites, Indent);

if (FI.MergedFunctions) {
assert(Indent == 0 && "MergedFunctionsInfo should only exist at top level");
dump(OS, *FI.MergedFunctions);
}

if (FI.CallSites)
dump(OS, *FI.CallSites);
}

void GsymReader::dump(raw_ostream &OS, const MergedFunctionsInfo &MFI) {
Expand Down Expand Up @@ -454,10 +454,13 @@ void GsymReader::dump(raw_ostream &OS, const CallSiteInfo &CSI) {
}
}

void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC) {
void GsymReader::dump(raw_ostream &OS, const CallSiteInfoCollection &CSIC,
uint32_t Indent) {
OS.indent(Indent);
OS << "CallSites (by relative return offset):\n";
for (const auto &CS : CSIC.CallSites) {
OS.indent(2);
OS.indent(Indent);
OS << " ";
dump(OS, CS);
OS << "\n";
}
Expand Down
Loading

0 comments on commit d015578

Please sign in to comment.