From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 3S+uOO9J6WmWbTQAWB0awg (envelope-from ) for ; Wed, 22 Apr 2026 18:21:35 -0400 Received: by simark.ca (Postfix, from userid 112) id D32A51E0C3; Wed, 22 Apr 2026 18:21:35 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9E97C1E093 for ; Wed, 22 Apr 2026 18:21:34 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 62BD44B80D6A for ; Wed, 22 Apr 2026 22:21:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62BD44B80D6A Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id C26904BC22F3 for ; Wed, 22 Apr 2026 22:21:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C26904BC22F3 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=orcam.me.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=orcam.me.uk ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C26904BC22F3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776896467; cv=none; b=hr9096fzmIfmIrCxPs6Dfm6eptRSKnukGDurP7gPLPASZqtoOFZ6Wc+BaJ45jqMpVOCUSpjPwa6bNu1+QploUepYE5EpwMuqvDc0VvzIc3Go7zy0RDMz97XFq46zLR2sl6bEN7FaZrGPba3mm+GL4ZYoLn2X6ZcDy9QA2D9JC98= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776896467; c=relaxed/simple; bh=cDX5Jih6TFkGu+WE6388enGnA/riu5tZl2FTT29odP8=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=WblU1bQ3goomWeAL24GCh7EU9nhU3dfA04KShGJrXIi+sgDmFAVFyeQjgZGfyNj6iHZDTr7ozNYs5Uhp2G2W6shqlIBm+E8rznCi2+v3D8EeoRVNNMx+JnEOhrtUUUO2p3MPTBFCn464cCPqmmWLPy5883O+T+inzm3RH0OD+Vw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C26904BC22F3 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 6E9B092009D; Thu, 23 Apr 2026 00:21:05 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 6893892009C for ; Wed, 22 Apr 2026 23:21:05 +0100 (BST) Date: Wed, 22 Apr 2026 23:21:05 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org Subject: [PATCH] GDB/testsuite: Fix schedlock.exp crash due to empty $after_args Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org 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)"