2008-08-19 Pedro Alves * aix-thread.c (sync_threadlists): Claim the main thread. If no thread is found, and we never had thread info bail out early. (pd_update): Don't update inferior_ptid here. --- gdb/aix-thread.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) Index: src/gdb/aix-thread.c =================================================================== --- src.orig/gdb/aix-thread.c 2008-08-19 16:37:56.000000000 +0100 +++ src/gdb/aix-thread.c 2008-08-19 18:06:04.000000000 +0100 @@ -679,6 +679,7 @@ sync_threadlists (void) pthdb_pthread_t pdtid; pthread_t pthid; pthdb_tid_t tid; + infpid = PIDGET (inferior_ptid); /* Accumulate an array of libpthdebug threads sorted by pthread id. */ @@ -717,6 +718,44 @@ sync_threadlists (void) qsort (pbuf, pcount, sizeof *pbuf, pcmp); + /* If the main thread is still listed without extra lwp/tid info, + update its ptid and set its private field before synching the + lists. */ + + main_thread = find_thread_pid (infpid); + if (main_thread) + { + struct pd_thread *first; + + /* We should have found at least one thread. */ + /* Could it be we can get here with no threads while starting up + the inferior, and the thread library is still not + initialized? In that case, we'd just better skip over the + thread synching? */ +#if 0 + gdb_assert (pcount > 0); +#else + if (pcount == 0) + { + xfree (pbuf); + return; + } +#endif + + /* Assume the first listed is the main thread. */ + first = &pbuf[0]; + + main_thread->private = xmalloc (sizeof (struct private_thread_info)); + main_thread->private->pdtid = first->pdtid; + main_thread->private->tid = first->tid; + + /* This also updates inferior_ptid if it is pointing at the main + thread (currently, it always is, but even if is wasn't + because we supported multi-process on AIX, it would be + ok). */ + thread_change_ptid (main_thread->ptid, BUILD_THREAD (first->pthid, infpid)); + } + /* Accumulate an array of GDB threads sorted by pid. */ gcount = 0; @@ -727,7 +766,6 @@ sync_threadlists (void) /* Apply differences between the two arrays to GDB's thread list. */ - infpid = PIDGET (inferior_ptid); for (pi = gi = 0; pi < pcount || gi < gcount;) { if (pi == pcount) @@ -816,6 +854,10 @@ pd_update (int set_infpid) /* Define "current thread" as one that just received a trap signal. */ + /* Can the bit below now ever return without a valid thread? + get_signaled_thread will return 0 if it doesn't find any + signalled thread. If sync_thread_lists didn't find any thread + yet, will iter_tid crash on the reference to thread->private? */ tid = get_signaled_thread (); if (tid != 0) thread = iterate_over_threads (iter_tid, &tid); @@ -824,8 +866,12 @@ pd_update (int set_infpid) else { ptid = thread->ptid; +#if 0 + /* sync_threadlists should be already taking care of updating + inferior_ptid, with the thread_change_ptid call. */ if (set_infpid) inferior_ptid = ptid; +#endif } return ptid; } @@ -940,6 +986,8 @@ new_objfile (struct objfile *objfile) static void aix_thread_attach (char *args, int from_tty) { + /* inf-ptrace already adds the thread we attach to, and pd_activate + should end up claiming it. */ base_target.to_attach (args, from_tty); pd_activate (1); }