summaryrefslogtreecommitdiffstats
path: root/lib/libthread_db
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2008-09-14 16:07:21 +0000
committermarcel <marcel@FreeBSD.org>2008-09-14 16:07:21 +0000
commitead754945e1303f4902bb9c1d2f3da9dcc13c967 (patch)
tree02668a21719febb89d083b97a83b079abb56473a /lib/libthread_db
parentae2f507eb0c3fb503f9f2b78128db903aceeabc1 (diff)
downloadFreeBSD-src-ead754945e1303f4902bb9c1d2f3da9dcc13c967.zip
FreeBSD-src-ead754945e1303f4902bb9c1d2f3da9dcc13c967.tar.gz
Allow psaddr_t to be widened by using thr_pread_{int,long,ptr},
where critical. Some places still use ps_pread/ps_pwrite directly, but only need changed when byte-order comes into the picture. Also, change th_p in td_event_msg_t from a pointer type to psaddr_t, so that events also work when psaddr_t is widened.
Diffstat (limited to 'lib/libthread_db')
-rw-r--r--lib/libthread_db/libpthread_db.c93
-rw-r--r--lib/libthread_db/libthr_db.c90
-rw-r--r--lib/libthread_db/thread_db.c20
-rw-r--r--lib/libthread_db/thread_db.h2
-rw-r--r--lib/libthread_db/thread_db_int.h12
5 files changed, 94 insertions, 123 deletions
diff --git a/lib/libthread_db/libpthread_db.c b/lib/libthread_db/libpthread_db.c
index 74394d2..65478a7 100644
--- a/lib/libthread_db/libpthread_db.c
+++ b/lib/libthread_db/libpthread_db.c
@@ -220,7 +220,6 @@ static td_err_e
pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
{
prgregset_t gregs;
- TAILQ_HEAD(, pthread) thread_list;
psaddr_t pt, tcb_addr;
lwpid_t lwp;
int ret;
@@ -229,27 +228,24 @@ pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
if (id < 0 || id >= ta->map_len || ta->map[id].type == PT_NONE)
return (TD_NOTHR);
- ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
- sizeof(thread_list));
+
+ ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt);
if (ret != 0)
- return (P2T(ret));
- pt = (psaddr_t)thread_list.tqh_first;
+ return (TD_ERR);
if (ta->map[id].type == PT_LWP) {
/*
* if we are referencing a lwp, make sure it was not already
* mapped to user thread.
*/
while (pt != 0) {
- ret = ps_pread(ta->ph, pt + ta->thread_off_tcb,
- &tcb_addr, sizeof(tcb_addr));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_tcb,
+ &tcb_addr);
if (ret != 0)
- return (P2T(ret));
- ret = ps_pread(ta->ph,
- tcb_addr + ta->thread_off_tmbx +
- offsetof(struct kse_thr_mailbox, tm_lwp),
- &lwp, sizeof(lwp));
+ return (TD_ERR);
+ ret = thr_pread_int(ta, tcb_addr + ta->thread_off_tmbx +
+ offsetof(struct kse_thr_mailbox, tm_lwp), &lwp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
/*
* If the lwp was already mapped to userland thread,
* we shouldn't reference it directly in future.
@@ -259,11 +255,9 @@ pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
return (TD_NOTHR);
}
/* get next thread */
- ret = ps_pread(ta->ph,
- pt + ta->thread_off_next,
- &pt, sizeof(pt));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
}
/* check lwp */
ret = ps_lgetregs(ta->ph, ta->map[id].lwp, gregs);
@@ -274,17 +268,14 @@ pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
}
} else {
while (pt != 0 && ta->map[id].thr != pt) {
- ret = ps_pread(ta->ph,
- pt + ta->thread_off_tcb,
- &tcb_addr, sizeof(tcb_addr));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_tcb,
+ &tcb_addr);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
/* get next thread */
- ret = ps_pread(ta->ph,
- pt + ta->thread_off_next,
- &pt, sizeof(pt));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
}
if (pt == 0) {
@@ -302,29 +293,24 @@ pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
static td_err_e
pt_ta_map_lwp2thr(const td_thragent_t *ta, lwpid_t lwp, td_thrhandle_t *th)
{
- TAILQ_HEAD(, pthread) thread_list;
- psaddr_t pt, ptr;
- lwpid_t tmp_lwp;
+ psaddr_t pt, tcb_addr;
+ lwpid_t lwp1;
int ret;
-
+
TDBG_FUNC();
- ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
- sizeof(thread_list));
+ ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt);
if (ret != 0)
- return (P2T(ret));
- pt = (psaddr_t)thread_list.tqh_first;
+ return (TD_ERR);
while (pt != 0) {
- ret = ps_pread(ta->ph, pt + ta->thread_off_tcb,
- &ptr, sizeof(ptr));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_tcb, &tcb_addr);
if (ret != 0)
- return (P2T(ret));
- ptr += ta->thread_off_tmbx +
- offsetof(struct kse_thr_mailbox, tm_lwp);
- ret = ps_pread(ta->ph, ptr, &tmp_lwp, sizeof(lwpid_t));
+ return (TD_ERR);
+ ret = thr_pread_int(ta, tcb_addr + ta->thread_off_tmbx +
+ offsetof(struct kse_thr_mailbox, tm_lwp), &lwp1);
if (ret != 0)
- return (P2T(ret));
- if (tmp_lwp == lwp) {
+ return (TD_ERR);
+ if (lwp1 == lwp) {
th->th_ta = ta;
th->th_tid = pt_map_thread(ta, pt, PT_USER);
if (th->th_tid == -1)
@@ -335,11 +321,9 @@ pt_ta_map_lwp2thr(const td_thragent_t *ta, lwpid_t lwp, td_thrhandle_t *th)
}
/* get next thread */
- ret = ps_pread(ta->ph,
- pt + ta->thread_off_next,
- &pt, sizeof(pt));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
}
return (TD_NOTHR);
@@ -350,11 +334,10 @@ pt_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *callback,
void *cbdata_p, td_thr_state_e state __unused, int ti_pri __unused,
sigset_t *ti_sigmask_p __unused, unsigned int ti_user_flags __unused)
{
- TAILQ_HEAD(, pthread) thread_list;
td_thrhandle_t th;
psaddr_t pt;
ps_err_e pserr;
- int activated;
+ int activated, ret;
TDBG_FUNC();
@@ -365,11 +348,9 @@ pt_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *callback,
if (!activated)
return (TD_OK);
- pserr = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
- sizeof(thread_list));
- if (pserr != 0)
- return (P2T(pserr));
- pt = (psaddr_t)thread_list.tqh_first;
+ ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt);
+ if (ret != 0)
+ return (TD_ERR);
while (pt != 0) {
th.th_ta = ta;
th.th_tid = pt_map_thread(ta, pt, PT_USER);
@@ -380,11 +361,9 @@ pt_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *callback,
if ((*callback)(&th, cbdata_p))
return (TD_DBERR);
/* get next thread */
- pserr = ps_pread(ta->ph,
- pt + ta->thread_off_next, &pt,
- sizeof(pt));
- if (pserr != PS_OK)
- return (P2T(pserr));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
+ if (ret != 0)
+ return (TD_ERR);
}
return (TD_OK);
}
diff --git a/lib/libthread_db/libthr_db.c b/lib/libthread_db/libthr_db.c
index cdf2257..7c6aa2d 100644
--- a/lib/libthread_db/libthr_db.c
+++ b/lib/libthread_db/libthr_db.c
@@ -201,34 +201,28 @@ pt_ta_delete(td_thragent_t *ta)
static td_err_e
pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
{
- TAILQ_HEAD(, pthread) thread_list;
psaddr_t pt;
- long lwp;
+ int32_t lwp;
int ret;
TDBG_FUNC();
if (id == 0)
return (TD_NOTHR);
- ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
- sizeof(thread_list));
+ ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
/* Iterate through thread list to find pthread */
- pt = (psaddr_t)thread_list.tqh_first;
while (pt != 0) {
- ret = ps_pread(ta->ph, pt + ta->thread_off_tid,
- &lwp, sizeof(lwp));
+ ret = thr_pread_int(ta, pt + ta->thread_off_tid, &lwp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
if (lwp == id)
break;
/* get next thread */
- ret = ps_pread(ta->ph,
- pt + ta->thread_off_next,
- &pt, sizeof(pt));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
}
if (pt == 0)
return (TD_NOTHR);
@@ -249,24 +243,20 @@ pt_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *callback,
void *cbdata_p, td_thr_state_e state __unused, int ti_pri __unused,
sigset_t *ti_sigmask_p __unused, unsigned int ti_user_flags __unused)
{
- TAILQ_HEAD(, pthread) thread_list;
td_thrhandle_t th;
psaddr_t pt;
- long lwp;
+ int32_t lwp;
int ret;
TDBG_FUNC();
- ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
- sizeof(thread_list));
+ ret = thr_pread_ptr(ta, ta->thread_list_addr, &pt);
if (ret != 0)
- return (P2T(ret));
- pt = (psaddr_t)thread_list.tqh_first;
+ return (TD_ERR);
while (pt != 0) {
- ret = ps_pread(ta->ph, pt + ta->thread_off_tid, &lwp,
- sizeof(lwp));
+ ret = thr_pread_int(ta, pt + ta->thread_off_tid, &lwp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
if (lwp != 0 && lwp != TERMINATED) {
th.th_ta = ta;
th.th_tid = (thread_t)lwp;
@@ -275,10 +265,9 @@ pt_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *callback,
return (TD_DBERR);
}
/* get next thread */
- ret = ps_pread(ta->ph, pt + ta->thread_off_next, &pt,
- sizeof(pt));
+ ret = thr_pread_ptr(ta, pt + ta->thread_off_next, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
}
return (TD_OK);
}
@@ -377,24 +366,23 @@ pt_ta_event_getmsg(const td_thragent_t *ta, td_event_msg_t *msg)
{
static td_thrhandle_t handle;
- psaddr_t pt, pt_temp;
+ psaddr_t pt;
td_thr_events_e tmp;
- long lwp;
+ int32_t lwp;
int ret;
TDBG_FUNC();
- ret = ps_pread(ta->ph, ta->thread_last_event_addr, &pt, sizeof(pt));
+ ret = thr_pread_ptr(ta, ta->thread_last_event_addr, &pt);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
if (pt == 0)
return (TD_NOMSG);
/*
* Take the event pointer, at the time, libthr only reports event
* once a time, so it is not a link list.
*/
- pt_temp = 0;
- ps_pwrite(ta->ph, ta->thread_last_event_addr, &pt_temp, sizeof(pt_temp));
+ thr_pwrite_ptr(ta, ta->thread_last_event_addr, 0);
/* Read event info */
ret = ps_pread(ta->ph, pt + ta->thread_off_event_buf, msg, sizeof(*msg));
@@ -406,14 +394,14 @@ pt_ta_event_getmsg(const td_thragent_t *ta, td_event_msg_t *msg)
tmp = 0;
ps_pwrite(ta->ph, pt + ta->thread_off_event_buf, &tmp, sizeof(tmp));
/* Convert event */
- pt = (psaddr_t)msg->th_p;
- ret = ps_pread(ta->ph, pt + ta->thread_off_tid, &lwp, sizeof(lwp));
+ pt = msg->th_p;
+ ret = thr_pread_int(ta, pt + ta->thread_off_tid, &lwp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
handle.th_ta = ta;
handle.th_tid = lwp;
handle.th_thread = pt;
- msg->th_p = &handle;
+ msg->th_p = (uintptr_t)&handle;
return (0);
}
@@ -478,14 +466,13 @@ pt_thr_get_info(const td_thrhandle_t *th, td_thrinfo_t *info)
ret = pt_validate(th);
if (ret)
return (ret);
- ret = ps_pread(ta->ph, th->th_thread + ta->thread_off_state,
- &state, sizeof(state));
+ ret = thr_pread_int(ta, th->th_thread + ta->thread_off_state, &state);
if (ret != 0)
- return (P2T(ret));
- ret = ps_pread(ta->ph, th->th_thread + ta->thread_off_report_events,
- &info->ti_traceme, sizeof(int));
+ return (TD_ERR);
+ ret = thr_pread_int(ta, th->th_thread + ta->thread_off_report_events,
+ &info->ti_traceme);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
ret = ps_pread(ta->ph, th->th_thread + ta->thread_off_event_mask,
&info->ti_events, sizeof(td_thr_events_t));
if (ret != 0)
@@ -662,15 +649,15 @@ pt_thr_event_getmsg(const td_thrhandle_t *th, td_event_msg_t *msg)
static td_thrhandle_t handle;
const td_thragent_t *ta = th->th_ta;
psaddr_t pt, pt_temp;
- long lwp;
+ int32_t lwp;
int ret;
td_thr_events_e tmp;
TDBG_FUNC();
pt = th->th_thread;
- ret = ps_pread(ta->ph, ta->thread_last_event_addr, &pt_temp, sizeof(pt_temp));
+ ret = thr_pread_ptr(ta, ta->thread_last_event_addr, &pt_temp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
/* Get event */
ret = ps_pread(ta->ph, pt + ta->thread_off_event_buf, msg, sizeof(*msg));
if (ret != 0)
@@ -681,22 +668,21 @@ pt_thr_event_getmsg(const td_thrhandle_t *th, td_event_msg_t *msg)
* Take the event pointer, at the time, libthr only reports event
* once a time, so it is not a link list.
*/
- if (pt == pt_temp) {
- pt_temp = 0;
- ps_pwrite(ta->ph, ta->thread_last_event_addr, &pt_temp, sizeof(pt_temp));
- }
+ if (pt == pt_temp)
+ thr_pwrite_ptr(ta, ta->thread_last_event_addr, 0);
+
/* Clear event */
tmp = 0;
ps_pwrite(ta->ph, pt + ta->thread_off_event_buf, &tmp, sizeof(tmp));
/* Convert event */
- pt = (psaddr_t)msg->th_p;
- ret = ps_pread(ta->ph, pt + ta->thread_off_tid, &lwp, sizeof(lwp));
+ pt = msg->th_p;
+ ret = thr_pread_int(ta, pt + ta->thread_off_tid, &lwp);
if (ret != 0)
- return (P2T(ret));
+ return (TD_ERR);
handle.th_ta = ta;
handle.th_tid = lwp;
handle.th_thread = pt;
- msg->th_p = &handle;
+ msg->th_p = (uintptr_t)&handle;
return (0);
}
diff --git a/lib/libthread_db/thread_db.c b/lib/libthread_db/thread_db.c
index 69cc42e..dc8195d 100644
--- a/lib/libthread_db/thread_db.c
+++ b/lib/libthread_db/thread_db.c
@@ -324,7 +324,7 @@ thr_pread(struct ps_prochandle *ph, psaddr_t addr, uint64_t *val,
}
int
-thr_pread_int(struct td_thragent *ta, psaddr_t addr, uint32_t *val)
+thr_pread_int(const struct td_thragent *ta, psaddr_t addr, uint32_t *val)
{
uint64_t tmp;
int error;
@@ -337,17 +337,23 @@ thr_pread_int(struct td_thragent *ta, psaddr_t addr, uint32_t *val)
}
int
-thr_pread_long(struct td_thragent *ta, psaddr_t addr, uint64_t *val)
+thr_pread_long(const struct td_thragent *ta, psaddr_t addr, uint64_t *val)
{
return (thr_pread(ta->ph, addr, val, sizeof(long), BYTE_ORDER));
}
int
-thr_pread_ptr(struct td_thragent *ta, psaddr_t addr, uint64_t *val)
+thr_pread_ptr(const struct td_thragent *ta, psaddr_t addr, psaddr_t *val)
{
+ uint64_t tmp;
+ int error;
+
+ error = thr_pread(ta->ph, addr, &tmp, sizeof(void *), BYTE_ORDER);
+ if (!error)
+ *val = tmp;
- return (thr_pread(ta->ph, addr, val, sizeof(void *), BYTE_ORDER));
+ return (error);
}
static int
@@ -406,21 +412,21 @@ thr_pwrite(struct ps_prochandle *ph, psaddr_t addr, uint64_t val,
}
int
-thr_pwrite_int(struct td_thragent *ta, psaddr_t addr, uint32_t val)
+thr_pwrite_int(const struct td_thragent *ta, psaddr_t addr, uint32_t val)
{
return (thr_pwrite(ta->ph, addr, val, sizeof(int), BYTE_ORDER));
}
int
-thr_pwrite_long(struct td_thragent *ta, psaddr_t addr, uint64_t val)
+thr_pwrite_long(const struct td_thragent *ta, psaddr_t addr, uint64_t val)
{
return (thr_pwrite(ta->ph, addr, val, sizeof(long), BYTE_ORDER));
}
int
-thr_pwrite_ptr(struct td_thragent *ta, psaddr_t addr, uint64_t val)
+thr_pwrite_ptr(const struct td_thragent *ta, psaddr_t addr, psaddr_t val)
{
return (thr_pwrite(ta->ph, addr, val, sizeof(void *), BYTE_ORDER));
diff --git a/lib/libthread_db/thread_db.h b/lib/libthread_db/thread_db.h
index 3508eba..ee71e06 100644
--- a/lib/libthread_db/thread_db.h
+++ b/lib/libthread_db/thread_db.h
@@ -95,7 +95,7 @@ typedef enum {
typedef struct {
td_thr_events_e event;
- const td_thrhandle_t *th_p;
+ psaddr_t th_p;
uintptr_t data;
} td_event_msg_t;
diff --git a/lib/libthread_db/thread_db_int.h b/lib/libthread_db/thread_db_int.h
index bffa0f3..3b03062 100644
--- a/lib/libthread_db/thread_db_int.h
+++ b/lib/libthread_db/thread_db_int.h
@@ -95,12 +95,12 @@ struct ta_ops {
struct td_thragent;
-int thr_pread_int(struct td_thragent *, psaddr_t, uint32_t *);
-int thr_pread_long(struct td_thragent *, psaddr_t, uint64_t *);
-int thr_pread_ptr(struct td_thragent *, psaddr_t, uint64_t *);
+int thr_pread_int(const struct td_thragent *, psaddr_t, uint32_t *);
+int thr_pread_long(const struct td_thragent *, psaddr_t, uint64_t *);
+int thr_pread_ptr(const struct td_thragent *, psaddr_t, psaddr_t *);
-int thr_pwrite_int(struct td_thragent *, psaddr_t, uint32_t);
-int thr_pwrite_long(struct td_thragent *, psaddr_t, uint64_t);
-int thr_pwrite_ptr(struct td_thragent *, psaddr_t, uint64_t);
+int thr_pwrite_int(const struct td_thragent *, psaddr_t, uint32_t);
+int thr_pwrite_long(const struct td_thragent *, psaddr_t, uint64_t);
+int thr_pwrite_ptr(const struct td_thragent *, psaddr_t, psaddr_t);
#endif /* _THREAD_DB_INT_H_ */
OpenPOWER on IntegriCloud