[PATCH 5/7] MIPS/testsuite: Verify MIPS II CPU branch stepping
"Maciej W. Rozycki" <[email protected]> Thu, 23 Jul 2026 19:53:06 +0100 (BST)
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
From: Maciej W. Rozycki <[email protected]> Verify that breakpoints are correctly placed via `mips32_next_pc' while single-stepping through MIPS II CPU branches. Approved-by: Maciej W. Rozycki <[email protected]> --- gdb/testsuite/gdb.arch/mips-allow.exp.tcl | 25 ++++++++ gdb/testsuite/gdb.arch/mips2-branch.c | 86 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips2-branch.exp | 30 ++++++++++ 3 files changed, 141 insertions(+) gdb-mips2-next-pc-test.diff Index: binutils-gdb/gdb/testsuite/gdb.arch/mips-allow.exp.tcl =================================================================== --- binutils-gdb.orig/gdb/testsuite/gdb.arch/mips-allow.exp.tcl +++ binutils-gdb/gdb/testsuite/gdb.arch/mips-allow.exp.tcl @@ -59,3 +59,28 @@ proc allow_mips1_bal_tests {} { } \ {-Wa,-fatal-warnings -mno-mips16 -minterlink-compressed}] } + +# Check for MIPS II branch-likely support. These instructions may be +# absent, such as with MIPS I, MIPSr6, or MIPS16 compilations, or only +# supported as assembler macros, such as with microMIPS compilations. +# Make sure an actual BEQL machine instruction is produced and no macro +# expanded. +proc allow_mips2_branch_tests {} { + return [allow_target_tests "allow_mips2_branch_tests" \ + "MIPS II branch support" "Illegal instruction" \ + { + int main() { + asm volatile ( + ".set push\n\t" + ".set noreorder\n\t" + ".set nomacro\n\t" + "beql $0, $0, 0f\n\t" + " nop\n" + "0:\n\t" + ".set pop\n"); + return 0; + } + } \ + {-Wa,-fatal-warnings -mno-mips16 -mno-micromips + -minterlink-compressed}] +} Index: binutils-gdb/gdb/testsuite/gdb.arch/mips2-branch.c =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips2-branch.c @@ -0,0 +1,86 @@ +/* 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 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 <http://www.gnu.org/licenses/>. */ + +/* Test single-stepping through MIPS II branch instructions. */ + +int +test_mips2_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 beql, %[any], %[any]\n\t" /* Taken: 1s */ + "b_test beql, %[any], %[one]\n\t" /* Not taken: 2s */ + "b_test bnel, %[any], %[any]\n\t" /* Not taken: 2s */ + "b_test bnel, %[any], %[one]\n\t" /* Taken: 1s */ + "b_test bltzl, %[mone]\n\t" /* Taken: 1s */ + "b_test bltzl, %[zero]\n\t" /* Not taken: 2s */ + "b_test bltzl, %[one]\n\t" /* Not taken: 2s */ + "b_test blezl, %[mone]\n\t" /* Taken: 1s */ + "b_test blezl, %[zero]\n\t" /* Taken: 1s */ + "b_test blezl, %[one]\n\t" /* Not taken: 2s */ + "b_test bgezl, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgezl, %[zero]\n\t" /* Taken: 1s */ + "b_test bgezl, %[one]\n\t" /* Taken: 1s */ + "b_test bgtzl, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgtzl, %[zero]\n\t" /* Not taken: 2s */ + "b_test bgtzl, %[one]\n\t" /* Taken: 1s */ + "b_test bltzall, %[mone]\n\t" /* Taken: 1s */ + "b_test bltzall, %[zero]\n\t" /* Not taken: 2s */ + "b_test bltzall, %[one]\n\t" /* Not taken: 2s */ + "b_test bgezall, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgezall, %[zero]\n\t" /* Taken: 1s */ + "b_test bgezall, %[one]\n\t" /* Taken: 1s */ + "nop\n\t" /* NOP: 1s */ + ".globl step_stop\n\t" /* Total: 35s */ + ".type step_stop, @function\n" + "step_stop:\n\t" + ".set pop\n" + : + : [mone] "r" (mone), [zero] "r" (zero), [one] "r" (one), + [any] "r" (any) + : "$31"); + + return err; +} + +int +main (void) +{ + return test_mips2_branch (); +} Index: binutils-gdb/gdb/testsuite/gdb.arch/mips2-branch.exp =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/mips2-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 <http://www.gnu.org/licenses/>. + +# Test single-stepping through MIPS II branch instructions. + +require {istarget "mips*-*-*"} + +source $srcdir/$subdir/mips-allow.exp.tcl + +require allow_mips2_branch_tests + +standard_testfile + +set steps 35 +foreach flag {-mno-mips16 -mno-micromips -minterlink-compressed} { + lappend compile_flags "additional_flags=$flag" +} +source $srcdir/$subdir/mips-stepi.exp.tcl