public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Adjust gdb_continue_to_end for Windows
@ 2024-04-29 19:19 Pedro Alves
  2024-05-01 15:48 ` Andrew Burgess
  0 siblings, 1 reply; 2+ messages in thread
From: Pedro Alves @ 2024-04-29 19:19 UTC (permalink / raw)
  To: gdb-patches

On Cygwin, supposely single-threaded programs are always
multi-threaded, due to the extra threads spawned by the Cygwin
runtime.  Because of that, any gdb_continue_to_end call that doesn't
specify "allow_extra" fails, like so:

 (gdb) PASS: gdb.base/langs.exp: show language at main
 continue
 Continuing.
 [Thread 16140.0x1fbc exited with code 0]
 [Thread 16140.0x2458 exited with code 0]
 [Thread 16140.0x3494 exited with code 0]
 [Inferior 1 (process 16140) exited normally]
 (gdb) FAIL: gdb.base/langs.exp: continue until exit at first session (the program exited)

Similarly, with this simple program compiled with MinGW:

 $ cat ~/sleeper.c
 #include <windows.h>

 int main ()
 {
   Sleep (2000);
   return 0;
 }

and with a MinGW GDB, I see:

 (gdb) start
 ...
 (gdb) info threads
   Id   Target Id           Frame
 * 1    Thread 15292.0x3850 main () at /home/alves/sleeper.c:5
   2    Thread 15292.0x3048 0x00007ff9630d2fb7 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\Windows\SYSTEM32\ntdll.dll
 (gdb) c
 Continuing.
 [Thread 15292.0x3850 exited with code 0]
 [Inferior 1 (process 15292) exited normally]
 (gdb)

This commit adjusts gdb_continue_to_end to expect the thread exited
messages, on Cygwin and MinGW.

Change-Id: I5e410a7252c11cd9ecea632f1e00c2a7fcd69098
---
 gdb/testsuite/lib/gdb.exp | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index d092258a9e5..5c3baeb4537 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -7473,8 +7473,23 @@ proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
   } else {
       set text "continue until exit at $mssg"
   }
+
   if {$allow_extra} {
       set extra ".*"
+  } elseif {[istarget *-*-cygwin*] || [istarget *-*-mingw*]} {
+      # On Windows, even on supposedly single-threaded programs, we
+      # may see thread exit output when running to end, for threads
+      # spawned by the runtime.  E.g.:
+      #
+      #  (gdb) continue
+      #  Continuing.
+      #  [Thread 14364.0x21d4 exited with code 0]
+      #  [Thread 14364.0x4374 exited with code 0]
+      #  [Thread 14364.0x3aec exited with code 0]
+      #  [Thread 14364.0x3368 exited with code 0]
+      #  [Inferior 1 (process 14364) exited normally]
+      #
+      set extra "(\\\[Thread \[^\r\n\]+ exited with code $::decimal\\\]\r\n)*"
   } else {
       set extra ""
   }

base-commit: 43ca4ec2996a6bfbb8726f1c753aeb85fe0f92a4
-- 
2.43.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Adjust gdb_continue_to_end for Windows
  2024-04-29 19:19 [PATCH] Adjust gdb_continue_to_end for Windows Pedro Alves
@ 2024-05-01 15:48 ` Andrew Burgess
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Burgess @ 2024-05-01 15:48 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Pedro Alves <pedro@palves.net> writes:

> On Cygwin, supposely single-threaded programs are always
> multi-threaded, due to the extra threads spawned by the Cygwin
> runtime.  Because of that, any gdb_continue_to_end call that doesn't
> specify "allow_extra" fails, like so:
>
>  (gdb) PASS: gdb.base/langs.exp: show language at main
>  continue
>  Continuing.
>  [Thread 16140.0x1fbc exited with code 0]
>  [Thread 16140.0x2458 exited with code 0]
>  [Thread 16140.0x3494 exited with code 0]
>  [Inferior 1 (process 16140) exited normally]
>  (gdb) FAIL: gdb.base/langs.exp: continue until exit at first session (the program exited)
>
> Similarly, with this simple program compiled with MinGW:
>
>  $ cat ~/sleeper.c
>  #include <windows.h>
>
>  int main ()
>  {
>    Sleep (2000);
>    return 0;
>  }
>
> and with a MinGW GDB, I see:
>
>  (gdb) start
>  ...
>  (gdb) info threads
>    Id   Target Id           Frame
>  * 1    Thread 15292.0x3850 main () at /home/alves/sleeper.c:5
>    2    Thread 15292.0x3048 0x00007ff9630d2fb7 in ntdll!ZwWaitForWorkViaWorkerFactory () from C:\Windows\SYSTEM32\ntdll.dll
>  (gdb) c
>  Continuing.
>  [Thread 15292.0x3850 exited with code 0]
>  [Inferior 1 (process 15292) exited normally]
>  (gdb)
>
> This commit adjusts gdb_continue_to_end to expect the thread exited
> messages, on Cygwin and MinGW.

LGTM.

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Change-Id: I5e410a7252c11cd9ecea632f1e00c2a7fcd69098
> ---
>  gdb/testsuite/lib/gdb.exp | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index d092258a9e5..5c3baeb4537 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -7473,8 +7473,23 @@ proc gdb_continue_to_end {{mssg ""} {command continue} {allow_extra 0}} {
>    } else {
>        set text "continue until exit at $mssg"
>    }
> +
>    if {$allow_extra} {
>        set extra ".*"
> +  } elseif {[istarget *-*-cygwin*] || [istarget *-*-mingw*]} {
> +      # On Windows, even on supposedly single-threaded programs, we
> +      # may see thread exit output when running to end, for threads
> +      # spawned by the runtime.  E.g.:
> +      #
> +      #  (gdb) continue
> +      #  Continuing.
> +      #  [Thread 14364.0x21d4 exited with code 0]
> +      #  [Thread 14364.0x4374 exited with code 0]
> +      #  [Thread 14364.0x3aec exited with code 0]
> +      #  [Thread 14364.0x3368 exited with code 0]
> +      #  [Inferior 1 (process 14364) exited normally]
> +      #
> +      set extra "(\\\[Thread \[^\r\n\]+ exited with code $::decimal\\\]\r\n)*"
>    } else {
>        set extra ""
>    }
>
> base-commit: 43ca4ec2996a6bfbb8726f1c753aeb85fe0f92a4
> -- 
> 2.43.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-05-01 15:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 19:19 [PATCH] Adjust gdb_continue_to_end for Windows Pedro Alves
2024-05-01 15:48 ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).