Change py-thread-exited.exp to work with gdbserver
authorTom Tromey <tromey@adacore.com>
Mon, 31 Jul 2023 17:30:30 +0000 (11:30 -0600)
committerTom Tromey <tromey@adacore.com>
Thu, 10 Aug 2023 17:42:38 +0000 (11:42 -0600)
gdbserver does not notify gdb of new threads when they are created.
I'm not sure if this is documented anywhere, but it is mentioned on
this page:

https://sourceware.org/gdb/wiki/LocalRemoteFeatureParity

Search for "Finding new threads in the inferior".

This behavior is a bit unfortunate -- I would think that it would be
better to arrange for such notification if something on the gdb side
is interested.

Meanwhile, this patch fixes py-thread-exited.exp to work around this
problem.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30677

gdb/testsuite/gdb.python/py-thread-exited.c
gdb/testsuite/gdb.python/py-thread-exited.exp

index fd0342b..d62133b 100644 (file)
@@ -24,14 +24,14 @@ pthread_t thread3_id;
 
 void* do_thread (void* d)
 {
-  return NULL;
+  return NULL;                 /* In thread */
 }
 
 int main (void)
 {
   pthread_create (&thread2_id, NULL, do_thread, NULL);
-  pthread_join (thread2_id, NULL);
   pthread_create (&thread3_id, NULL, do_thread, NULL);
+  pthread_join (thread2_id, NULL);
   pthread_join (thread3_id, NULL);
-  return 12;
+  return 12;                   /* Done */
 }
index 9575859..9378161 100644 (file)
@@ -36,9 +36,17 @@ if ![runto_main] {
     return -1
 }
 
-gdb_breakpoint 37 "last of main"
 
-gdb_continue_to_breakpoint "continue to breakpoint"
+gdb_breakpoint [gdb_get_line_number "In thread" ${testfile}.c]
+gdb_breakpoint [gdb_get_line_number "Done" ${testfile}.c]
+
+# gdbserver does not notify new threads on creation.  In order for
+# this test to even see that the threads are created, we have to
+# arrange to stop when they are running.
+gdb_continue_to_breakpoint "continue to first in-thread breakpoint"
+gdb_continue_to_breakpoint "continue to second in-thread breakpoint"
+
+gdb_continue_to_breakpoint "continue to end breakpoint"
 
 gdb_test "python print(threadOneExit)" \
         ".*event type: thread-exited. global num: 2.*"