From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OWa9OrA8g2p8RC0AWB0awg (envelope-from ) for ; Mon, 17 Aug 2026 12:54:08 -0400 Received: by simark.ca (Postfix, from userid 112) id EC7421E033; Mon, 17 Aug 2026 12:54:08 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.3 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 163B71E033 for ; Mon, 17 Aug 2026 12:54:07 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4B154BAE7E4 for ; Mon, 17 Aug 2026 16:54:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4B154BAE7E4 Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 010A94BAE7D2 for ; Mon, 17 Aug 2026 16:53:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 010A94BAE7D2 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 010A94BAE7D2 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:4190:8020::34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786985612; cv=none; b=An+vCwgwLge9IgUL862zmtmp4hyRdmffZdVt1K5fcXkEsMVE6Cny8HV+6wp6oVzlcZ+ysl9PKtjNkkcGBlZ+tg4Yn7NuVbLNrvVexYrrykH49hAM1+8NVwGTlG6U29rcy2Kuhi3StUe3oTU64+DnRE2AQyTXjugCjLPytyj88c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1786985612; c=relaxed/simple; bh=UDexQyC6hb5wMmiBSe9ZLWS1m5J0EnspRvwgXftNTBw=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=GDUh/FmYRnYs29SxwTRCIWqxXGo0+VU58kdiBNIN9LSl0Fkfz2lrAhUmylZXYtqRMSC29nHMcq6OUoYcFNIE0/8S+Hu/vQSt2WKeyiFndO3dnDMwY39GsUjDqoLE5nWah3ik9nl+4QsfbexhXrJ5ETzFjNOqTAjueOFPd0z+Kxw= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 010A94BAE7D2 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 7BCC192009D; Mon, 17 Aug 2026 18:53:31 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 75B1592009B; Mon, 17 Aug 2026 17:53:31 +0100 (BST) Date: Mon, 17 Aug 2026 17:53:31 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH v2 03/12] MIPS/testsuite: Verify MIPS I CPU branch stepping In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT 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: , Reply-To: "Maciej W. Rozycki" Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Maciej W. Rozycki Verify that breakpoints are correctly placed via `mips32_next_pc' while single-stepping through MIPS I CPU branches. The idea behind these test cases is that if a branch is misinterpreted by the stepping code, then the breakpoint will be placed at the wrong place, usually at the branch destination rather than immediately beyond the delay slot or vice versa. In the former case a step will be missed over the extra NOP placed beyond the delay slot and therefore from the count and in the latter case the single-stepping breakpoint will be missed altogether, letting code run through to the end of the intended stepping range. In either case the stepping counter will not reach 0 at conclusion, causing the test case to fail. It is perhaps worth noting that any missed steps from individual branch interpretation failures recorded in the counter cannot be made up for by other branch interpretation failures, because the structure of the code does not make it possible for additional steps to be made in the case of a single-stepping breakpoint misplacement save for the breakpoint having been placed at the branch or its delay slot being stepped over, in which case however stepping will loop over the branch and eventually fail once the counter has reached zero prematurely, having not reached the end of the intended stepping range. The target feature tests for these test cases have been written somewhat overly cautiously, for example BLTZL is never a macro, so `.set nomacro' doesn't really guard against anything. This is however harmless while making the feature tests more uniform. Co-Authored-By: Andrew Bennett Co-Authored-By: Matthew Fortune Co-Authored-By: Faraz Shahbazker Co-Authored-By: Milica Matic Co-Authored-By: Jovan Dmitrović Approved-By: Maciej W. Rozycki --- Changes from v1 (3/7), : - Robustify `stepi' for better performance in the case of test failures: * Handle timeouts and EOF. * Handle unexpected output in response to assignment to `err'. * Bail out right away when `err' has reached zero and no breakpoint hit. - Remove unused `any' variable from `test_mips1_bal'. - Remove unnecessary "$31" clobber from `test_mips1_branch'. - Clarify in the change description that individual branch interpretation failures cannot make up for each other. --- gdb/testsuite/gdb.arch/mips-allow.exp.tcl | 61 ++++++++++++++++ gdb/testsuite/gdb.arch/mips-stepi.exp.tcl | 108 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-bal.c | 68 ++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-bal.exp | 30 ++++++++ gdb/testsuite/gdb.arch/mips1-branch.c | 79 +++++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-branch.exp | 30 ++++++++ 6 files changed, 376 insertions(+) gdb-mips1-next-pc-test.diff Index: binutils-gdb/gdb/testsuite/gdb.arch/mips-allow.exp.tcl =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips-allow.exp.tcl @@ -0,0 +1,61 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Feature availability check helpers for MIPS tests. + +# Check for MIPS I branch support. These instructions may be absent, +# such as with MIPS16 compilations. Make sure an actual BLTZ machine +# instruction is produced and no macro expanded. +proc allow_mips1_branch_tests {} { + return [allow_target_tests "allow_mips1_branch_tests" \ + "MIPS I branch support" "Illegal instruction" \ + { + int main() { + asm volatile ( + ".set push\n\t" + ".set noreorder\n\t" + ".set nomacro\n\t" + "bltz $0, 0f\n\t" + " nop\n" + "0:\n\t" + ".set pop\n"); + return 0; + } + } \ + {-Wa,-fatal-warnings -mno-mips16 -minterlink-compressed}] +} + +# Check for MIPS I branch-and-link support. These instructions may be +# absent, such as with MIPSr6, or MIPS16 compilations. Make sure an +# actual BLTZAL machine instruction is produced and no macro expanded. +proc allow_mips1_bal_tests {} { + return [allow_target_tests "allow_mips1_bal_tests" \ + "MIPS I branch-and-link support" "Illegal instruction" \ + { + int main() { + asm volatile ( + ".set push\n\t" + ".set noreorder\n\t" + ".set nomacro\n\t" + "bltzal $4, 0f\n\t" + " nop\n" + "0:\n\t" + ".set pop\n" + : : : "$31"); + return 0; + } + } \ + {-Wa,-fatal-warnings -mno-mips16 -minterlink-compressed}] +} Index: binutils-gdb/gdb/testsuite/gdb.arch/mips-stepi.exp.tcl =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips-stepi.exp.tcl @@ -0,0 +1,108 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Template for MIPS single-stepping tests. + +# Send `stepi' to gdb until inferior hits a breakpoint, starting with +# ERR (which is a program variable) set to STEPS and decrementing it +# with each step. Use MESSAGE for the test result. +proc stepi { steps message } { + global gdb_prompt + global positive + + set timeout [get_largest_timeout] + set start [timestamp] + + gdb_test_no_output -nopass "set err = $steps" + while { [timestamp] - $start < $steps * $timeout } { + gdb_test_multiple "stepi" "" { + -re ".*Breakpoint.*$gdb_prompt" { + send_gdb "set err -= 1\n" + gdb_expect { + -re "$gdb_prompt" { + } + eof { + fail "$message (eof)" + return 0 + } + timeout { + fail "$message (timeout)" + return 0 + } + } + pass $message + return 1 + } + -re ".*$gdb_prompt" { + send_gdb "print err -= 1\n" + gdb_expect { + -re "\\$$positive = $positive\r\n$gdb_prompt" { + } + -re "\\$$positive = 0\r\n$gdb_prompt" { + fail "$message (number of steps exceeded)" + return 0 + } + -re "$gdb_prompt" { + fail "$message (unexpected output)" + return 0 + } + eof { + fail "$message (eof)" + return 0 + } + timeout { + fail "$message (timeout)" + return 0 + } + } + } + default { + return 0 + } + } + } + fail "$message (stepping duration exceeded)" + return 0 +} + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + [lappend compile_flags debug]] } { + return +} + +if { ![runto_main] } { + return +} + +# Put breakpoints at the boundaries of the stepping range. +foreach place [list step_start step_stop] { + if {![gdb_breakpoint "$place"]} { + unresolved "couldn't put breakpoint at $place" + return + } +} + +# Advance to the beginning of the range. +gdb_test "continue" ".*Breakpoint.*" "continue to step_start" + +# Make it easier to match results against expectations in the case of failures. +gdb_test "info registers" ".*" +gdb_test "display /i \$pc" ".*" + +# Step through to the end of the range. +stepi $steps "step through to step_stop" + +# And run to completion to retrieve the result. +gdb_test "continue" ".*exited normally.*" "continue to completion" Index: binutils-gdb/gdb/testsuite/gdb.arch/mips1-bal.c =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips1-bal.c @@ -0,0 +1,68 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright (C) 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be usefu, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Test single-stepping through MIPS I branch-and-link instructions. */ + +int +test_mips1_bal (void) +{ + /* Make 'err' available to the debugger to track the number of single + steps executed. Use `volatile' to prevent the variable from being + optimized away. */ + volatile int err = -1; + + int mone = -1; + int zero = 0; + int one = 1; + + asm volatile ( + ".macro b_test op, args:vararg\n\t" + "\\op \\args, 0f\n\t" + " nop\n\t" + "nop\n" + "0:\n\t" + ".endm\n\t" + + ".set push\n\t" + ".set noreorder\n\t" + ".globl step_start\n\t" + ".type step_start, @function\n" + "step_start:\n\t" /* Units: steps. */ + "nop\n\t" /* NOP: 1s */ + "b_test bltzal, %[mone]\n\t" /* Taken: 1s */ + "b_test bltzal, %[zero]\n\t" /* Not taken: 2s */ + "b_test bltzal, %[one]\n\t" /* Not taken: 2s */ + "b_test bgezal, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgezal, %[zero]\n\t" /* Taken: 1s */ + "b_test bgezal, %[one]\n\t" /* Taken: 1s */ + "nop\n\t" /* NOP: 1s */ + ".globl step_stop\n\t" /* Total: 11s */ + ".type step_stop, @function\n" + "step_stop:\n\t" + ".set pop\n" + : + : [mone] "r" (mone), [zero] "r" (zero), [one] "r" (one) + : "$31"); + + return err; +} + +int +main (void) +{ + return test_mips1_bal (); +} Index: binutils-gdb/gdb/testsuite/gdb.arch/mips1-bal.exp =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips1-bal.exp @@ -0,0 +1,30 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test single-stepping through MIPS I branch-and-link instructions. + +require {istarget "mips*-*-*"} + +source $srcdir/$subdir/mips-allow.exp.tcl + +require allow_mips1_bal_tests + +standard_testfile + +set steps 11 +foreach flag {-mno-mips16 -minterlink-compressed} { + lappend compile_flags "additional_flags=$flag" +} +source $srcdir/$subdir/mips-stepi.exp.tcl Index: binutils-gdb/gdb/testsuite/gdb.arch/mips1-branch.c =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips1-branch.c @@ -0,0 +1,79 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright (C) 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be usefu, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Test single-stepping through MIPS I branch instructions. */ + +int +test_mips1_branch (void) +{ + /* Make 'err' available to the debugger to track the number of single + steps executed. Use `volatile' to prevent the variable from being + optimized away. */ + volatile int err = -1; + + int any = 0x55aa; + int mone = -1; + int zero = 0; + int one = 1; + + asm volatile ( + ".macro b_test op, args:vararg\n\t" + "\\op \\args, 0f\n\t" + " nop\n\t" + "nop\n" + "0:\n\t" + ".endm\n\t" + + ".set push\n\t" + ".set noreorder\n\t" + ".globl step_start\n\t" + ".type step_start, @function\n" + "step_start:\n\t" /* Units: steps. */ + "nop\n\t" /* NOP: 1s */ + "b_test beq, %[any], %[any]\n\t" /* Taken: 1s */ + "b_test beq, %[any], %[one]\n\t" /* Not taken: 2s */ + "b_test bne, %[any], %[any]\n\t" /* Not taken: 2s */ + "b_test bne, %[any], %[one]\n\t" /* Taken: 1s */ + "b_test bltz, %[mone]\n\t" /* Taken: 1s */ + "b_test bltz, %[zero]\n\t" /* Not taken: 2s */ + "b_test bltz, %[one]\n\t" /* Not taken: 2s */ + "b_test blez, %[mone]\n\t" /* Taken: 1s */ + "b_test blez, %[zero]\n\t" /* Taken: 1s */ + "b_test blez, %[one]\n\t" /* Not taken: 2s */ + "b_test bgez, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgez, %[zero]\n\t" /* Taken: 1s */ + "b_test bgez, %[one]\n\t" /* Taken: 1s */ + "b_test bgtz, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgtz, %[zero]\n\t" /* Not taken: 2s */ + "b_test bgtz, %[one]\n\t" /* Taken: 1s */ + "nop\n\t" /* NOP: 1s */ + ".globl step_stop\n\t" /* Total: 26s */ + ".type step_stop, @function\n" + "step_stop:\n\t" + ".set pop\n" + : + : [mone] "r" (mone), [zero] "r" (zero), [one] "r" (one), + [any] "r" (any)); + + return err; +} + +int +main (void) +{ + return test_mips1_branch (); +} Index: binutils-gdb/gdb/testsuite/gdb.arch/mips1-branch.exp =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips1-branch.exp @@ -0,0 +1,30 @@ +# Copyright (C) 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test single-stepping through MIPS I branch instructions. + +require {istarget "mips*-*-*"} + +source $srcdir/$subdir/mips-allow.exp.tcl + +require allow_mips1_branch_tests + +standard_testfile + +set steps 26 +foreach flag {-mno-mips16 -minterlink-compressed} { + lappend compile_flags "additional_flags=$flag" +} +source $srcdir/$subdir/mips-stepi.exp.tcl