[PATCH v2 08/12] MIPS/testsuite: Verify microMIPS branch stepping
"Maciej W. Rozycki" <[email protected]>
| Newsgroups | gmane.comp.gdb.patches |
|---|---|
| Message-ID | <[email protected]> |
From: Maciej W. Rozycki <[email protected]> Verify that breakpoints are correctly placed via `micromips_next_pc' while single-stepping through branches specific to the microMIPS ASE. Approved-By: Maciej W. Rozycki <[email protected]> --- New change in v2. --- gdb/testsuite/gdb.arch/micromips-branch.c | 78 ++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/micromips-branch.exp | 30 ++++++++++ gdb/testsuite/gdb.arch/mips-allow.exp.tcl | 29 ++++++++++ 3 files changed, 137 insertions(+) gdb-micromips-next-pc-test.diff Index: binutils-gdb/gdb/testsuite/gdb.arch/micromips-branch.c =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/micromips-branch.c @@ -0,0 +1,78 @@ +/* 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 <http://www.gnu.org/licenses/>. */ + +/* Test single-stepping through microMIPS branch instructions. */ + +int +test_micromips_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" + "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 beqz16 %[zero]\n\t" /* Taken: 1s */ + "b_test beqz16 %[any]\n\t" /* Not taken: 2s */ + "b_test beqzc %[zero]\n\t" /* Taken: 1s */ + "b_test beqzc %[any]\n\t" /* Not taken: 3s */ + "b_test bnez16 %[zero]\n\t" /* Not taken: 2s */ + "b_test bnez16 %[any]\n\t" /* Taken: 1s */ + "b_test bnezc %[zero]\n\t" /* Not taken: 3s */ + "b_test bnezc %[any]\n\t" /* Taken: 1s */ + "b_test bltzals, %[mone]\n\t" /* Taken: 1s */ + "b_test bltzals, %[zero]\n\t" /* Not taken: 2s */ + "b_test bltzals, %[one]\n\t" /* Not taken: 2s */ + "b_test bgezals, %[mone]\n\t" /* Not taken: 2s */ + "b_test bgezals, %[zero]\n\t" /* Taken: 1s */ + "b_test bgezals, %[one]\n\t" /* Taken: 1s */ + "nop\n\t" /* NOP: 1s */ + ".globl step_stop\n\t" /* Total: 25s */ + ".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_micromips_branch (); +} Index: binutils-gdb/gdb/testsuite/gdb.arch/micromips-branch.exp =================================================================== --- /dev/null +++ binutils-gdb/gdb/testsuite/gdb.arch/micromips-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 microMIPS branch instructions. + +require {istarget "mips*-*-*"} + +source $srcdir/$subdir/mips-allow.exp.tcl + +require allow_micromips_ase_tests + +standard_testfile + +set steps 25 +foreach flag {-Wa,-W -mno-mips16 -mmicromips -minterlink-compressed} { + lappend compile_flags "additional_flags=$flag" +} +source $srcdir/$subdir/mips-stepi.exp.tcl 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 @@ -124,3 +124,32 @@ proc allow_mips16_ase_tests {} { } \ {-Wa,-fatal-warnings -mno-micromips -mips16 -minterlink-compressed}] } + +# Check for microMIPS ASE support. These instructions may be absent, +# such as with MIPS16 compilations. Make sure an actual JRADDIUSP +# machine instruction is produced and no macro expanded such as with +# `-Wa,-minsn32'. +proc allow_micromips_ase_tests {} { + return [allow_target_tests "allow_micromips_ase_tests" \ + "microMIPS instruction support" "(:?Bus error|Illegal instruction)" \ + { + int main() { + extern const char jr asm("jr"); + register char *ra asm("$31") = &jr; + + asm volatile ( + ".set push\n\t" + ".set noreorder\n\t" + ".set nomacro\n\t" + "jraddiusp 0\n\t" + ".globl jr\n\t" + ".type jr, @function\n" + "jr:\n\t" + ".set pop\n" + : + : "r" (ra)); + return 0; + } + } \ + {-Wa,-fatal-warnings -mno-mips16 -mmicromips -minterlink-compressed}] +}