- /* If we are attaching to our first thread, things are a little
- different. */
- if (all_threads.head == all_threads.tail)
+ inferior = (struct thread_info *) all_threads.head;
+ process = get_thread_process (inferior);
+ if (process->thread_known)
+ return 1;
+
+ /* Get information about the one thread we know we have. */
+ err = td_ta_map_lwp2thr (thread_agent, process->lwpid, &th);
+ if (err != TD_OK)
+ error ("Cannot get first thread handle: %s", thread_db_err_str (err));
+
+ err = td_thr_get_info (&th, &ti);
+ if (err != TD_OK)
+ error ("Cannot get first thread info: %s", thread_db_err_str (err));
+
+ if (debug_threads)
+ fprintf (stderr, "Found first thread %ld (LWP %d)\n",
+ ti.ti_tid, ti.ti_lid);
+
+ if (process->lwpid != ti.ti_lid)
+ fatal ("PID mismatch! Expected %ld, got %ld",
+ (long) process->lwpid, (long) ti.ti_lid);
+
+ /* If the new thread ID is zero, a final thread ID will be available
+ later. Do not enable thread debugging yet. */
+ if (ti.ti_tid == 0)