Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args
@ 2026-04-22 22:21 Maciej W. Rozycki
  2026-04-24  2:08 ` Kevin Buettner
  0 siblings, 1 reply; 3+ messages in thread
From: Maciej W. Rozycki @ 2026-04-22 22:21 UTC (permalink / raw)
  To: gdb-patches

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args
  2026-04-22 22:21 [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args Maciej W. Rozycki
@ 2026-04-24  2:08 ` Kevin Buettner
  2026-04-28 22:01   ` Maciej W. Rozycki
  0 siblings, 1 reply; 3+ messages in thread
From: Kevin Buettner @ 2026-04-24  2:08 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: gdb-patches

On Wed, 22 Apr 2026 23:21:05 +0100 (BST)
"Maciej W. Rozycki" <macro@orcam.me.uk> wrote:

> 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)
> User-Agent: Alpine 2.21 (DEB 202 2017-01-01)
> 
> 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)"
> 

LGTM.  Thanks for this fix.

Approved-by: Kevin Buettner <kevinb@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args
  2026-04-24  2:08 ` Kevin Buettner
@ 2026-04-28 22:01   ` Maciej W. Rozycki
  0 siblings, 0 replies; 3+ messages in thread
From: Maciej W. Rozycki @ 2026-04-28 22:01 UTC (permalink / raw)
  To: Kevin Buettner; +Cc: gdb-patches

On Thu, 23 Apr 2026, Kevin Buettner wrote:

> > 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:
[...]
> 
> LGTM.  Thanks for this fix.

 I have applied this change now, thank you for your review.

  Maciej

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-28 22:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-22 22:21 [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args Maciej W. Rozycki
2026-04-24  2:08 ` Kevin Buettner
2026-04-28 22:01   ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox