-/* Check if PID is currently stopped at the location of a thread event
- breakpoint location. If it is, read the event message and act upon
- the event. */
-
-static void
-check_event (ptid_t ptid)
-{
- struct regcache *regcache = get_thread_regcache (ptid);
- struct gdbarch *gdbarch = get_regcache_arch (regcache);
- td_event_msg_t msg;
- td_thrinfo_t ti;
- td_err_e err;
- CORE_ADDR stop_pc;
- int loop = 0;
- struct thread_db_info *info;
-
- info = get_thread_db_info (ptid_get_pid (ptid));
-
- /* Bail out early if we're not at a thread event breakpoint. */
- stop_pc = regcache_read_pc (regcache);
- if (!target_supports_stopped_by_sw_breakpoint ())
- stop_pc -= gdbarch_decr_pc_after_break (gdbarch);
-
- if (stop_pc != info->td_create_bp_addr
- && stop_pc != info->td_death_bp_addr)
- return;
-
- /* Access an lwp we know is stopped. */
- info->proc_handle.ptid = ptid;
-
- /* If we have only looked at the first thread before libpthread was
- initialized, we may not know its thread ID yet. Make sure we do
- before we add another thread to the list. */
- if (!have_threads (ptid))
- thread_db_find_new_threads_1 (ptid);
-
- /* If we are at a create breakpoint, we do not know what new lwp
- was created and cannot specifically locate the event message for it.
- We have to call td_ta_event_getmsg() to get
- the latest message. Since we have no way of correlating whether
- the event message we get back corresponds to our breakpoint, we must
- loop and read all event messages, processing them appropriately.
- This guarantees we will process the correct message before continuing
- from the breakpoint.
-
- Currently, death events are not enabled. If they are enabled,
- the death event can use the td_thr_event_getmsg() interface to
- get the message specifically for that lwp and avoid looping
- below. */
-
- loop = 1;
-
- do
- {
- err = info->td_ta_event_getmsg_p (info->thread_agent, &msg);
- if (err != TD_OK)
- {
- if (err == TD_NOMSG)
- return;
-
- error (_("Cannot get thread event message: %s"),
- thread_db_err_str (err));
- }
-
- err = info->td_thr_get_info_p (msg.th_p, &ti);
- if (err != TD_OK)
- error (_("Cannot get thread info: %s"), thread_db_err_str (err));
-
- ptid = ptid_build (ptid_get_pid (ptid), ti.ti_lid, 0);
-
- switch (msg.event)
- {
- case TD_CREATE:
- /* Call attach_thread whether or not we already know about a
- thread with this thread ID. */
- attach_thread (ptid, msg.th_p, &ti);
-
- break;
-
- case TD_DEATH:
-
- if (!in_thread_list (ptid))
- error (_("Spurious thread death event."));
-
- detach_thread (ptid);
-
- break;
-
- default:
- error (_("Spurious thread event."));
- }
- }
- while (loop);
-}
-