2 * Copyright (c) 2004 David Xu <davidxu@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
35 #include <sys/types.h>
37 #include <sys/ptrace.h>
38 #include <proc_service.h>
39 #include <thread_db.h>
41 #include "libpthread_db.h"
43 #define P2T(c) ps2td(c)
45 static void pt_unmap_lwp(const td_thragent_t *ta, lwpid_t lwp);
46 static int pt_validate(const td_thrhandle_t *th);
63 return TD_NOLIBTHREAD;
72 pt_map_thread(const td_thragent_t *const_ta, psaddr_t pt, int type)
74 td_thragent_t *ta = __DECONST(td_thragent_t *, const_ta);
79 for (i = 1; i < ta->map_len; ++i) {
80 if (ta->map[i].type == PT_NONE) {
83 } else if (ta->map[i].type == type && ta->map[i].thr == pt) {
89 if (ta->map_len == 0) {
90 ta->map = calloc(20, sizeof(struct pt_map));
96 new = realloc(ta->map,
97 sizeof(struct pt_map) * ta->map_len * 2);
100 memset(new + ta->map_len, '\0', sizeof(struct pt_map) *
108 ta->map[first].type = type;
109 ta->map[first].thr = pt;
121 pt_ta_new(struct ps_prochandle *ph, td_thragent_t **pta)
123 #define LOOKUP_SYM(proc, sym, addr) \
124 ret = ps_pglobal_lookup(proc, NULL, sym, addr); \
126 TDBG("can not find symbol: %s\n", sym); \
127 ret = TD_NOLIBTHREAD; \
131 #define LOOKUP_VAL(proc, sym, val) \
132 ret = ps_pglobal_lookup(proc, NULL, sym, &vaddr);\
134 TDBG("can not find symbol: %s\n", sym); \
135 ret = TD_NOLIBTHREAD; \
138 ret = ps_pread(proc, vaddr, val, sizeof(int)); \
140 TDBG("can not read value of %s\n", sym);\
141 ret = TD_NOLIBTHREAD; \
152 ta = malloc(sizeof(td_thragent_t));
157 ta->thread_activated = 0;
161 LOOKUP_SYM(ph, "_libkse_debug", &ta->libkse_debug_addr);
162 LOOKUP_SYM(ph, "_thread_list", &ta->thread_list_addr);
163 LOOKUP_SYM(ph, "_thread_activated", &ta->thread_activated_addr);
164 LOOKUP_SYM(ph, "_thread_active_threads",&ta->thread_active_threads_addr);
165 LOOKUP_SYM(ph, "_thread_keytable", &ta->thread_keytable_addr);
166 LOOKUP_VAL(ph, "_thread_off_dtv", &ta->thread_off_dtv);
167 LOOKUP_VAL(ph, "_thread_off_kse_locklevel", &ta->thread_off_kse_locklevel);
168 LOOKUP_VAL(ph, "_thread_off_kse", &ta->thread_off_kse);
169 LOOKUP_VAL(ph, "_thread_off_tlsindex", &ta->thread_off_tlsindex);
170 LOOKUP_VAL(ph, "_thread_off_attr_flags", &ta->thread_off_attr_flags);
171 LOOKUP_VAL(ph, "_thread_size_key", &ta->thread_size_key);
172 LOOKUP_VAL(ph, "_thread_off_tcb", &ta->thread_off_tcb);
173 LOOKUP_VAL(ph, "_thread_off_linkmap", &ta->thread_off_linkmap);
174 LOOKUP_VAL(ph, "_thread_off_tmbx", &ta->thread_off_tmbx);
175 LOOKUP_VAL(ph, "_thread_off_thr_locklevel", &ta->thread_off_thr_locklevel);
176 LOOKUP_VAL(ph, "_thread_off_next", &ta->thread_off_next);
177 LOOKUP_VAL(ph, "_thread_off_state", &ta->thread_off_state);
178 LOOKUP_VAL(ph, "_thread_max_keys", &ta->thread_max_keys);
179 LOOKUP_VAL(ph, "_thread_off_key_allocated", &ta->thread_off_key_allocated);
180 LOOKUP_VAL(ph, "_thread_off_key_destructor", &ta->thread_off_key_destructor);
181 LOOKUP_VAL(ph, "_thread_state_running", &ta->thread_state_running);
182 LOOKUP_VAL(ph, "_thread_state_zoombie", &ta->thread_state_zoombie);
183 LOOKUP_VAL(ph, "_thread_off_sigmask", &ta->thread_off_sigmask);
184 LOOKUP_VAL(ph, "_thread_off_sigpend", &ta->thread_off_sigpend);
187 * If this fails it probably means we're debugging a core file and
190 ps_pwrite(ph, ta->libkse_debug_addr, &dbg, sizeof(int));
200 pt_ta_delete(td_thragent_t *ta)
208 * Error returns from this write are not really a problem;
209 * the process doesn't exist any more.
211 ps_pwrite(ta->ph, ta->libkse_debug_addr, &dbg, sizeof(int));
219 pt_ta_map_id2thr(const td_thragent_t *ta, thread_t id, td_thrhandle_t *th)
222 TAILQ_HEAD(, pthread) thread_list;
223 psaddr_t pt, tcb_addr;
229 if (id < 0 || id >= ta->map_len || ta->map[id].type == PT_NONE)
231 ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
232 sizeof(thread_list));
235 pt = (psaddr_t)thread_list.tqh_first;
236 if (ta->map[id].type == PT_LWP) {
238 * if we are referencing a lwp, make sure it was not already
239 * mapped to user thread.
242 ret = ps_pread(ta->ph,
243 pt + ta->thread_off_tcb,
244 &tcb_addr, sizeof(tcb_addr));
247 ret = ps_pread(ta->ph,
248 tcb_addr + ta->thread_off_tmbx +
249 offsetof(struct kse_thr_mailbox, tm_lwp),
254 * If the lwp was already mapped to userland thread,
255 * we shouldn't reference it directly in future.
257 if (lwp == ta->map[id].lwp) {
258 ta->map[id].type = PT_NONE;
261 /* get next thread */
262 ret = ps_pread(ta->ph,
263 pt + ta->thread_off_next,
269 ret = ps_lgetregs(ta->ph, ta->map[id].lwp, gregs);
271 /* no longer exists */
272 ta->map[id].type = PT_NONE;
276 while (pt != 0 && ta->map[id].thr != pt) {
277 ret = ps_pread(ta->ph,
278 pt + ta->thread_off_tcb,
279 &tcb_addr, sizeof(tcb_addr));
282 /* get next thread */
283 ret = ps_pread(ta->ph,
284 pt + ta->thread_off_next,
291 /* no longer exists */
292 ta->map[id].type = PT_NONE;
303 pt_ta_map_lwp2thr(const td_thragent_t *ta, lwpid_t lwp, td_thrhandle_t *th)
305 TAILQ_HEAD(, pthread) thread_list;
312 ret = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
313 sizeof(thread_list));
316 pt = (psaddr_t)thread_list.tqh_first;
318 ret = ps_pread(ta->ph, pt + ta->thread_off_tcb,
322 ptr += ta->thread_off_tmbx +
323 offsetof(struct kse_thr_mailbox, tm_lwp);
324 ret = ps_pread(ta->ph, ptr, &tmp_lwp, sizeof(lwpid_t));
327 if (tmp_lwp == lwp) {
329 th->th_tid = pt_map_thread(ta, pt, PT_USER);
330 if (th->th_tid == -1)
332 pt_unmap_lwp(ta, lwp);
337 /* get next thread */
338 ret = ps_pread(ta->ph,
339 pt + ta->thread_off_next,
349 pt_ta_thr_iter(const td_thragent_t *ta,
350 td_thr_iter_f *callback, void *cbdata_p,
351 td_thr_state_e state, int ti_pri,
352 sigset_t *ti_sigmask_p,
353 unsigned int ti_user_flags)
355 TAILQ_HEAD(, pthread) thread_list;
363 pserr = ps_pread(ta->ph, ta->thread_activated_addr, &activated,
370 pserr = ps_pread(ta->ph, ta->thread_list_addr, &thread_list,
371 sizeof(thread_list));
374 pt = (psaddr_t)thread_list.tqh_first;
377 th.th_tid = pt_map_thread(ta, pt, PT_USER);
379 /* should we unmap lwp here ? */
382 if ((*callback)(&th, cbdata_p))
384 /* get next thread */
385 pserr = ps_pread(ta->ph,
386 pt + ta->thread_off_next, &pt,
395 pt_ta_tsd_iter(const td_thragent_t *ta, td_key_iter_f *ki, void *arg)
399 int i, ret, allocated;
403 keytable = malloc(ta->thread_max_keys * ta->thread_size_key);
404 if (keytable == NULL)
406 ret = ps_pread(ta->ph, (psaddr_t)ta->thread_keytable_addr, keytable,
407 ta->thread_max_keys * ta->thread_size_key);
412 for (i = 0; i < ta->thread_max_keys; i++) {
413 allocated = *(int *)(keytable + i * ta->thread_size_key +
414 ta->thread_off_key_allocated);
415 destructor = *(void **)(keytable + i * ta->thread_size_key +
416 ta->thread_off_key_destructor);
418 ret = (ki)(i, destructor, arg);
430 pt_ta_event_addr(const td_thragent_t *ta, td_event_e event, td_notify_t *ptr)
437 pt_ta_set_event(const td_thragent_t *ta, td_thr_events_t *events)
444 pt_ta_clear_event(const td_thragent_t *ta, td_thr_events_t *events)
451 pt_ta_event_getmsg(const td_thragent_t *ta, td_event_msg_t *msg)
458 pt_dbsuspend(const td_thrhandle_t *th, int suspend)
460 td_thragent_t *ta = (td_thragent_t *)th->th_ta;
461 psaddr_t tcb_addr, tmbx_addr, ptr;
464 int attrflags, locklevel, ret;
468 ret = pt_validate(th);
472 if (ta->map[th->th_tid].type == PT_LWP) {
474 ret = ps_lstop(ta->ph, ta->map[th->th_tid].lwp);
476 ret = ps_lcontinue(ta->ph, ta->map[th->th_tid].lwp);
480 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
481 ta->thread_off_attr_flags,
482 &attrflags, sizeof(attrflags));
485 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
487 &tcb_addr, sizeof(tcb_addr));
490 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
491 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
492 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
497 /* don't suspend signal thread */
498 if (attrflags & 0x200)
500 if (attrflags & PTHREAD_SCOPE_SYSTEM) {
502 * don't suspend system scope thread if it is holding
503 * some low level locks
505 ptr = ta->map[th->th_tid].thr + ta->thread_off_kse;
506 ret = ps_pread(ta->ph, ptr, &ptr, sizeof(ptr));
509 ret = ps_pread(ta->ph, ptr + ta->thread_off_kse_locklevel,
510 &locklevel, sizeof(int));
513 if (locklevel <= 0) {
514 ptr = ta->map[th->th_tid].thr +
515 ta->thread_off_thr_locklevel;
516 ret = ps_pread(ta->ph, ptr, &locklevel,
523 ret = ps_lstop(ta->ph, lwp);
525 ret = ps_lcontinue(ta->ph, lwp);
531 struct ptrace_lwpinfo pl;
533 if (ps_linfo(ta->ph, lwp, (caddr_t)&pl))
536 if (!(pl.pl_flags & PL_FLAG_BOUND))
537 ret = ps_lstop(ta->ph, lwp);
539 ret = ps_lcontinue(ta->ph, lwp);
547 ret = ps_pread(ta->ph,
548 tmbx_addr + offsetof(struct kse_thr_mailbox, tm_dflags),
549 &dflags, sizeof(dflags));
553 dflags |= TMDF_SUSPEND;
555 dflags &= ~TMDF_SUSPEND;
556 ret = ps_pwrite(ta->ph,
557 tmbx_addr + offsetof(struct kse_thr_mailbox, tm_dflags),
558 &dflags, sizeof(dflags));
563 pt_thr_dbresume(const td_thrhandle_t *th)
567 return pt_dbsuspend(th, 0);
571 pt_thr_dbsuspend(const td_thrhandle_t *th)
575 return pt_dbsuspend(th, 1);
579 pt_thr_validate(const td_thrhandle_t *th)
586 ret = pt_ta_map_id2thr(th->th_ta, th->th_tid,
592 pt_thr_get_info(const td_thrhandle_t *th, td_thrinfo_t *info)
594 const td_thragent_t *ta = th->th_ta;
595 struct ptrace_lwpinfo linfo;
605 bzero(info, sizeof(*info));
606 ret = pt_validate(th);
610 memset(info, 0, sizeof(*info));
611 if (ta->map[th->th_tid].type == PT_LWP) {
612 info->ti_type = TD_THR_SYSTEM;
613 info->ti_lid = ta->map[th->th_tid].lwp;
614 info->ti_tid = th->th_tid;
615 info->ti_state = TD_THR_RUN;
616 info->ti_type = TD_THR_SYSTEM;
620 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
621 ta->thread_off_attr_flags,
622 &attrflags, sizeof(attrflags));
625 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr + ta->thread_off_tcb,
626 &tcb_addr, sizeof(tcb_addr));
629 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr + ta->thread_off_state,
630 &state, sizeof(state));
631 ret = ps_pread(ta->ph,
632 tcb_addr + ta->thread_off_tmbx +
633 offsetof(struct kse_thr_mailbox, tm_lwp),
634 &info->ti_lid, sizeof(lwpid_t));
637 ret = ps_pread(ta->ph,
638 tcb_addr + ta->thread_off_tmbx +
639 offsetof(struct kse_thr_mailbox, tm_dflags),
640 &dflags, sizeof(dflags));
643 ret = ps_pread(ta->ph, tcb_addr + ta->thread_off_tmbx +
644 offsetof(struct kse_thr_mailbox, tm_lwp), &lwp, sizeof(lwpid_t));
647 info->ti_ta_p = th->th_ta;
648 info->ti_tid = th->th_tid;
650 if (attrflags & PTHREAD_SCOPE_SYSTEM) {
651 ret = ps_linfo(ta->ph, lwp, &linfo);
653 info->ti_sigmask = linfo.pl_sigmask;
654 info->ti_pending = linfo.pl_siglist;
658 ret = ps_pread(ta->ph,
659 ta->map[th->th_tid].thr + ta->thread_off_sigmask,
660 &info->ti_sigmask, sizeof(sigset_t));
663 ret = ps_pread(ta->ph,
664 ta->map[th->th_tid].thr + ta->thread_off_sigpend,
665 &info->ti_pending, sizeof(sigset_t));
670 if (state == ta->thread_state_running)
671 info->ti_state = TD_THR_RUN;
672 else if (state == ta->thread_state_zoombie)
673 info->ti_state = TD_THR_ZOMBIE;
675 info->ti_state = TD_THR_SLEEP;
676 info->ti_db_suspended = ((dflags & TMDF_SUSPEND) != 0);
677 info->ti_type = TD_THR_USER;
683 pt_thr_getxmmregs(const td_thrhandle_t *th, char *fxsave)
685 const td_thragent_t *ta = th->th_ta;
686 struct kse_thr_mailbox tmbx;
687 psaddr_t tcb_addr, tmbx_addr, ptr;
695 ret = pt_validate(th);
699 if (ta->map[th->th_tid].type == PT_LWP) {
700 ret = ps_lgetxmmregs(ta->ph, ta->map[th->th_tid].lwp, fxsave);
704 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr + ta->thread_off_tcb,
705 &tcb_addr, sizeof(tcb_addr));
708 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
709 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
710 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
714 ret = ps_lgetxmmregs(ta->ph, lwp, fxsave);
718 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
721 pt_ucontext_to_fxsave(&tmbx.tm_context, fxsave);
727 pt_thr_getfpregs(const td_thrhandle_t *th, prfpregset_t *fpregs)
729 const td_thragent_t *ta = th->th_ta;
730 struct kse_thr_mailbox tmbx;
731 psaddr_t tcb_addr, tmbx_addr, ptr;
737 ret = pt_validate(th);
741 if (ta->map[th->th_tid].type == PT_LWP) {
742 ret = ps_lgetfpregs(ta->ph, ta->map[th->th_tid].lwp, fpregs);
746 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr + ta->thread_off_tcb,
747 &tcb_addr, sizeof(tcb_addr));
750 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
751 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
752 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
756 ret = ps_lgetfpregs(ta->ph, lwp, fpregs);
760 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
763 pt_ucontext_to_fpreg(&tmbx.tm_context, fpregs);
768 pt_thr_getgregs(const td_thrhandle_t *th, prgregset_t gregs)
770 const td_thragent_t *ta = th->th_ta;
771 struct kse_thr_mailbox tmbx;
772 psaddr_t tcb_addr, tmbx_addr, ptr;
778 ret = pt_validate(th);
782 if (ta->map[th->th_tid].type == PT_LWP) {
783 ret = ps_lgetregs(ta->ph,
784 ta->map[th->th_tid].lwp, gregs);
788 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr + ta->thread_off_tcb,
789 &tcb_addr, sizeof(tcb_addr));
792 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
793 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
794 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
798 ret = ps_lgetregs(ta->ph, lwp, gregs);
801 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
804 pt_ucontext_to_reg(&tmbx.tm_context, gregs);
810 pt_thr_setxmmregs(const td_thrhandle_t *th, const char *fxsave)
812 const td_thragent_t *ta = th->th_ta;
813 struct kse_thr_mailbox tmbx;
814 psaddr_t tcb_addr, tmbx_addr, ptr;
822 ret = pt_validate(th);
826 if (ta->map[th->th_tid].type == PT_LWP) {
827 ret = ps_lsetxmmregs(ta->ph, ta->map[th->th_tid].lwp, fxsave);
831 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
833 &tcb_addr, sizeof(tcb_addr));
836 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
837 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
838 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
842 ret = ps_lsetxmmregs(ta->ph, lwp, fxsave);
846 * Read a copy of context, this makes sure that registers
847 * not covered by structure reg won't be clobbered
849 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
853 pt_fxsave_to_ucontext(fxsave, &tmbx.tm_context);
854 ret = ps_pwrite(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
860 pt_thr_setfpregs(const td_thrhandle_t *th, const prfpregset_t *fpregs)
862 const td_thragent_t *ta = th->th_ta;
863 struct kse_thr_mailbox tmbx;
864 psaddr_t tcb_addr, tmbx_addr, ptr;
870 ret = pt_validate(th);
874 if (ta->map[th->th_tid].type == PT_LWP) {
875 ret = ps_lsetfpregs(ta->ph, ta->map[th->th_tid].lwp, fpregs);
879 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
881 &tcb_addr, sizeof(tcb_addr));
884 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
885 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
886 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
890 ret = ps_lsetfpregs(ta->ph, lwp, fpregs);
894 * Read a copy of context, this makes sure that registers
895 * not covered by structure reg won't be clobbered
897 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
901 pt_fpreg_to_ucontext(fpregs, &tmbx.tm_context);
902 ret = ps_pwrite(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
907 pt_thr_setgregs(const td_thrhandle_t *th, const prgregset_t gregs)
909 const td_thragent_t *ta = th->th_ta;
910 struct kse_thr_mailbox tmbx;
911 psaddr_t tcb_addr, tmbx_addr, ptr;
917 ret = pt_validate(th);
921 if (ta->map[th->th_tid].type == PT_LWP) {
922 ret = ps_lsetregs(ta->ph, ta->map[th->th_tid].lwp, gregs);
926 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
928 &tcb_addr, sizeof(tcb_addr));
931 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
932 ptr = tmbx_addr + offsetof(struct kse_thr_mailbox, tm_lwp);
933 ret = ps_pread(ta->ph, ptr, &lwp, sizeof(lwpid_t));
937 ret = ps_lsetregs(ta->ph, lwp, gregs);
942 * Read a copy of context, make sure that registers
943 * not covered by structure reg won't be clobbered
945 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
948 pt_reg_to_ucontext(gregs, &tmbx.tm_context);
949 ret = ps_pwrite(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
954 pt_thr_event_enable(const td_thrhandle_t *th, int en)
961 pt_thr_set_event(const td_thrhandle_t *th, td_thr_events_t *setp)
968 pt_thr_clear_event(const td_thrhandle_t *th, td_thr_events_t *setp)
975 pt_thr_event_getmsg(const td_thrhandle_t *th, td_event_msg_t *msg)
982 pt_thr_sstep(const td_thrhandle_t *th, int step)
984 const td_thragent_t *ta = th->th_ta;
985 struct kse_thr_mailbox tmbx;
987 psaddr_t tcb_addr, tmbx_addr;
994 ret = pt_validate(th);
998 if (ta->map[th->th_tid].type == PT_LWP)
1001 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
1003 &tcb_addr, sizeof(tcb_addr));
1007 /* Clear or set single step flag in thread mailbox */
1008 ret = ps_pread(ta->ph,
1009 tcb_addr + ta->thread_off_tmbx +
1010 offsetof(struct kse_thr_mailbox, tm_dflags),
1011 &dflags, sizeof(uint32_t));
1015 dflags |= TMDF_SSTEP;
1017 dflags &= ~TMDF_SSTEP;
1018 ret = ps_pwrite(ta->ph,
1019 tcb_addr + ta->thread_off_tmbx +
1020 offsetof(struct kse_thr_mailbox, tm_dflags),
1021 &dflags, sizeof(uint32_t));
1025 ret = ps_pread(ta->ph,
1026 tcb_addr + ta->thread_off_tmbx +
1027 offsetof(struct kse_thr_mailbox, tm_lwp),
1028 &lwp, sizeof(lwpid_t));
1034 tmbx_addr = tcb_addr + ta->thread_off_tmbx;
1036 * context is in userland, some architectures store
1037 * single step status in registers, we should change
1040 ret = ps_pread(ta->ph, tmbx_addr, &tmbx, sizeof(tmbx));
1042 pt_ucontext_to_reg(&tmbx.tm_context, ®s);
1043 /* only write out if it is really changed. */
1044 if (pt_reg_sstep(®s, step) != 0) {
1045 pt_reg_to_ucontext(®s, &tmbx.tm_context);
1046 ret = ps_pwrite(ta->ph, tmbx_addr, &tmbx,
1054 pt_unmap_lwp(const td_thragent_t *ta, lwpid_t lwp)
1058 for (i = 0; i < ta->map_len; ++i) {
1059 if (ta->map[i].type == PT_LWP && ta->map[i].lwp == lwp) {
1060 ta->map[i].type = PT_NONE;
1067 pt_validate(const td_thrhandle_t *th)
1070 if (th->th_tid < 0 || th->th_tid >= th->th_ta->map_len ||
1071 th->th_ta->map[th->th_tid].type == PT_NONE)
1077 pt_thr_tls_get_addr(const td_thrhandle_t *th, void *_linkmap, size_t offset,
1081 const td_thragent_t *ta = th->th_ta;
1082 psaddr_t tcb_addr, *dtv_addr;
1085 /* linkmap is a member of Obj_Entry */
1086 obj_entry = (char *)_linkmap - ta->thread_off_linkmap;
1088 /* get tlsindex of the object file */
1089 ret = ps_pread(ta->ph,
1090 obj_entry + ta->thread_off_tlsindex,
1091 &tls_index, sizeof(tls_index));
1095 /* get thread tcb */
1096 ret = ps_pread(ta->ph, ta->map[th->th_tid].thr +
1098 &tcb_addr, sizeof(tcb_addr));
1102 /* get dtv array address */
1103 ret = ps_pread(ta->ph, tcb_addr + ta->thread_off_dtv,
1104 &dtv_addr, sizeof(dtv_addr));
1107 /* now get the object's tls block base address */
1108 ret = ps_pread(ta->ph, &dtv_addr[tls_index+1], address,
1117 struct ta_ops libpthread_db_ops = {
1119 .to_ta_clear_event = pt_ta_clear_event,
1120 .to_ta_delete = pt_ta_delete,
1121 .to_ta_event_addr = pt_ta_event_addr,
1122 .to_ta_event_getmsg = pt_ta_event_getmsg,
1123 .to_ta_map_id2thr = pt_ta_map_id2thr,
1124 .to_ta_map_lwp2thr = pt_ta_map_lwp2thr,
1125 .to_ta_new = pt_ta_new,
1126 .to_ta_set_event = pt_ta_set_event,
1127 .to_ta_thr_iter = pt_ta_thr_iter,
1128 .to_ta_tsd_iter = pt_ta_tsd_iter,
1129 .to_thr_clear_event = pt_thr_clear_event,
1130 .to_thr_dbresume = pt_thr_dbresume,
1131 .to_thr_dbsuspend = pt_thr_dbsuspend,
1132 .to_thr_event_enable = pt_thr_event_enable,
1133 .to_thr_event_getmsg = pt_thr_event_getmsg,
1134 .to_thr_get_info = pt_thr_get_info,
1135 .to_thr_getfpregs = pt_thr_getfpregs,
1136 .to_thr_getgregs = pt_thr_getgregs,
1137 .to_thr_set_event = pt_thr_set_event,
1138 .to_thr_setfpregs = pt_thr_setfpregs,
1139 .to_thr_setgregs = pt_thr_setgregs,
1140 .to_thr_validate = pt_thr_validate,
1141 .to_thr_tls_get_addr = pt_thr_tls_get_addr,
1143 /* FreeBSD specific extensions. */
1144 .to_thr_sstep = pt_thr_sstep,
1146 .to_thr_getxmmregs = pt_thr_getxmmregs,
1147 .to_thr_setxmmregs = pt_thr_setxmmregs,