[v2,2/2] Make thread_db_target::pid_to_str checkpoint-aware

Message ID 20240414032731.130266-3-kevinb@redhat.com
State New
Headers
Series Make linux checkpoints work with multiple inferiors |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm fail Testing failed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 fail Testing failed

Commit Message

Kevin Buettner April 14, 2024, 3:24 a.m. UTC
  This commit prevents thread_db_target::pid_to_str from considering
a checkpoint as a thread.  The reason for doing this is that pids
associated with checkpoints can never be a thread due to the fact
that checkpoints (which are implemented by forking a process) can
only work with single-threaded processes.

Without this commit, many of the "info checkpoints" commands
in gdb.multi/checkpoint-multi.exp will incorrectly show some
of the checkpoints as threads.  E.g...

*  1.0 A  Thread 0x7ffff7cd3740 (LWP 128534) at 0x401199, file hello.c, line 51
   1.2    process 128546 at 0x401199, file hello.c, line 51
   1.3    process 128547 at 0x401199, file hello.c, line 51
   2.1    process 128538 at 0x401258, file goodbye.c, line 62
   2.2 A  Thread 0x7ffff7cd3740 (LWP 128542) at 0x401258, file goodbye.c, line 62
   3.0 A  Thread 0x7ffff7cd3740 (LWP 128543) at 0x40115c, file hangout.c, line 31
   3.2    process 128545 at 0x40115c, file hangout.c, line 31

With this commit in place, the output looks like this instead:

*  1.0 A  process 129961 at 0x401199, file hello.c, line 51
   1.2    process 129974 at 0x401199, file hello.c, line 51
   1.3    process 129975 at 0x401199, file hello.c, line 51
   2.1    process 129965 at 0x401258, file goodbye.c, line 62
   2.2 A  process 129969 at 0x401258, file goodbye.c, line 62
   3.0 A  process 129970 at 0x40115c, file hangout.c, line 31
   3.2    process 129972 at 0x40115c, file hangout.c, line 31

(For brevity, I've removed the directory elements in each of the paths
above.)

The testcase, gdb.multi/checkpoint-multi.exp, has been updated to
reflect the fact that only "process" should now appear in output
from "info checkpoints".
---
 gdb/linux-thread-db.c                        | 4 +++-
 gdb/testsuite/gdb.multi/checkpoint-multi.exp | 2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)
  

Patch

diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 65bf4a79fdf..488a7086acf 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -48,6 +48,7 @@ 
 #include "gdbsupport/pathstuff.h"
 #include "valprint.h"
 #include "cli/cli-style.h"
+#include "linux-fork.h"
 
 /* GNU/Linux libthread_db support.
 
@@ -1657,7 +1658,8 @@  thread_db_target::pid_to_str (ptid_t ptid)
 {
   thread_info *thread_info = current_inferior ()->find_thread (ptid);
 
-  if (thread_info != NULL && thread_info->priv != NULL)
+  if (thread_info != NULL && thread_info->priv != NULL
+      && !forks_exist_p (current_inferior ()))
     {
       thread_db_thread_info *priv = get_thread_db_thread_info (thread_info);
 
diff --git a/gdb/testsuite/gdb.multi/checkpoint-multi.exp b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
index a880d31d326..755c8e9e0e1 100644
--- a/gdb/testsuite/gdb.multi/checkpoint-multi.exp
+++ b/gdb/testsuite/gdb.multi/checkpoint-multi.exp
@@ -170,7 +170,7 @@  with_test_prefix "check continue to exit on non-checkpointed inferior" {
     gdb_test "continue" "Inferior 1.*? exited normally.*"
 }
 
-set proc_re "(?:process $::decimal|Thread $::hex \\(LWP $::decimal\\))"
+set proc_re "(?:process $::decimal)"
 set main_proc "\\(main process\\)"
 set hello_c "hello\\.c"
 set goodbye_c "goodbye\\.c"