Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 10/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, no fork
Date: Mon, 25 May 2026 20:18:28 +0100	[thread overview]
Message-ID: <20260525191829.984105-11-pedro@palves.net> (raw)
In-Reply-To: <20260525191829.984105-1-pedro@palves.net>

The gdb.python/py-events.exp testcase currently uses fork, and relies
on "set detach-on-fork off".

Cygwin does support the fork syscall, but GDB can't follow forks
there, so "detach-on-fork off" has no effect.  And also, there is no
fork on native Windows, which makes the testcase unusable on MinGW
currently.

I don't see any reason the testcase needs to use fork or multiple
inferiors.  We can replace what those parts were testing by more
focused tests:

 - The clear_objfiles event was tested via following a fork.  Instead,
   test a more directed "file" command.

 - Two-inferior quit was being used to test that gdb.ExitedEvent has
   no "exit_code".  Quitting while an inferior is being debugged makes
   GDB kill the inferior.  What's really being tested is the kill
   path, so write an explicit (single-inferior) kill test.

Tested on x86_64-unknown-linux-gnu.

Change-Id: I21ee8af7b52653c6fdff9b4c1596cdde3cfe751a
commit-id: de2bf164
---
 gdb/testsuite/gdb.python/py-events.c   |  3 --
 gdb/testsuite/gdb.python/py-events.exp | 59 +++++++++++++-------------
 2 files changed, 30 insertions(+), 32 deletions(-)

diff --git a/gdb/testsuite/gdb.python/py-events.c b/gdb/testsuite/gdb.python/py-events.c
index b1910f75ed9..6a0b407042a 100644
--- a/gdb/testsuite/gdb.python/py-events.c
+++ b/gdb/testsuite/gdb.python/py-events.c
@@ -15,12 +15,9 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see  <http://www.gnu.org/licenses/>.  */
 
-#include <unistd.h>
-
 extern void do_nothing (void);
 
 int second(){
-  fork() ;
   return 12;
 }
 
diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp
index b07eb2ec9b0..a34a423c014 100644
--- a/gdb/testsuite/gdb.python/py-events.exp
+++ b/gdb/testsuite/gdb.python/py-events.exp
@@ -45,8 +45,6 @@ gdb_breakpoint "main" {temporary}
 
 gdb_test "run" ".*event type: new_objfile.*new objfile name.*" "new objfile notification"
 
-gdb_test_no_output "set detach-on-fork off" ""
-
 gdb_test "test-events" "Event testers registered."
 
 gdb_breakpoint "first"
@@ -217,24 +215,13 @@ proc get_process_id {test} {
     return ${process_id}
 }
 
-set process_id [get_process_id "get inferior 1 process id"]
+set process_id [get_process_id "get inferior process id"]
 gdb_test "continue" ".*event type: continue.*
-.*clear_objfiles\[\r\n\]*progspace: .*py-events.*
 .*event type: exit.*
 .*exit code: 12.*
 .*exit inf: 1.*
 .*exit pid: $process_id.*
-dir ok: True.*" "Inferior 1 terminated."
-
-gdb_test "inferior 2" ".*Switching to inferior 2.*"
-set process_id [get_process_id "get inferior 2 process id"]
-gdb_test "continue" ".*event type: continue.*
-.*event type: exit.*
-.*exit code: 12.*
-.*exit inf: 2.*
-.*exit pid: $process_id.*
-dir ok: True.*" "Inferior 2 terminated."
-
+dir ok: True.*" "inferior terminated"
 
 # Test before_prompt event.
 gdb_test_multiline "define new user command" \
@@ -286,29 +273,30 @@ with_test_prefix "inferior continue exit" {
     gdb_test "print \$_foo" "= 2" "check foo after start continue"
 }
 
-# Check that when GDB exits, we see gdb.ExitedEvent objects with no
-# 'exit_code' attribute, and that a gdb.GdbExitingEvent is emitted.
-with_test_prefix "gdb exiting: normal" {
+# Check that when GDB kills an inferior, we see gdb.ExitedEvent
+# objects with no 'exit_code' attribute.
+with_test_prefix "kill inferior" {
+    if {![runto_main]} {
+	return
+    }
     gdb_test "test-exiting-event normal" "GDB exiting event registered\\."
 
+    gdb_test "with confirm off -- kill" \
+	"event type: exit\r\nexit code: not-present\r\nexit inf: $decimal\r\nexit pid: $decimal\r\ndir ok: False\r\n.*" \
+	"exit code not present"
+}
+
+# Check that when GDB exits, we see that a gdb.GdbExitingEvent is
+# emitted.
+with_test_prefix "gdb exiting: normal" {
     set saw_exiting_event 0
-    set saw_inferior_exit 0
-    gdb_test_multiple "quit" "" {
-	-re "Quit anyway\\? \\(y or n\\) $" {
-	    send_gdb "y\n"
-	    exp_continue
-	}
+    gdb_test_multiple "with confirm off -- quit" "quit" {
 	-re "event type: gdb-exiting\r\nexit code: $decimal" {
 	    incr saw_exiting_event
 	    exp_continue
 	}
-	-re "event type: exit\r\nexit code: not-present\r\nexit inf: $decimal\r\nexit pid: $decimal\r\ndir ok: False\r\n" {
-	    incr saw_inferior_exit
-	    exp_continue
-	}
 	eof {
 	    gdb_assert { $saw_exiting_event == 1 }
-	    gdb_assert { $saw_inferior_exit == 2 }
 	    pass $gdb_test_name
 	}
     }
@@ -354,3 +342,16 @@ with_test_prefix "gdb exiting: error" {
 	}
     }
 }
+
+# Test clear_objfiles event.
+
+with_test_prefix "clear_objfiles" {
+    clean_restart ${testfile}
+
+    gdb_test_no_output "source ${pyfile}" "load python file"
+    gdb_test "test-objfile-events" "Object file events registered."
+
+    gdb_test "with confirm off -- file" \
+	"event type: clear_objfiles\r\nprogspace: None\r\n.*" \
+	"file cleared"
+}
-- 
2.53.0


  parent reply	other threads:[~2026-05-25 19:20 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25 19:18 [PATCH v2 00/11] Fix a few Cygwin/MinGW problems Pedro Alves
2026-05-25 19:18 ` [PATCH v2 01/11] Adjust gdb.base/exitsignal.exp for MinGW, trigger fault Pedro Alves
2026-05-25 19:18 ` [PATCH v2 02/11] Adjust gdb.base/exitsignal.exp for MinGW, second-chance SIGSEGV Pedro Alves
2026-05-26 11:18   ` Eli Zaretskii
2026-05-27 12:56     ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 03/11] Adjust gdb.base/exitsignal.exp for MinGW, separate program names Pedro Alves
2026-05-27 21:59   ` Thiago Jung Bauermann
2026-06-12 14:00     ` Pedro Alves
2026-05-25 19:18 ` [PATCH v2 04/11] gdb.base/exitsignal.exp: Exit with non-zero Pedro Alves
2026-05-25 19:18 ` [PATCH v2 05/11] gdb.base/exitsignal.exp: Test attaching too Pedro Alves
2026-05-25 19:18 ` [PATCH v2 06/11] gdb/testsuite: Add mechanism to compile Windows native programs on Cygwin Pedro Alves
2026-05-25 19:18 ` [PATCH v2 07/11] Windows gdb+gdbserver: Share exit status logic Pedro Alves
2026-05-25 19:18 ` [PATCH v2 08/11] Windows gdb+gdbserver: Decode Cygwin ExitProcess codes Pedro Alves
2026-05-26 11:31   ` Eli Zaretskii
2026-05-27 13:58     ` Pedro Alves
2026-05-27 14:12       ` Eli Zaretskii
2026-05-27 22:00   ` Thiago Jung Bauermann
2026-05-25 19:18 ` [PATCH v2 09/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, thread IDs Pedro Alves
2026-05-25 19:18 ` Pedro Alves [this message]
2026-05-25 19:18 ` [PATCH v2 11/11] Adjust gdb.python/py-events.exp for Cygwin/MinGW, "info proc" => "inferior" Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260525191829.984105-11-pedro@palves.net \
    --to=pedro@palves.net \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox