Skip to content

Commit

Permalink
Correctly assign frames in ROAR symbolization
Browse files Browse the repository at this point in the history
Summary:
Previously we were just assigning frame name to a string
returned by the runtime, and such string was decorated with multiple
information which would imply folly's demangler does not work. Assign
the symbol name correctly, so the demangler works, and put file name
and line info in their correct fields. Assign each inlined frame
separately from caller and pass to the runtime correct mode (with
source info, with inline info).

Reviewed By: mofarrell

Differential Revision: D67418699

fbshipit-source-id: b0b30e79315a8eb8d78856a7c3e1fa9676d554d7
  • Loading branch information
rafaelauler authored and facebook-github-bot committed Dec 19, 2024
1 parent 2587ce2 commit ad12236
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions folly/debugging/symbolizer/Symbolizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
#endif

#ifdef __roar__
extern "C" char* _roar_upcall_symbolizeAddress(void* Address);
extern "C" char* _roar_upcall_symbolizeAddress(
void* Address, unsigned* NumFrames, bool WithSrcLine, bool WithInline);
#endif

namespace folly {
Expand Down Expand Up @@ -102,6 +103,52 @@ ElfCache* defaultElfCache() {
return cache;
}

#ifdef __roar__
bool setROARSymbolizedFrame(
SymbolizedFrame& frame,
uintptr_t address,
LocationInfoMode mode,
folly::Range<SymbolizedFrame*> extraInlineFrames = {}) {
const bool withSrcLine = mode != LocationInfoMode::DISABLED;
const bool withInline = mode == LocationInfoMode::FULL_WITH_INLINE;
unsigned numFrames = 0;
char* jitNames = _roar_upcall_symbolizeAddress(
reinterpret_cast<void*>(address), &numFrames, withSrcLine, withInline);
if (numFrames == 0)
return false;
unsigned firstFrame =
numFrames - std::min<unsigned>(numFrames, extraInlineFrames.size() + 1);
unsigned i = 0;
for (unsigned curFrame = 0; curFrame < numFrames; ++curFrame) {
std::string_view name = std::string_view(jitNames);
jitNames += name.size() + 1;
std::string_view fileName = std::string_view(jitNames);
jitNames += fileName.size() + 1;
std::string_view lineNo = std::string_view(jitNames);
jitNames += lineNo.size() + 1;
if (curFrame < firstFrame) {
continue;
}
if (curFrame == numFrames - 1) {
frame.name = name.data();
frame.location.hasFileAndLine = withSrcLine && !fileName.empty();
frame.location.file = Path({}, {}, fileName);
frame.location.line = atoi(lineNo.data());
break;
}
extraInlineFrames[i].found = true;
extraInlineFrames[i].addr = address;
extraInlineFrames[i].name = name.data();
extraInlineFrames[i].location.hasFileAndLine =
withSrcLine && !fileName.empty();
extraInlineFrames[i].location.file = Path({}, {}, fileName);
extraInlineFrames[i].location.line = atoi(lineNo.data());
++i;
}
return true;
}
#endif

void setSymbolizedFrame(
ElfCacheBase* const elfCache,
SymbolizedFrame& frame,
Expand All @@ -115,11 +162,9 @@ void setSymbolizedFrame(
frame.file = file;
frame.name = file->getSymbolName(file->getDefinitionByAddress(address));
#ifdef __roar__
if (!frame.name) {
char* jit_name =
_roar_upcall_symbolizeAddress(reinterpret_cast<void*>(address));
if (jit_name && jit_name[0] != '\0')
frame.name = jit_name;
if (!frame.name &&
setROARSymbolizedFrame(frame, address, mode, extraInlineFrames)) {
return;
}
#endif

Expand Down

0 comments on commit ad12236

Please sign in to comment.