Skip to content

Commit

Permalink
Add optional rust demangling support in perfparser
Browse files Browse the repository at this point in the history
When librustc_demangle.so and rustc_demangle.h are provided
externally, perfparser can now leverage that to demangle rust
symbols.

See also: https://github.com/alexcrichton/rustc-demangle

Relates-To: KDAB/hotspot#237
Change-Id: I0a66598e4ae3aa1dbf2776587934677beadd5968
  • Loading branch information
milianw committed May 16, 2020
1 parent 18c0e89 commit 07ce8fb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/perfsymboltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#define O_BINARY 0
#endif

#ifdef HAVE_RUSTC_DEMANGLE
#include <rustc_demangle.h>
#endif

PerfSymbolTable::PerfSymbolTable(qint32 pid, Dwfl_Callbacks *callbacks, PerfUnwind *parent) :
m_perfMapFile(QDir::tempPath() + QDir::separator()
+ QString::fromLatin1("perf-%1.map").arg(pid)),
Expand Down Expand Up @@ -334,13 +338,18 @@ static QByteArray demangle(const QByteArray &mangledName)
if (mangledName.length() < 3) {
return mangledName;
} else {
static size_t demangleBufferLength = 0;
static char *demangleBuffer = nullptr;
static size_t demangleBufferLength = 1024;
static char *demangleBuffer = reinterpret_cast<char *>(eu_compat_malloc(demangleBufferLength));

#ifdef HAVE_RUSTC_DEMANGLE
if (rustc_demangle(mangledName.constData(), demangleBuffer, demangleBufferLength))
return demangleBuffer;
#endif

// Require GNU v3 ABI by the "_Z" prefix.
if (mangledName[0] == '_' && mangledName[1] == 'Z') {
int status = -1;
char *dsymname = eu_compat_demangle(mangledName, demangleBuffer, &demangleBufferLength,
char *dsymname = eu_compat_demangle(mangledName.constData(), demangleBuffer, &demangleBufferLength,
&status);
if (status == 0)
return demangleBuffer = dsymname;
Expand Down

0 comments on commit 07ce8fb

Please sign in to comment.