From 5a734ada7e1c9f9d3ff2c610b9a146a60994b798 Mon Sep 17 00:00:00 2001 From: Keith Seitz Date: Mon, 28 Feb 2022 11:55:51 -0800 Subject: [PATCH] Fix "spawn id XYZ not open" errors in gdb.mi/mi-exec-run.exp Running mi-exec-run.exp on native-extended-gdbserver/-m{32,64} causes several Tcl errors to appear. For example, (gdb) ERROR: : spawn id exp20 not open while executing "expect { -i exp11 -timeout 10 -i "$inferior_spawn_id" -re ".*Cannot exec.*Permission denied" { set saw_perm_error 1 verbose -log "saw..." ("uplevel" body line 1) invoked from within "uplevel $body" NONE : spawn id exp20 not open UNRESOLVED: gdb.mi/mi-exec-run.exp: inferior-tty=separate: mi=separate: force-fail=1: run failure detected (eof) This is happening because of the way this test is implemented: while {1} { gdb_expect { -i "$inferior_spawn_id" -re ".*Cannot exec.*Permission denied" { set saw_perm_error 1 verbose -log "saw mi error" } -i "$gdb_spawn_id" -re "\\^error,msg=\"During startup program exited with code 127" { set saw_mi_error 1 verbose -log "saw mi error" } # and so on } } The first time this loop is executed, `inferior_spawn_id' is valid. When the first branch of the expect statement is reached, gdbserver has exited, closing the spawn_id. Since we haven't seen the gdb-side error yet, the loop is executed again. The first branch now refers to a non-existent spawn_id, leading to the error. This can be fixed by using exp_continue to loop in expect instead of looping around expect, which is the approach I have used[1]. Note I've had to update the expected message for the "During startup..." error message when running with gdbserver. One other small change I've made is to add a log entry which spills the values of the two variables, saw_mi_error and saw_perm_error (and updated the log output for the later). This should make the log output clearer about why the test failed. With this patch installed, all the ERRORs disappear, leaving previously masked FAILs (which I have not attempted to fix). [1] Anyone know why this test doesn't simply use gdb_test_multiple? I can only assume that it was intentionally written this way, and I've modified the code with that assumption. I have tested a version using gdb_test_multiple, and that appears to work fine, too, if that is preferred. [It still employs exp_continue to fix the spawn_id errors.] --- gdb/testsuite/gdb.mi/mi-exec-run.exp | 53 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/gdb/testsuite/gdb.mi/mi-exec-run.exp b/gdb/testsuite/gdb.mi/mi-exec-run.exp index eaf7dfa68bf..f397159078f 100644 --- a/gdb/testsuite/gdb.mi/mi-exec-run.exp +++ b/gdb/testsuite/gdb.mi/mi-exec-run.exp @@ -89,36 +89,43 @@ proc test {inftty_mode mi_mode force_fail} { if {$force_fail} { set saw_perm_error 0 set saw_mi_error 0 + set already_failed 0 set test "run failure detected" send_gdb "-exec-run --start\n" - while {1} { - gdb_expect { - -i "$inferior_spawn_id" - -re ".*Cannot exec.*Permission denied" { - set saw_perm_error 1 - verbose -log "saw mi error" + gdb_expect { + -i "$inferior_spawn_id" + -re ".*Cannot exec.*Permission denied" { + set saw_perm_error 1 + verbose -log "saw perm error" + if {!$saw_mi_error} { + exp_continue } - -i "$gdb_spawn_id" - -re "\\^error,msg=\"During startup program exited with code 127" { - set saw_mi_error 1 - verbose -log "saw mi error" - } - timeout { - fail "$test (timeout)" - break - } - -i "$gdb_main_spawn_id" - eof { - fail "$test (eof)" - break + } + -i "$gdb_spawn_id" + -re "\\^error,msg=\"(During startup program exited with code 127|Running .* on the remote target failed)" { + set saw_mi_error 1 + verbose -log "saw mi error" + if {!$saw_perm_error} { + exp_continue } } - - if {$saw_perm_error && $saw_mi_error} { - pass $test - break + timeout { + set already_failed 1 + fail "$test (timeout)" } + -i "$gdb_main_spawn_id" + eof { + set already_failed 1 + fail "$test (eof)" + } + } + + if {$saw_perm_error && $saw_mi_error} { + pass $test + } elseif {!$already_failed} { + verbose -log "saw_perm_error=$saw_perm_error; saw_mi_error=$saw_mi_error" + fail $test } } else { mi_run_cmd "--start" -- 2.30.2