Date: Sun, 4 Jul 2004 19:03:15 GMT From: Marcel Moolenaar <marcel@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 56456 for review Message-ID: <200407041903.i64J3FIf054941@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=56456 Change 56456 by marcel@marcel_nfs on 2004/07/04 19:03:05 Rudimentary debugging support for libthr. Affected files ... .. //depot/projects/gdb/lib/libthread_db/libthr_db.c#2 edit Differences ... ==== //depot/projects/gdb/lib/libthread_db/libthr_db.c#2 (text+ko) ==== @@ -36,6 +36,10 @@ struct td_thragent { TD_THRAGENT_FIELDS; struct ps_prochandle *ta_ph; + psaddr_t ta_thread_list; + int ta_ofs_ctx; + int ta_ofs_next; + int ta_ofs_thr_id; }; static td_err_e @@ -87,19 +91,49 @@ static td_err_e libthr_db_ta_new(struct ps_prochandle *ph, td_thragent_t **ta_p) { - psaddr_t debug; + td_thragent_t *ta; + psaddr_t addr; ps_err_e err; - err = ps_pglobal_lookup(ph, NULL, "_libthr_debug", &debug); + err = ps_pglobal_lookup(ph, NULL, "_libthr_debug", &addr); if (err != PS_OK) return (TD_NOLIBTHREAD); - *ta_p = malloc(sizeof(td_thragent_t)); - if (*ta_p == NULL) + ta = malloc(sizeof(td_thragent_t)); + if (ta == NULL) return (TD_MALLOC); - (*ta_p)->ta_ph = ph; + ta->ta_ph = ph; + + err = ps_pglobal_lookup(ph, NULL, "_thread_list", &ta->ta_thread_list); + if (err != PS_OK) + goto fail; + err = ps_pglobal_lookup(ph, NULL, "_thread_ctx_offset", &addr); + if (err != PS_OK) + goto fail; + err = ps_pread(ph, addr, &ta->ta_ofs_ctx, sizeof(int)); + if (err != PS_OK) + goto fail; + err = ps_pglobal_lookup(ph, NULL, "_thread_next_offset", &addr); + if (err != PS_OK) + goto fail; + err = ps_pread(ph, addr, &ta->ta_ofs_next, sizeof(int)); + if (err != PS_OK) + goto fail; + err = ps_pglobal_lookup(ph, NULL, "_thread_thr_id_offset", &addr); + if (err != PS_OK) + goto fail; + err = ps_pread(ph, addr, &ta->ta_ofs_thr_id, sizeof(int)); + if (err != PS_OK) + goto fail; + + *ta_p = ta; return (TD_OK); + + fail: + free(ta); + *ta_p = NULL; + return (TD_ERR); } static td_err_e @@ -112,7 +146,26 @@ libthr_db_ta_thr_iter(const td_thragent_t *ta, td_thr_iter_f *cb, void *data, td_thr_state_e state, int pri, sigset_t *mask, unsigned int flags) { - return (TD_NOTHR); + td_thrhandle_t th; + psaddr_t addr; + ps_err_e err; + + th.th_ta = ta; + + err = ps_pread(ta->ta_ph, ta->ta_thread_list, &th.th_thread, + sizeof(th.th_thread)); + if (err != PS_OK) + return (TD_ERR); + while (th.th_thread != NULL) { + if (cb(&th, data) != 0) + return (TD_OK); + addr = (psaddr_t)((uintptr_t)th.th_thread + ta->ta_ofs_next); + err = ps_pread(ta->ta_ph, addr, &th.th_thread, + sizeof(th.th_thread)); + if (err != PS_OK) + return (TD_ERR); + } + return (TD_OK); } static td_err_e @@ -136,19 +189,52 @@ static td_err_e libthr_db_thr_get_info(const td_thrhandle_t *th, td_thrinfo_t *ti) { - return (TD_ERR); + const td_thragent_t *ta; + psaddr_t addr; + thread_t tid; + ps_err_e err; + + ta = th->th_ta; + ti->ti_ta = ta; + addr = (psaddr_t)((uintptr_t)th->th_thread + ta->ta_ofs_thr_id); + err = ps_pread(ta->ta_ph, addr, &tid, sizeof(thread_t)); + ti->ti_lid = tid; + ti->ti_tid = tid; + return ((err == PS_OK) ? TD_OK : TD_ERR); } static td_err_e libthr_db_thr_getfpregs(const td_thrhandle_t *th, prfpregset_t *r) { - return (TD_ERR); + const td_thragent_t *ta; + psaddr_t addr; + thread_t tid; + ps_err_e err; + + ta = th->th_ta; + addr = (psaddr_t)((uintptr_t)th->th_thread + ta->ta_ofs_thr_id); + err = ps_pread(ta->ta_ph, addr, &tid, sizeof(thread_t)); + if (err != PS_OK) + return (TD_ERR); + err = ps_lgetfpregs(ta->ta_ph, tid, r); + return ((err == PS_OK) ? TD_OK : TD_ERR); } static td_err_e libthr_db_thr_getgregs(const td_thrhandle_t *th, prgregset_t *r) { - return (TD_ERR); + const td_thragent_t *ta; + psaddr_t addr; + thread_t tid; + ps_err_e err; + + ta = th->th_ta; + addr = (psaddr_t)((uintptr_t)th->th_thread + ta->ta_ofs_thr_id); + err = ps_pread(ta->ta_ph, addr, &tid, sizeof(thread_t)); + if (err != PS_OK) + return (TD_ERR); + err = ps_lgetregs(ta->ta_ph, tid, r); + return ((err == PS_OK) ? TD_OK : TD_ERR); } static td_err_e
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200407041903.i64J3FIf054941>