diff options
author | rpaulo <rpaulo@FreeBSD.org> | 2012-09-02 18:14:01 +0000 |
---|---|---|
committer | rpaulo <rpaulo@FreeBSD.org> | 2012-09-02 18:14:01 +0000 |
commit | 70630d664ef4716dd247b13bdb90a3e2c77aef78 (patch) | |
tree | 0b809a0fdec0766fe105ed13fcf5ea493fc5f5cd | |
parent | b017762c1596eb0dff9820887de8e51c637d4103 (diff) | |
download | FreeBSD-src-70630d664ef4716dd247b13bdb90a3e2c77aef78.zip FreeBSD-src-70630d664ef4716dd247b13bdb90a3e2c77aef78.tar.gz |
Make sure we visit both symbol sections even if one of them doesn't
exist. This makes it possible to dtrace some C++ programs like devd.
-rw-r--r-- | lib/libproc/proc_sym.c | 45 |
1 files changed, 21 insertions, 24 deletions
diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index 1d56df0..a72ba04 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -254,7 +254,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) { @@ -274,11 +274,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) @@ -430,18 +430,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 +449,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: |