From: "Maciej W. Rozycki" <macro@orcam.me.uk>
To: gdb-patches@sourceware.org
Subject: [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args
Date: Wed, 22 Apr 2026 23:21:05 +0100 (BST) [thread overview]
Message-ID: <alpine.DEB.2.21.2604222229050.44694@angie.orcam.me.uk> (raw)
Prevent gdb.threads/schedlock.exp from crashing due to a premature exit
of the debuggee causing an attempt to use a nil value as an arithmetic
operand:
[...]
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: next to increment, 9
bt
The current thread has terminated
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: find current thread, after
FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: next does not change thread (switched to thread )
print args
Cannot access memory at address 0x410ab0
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: listed args, after
ERROR: tcl error sourcing .../gdb/testsuite/gdb.threads/schedlock.exp.
ERROR: can't use empty string as operand of "-"
while executing
"if {$cmd == "continue"
|| [lindex $before_args $i] == [lindex $after_args $i] - 10} {
pass "$test"
} else {
fail "$test (wrong amo..."
(procedure "check_result" line 31)
invoked from within
"check_result $cmd $curthread $before_args $locked"
(procedure "test_step" line 26)
invoked from within
"test_step $schedlock "next" $call_function"
("uplevel" body line 2)
invoked from within
"uplevel 1 $body"
invoked from within
"with_test_prefix "call_function=$call_function" {
test_step $schedlock "next" $call_function
}"
("foreach" body line 2)
invoked from within
"foreach call_function {0 1} {
with_test_prefix "call_function=$call_function" {
test_step $schedlock "next" $call_function
}
}"
("uplevel" body line 6)
invoked from within
"uplevel 1 $body"
invoked from within
"with_test_prefix "cmd=next" {
# In GDB <= 7.9, with schedlock "step", "next" would
# unlock threads when stepping over a function call. Thi..."
("uplevel" body line 5)
invoked from within
"uplevel 1 $body"
invoked from within
"with_test_prefix "schedlock=$schedlock" {
with_test_prefix "cmd=step" {
test_step $schedlock "step" 0
}
with_test_prefix "cmd=next" {
# I..."
("foreach" body line 2)
invoked from within
"foreach schedlock {"off" "step" "on"} {
with_test_prefix "schedlock=$schedlock" {
with_test_prefix "cmd=step" {
test_step $schedlock "step" ..."
(file ".../gdb/testsuite/gdb.threads/schedlock.exp" line 297)
invoked from within
"source .../gdb/testsuite/gdb.threads/schedlock.exp"
("uplevel" body line 1)
invoked from within
"uplevel #0 source .../gdb/testsuite/gdb.threads/schedlock.exp"
invoked from within
"catch "uplevel #0 source $test_file_name""
Remote debugging from host xx.xx.xx.xx, port 56596
monitor exit
(gdb) Killing process(es): 22658
testcase .../gdb/testsuite/gdb.threads/schedlock.exp completed in 32 seconds
Here `print args' has failed to produce output matching the pattern
expected by `get_args' and consequently an empty value has been assigned
to $after_args. Subsequently a calculation is attempted on an element
of said value treated as a list: `[lindex $after_args $i] - 10' and that
has caused the crash because the resulting minuend is nil.
There are various expressions $after_args and other variables set from
the result of `get_args' are used in, however the majority are equality
operations, which succeed producing a result even where a nil operand is
involved. Given that this is a test failure scenario anyway follow the
path of least resistance, ignore the other expressions and just prevent
the crash from triggering here by checking for an attempt to retrieve an
inexistent element of $after_args for this calculation, and report it as
a test failure outright letting the script proceed:
[...]
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: next to increment, 9
bt
The current thread has terminated
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: find current thread, after
FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: next does not change thread (switched to thread )
print args
Cannot access memory at address 0x410ab0
(gdb) FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: listed args, after
FAIL: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: current thread advanced - unlocked (no arg #1)
PASS: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=0: other threads ran - unlocked
set scheduler-locking off
(gdb) PASS: gdb.threads/schedlock.exp: schedlock=off: cmd=next: call_function=1: set scheduler-locking off
[...]
---
gdb/testsuite/gdb.threads/schedlock.exp | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
gdb-test-schedlock-no-args.diff
Index: binutils-gdb/gdb/testsuite/gdb.threads/schedlock.exp
===================================================================
--- binutils-gdb.orig/gdb/testsuite/gdb.threads/schedlock.exp
+++ binutils-gdb/gdb/testsuite/gdb.threads/schedlock.exp
@@ -232,8 +232,12 @@ proc check_result { cmd before_thread be
}
} else {
if {$i == $before_thread} {
- if {$cmd == "continue"
- || [lindex $before_args $i] == [lindex $after_args $i] - 10} {
+ if {$cmd == "continue"} {
+ pass "$test"
+ } elseif {[llength $after_args] <= $i} {
+ fail "$test (no arg #$i)"
+ } elseif {[lindex $before_args $i] \
+ == [lindex $after_args $i] - 10} {
pass "$test"
} else {
fail "$test (wrong amount)"
next reply other threads:[~2026-04-22 22:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 22:21 Maciej W. Rozycki [this message]
2026-04-24 2:08 ` Kevin Buettner
2026-04-28 22:01 ` Maciej W. Rozycki
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=alpine.DEB.2.21.2604222229050.44694@angie.orcam.me.uk \
--to=macro@orcam.me.uk \
--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