public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] Clear board_info entry after waiting for process
@ 2024-03-18 13:01 Tom Tromey
  0 siblings, 0 replies; only message in thread
From: Tom Tromey @ 2024-03-18 13:01 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2518ce94704e54597bec273cafb090693b2de098

commit 2518ce94704e54597bec273cafb090693b2de098
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Mar 14 11:35:25 2024 -0600

    Clear board_info entry after waiting for process
    
    When certain DAP tests are run in a certain order, dejagnu will throw
    an exception during shutdown.  After adding many logging statements, I
    tracked this down to kill_wait_spawned_process not clearing the
    'fileid' board_info entry, causing dejagnu to try to wait for the
    process a second time -- and fail.
    
    Tom de Vries then pointed out a second instance of this, which I
    tracked down to the same problem occurring when spawning gdbserver.
    
    This version of the patch fixes this by adding a new proc that can be
    used to clean up board_info after waiting for a process to exit.  I'm
    not sure why this problem hasn't affected the test suite in the past.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31435
    Approved-By: Andrew Burgess <aburgess@redhat.com>

Diff:
---
 gdb/testsuite/lib/gdb.exp               | 15 +++++++++++++++
 gdb/testsuite/lib/gdbserver-support.exp |  1 +
 2 files changed, 16 insertions(+)

diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index fe4ac7d2719..4d27b60ef49 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -3310,6 +3310,20 @@ proc with_spawn_id { spawn_id body } {
     }
 }
 
+# DejaGNU records spawn ids in a global array and tries to wait for
+# them when exiting.  Sometimes this caused problems if gdb's test
+# suite has already waited for the particular spawn id.  And, dejagnu
+# only seems to allow a single spawn id per "machine".  This proc can
+# be used to clean up after a spawn id has been closed.
+proc clean_up_spawn_id {host id} {
+    global board_info
+    set name [board_info $host name]
+    if {[info exists board_info($name,fileid)]
+	&& $board_info($name,fileid) == $id} {
+	unset -nocomplain board_info($name,fileid)
+    }
+}
+
 # Select the largest timeout from all the timeouts:
 # - the local "timeout" variable of the scope two levels above,
 # - the global "timeout" variable,
@@ -6194,6 +6208,7 @@ proc kill_wait_spawned_process { proc_spawn_id } {
     # wait for the PID in the background.  That's fine because we
     # don't care about the exit status.  */
     wait -nowait -i $proc_spawn_id
+    clean_up_spawn_id target $proc_spawn_id
 }
 
 # Returns the process id corresponding to the given spawn id.
diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp
index 8bcf4fbbb01..e8ab057647d 100644
--- a/gdb/testsuite/lib/gdbserver-support.exp
+++ b/gdb/testsuite/lib/gdbserver-support.exp
@@ -433,6 +433,7 @@ proc close_gdbserver {} {
     # -nowait makes expect tell Tcl to wait for the process in the
     # background.
     catch "wait -nowait -i $server_spawn_id"
+    clean_up_spawn_id target $server_spawn_id
     unset server_spawn_id
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-18 13:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-18 13:01 [binutils-gdb] Clear board_info entry after waiting for process Tom Tromey

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).