svn commit: r259894 - stable/9/lib/libproc
Mark Johnston
markj at FreeBSD.org
Wed Dec 25 22:32:54 UTC 2013
Author: markj
Date: Wed Dec 25 22:32:52 2013
New Revision: 259894
URL: http://svnweb.freebsd.org/changeset/base/259894
Log:
MFC r256661 r257222 r257235 r257248 r257298.
MFC r256661:
Fix the libproc build when DEBUG is defined.
MFC r257222:
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.
MFC r257235:
Remove an incorrect debug printf.
MFC r257248:
Fix the build with gcc.
MFC r257298:
Revert r257248 and fix the problem in a way that doesn't violate style(9).
Modified:
stable/9/lib/libproc/_libproc.h
stable/9/lib/libproc/proc_bkpt.c
stable/9/lib/libproc/proc_create.c
stable/9/lib/libproc/proc_regs.c
stable/9/lib/libproc/proc_sym.c
stable/9/lib/libproc/proc_util.c
Directory Properties:
stable/9/lib/libproc/ (props changed)
Modified: stable/9/lib/libproc/_libproc.h
==============================================================================
--- stable/9/lib/libproc/_libproc.h Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/_libproc.h Wed Dec 25 22:32:52 2013 (r259894)
@@ -49,7 +49,9 @@ struct proc_handle {
};
#ifdef DEBUG
-#define DPRINTF(fmt, ...) warn(fmt, __VA_ARGS__)
+#define DPRINTF(...) warn(__VA_ARGS__)
+#define DPRINTFX(...) warnx(__VA_ARGS__)
#else
-#define DPRINTF(fmt, ...)
+#define DPRINTF(...) do { } while (0)
+#define DPRINTFX(...) do { } while (0)
#endif
Modified: stable/9/lib/libproc/proc_bkpt.c
==============================================================================
--- stable/9/lib/libproc/proc_bkpt.c Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/proc_bkpt.c Wed Dec 25 22:32:52 2013 (r259894)
@@ -72,8 +72,8 @@ proc_bkptset(struct proc_handle *phdl, u
piod.piod_addr = &paddr;
piod.piod_len = BREAKPOINT_INSTR_SZ;
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
- DPRINTF("ERROR: couldn't read instruction at address 0x%" PRIuPTR,
- address);
+ DPRINTF("ERROR: couldn't read instruction at address 0x%"
+ PRIuPTR, address);
return (-1);
}
*saved = paddr;
@@ -87,8 +87,8 @@ proc_bkptset(struct proc_handle *phdl, u
piod.piod_addr = &paddr;
piod.piod_len = BREAKPOINT_INSTR_SZ;
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
- warn("ERROR: couldn't write instruction at address 0x%" PRIuPTR,
- address);
+ DPRINTF("ERROR: couldn't write instruction at address 0x%"
+ PRIuPTR, address);
return (-1);
}
@@ -107,7 +107,7 @@ proc_bkptdel(struct proc_handle *phdl, u
errno = ENOENT;
return (-1);
}
- DPRINTF("removing breakpoint at 0x%lx\n", address);
+ DPRINTFX("removing breakpoint at 0x%lx\n", address);
/*
* Overwrite the breakpoint instruction that we setup previously.
*/
@@ -118,8 +118,8 @@ proc_bkptdel(struct proc_handle *phdl, u
piod.piod_addr = &paddr;
piod.piod_len = BREAKPOINT_INSTR_SZ;
if (ptrace(PT_IO, proc_getpid(phdl), (caddr_t)&piod, 0) < 0) {
- DPRINTF("ERROR: couldn't write instruction at address 0x%" PRIuPTR,
- address);
+ DPRINTF("ERROR: couldn't write instruction at address 0x%"
+ PRIuPTR, address);
return (-1);
}
@@ -147,12 +147,12 @@ proc_bkptexec(struct proc_handle *phdl,
int status;
if (proc_regget(phdl, REG_PC, &pc) < 0) {
- warn("ERROR: couldn't get PC register");
+ DPRINTFX("ERROR: couldn't get PC register");
return (-1);
}
proc_bkptregadj(&pc);
if (proc_bkptdel(phdl, pc, saved) < 0) {
- warn("ERROR: couldn't delete breakpoint");
+ DPRINTFX("ERROR: couldn't delete breakpoint");
return (-1);
}
/*
@@ -161,13 +161,13 @@ proc_bkptexec(struct proc_handle *phdl,
*/
proc_regset(phdl, REG_PC, pc);
if (ptrace(PT_STEP, proc_getpid(phdl), (caddr_t)1, 0) < 0) {
- warn("ERROR: ptrace step failed");
+ DPRINTFX("ERROR: ptrace step failed");
return (-1);
}
proc_wstatus(phdl);
status = proc_getwstat(phdl);
if (!WIFSTOPPED(status)) {
- warn("ERROR: don't know why process stopped");
+ DPRINTFX("ERROR: don't know why process stopped");
return (-1);
}
/*
@@ -175,7 +175,7 @@ proc_bkptexec(struct proc_handle *phdl,
* the same as the one that we were passed in.
*/
if (proc_bkptset(phdl, pc, &samesaved) < 0) {
- warn("ERROR: couldn't restore breakpoint");
+ DPRINTFX("ERROR: couldn't restore breakpoint");
return (-1);
}
assert(samesaved == saved);
Modified: stable/9/lib/libproc/proc_create.c
==============================================================================
--- stable/9/lib/libproc/proc_create.c Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/proc_create.c Wed Dec 25 22:32:52 2013 (r259894)
@@ -75,7 +75,7 @@ proc_attach(pid_t pid, int flags, struct
/* Check for an unexpected status. */
if (WIFSTOPPED(status) == 0)
- DPRINTF("ERROR: child process %d status 0x%x", pid, status);
+ DPRINTFX("ERROR: child process %d status 0x%x", pid, status);
else
phdl->status = PS_STOP;
@@ -130,14 +130,14 @@ proc_create(const char *file, char * con
/* Wait for the child process to stop. */
if (waitpid(pid, &status, WUNTRACED) == -1) {
error = errno;
- DPRINTF("ERROR: child process %d didn't stop as expected", pid);
+ DPRINTF("ERROR: child process %d didn't stop as expected", pid);
goto bad;
}
/* Check for an unexpected status. */
if (WIFSTOPPED(status) == 0) {
error = errno;
- DPRINTF("ERROR: child process %d status 0x%x", pid, status);
+ DPRINTFX("ERROR: child process %d status 0x%x", pid, status);
goto bad;
} else
phdl->status = PS_STOP;
Modified: stable/9/lib/libproc/proc_regs.c
==============================================================================
--- stable/9/lib/libproc/proc_regs.c Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/proc_regs.c Wed Dec 25 22:32:52 2013 (r259894)
@@ -68,7 +68,7 @@ proc_regget(struct proc_handle *phdl, pr
#endif
break;
default:
- warn("ERROR: no support for reg number %d", reg);
+ DPRINTFX("ERROR: no support for reg number %d", reg);
return (-1);
}
@@ -103,7 +103,7 @@ proc_regset(struct proc_handle *phdl, pr
#endif
break;
default:
- warn("ERROR: no support for reg number %d", reg);
+ DPRINTFX("ERROR: no support for reg number %d", reg);
return (-1);
}
if (ptrace(PT_SETREGS, proc_getpid(phdl), (caddr_t)®s, 0) < 0)
Modified: stable/9/lib/libproc/proc_sym.c
==============================================================================
--- stable/9/lib/libproc/proc_sym.c Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/proc_sym.c Wed Dec 25 22:32:52 2013 (r259894)
@@ -216,16 +216,16 @@ proc_addr2sym(struct proc_handle *p, uin
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;
}
/*
@@ -253,7 +253,7 @@ proc_addr2sym(struct proc_handle *p, uin
* 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 err2;
}
i = 0;
@@ -286,7 +286,7 @@ proc_addr2sym(struct proc_handle *p, uin
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;
@@ -391,7 +391,7 @@ proc_name2sym(struct proc_handle *p, con
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) {
@@ -399,11 +399,11 @@ proc_name2sym(struct proc_handle *p, con
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;
}
/*
@@ -431,7 +431,6 @@ proc_name2sym(struct proc_handle *p, con
* Then look up the string name in STRTAB (.dynstr)
*/
if ((data = elf_getdata(dynsymscn, NULL)) == NULL) {
- DPRINTF("ERROR: elf_getdata() failed");
goto err2;
}
i = 0;
@@ -493,11 +492,11 @@ proc_iter_symbyaddr(struct proc_handle *
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;
}
/*
@@ -520,7 +519,7 @@ proc_iter_symbyaddr(struct proc_handle *
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;
Modified: stable/9/lib/libproc/proc_util.c
==============================================================================
--- stable/9/lib/libproc/proc_util.c Wed Dec 25 22:32:34 2013 (r259893)
+++ stable/9/lib/libproc/proc_util.c Wed Dec 25 22:32:52 2013 (r259894)
@@ -146,7 +146,7 @@ proc_wstatus(struct proc_handle *phdl)
return (-1);
if (waitpid(phdl->pid, &status, WUNTRACED) < 0) {
if (errno != EINTR)
- warn("waitpid");
+ DPRINTF("waitpid");
return (-1);
}
if (WIFSTOPPED(status))
More information about the svn-src-stable-9
mailing list