summaryrefslogtreecommitdiffstats
path: root/lib/libproc
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2010-08-11 17:33:26 +0000
committerrpaulo <rpaulo@FreeBSD.org>2010-08-11 17:33:26 +0000
commitafd44137e854c021c1e26e7a5d261dcf706ee9dc (patch)
tree6df5d79ff9e595481ae54191003939135774e4d9 /lib/libproc
parent5688dd21e911eab4ec09be1089f77d8d58fff05c (diff)
downloadFreeBSD-src-afd44137e854c021c1e26e7a5d261dcf706ee9dc.zip
FreeBSD-src-afd44137e854c021c1e26e7a5d261dcf706ee9dc.tar.gz
Several fixes for libproc:
o return the correct status in proc_wstatus() o proc_read takes a void * o correctly allocate the objs structure array Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'lib/libproc')
-rw-r--r--lib/libproc/libproc.h2
-rw-r--r--lib/libproc/proc_bkpt.c3
-rw-r--r--lib/libproc/proc_rtld.c7
-rw-r--r--lib/libproc/proc_sym.c11
-rw-r--r--lib/libproc/proc_util.c11
5 files changed, 25 insertions, 9 deletions
diff --git a/lib/libproc/libproc.h b/lib/libproc/libproc.h
index ca8c7be..d80e88c 100644
--- a/lib/libproc/libproc.h
+++ b/lib/libproc/libproc.h
@@ -131,7 +131,7 @@ pid_t proc_getpid(struct proc_handle *);
int proc_wstatus(struct proc_handle *);
int proc_getwstat(struct proc_handle *);
char * proc_signame(int, char *, size_t);
-int proc_read(struct proc_handle *, char *, size_t, size_t);
+int proc_read(struct proc_handle *, void *, size_t, size_t);
const lwpstatus_t *
proc_getlwpstatus(struct proc_handle *);
void proc_free(struct proc_handle *);
diff --git a/lib/libproc/proc_bkpt.c b/lib/libproc/proc_bkpt.c
index 862a1bb..c426471 100644
--- a/lib/libproc/proc_bkpt.c
+++ b/lib/libproc/proc_bkpt.c
@@ -164,7 +164,8 @@ proc_bkptexec(struct proc_handle *phdl, unsigned long saved)
warn("ERROR: ptrace step failed");
return (-1);
}
- status = proc_wstatus(phdl);
+ proc_wstatus(phdl);
+ status = proc_getwstat(phdl);
if (!WIFSTOPPED(status)) {
warn("ERROR: don't know why process stopped");
return (-1);
diff --git a/lib/libproc/proc_rtld.c b/lib/libproc/proc_rtld.c
index 5caadd9e..2a9ed39 100644
--- a/lib/libproc/proc_rtld.c
+++ b/lib/libproc/proc_rtld.c
@@ -42,14 +42,13 @@ map_iter(const rd_loadobj_t *lop, void *arg)
{
struct proc_handle *phdl = arg;
- phdl->nobjs++;
if (phdl->nobjs >= phdl->rdobjsz) {
phdl->rdobjsz *= 2;
phdl->rdobjs = realloc(phdl->rdobjs, phdl->rdobjsz);
if (phdl->rdobjs == NULL)
return (-1);
}
- memcpy(&phdl->rdobjs[phdl->nobjs++], lop, sizeof(*phdl->rdobjs));
+ memcpy(&phdl->rdobjs[phdl->nobjs++], lop, sizeof(*lop));
return (0);
}
@@ -61,6 +60,7 @@ proc_rdagent(struct proc_handle *phdl)
phdl->status != PS_IDLE) {
if ((phdl->rdap = rd_new(phdl)) != NULL) {
phdl->rdobjs = malloc(sizeof(*phdl->rdobjs) * 64);
+ phdl->rdobjsz = 64;
if (phdl->rdobjs == NULL)
return (phdl->rdap);
rd_loadobj_iter(phdl->rdap, map_iter, phdl);
@@ -73,7 +73,8 @@ proc_rdagent(struct proc_handle *phdl)
void
proc_updatesyms(struct proc_handle *phdl)
{
- memset(&phdl->rdobjs, 0, sizeof(*phdl->rdobjs) * phdl->rdobjsz);
+
+ memset(phdl->rdobjs, 0, sizeof(*phdl->rdobjs) * phdl->rdobjsz);
phdl->nobjs = 0;
rd_loadobj_iter(phdl->rdap, map_iter, phdl);
}
diff --git a/lib/libproc/proc_sym.c b/lib/libproc/proc_sym.c
index 82c4c74..1d56df0 100644
--- a/lib/libproc/proc_sym.c
+++ b/lib/libproc/proc_sym.c
@@ -110,14 +110,25 @@ proc_iter_objs(struct proc_handle *p, proc_map_f *func, void *cd)
rd_loadobj_t *rdl;
prmap_t map;
char path[MAXPATHLEN];
+ char last[MAXPATHLEN];
if (p->nobjs == 0)
return (-1);
+ memset(last, 0, sizeof(last));
for (i = 0; i < p->nobjs; i++) {
rdl = &p->rdobjs[i];
proc_rdl2prmap(rdl, &map);
basename_r(rdl->rdl_path, path);
+ /*
+ * We shouldn't call the callback twice with the same object.
+ * To do that we are assuming the fact that if there are
+ * repeated object names (i.e. different mappings for the
+ * same object) they occur next to each other.
+ */
+ if (strcmp(path, last) == 0)
+ continue;
(*func)(cd, &map, path);
+ strlcpy(last, path, sizeof(last));
}
return (0);
diff --git a/lib/libproc/proc_util.c b/lib/libproc/proc_util.c
index 9a53977..0ab848d 100644
--- a/lib/libproc/proc_util.c
+++ b/lib/libproc/proc_util.c
@@ -144,15 +144,17 @@ proc_wstatus(struct proc_handle *phdl)
if (phdl == NULL)
return (-1);
- if (waitpid(phdl->pid, &status, WUNTRACED) < 0)
+ if (waitpid(phdl->pid, &status, WUNTRACED) < 0) {
+ warn("waitpid");
return (-1);
+ }
if (WIFSTOPPED(status))
phdl->status = PS_STOP;
if (WIFEXITED(status) || WIFSIGNALED(status))
phdl->status = PS_UNDEAD;
phdl->wstat = status;
- return (status);
+ return (phdl->status);
}
int
@@ -175,7 +177,7 @@ proc_signame(int sig, char *name, size_t namesz)
}
int
-proc_read(struct proc_handle *phdl, char *buf, size_t size, size_t addr)
+proc_read(struct proc_handle *phdl, void *buf, size_t size, size_t addr)
{
struct ptrace_io_desc piod;
@@ -200,7 +202,8 @@ proc_getlwpstatus(struct proc_handle *phdl)
if (phdl == NULL)
return (NULL);
- if (ptrace(PT_LWPINFO, phdl->pid, (caddr_t)&lwpinfo,sizeof(lwpinfo)) < 0)
+ if (ptrace(PT_LWPINFO, phdl->pid, (caddr_t)&lwpinfo,
+ sizeof(lwpinfo)) < 0)
return (NULL);
siginfo = &lwpinfo.pl_siginfo;
if (lwpinfo.pl_event == PL_EVENT_SIGNAL &&
OpenPOWER on IntegriCloud