aboutsummaryrefslogtreecommitdiff
path: root/gdb/thread.c
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2023-10-10 10:17:35 +0100
committerAndrew Burgess <aburgess@redhat.com>2023-11-08 13:28:09 +0000
commit75b2eb97a49bf3b539d7e016b2d9a2339170a680 (patch)
tree2c9d050f04915be73cb5372c7bdc46784c828860 /gdb/thread.c
parentb20885b0a439ff8bd0e4fd00c666589ffca10fa2 (diff)
downloadfsf-binutils-gdb-75b2eb97a49bf3b539d7e016b2d9a2339170a680.zip
fsf-binutils-gdb-75b2eb97a49bf3b539d7e016b2d9a2339170a680.tar.gz
fsf-binutils-gdb-75b2eb97a49bf3b539d7e016b2d9a2339170a680.tar.bz2
gdb: call update_thread_list for $_inferior_thread_count function
I noticed that sometimes the value returned by $_inferior_thread_count can become out of sync with the actual thread count of the inferior, and will disagree with the number of threads reported by 'info threads'. This commit fixes this issue. The cause of the problem is that 'info threads' includes a call to update_thread_list, this can be seen in print_thread_info_1 in thread.c, while $_inferior_thread_count doesn't include a similar call, see the function inferior_thread_count_make_value also in thread.c. Of course, this is only a problem when GDB is running on a target that relies on update_thread_list calls to learn about new threads, e.g. remote or extended-remote targets. Native targets generally learn about new threads as soon as they appear and will not have this problem. I ran into this issue when writing a test for the next commit which uses inferior function calls to add an remove threads from an inferior. But for testing I've made use of non-stop mode and asynchronous inferior execution; by reading the inferior state I can know when a new thread has been created, at which point I can print $_inferior_thread_count while the inferior is still running. This is important, if I stop the inferior then GDB will pass through an update_thread_list call in the normal stop code, which will synchronise the thread list, after which $_inferior_thread_count will report the correct value. With this change in place $_inferior_thread_count is now correct.
Diffstat (limited to 'gdb/thread.c')
-rw-r--r--gdb/thread.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/gdb/thread.c b/gdb/thread.c
index c8145da..0660589 100644
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -2183,6 +2183,8 @@ inferior_thread_count_make_value (struct gdbarch *gdbarch,
{
int int_val = 0;
+ update_thread_list ();
+
if (inferior_ptid != null_ptid)
int_val = current_inferior ()->non_exited_threads ().size ();