diff options
Diffstat (limited to 'lib/libproc')
-rw-r--r-- | lib/libproc/Makefile | 10 | ||||
-rw-r--r-- | lib/libproc/proc_sym.c | 77 | ||||
-rw-r--r-- | lib/libproc/test/t1-bkpt/t1-bkpt.c | 6 | ||||
-rw-r--r-- | lib/libproc/test/t3-name2sym/t3-name2sym.c | 1 |
4 files changed, 65 insertions, 29 deletions
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 <bsd.own.mk> + 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 1d56df0..4bef7f0 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -46,9 +46,31 @@ #include "_libproc.h" +extern char *__cxa_demangle(const char *, char *, size_t *, int *); + static void proc_rdl2prmap(rd_loadobj_t *, prmap_t *); static void +demangle(const char *symbol, char *buf, size_t len) +{ + char *dembuf; + size_t demlen = len; + + dembuf = malloc(len); + if (!dembuf) + goto fail; + dembuf = __cxa_demangle(symbol, dembuf, &demlen, NULL); + if (!dembuf) + goto fail; + strlcpy(buf, dembuf, len); + free(dembuf); + + return; +fail: + strlcpy(buf, symbol, len); +} + +static void proc_rdl2prmap(rd_loadobj_t *rdl, prmap_t *map) { map->pr_vaddr = rdl->rdl_saddr; @@ -254,7 +276,7 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, */ if ((data = elf_getdata(dynsymscn, NULL)) == NULL) { DPRINTF("ERROR: elf_getdata() failed"); - goto err2; + goto symtab; } i = 0; while (gelf_getsym(data, i++, &sym) != NULL) { @@ -266,7 +288,10 @@ 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 (s[0] == '_' && s[1] == 'Z' && s[2]) + demangle(s, name, namesz); + else + strlcpy(name, s, namesz); memcpy(symcopy, &sym, sizeof(sym)); /* * DTrace expects the st_value to contain @@ -274,11 +299,11 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, * the function. */ symcopy->st_value = rsym; - error = 0; goto out; } } } +symtab: /* * Iterate over the Symbols Table to find the symbol. * Then look up the string name in STRTAB (.dynstr) @@ -302,7 +327,10 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, if (addr >= rsym && addr <= (rsym + sym.st_size)) { s = elf_strptr(e, symtabstridx, sym.st_name); if (s) { - strlcpy(name, s, namesz); + if (s[0] == '_' && s[1] == 'Z' && s[2]) + demangle(s, name, namesz); + else + strlcpy(name, s, namesz); memcpy(symcopy, &sym, sizeof(sym)); /* * DTrace expects the st_value to contain @@ -430,18 +458,17 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, * Iterate over the Dynamic Symbols table to find the symbol. * Then look up the string name in STRTAB (.dynstr) */ - if ((data = elf_getdata(dynsymscn, NULL)) == NULL) { + if ((data = elf_getdata(dynsymscn, NULL))) { DPRINTF("ERROR: elf_getdata() failed"); - goto err2; - } - i = 0; - while (gelf_getsym(data, i++, &sym) != NULL) { - s = elf_strptr(e, dynsymstridx, sym.st_name); - if (s && strcmp(s, symbol) == 0) { - memcpy(symcopy, &sym, sizeof(sym)); - symcopy->st_value = map->pr_vaddr + sym.st_value; - error = 0; - goto out; + i = 0; + while (gelf_getsym(data, i++, &sym) != NULL) { + s = elf_strptr(e, dynsymstridx, sym.st_name); + if (s && strcmp(s, symbol) == 0) { + memcpy(symcopy, &sym, sizeof(sym)); + symcopy->st_value = map->pr_vaddr + sym.st_value; + error = 0; + goto out; + } } } /* @@ -450,17 +477,15 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, */ if (symtabscn == NULL) goto err2; - if ((data = elf_getdata(symtabscn, NULL)) == NULL) { - DPRINTF("ERROR: elf_getdata() failed"); - goto err2; - } - i = 0; - while (gelf_getsym(data, i++, &sym) != NULL) { - s = elf_strptr(e, symtabstridx, sym.st_name); - if (s && strcmp(s, symbol) == 0) { - memcpy(symcopy, &sym, sizeof(sym)); - error = 0; - goto out; + if ((data = elf_getdata(symtabscn, NULL))) { + i = 0; + while (gelf_getsym(data, i++, &sym) != NULL) { + s = elf_strptr(e, symtabstridx, sym.st_name); + if (s && strcmp(s, symbol) == 0) { + memcpy(symcopy, &sym, sizeof(sym)); + error = 0; + goto out; + } } } out: diff --git a/lib/libproc/test/t1-bkpt/t1-bkpt.c b/lib/libproc/test/t1-bkpt/t1-bkpt.c index 6b4e2fa..37a9fcf 100644 --- a/lib/libproc/test/t1-bkpt/t1-bkpt.c +++ b/lib/libproc/test/t1-bkpt/t1-bkpt.c @@ -50,12 +50,12 @@ t1_bkpt_d() unsigned long saved; proc_create("./t1-bkpt", targv, NULL, NULL, &phdl); - proc_bkptset(phdl, (uintptr_t)t1_bkpt_t, &saved); + assert(proc_bkptset(phdl, (uintptr_t)t1_bkpt_t, &saved) == 0); proc_continue(phdl); - assert(WIFSTOPPED(proc_wstatus(phdl))); + assert(proc_wstatus(phdl) == PS_STOP); proc_bkptexec(phdl, saved); proc_continue(phdl); - proc_wait(phdl); + proc_wstatus(phdl); proc_free(phdl); } diff --git a/lib/libproc/test/t3-name2sym/t3-name2sym.c b/lib/libproc/test/t3-name2sym/t3-name2sym.c index 6d90a48..0be8653 100644 --- a/lib/libproc/test/t3-name2sym/t3-name2sym.c +++ b/lib/libproc/test/t3-name2sym/t3-name2sym.c @@ -33,6 +33,7 @@ #include <stdio.h> #include <libproc.h> #include <gelf.h> +#include <string.h> int main(int argc, char *argv[]) |