[PATCH v2 07/12] MIPS/testsuite: Verify MIPS16 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 `mips16_next_pc' while 
single-stepping through MIPS16 branches.  Explicit instruction suffixes 
are used to get both regular and extended instruction forms covered, and 
`-Wa,-W' GAS option is used to quiesce warnings as the tool is keen to 
complain about the extended form where requested unnecessarily.

Approved-By: Maciej W. Rozycki <[email protected]>
---
Changes from v1 (6/7),
<https://inbox.sourceware.org/gdb-patches/[email protected]/>:

- Correct the printed description of `allow_mips16_ase_tests'.

- Remove unused `mone' and `one' variables from `test_mips16_branch'; 
  correct the function description.
---
 gdb/testsuite/gdb.arch/mips-allow.exp.tcl |   21 +++++++
 gdb/testsuite/gdb.arch/mips16-branch.c    |   80 ++++++++++++++++++++++++++++++
 gdb/testsuite/gdb.arch/mips16-branch.exp  |   30 +++++++++++
 3 files changed, 131 insertions(+)

gdb-mips16-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
@@ -103,3 +103,24 @@ proc allow_mips_dsp_ase_tests {} {
 	    } \
 	{-Wa,-fatal-warnings -mno-mips16 -minterlink-compressed -mdsp}]
 }
+
+# Check for MIPS16 ASE support.  These instructions may be absent,
+# such as with microMIPS compilations.  Make sure an actual BTEQZ
+# machine instruction is produced and no macro expanded.
+proc allow_mips16_ase_tests {} {
+    return [allow_target_tests "allow_mips16_ase_tests" \
+	"MIPS16 instruction support" "(:?Bus error|Illegal instruction)" \
+	    {
+		int main() {
+		    asm volatile (
+			".set	push\n\t"
+			".set	noreorder\n\t"
+			".set	nomacro\n\t"
+			"bteqz	0f\n\t"
+			"0:\n\t"
+			".set	pop\n");
+		    return 0;
+		}
+	    } \
+	{-Wa,-fatal-warnings -mno-micromips -mips16 -minterlink-compressed}]
+}
Index: binutils-gdb/gdb/testsuite/gdb.arch/mips16-branch.c
===================================================================
--- /dev/null
+++ binutils-gdb/gdb/testsuite/gdb.arch/mips16-branch.c
@@ -0,0 +1,80 @@
+/* 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 MIPS16 branch instructions.  */
+
+int
+test_mips16_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 zero = 0;
+
+  asm volatile (
+	".macro	b_test op, args:vararg\n\t"
+	".ifb	\\args\n\t"
+	"\\op	0f\n\t"
+	".else\n\t"
+	"\\op	\\args, 0f\n\t"
+	".endif\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	beqz.t %[zero]\n\t"		/* Taken:     1s  */
+	"b_test	beqz.e %[zero]\n\t"		/* Taken:     1s  */
+	"b_test	beqz.t %[any]\n\t"		/* Not taken: 2s  */
+	"b_test	beqz.e %[any]\n\t"		/* Not taken: 2s  */
+	"b_test	bnez.t %[zero]\n\t"		/* Not taken: 2s  */
+	"b_test	bnez.e %[zero]\n\t"		/* Not taken: 2s  */
+	"b_test	bnez.t %[any]\n\t"		/* Taken:     1s  */
+	"b_test	bnez.e %[any]\n\t"		/* Taken:     1s  */
+	"b_test	bteqz.t\n\t"			/* Taken:     1s  */
+	"b_test	bteqz.e\n\t"			/* Taken:     1s  */
+	"b_test	btnez.t\n\t"			/* Not taken: 2s  */
+	"b_test	btnez.e\n\t"			/* Not taken: 2s  */
+	"move	%[t], %[any]\n\t"		/* MOVE:      1s  */
+	"b_test	bteqz.t\n\t"			/* Not taken: 2s  */
+	"b_test	bteqz.e\n\t"			/* Not taken: 2s  */
+	"b_test	btnez.t\n\t"			/* Taken:     1s  */
+	"b_test	btnez.e\n\t"			/* Taken:     1s  */
+	"nop\n\t"				/* NOP:       1s  */
+	".globl	step_stop\n\t"			/* Total:    27s  */
+	".type	step_stop, @function\n"
+	"step_stop:\n\t"
+	".set pop\n"
+	: [t] "+t" (zero)
+	: [zero] "u" (zero), [any] "u" (any));
+
+  return err;
+}
+
+int
+main (void)
+{
+  return test_mips16_branch ();
+}
Index: binutils-gdb/gdb/testsuite/gdb.arch/mips16-branch.exp
===================================================================
--- /dev/null
+++ binutils-gdb/gdb/testsuite/gdb.arch/mips16-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 MIPS16 branch instructions.
+
+require {istarget "mips*-*-*"}
+
+source $srcdir/$subdir/mips-allow.exp.tcl
+
+require allow_mips16_ase_tests
+
+standard_testfile
+
+set steps 27
+foreach flag {-Wa,-W -mno-micromips -mips16 -minterlink-compressed} {
+    lappend compile_flags "additional_flags=$flag"
+}
+source $srcdir/$subdir/mips-stepi.exp.tcl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.