Skip to content
Snippets Groups Projects
Commit 4474ac95 authored by Takuya ASADA's avatar Takuya ASADA Committed by Pekka Enberg
Browse files

Add lookup_name_demangled(), which converts addr to demangled symbol name.


lookup_name_demangled() lookups a symbol name, demangle it, then
snprintf onto preallocated buffer.

Signed-off-by: default avatarTakuya ASADA <syuu@cloudius-systems.com>
Signed-off-by: default avatarPekka Enberg <penberg@cloudius-systems.com>
parent 8b778b34
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
#include <string.h> #include <string.h>
#include <algorithm> #include <algorithm>
#include <osv/elf.hh>
namespace osv {
extern "C" int __gcclibcxx_demangle_callback (const char *, extern "C" int __gcclibcxx_demangle_callback (const char *,
void (*)(const char *, size_t, void *), void (*)(const char *, size_t, void *),
...@@ -35,3 +38,20 @@ bool demangle(const char *name, char *buf, size_t len) ...@@ -35,3 +38,20 @@ bool demangle(const char *name, char *buf, size_t len)
&arg); &arg);
return (ret == 0); return (ret == 0);
} }
void lookup_name_demangled(void *addr, char *buf, size_t len)
{
auto ei = elf::get_program()->lookup_addr(addr);
int funclen;
if (!ei.sym)
strncpy(buf, "???", len);
else if (!demangle(ei.sym, buf, len))
strncpy(buf, ei.sym, len);
funclen = strlen(buf);
snprintf(buf + funclen, len - funclen, "+%d",
reinterpret_cast<uintptr_t>(addr)
- reinterpret_cast<uintptr_t>(ei.addr));
}
}
...@@ -8,6 +8,11 @@ ...@@ -8,6 +8,11 @@
#ifndef DEMANGLE_HH_ #ifndef DEMANGLE_HH_
#define DEMANGLE_HH_ #define DEMANGLE_HH_
namespace osv {
bool demangle(const char *name, char *buf, size_t len); bool demangle(const char *name, char *buf, size_t len);
void lookup_name_demangled(void *addr, char *buf, size_t len);
}
#endif /* DEMANGLE_HH_ */ #endif /* DEMANGLE_HH_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment