diff --git a/gdb/gdbserver/remote-utils.c b/gdb/gdbserver/remote-utils.c index d638a3f..76953ae 100644 --- a/gdb/gdbserver/remote-utils.c +++ b/gdb/gdbserver/remote-utils.c @@ -1181,8 +1181,8 @@ prepare_resume_reply (char *buf, ptid_t ptid, strcat (buf, ";"); buf += strlen (buf); - if (the_target->core_for_thread) - core = (*the_target->core_for_thread) (ptid); + if (the_target->core_of_thread) + core = (*the_target->core_of_thread) (ptid); if (core != -1) { sprintf (buf, "core:"); diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index dfc92a8..c781552 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -723,8 +723,8 @@ handle_threads_qxfer_proper (struct buffer *buffer) write_ptid (ptid_s, ptid); - if (the_target->core_for_thread) - core = (*the_target->core_for_thread) (ptid); + if (the_target->core_of_thread) + core = (*the_target->core_of_thread) (ptid); if (core != -1) { diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h index 0ee0d41..0c761e9 100644 --- a/gdb/gdbserver/target.h +++ b/gdb/gdbserver/target.h @@ -285,7 +285,7 @@ struct target_ops int (*handle_monitor_command) (char *); /* Returns the core given a thread, or -1 if not known. */ - int (*core_for_thread) (ptid_t); + int (*core_of_thread) (ptid_t); }; extern struct target_ops *the_target; diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index 717f78c..bf0a5f1 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -1184,6 +1184,7 @@ add_lwp (ptid_t ptid) lp->waitstatus.kind = TARGET_WAITKIND_IGNORE; lp->ptid = ptid; + lp->core = -1; lp->next = lwp_list; lwp_list = lp; @@ -3642,6 +3643,7 @@ retry: fprintf_unfiltered (gdb_stdlog, "LLW: exit\n"); restore_child_signals_mask (&prev_mask); + lp->core = linux_nat_core_of_thread_1 (lp->ptid); return lp->ptid; } @@ -5423,10 +5425,8 @@ linux_nat_thread_address_space (struct target_ops *t, ptid_t ptid) return inf->aspace; } -/* Return the core for a thread. */ - -static int -linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid) +int +linux_nat_core_of_thread_1 (ptid_t ptid) { struct cleanup *back_to; char *filename; @@ -5483,6 +5483,17 @@ linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid) return core; } +/* Return the cached value of the processor core for thread PTID. */ + +int +linux_nat_core_of_thread (struct target_ops *ops, ptid_t ptid) +{ + struct lwp_info *info = find_lwp_pid (ptid); + if (info) + return info->core; + return -1; +} + void linux_nat_add_target (struct target_ops *t) { diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h index 9537740..5aba089 100644 --- a/gdb/linux-nat.h +++ b/gdb/linux-nat.h @@ -89,6 +89,9 @@ struct lwp_info - TARGET_WAITKIND_SYSCALL_RETURN */ int syscall_state; + /* The processor core this LWP was last seen on. */ + int core; + /* Next LWP in list. */ struct lwp_info *next; }; @@ -163,3 +166,6 @@ void linux_nat_switch_fork (ptid_t new_ptid); /* Return the saved siginfo associated with PTID. */ struct siginfo *linux_nat_get_siginfo (ptid_t ptid); + +/* Compute and return the processor core of a given thread. */ +int linux_nat_core_of_thread_1 (ptid_t ptid); diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 659d99d..2c66da7 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -1454,6 +1454,12 @@ thread_db_find_new_threads_1 (ptid_t ptid) thread_db_find_new_threads_2 (ptid, 0); } +static int +update_thread_core (struct lwp_info *info, void *closure) +{ + info->core = linux_nat_core_of_thread_1 (info->ptid); + return 0; +} static void thread_db_find_new_threads (struct target_ops *ops) @@ -1466,6 +1472,9 @@ thread_db_find_new_threads (struct target_ops *ops) return; thread_db_find_new_threads_1 (inferior_ptid); + + iterate_over_lwps (minus_one_ptid /* iterate over all */, + update_thread_core, NULL); } static char * diff --git a/gdb/remote.c b/gdb/remote.c index 992ef9a..beb585e 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1411,7 +1411,7 @@ remote_notice_new_inferior (ptid_t currthread, int running) remote_add_thread (currthread, running); inferior_ptid = currthread; } - return; + return; } if (ptid_equal (magic_null_ptid, inferior_ptid)) @@ -1421,7 +1421,7 @@ remote_notice_new_inferior (ptid_t currthread, int running) doesn't support qC. This is the first stop reported after an attach, so this is the main thread. Update the ptid in the thread list. */ - thread_change_ptid (inferior_ptid, currthread); + thread_change_ptid (inferior_ptid, currthread); return; } @@ -1452,12 +1452,12 @@ demand_private_info (ptid_t ptid) gdb_assert (info); - if (!info->private) + if (!info->private) { info->private = xmalloc (sizeof (*(info->private))); info->private_dtor = free_private_thread_info; } - + return info->private; } diff --git a/gdb/target.h b/gdb/target.h index 9725375..a020bf7 100644 --- a/gdb/target.h +++ b/gdb/target.h @@ -653,11 +653,10 @@ struct target_ops disconnection - set VAL to 1 to keep tracing, 0 to stop. */ void (*to_set_disconnected_tracing) (int val); - /* Return the core that thread PTID is on. For a stopped thread, should - return the core the thread was last running on. For a running thread, - should return one of the cores that the thread was running between - the call to this function and return -- and if it was running on - several cores, any other may be returned. + /* Return the processor core that thread PTID was last seen on. + This information is updated only when: + - update_thread_list is called + - thread stops If the core cannot be determined -- either for the specified thread, or right now, or in this debug session, or for this target -- return -1. */ int (*to_core_of_thread) (struct target_ops *, ptid_t ptid);