static void check_for_thread_db (void) { td_err_e err; if (td_ta_new_p == NULL) return; /* Don't try to attach to a dead target if there is no core file. */ if (!target_has_execution && core_bfd == NULL) return; /* Nothing to do. The thread library was already detected and the target vector was already activated. */ if (fbsd_thread_active) return; /* Now, initialize libthread_db. This needs to be done after the shared libraries are located because it needs information from the user's thread library. */ err = td_init_p (); if (err != TD_OK) { warning ("Cannot initialize libthread_db: %s", thread_db_err_str (err)); return; } /* Initialize the structure that identifies the child process. Note that at this point there is no guarantee that we actually have a child process. */ proc_handle.pid = GET_PID (inferior_ptid); /* Now attempt to open a connection to the thread library. */ err = td_ta_new_p (&proc_handle, &thread_agent); switch (err) { case TD_NOLIBTHREAD: /* No thread library was detected. */ break; case TD_OK: /* The thread library was detected. Activate the thread_db target. */ push_target(&fbsd_thread_ops); fbsd_thread_present = 1; fbsd_thread_activate(); break; default: warning ("Cannot initialize thread debugging library: %s", thread_db_err_str (err)); break; } }
static int thread_db_load (void) { void *handle; td_err_e err; handle = dlopen (LIBTHREAD_DB_SO, RTLD_NOW); if (handle == NULL) return 0; #define resolve(X) \ if (!(X##_p = dlsym (handle, #X))) \ return 0; resolve(td_init); resolve(td_ta_new); resolve(td_ta_delete); resolve(td_ta_map_id2thr); resolve(td_ta_map_lwp2thr); resolve(td_ta_thr_iter); resolve(td_thr_get_info); #ifdef PT_GETXMMREGS resolve(td_thr_getxmmregs); #endif resolve(td_thr_getfpregs); resolve(td_thr_getgregs); #ifdef PT_GETXMMREGS resolve(td_thr_setxmmregs); #endif resolve(td_thr_setfpregs); resolve(td_thr_setgregs); resolve(td_thr_sstep); resolve(td_ta_tsd_iter); resolve(td_thr_dbsuspend); resolve(td_thr_dbresume); resolve(td_thr_tls_get_addr); /* Initialize the library. */ err = td_init_p (); if (err != TD_OK) { warning ("Cannot initialize libthread_db: %s", thread_db_err_str (err)); return 0; } /* These are not essential. */ td_ta_event_addr_p = dlsym (handle, "td_ta_event_addr"); td_ta_set_event_p = dlsym (handle, "td_ta_set_event"); td_ta_event_getmsg_p = dlsym (handle, "td_ta_event_getmsg"); td_thr_event_enable_p = dlsym (handle, "td_thr_event_enable"); td_thr_tls_get_addr_p = dlsym (handle, "td_thr_tls_get_addr"); return 1; }