* [pushed 1/3] [gdb/testsuite] Rename variable in test-case gdb.base/attach-twice.exp
2026-11-23 13:03 [pushed 0/3] [gdb/testsuite] Modernize two test-cases Tom de Vries
@ 2026-11-23 13:03 ` Tom de Vries
2026-11-23 13:03 ` [pushed 2/3] [gdb/testsuite] Modernize gdb.base/attach-twice.exp Tom de Vries
2026-11-23 13:03 ` [pushed 3/3] [gdb/testsuite] Modernize gdb.base/attach-non-pgrp-leader.exp Tom de Vries
2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-11-23 13:03 UTC (permalink / raw)
To: gdb-patches
Test-case gdb.base/attach-twice.exp uses an inferior calling fork, resulting
in a parent and child process.
For cleanup, it:
- kills the parent process using kill_wait_spawned_process
- opportunistically kills the child process, if gdb printed it in reaction to
attach
However, the child process is tracked in a variable called parentpid.
Rename the parentpid variable to the more appropriate child_pid.
---
gdb/testsuite/gdb.base/attach-twice.exp | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/gdb/testsuite/gdb.base/attach-twice.exp b/gdb/testsuite/gdb.base/attach-twice.exp
index a3677f2fad9..e2db55187d2 100644
--- a/gdb/testsuite/gdb.base/attach-twice.exp
+++ b/gdb/testsuite/gdb.base/attach-twice.exp
@@ -28,12 +28,12 @@ if { [prepare_for_testing "failed to prepare" $executable] } {
set test_spawn_id [spawn_wait_for_attach $binfile]
set testpid [spawn_id_get_pid $test_spawn_id]
-set parentpid 0
+set child_pid 0
set test "attach"
gdb_test_multiple "attach $testpid" $test {
-re "Attaching to program: \[^\r\n\]*, process $testpid\r\n.*warning: process $testpid is already traced by process (${::decimal})\r\n.*ptrace: Operation not permitted\\.\r\n$gdb_prompt $" {
- set parentpid $expect_out(1,string)
+ set child_pid $expect_out(1,string)
pass $test
}
-re "Attaching to program: \[^\r\n\]*, process $testpid\r\n.*ptrace: Operation not permitted\\.\r\n$gdb_prompt $" {
@@ -44,7 +44,7 @@ gdb_test_multiple "attach $testpid" $test {
}
}
-if {$parentpid != 0} {
- exec kill -9 $parentpid
+if {$child_pid != 0} {
+ exec kill -9 $child_pid
}
kill_wait_spawned_process $test_spawn_id
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [pushed 2/3] [gdb/testsuite] Modernize gdb.base/attach-twice.exp
2026-11-23 13:03 [pushed 0/3] [gdb/testsuite] Modernize two test-cases Tom de Vries
2026-11-23 13:03 ` [pushed 1/3] [gdb/testsuite] Rename variable in test-case gdb.base/attach-twice.exp Tom de Vries
@ 2026-11-23 13:03 ` Tom de Vries
2026-11-23 13:03 ` [pushed 3/3] [gdb/testsuite] Modernize gdb.base/attach-non-pgrp-leader.exp Tom de Vries
2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-11-23 13:03 UTC (permalink / raw)
To: gdb-patches
Modernize gdb.base/attach-twice.exp:
- use multi_line, -wrap, $gdb_test_name and subst_vars
- drop the superfluous variable executable
---
gdb/testsuite/gdb.base/attach-twice.exp | 27 ++++++++++++++++---------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/gdb/testsuite/gdb.base/attach-twice.exp b/gdb/testsuite/gdb.base/attach-twice.exp
index e2db55187d2..8daca83380c 100644
--- a/gdb/testsuite/gdb.base/attach-twice.exp
+++ b/gdb/testsuite/gdb.base/attach-twice.exp
@@ -16,9 +16,8 @@
require can_spawn_for_attach
standard_testfile
-set executable ${testfile}
-if { [prepare_for_testing "failed to prepare" $executable] } {
+if { [prepare_for_testing "failed to prepare" $testfile] } {
return
}
@@ -30,17 +29,25 @@ set testpid [spawn_id_get_pid $test_spawn_id]
set child_pid 0
-set test "attach"
-gdb_test_multiple "attach $testpid" $test {
- -re "Attaching to program: \[^\r\n\]*, process $testpid\r\n.*warning: process $testpid is already traced by process (${::decimal})\r\n.*ptrace: Operation not permitted\\.\r\n$gdb_prompt $" {
+set re_pass \
+ [multi_line \
+ [subst_vars {Attaching to program: [^\r\n]*, process $testpid}] \
+ ".*warning: process $testpid is already traced by process ($decimal)" \
+ {.*ptrace: Operation not permitted[.]}]
+set re_fail \
+ [multi_line \
+ [subst_vars {Attaching to program: [^\r\n]*, process $testpid}] \
+ {.*ptrace: Operation not permitted[.]}]
+gdb_test_multiple "attach $testpid" "attach" {
+ -re -wrap $re_pass {
set child_pid $expect_out(1,string)
- pass $test
+ pass $gdb_test_name
}
- -re "Attaching to program: \[^\r\n\]*, process $testpid\r\n.*ptrace: Operation not permitted\\.\r\n$gdb_prompt $" {
- fail $test
+ -re -wrap $re_fail {
+ fail $gdb_test_name
}
- -re "\r\n$gdb_prompt $" {
- xfail $test
+ -re -wrap "" {
+ xfail $gdb_test_name
}
}
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [pushed 3/3] [gdb/testsuite] Modernize gdb.base/attach-non-pgrp-leader.exp
2026-11-23 13:03 [pushed 0/3] [gdb/testsuite] Modernize two test-cases Tom de Vries
2026-11-23 13:03 ` [pushed 1/3] [gdb/testsuite] Rename variable in test-case gdb.base/attach-twice.exp Tom de Vries
2026-11-23 13:03 ` [pushed 2/3] [gdb/testsuite] Modernize gdb.base/attach-twice.exp Tom de Vries
@ 2026-11-23 13:03 ` Tom de Vries
2 siblings, 0 replies; 4+ messages in thread
From: Tom de Vries @ 2026-11-23 13:03 UTC (permalink / raw)
To: gdb-patches
Modernize test-case gdb.base/attach-non-pgrp-leader.exp:
- use multi_line and subst_vars
- use :: prefix instead of global
---
gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp b/gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp
index ded09db5d13..897679c37b9 100644
--- a/gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp
+++ b/gdb/testsuite/gdb.base/attach-non-pgrp-leader.exp
@@ -27,10 +27,7 @@ if { [build_executable ${testfile}.exp ${testfile} $srcfile {debug}] == -1 } {
}
proc do_test {} {
- global binfile
- global decimal
-
- set test_spawn_id [spawn_wait_for_attach $binfile]
+ set test_spawn_id [spawn_wait_for_attach $::binfile]
set parent_pid [spawn_id_get_pid $test_spawn_id]
# Attach to the parent, run it to a known point, extract the
@@ -51,7 +48,9 @@ proc do_test {} {
}
gdb_test "detach" \
- "Detaching from program: .*process $parent_pid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
+ [multi_line \
+ "Detaching from program: .*process $parent_pid" \
+ [subst_vars {\[Inferior $::decimal \(.*\) detached\]}]]
}
# Start over, and attach to the child this time.
@@ -66,7 +65,9 @@ proc do_test {} {
gdb_continue_to_breakpoint "marker"
gdb_test "detach" \
- "Detaching from program: .*process $child_pid\r\n\\\[Inferior $decimal \\(.*\\) detached\\\]"
+ [multi_line \
+ "Detaching from program: .*process $child_pid" \
+ [subst_vars {\[Inferior $::decimal \(.*\) detached\]}]]
}
kill_wait_spawned_process $test_spawn_id
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread