1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-27 08:00:11 +00:00

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
This commit is contained in:
Rui Paulo 2010-08-11 17:33:26 +00:00
parent 288f3fd63a
commit 4c74b2455d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=211184
5 changed files with 25 additions and 9 deletions

View File

@ -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 *);

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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 &&