From 0160930e18300f23b566937e2710f55d991c653b Mon Sep 17 00:00:00 2001 From: rpaulo Date: Thu, 6 Sep 2012 03:19:48 +0000 Subject: Add support for demangling C++ symbols. This requires linking libproc with libc++rt/libsupc++. Discussed with: theraven --- lib/libproc/Makefile | 10 ++++++++++ lib/libproc/proc_sym.c | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'lib/libproc') diff --git a/lib/libproc/Makefile b/lib/libproc/Makefile index c02e719..4449c06 100644 --- a/lib/libproc/Makefile +++ b/lib/libproc/Makefile @@ -1,5 +1,7 @@ # $FreeBSD$ +.include + LIB= proc SRCS= proc_bkpt.c \ @@ -13,6 +15,14 @@ INCS= libproc.h CFLAGS+= -I${.CURDIR} +.if ${MK_LIBCPLUSPLUS} != "no" +LDADD+= -lcxxrt +DPADD+= ${LIBCXXRT} +.else +LDADD+= -lsupc++ +DPADD+= ${LIBSTDCPLUSPLUS} +.endif + SHLIB_MAJOR= 2 WITHOUT_MAN= diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index a72ba04..0940df8 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -46,6 +46,8 @@ #include "_libproc.h" +extern char *__cxa_demangle(const char *, char *, size_t *, int *); + static void proc_rdl2prmap(rd_loadobj_t *, prmap_t *); static void @@ -266,7 +268,11 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, if (addr >= rsym && addr <= (rsym + sym.st_size)) { s = elf_strptr(e, dynsymstridx, sym.st_name); if (s) { - strlcpy(name, s, namesz); + if (strlen(s) > 2 && + s[0] == '_' && s[1] == 'Z') + __cxa_demangle(s, name, &namesz, NULL); + else + strlcpy(name, s, namesz); memcpy(symcopy, &sym, sizeof(sym)); /* * DTrace expects the st_value to contain @@ -302,7 +308,11 @@ symtab: if (addr >= rsym && addr <= (rsym + sym.st_size)) { s = elf_strptr(e, symtabstridx, sym.st_name); if (s) { - strlcpy(name, s, namesz); + if (strlen(s) > 2 && + s[0] == '_' && s[1] == 'Z') + __cxa_demangle(s, name, &namesz, NULL); + else + strlcpy(name, s, namesz); memcpy(symcopy, &sym, sizeof(sym)); /* * DTrace expects the st_value to contain -- cgit v1.1