diff options
author | markj <markj@FreeBSD.org> | 2013-10-27 20:39:10 +0000 |
---|---|---|
committer | markj <markj@FreeBSD.org> | 2013-10-27 20:39:10 +0000 |
commit | 7799e7909514ade5a6bed2c5c96437f480fb66ff (patch) | |
tree | c3e5d57b0ede806e1bbdfd6008e59072bea60245 /lib/libproc/proc_sym.c | |
parent | 977e19e0686a42b91c6eeb80be9a14338f1b7f2e (diff) | |
download | FreeBSD-src-7799e7909514ade5a6bed2c5c96437f480fb66ff.zip FreeBSD-src-7799e7909514ade5a6bed2c5c96437f480fb66ff.tar.gz |
Clean up the debug printing in libproc a bit. In particular:
* Don't print any error messages to stderr unless DEBUG is defined.
* Add a DPRINTFX macro for use when errno isn't set.
* Print the error string from libelf when appropriate.
Diffstat (limited to 'lib/libproc/proc_sym.c')
-rw-r--r-- | lib/libproc/proc_sym.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c index 2dd21fe..e9f79ea 100644 --- a/lib/libproc/proc_sym.c +++ b/lib/libproc/proc_sym.c @@ -238,16 +238,16 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, if ((map = proc_addr2map(p, addr)) == NULL) return (-1); - if (!map->pr_mapname || (fd = open(map->pr_mapname, O_RDONLY, 0)) < 0) { - warn("ERROR: open %s failed", map->pr_mapname); + if ((fd = open(map->pr_mapname, O_RDONLY, 0)) < 0) { + DPRINTF("ERROR: open %s failed", map->pr_mapname); goto err0; } if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { - warn("ERROR: elf_begin() failed"); + DPRINTFX("ERROR: elf_begin() failed: %s", elf_errmsg(-1)); goto err1; } if (gelf_getehdr(e, &ehdr) == NULL) { - warn("ERROR: gelf_getehdr() failed"); + DPRINTFX("ERROR: gelf_getehdr() failed: %s", elf_errmsg(-1)); goto err2; } /* @@ -275,7 +275,7 @@ proc_addr2sym(struct proc_handle *p, uintptr_t addr, char *name, * Then look up the string name in STRTAB (.dynstr) */ if ((data = elf_getdata(dynsymscn, NULL)) == NULL) { - DPRINTF("ERROR: elf_getdata() failed"); + DPRINTFX("ERROR: elf_getdata() failed: %s", elf_errmsg(-1)); goto symtab; } i = 0; @@ -312,7 +312,7 @@ symtab: if (symtabscn == NULL) goto err2; if ((data = elf_getdata(symtabscn, NULL)) == NULL) { - DPRINTF("ERROR: elf_getdata() failed"); + DPRINTFX("ERROR: elf_getdata() failed: %s", elf_errmsg(-1)); goto err2; } i = 0; @@ -420,7 +420,7 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, unsigned long symtabstridx = 0, dynsymstridx = 0; if ((map = proc_name2map(p, object)) == NULL) { - DPRINTF("ERROR: couldn't find object %s", object); + DPRINTFX("ERROR: couldn't find object %s", object); goto err0; } if ((fd = open(map->pr_mapname, O_RDONLY, 0)) < 0) { @@ -428,11 +428,11 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, goto err0; } if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { - warn("ERROR: elf_begin() failed"); + DPRINTFX("ERROR: elf_begin() failed: %s", elf_errmsg(-1)); goto err1; } if (gelf_getehdr(e, &ehdr) == NULL) { - warn("ERROR: gelf_getehdr() failed"); + DPRINTFX("ERROR: gelf_getehdr() failed: %s", elf_errmsg(-1)); goto err2; } /* @@ -460,7 +460,7 @@ proc_name2sym(struct proc_handle *p, const char *object, const char *symbol, * Then look up the string name in STRTAB (.dynstr) */ if ((data = elf_getdata(dynsymscn, NULL))) { - DPRINTF("ERROR: elf_getdata() failed"); + DPRINTFX("ERROR: elf_getdata() failed: %s", elf_errmsg(-1)); i = 0; while (gelf_getsym(data, i++, &sym) != NULL) { s = elf_strptr(e, dynsymstridx, sym.st_name); @@ -519,11 +519,11 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, if ((map = proc_name2map(p, object)) == NULL) return (-1); if ((fd = open(map->pr_mapname, O_RDONLY)) < 0) { - warn("ERROR: open %s failed", map->pr_mapname); + DPRINTF("ERROR: open %s failed", map->pr_mapname); goto err0; } if ((e = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { - warn("ERROR: elf_begin() failed"); + DPRINTFX("ERROR: elf_begin() failed: %s", elf_errmsg(-1)); goto err1; } /* @@ -546,7 +546,7 @@ proc_iter_symbyaddr(struct proc_handle *p, const char *object, int which, return (-1); stridx = shdr.sh_link; if ((data = elf_getdata(foundscn, NULL)) == NULL) { - DPRINTF("ERROR: elf_getdata() failed"); + DPRINTFX("ERROR: elf_getdata() failed: %s", elf_errmsg(-1)); goto err2; } i = 0; |