From patchwork Thu Jul 23 18:52:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139855 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1FC734BA7998 for ; Thu, 23 Jul 2026 18:53:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1FC734BA7998 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 78A9C4BA540B for ; Thu, 23 Jul 2026 18:52:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 78A9C4BA540B 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 78A9C4BA540B 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=1784832767; cv=none; b=gjwhwNsaOZ9tGInDZnFHmhLCRJN8SdfnXE0cG9zrCXXB/tk5hm9Nw8yM8aaHLfhFtPxotv9qXfs+EM3B5i+xue2Z7m40mdBJJry4Mva9d2mTIYeRy9WBpe2LLD2JOPoRAhgqKULRfh4AqfGzcGxQgeJAeLbOQDGIZlVkWGckRSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832767; c=relaxed/simple; bh=BN9/apS58Nbtbmf3oCzfxttX2lL7X2gOEJdkaiJM9v8=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=pFdj/kpVuk0gjr0Uec+/TKoY7JgRpbcTfLIA4zfc7HcY9P3YoNvUblkGVywiToSw6CXUDECQ0QDBizM4CAMbSoSyxLlKCvp72OhPQK+GAj1g9rlQj2Q2zAuOh2XzNGbjQP09xwo+BDp0opXYw7bHZ5aj4XqNMH0LbPb0Hmm/bRk= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 78A9C4BA540B Received: by angie.orcam.me.uk (Postfix, from userid 500) id 643C392009D; Thu, 23 Jul 2026 20:52:46 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 5D47792009B; Thu, 23 Jul 2026 19:52:46 +0100 (BST) Date: Thu, 23 Jul 2026 19:52:46 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 1/7] testsuite: Factor out target feature test template In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3486.5 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Implement `allow_target_tests' generic target feature test procedure, factoring out duplicate code from tests such as `allow_altivec_tests', `allow_power_isa_3_1_tests', `allow_vsx_tests', etc. --- gdb/testsuite/lib/gdb.exp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) gdb-test-target-allow.diff Index: binutils-gdb/gdb/testsuite/lib/gdb.exp =================================================================== --- binutils-gdb.orig/gdb/testsuite/lib/gdb.exp +++ binutils-gdb/gdb/testsuite/lib/gdb.exp @@ -4285,6 +4285,50 @@ gdb_caching_proc libc_has_debug_info {} } } +# Using name ME for reporting, check for target feature FEATURE, the +# absence of which is supposed to get message MESSAGE produced by GDB. +# Use source SRC and optional list of additional compiler flags FLAGS +# for the check. Make sure the source provided builds and then that +# target hardware runs it. +proc allow_target_tests { me feature message src { flags {} } } { + global srcdir subdir gdb_prompt inferior_exited_re + + set compile_flags {} + foreach flag $flags { + require {have_compile_flag $flag} + lappend compile_flags "additional_flags=$flag" + } + + if {![gdb_simple_compile $me $src executable $compile_flags]} { + return 0 + } + + gdb_exit + gdb_start + gdb_reinitialize_dir $srcdir/$subdir + gdb_load "$obj" + gdb_run_cmd + gdb_expect { + -re ".*${message}.*${gdb_prompt} $" { + verbose -log "\n$me $feature not detected" + set allow_target_tests 0 + } + -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { + verbose -log "\n$me: $feature detected" + set allow_target_tests 1 + } + default { + warning "\n$me: default case taken" + set allow_target_tests 0 + } + } + gdb_exit + remote_file build delete $obj + + verbose "$me: returning $allow_target_tests" 2 + return $allow_target_tests +} + # Run a test on the target to see if it supports vmx hardware. Return 1 if so, # 0 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. From patchwork Thu Jul 23 18:52:51 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139852 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 108FB4BA79B5 for ; Thu, 23 Jul 2026 18:53:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 108FB4BA79B5 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id D64834BA23D9 for ; Thu, 23 Jul 2026 18:52:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D64834BA23D9 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 D64834BA23D9 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=1784832772; cv=none; b=fjSySQMZWf4emZQdBluOO2HE/hj/v7PcOlIykqC9x6UliZ+iqb/MDnpJEzkU37+51EC/bfD/ByI++ENpow/UshqThxhP+hA8/dlrQ+tKqa8RsPenchxQr5tvAkZfN1vc/2nGXOah8YHDEpesX1Anr0y7lX+WgysPpL9FUK/6edc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832772; c=relaxed/simple; bh=xcqF509HBvO5G0IuMknEUSKEt2uD579Y7ygl/hZvrOs=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=joZgiJU5sQ6N/+MhRJCKT6NNQPZgPR8J55fgRLG+GiNP50EdH1jPQptqtJakWt8fPswsHCreGF7vHCqL4VHGjDxuC6ad9fvf16HhbgBEr5nNIIToDJx5OvrYWXixkCsmEm+qUe2TudvN851ySkl8KEETjtZffTM4/JWDvf4bgqw= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D64834BA23D9 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 5EEDE92009C; Thu, 23 Jul 2026 20:52:51 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 5861A92009B; Thu, 23 Jul 2026 19:52:51 +0100 (BST) Date: Thu, 23 Jul 2026 19:52:51 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 2/7] PowerPC/testsuite: Reduce feature tests in terms of `allow_target_tests' In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3486.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Reimplement `allow_altivec_tests', `allow_power_isa_3_1_tests', and `allow_vsx_tests' in terms of `allow_target_tests', removing duplicate code. No functional change. Eventually it may make sense to migrate the resulting wrappers to testsuite/gdb.arch/ so as to declutter generic test framework from target-specific stuff. --- gdb/testsuite/lib/gdb.exp | 163 +++++++++------------------------------------- 1 file changed, 35 insertions(+), 128 deletions(-) gdb-powerpc-test-target-allow.diff Index: binutils-gdb/gdb/testsuite/lib/gdb.exp =================================================================== --- binutils-gdb.orig/gdb/testsuite/lib/gdb.exp +++ binutils-gdb/gdb/testsuite/lib/gdb.exp @@ -4333,8 +4333,6 @@ proc allow_target_tests { me feature mes # 0 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. gdb_caching_proc allow_altivec_tests {} { - global srcdir subdir gdb_prompt inferior_exited_re - set me "allow_altivec_tests" # Some simulators are known to not support VMX instructions. @@ -4350,110 +4348,47 @@ gdb_caching_proc allow_altivec_tests {} # Make sure we have a compiler that understands altivec. if {[test_compiler_info gcc*]} { - set compile_flags "additional_flags=-maltivec" + set flags "-maltivec" } elseif {[test_compiler_info xlc*]} { - set compile_flags "additional_flags=-qaltivec" + set flags "-qaltivec" } else { verbose "Could not compile with altivec support, returning 0" 2 return 0 } # Compile a test program containing VMX instructions. - set src { - int main() { - #ifdef __MACH__ - asm volatile ("vor v0,v0,v0"); - #else - asm volatile ("vor 0,0,0"); - #endif - return 0; - } - } - if {![gdb_simple_compile $me $src executable $compile_flags]} { - return 0 - } - - # Compilation succeeded so now run it via gdb. - - gdb_exit - gdb_start - gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$obj" - gdb_run_cmd - gdb_expect { - -re ".*Illegal instruction.*${gdb_prompt} $" { - verbose -log "\n$me altivec hardware not detected" - set allow_vmx_tests 0 - } - -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { - verbose -log "\n$me: altivec hardware detected" - set allow_vmx_tests 1 - } - default { - warning "\n$me: default case taken" - set allow_vmx_tests 0 - } - } - gdb_exit - remote_file build delete $obj - - verbose "$me: returning $allow_vmx_tests" 2 - return $allow_vmx_tests + return [allow_target_tests $me "altivec hardware" "Illegal instruction" \ + { + int main() { + #ifdef __MACH__ + asm volatile ("vor v0,v0,v0"); + #else + asm volatile ("vor 0,0,0"); + #endif + return 0; + } + } \ + $flags] } # Run a test on the power target to see if it supports ISA 3.1 instructions gdb_caching_proc allow_power_isa_3_1_tests {} { - global srcdir subdir gdb_prompt inferior_exited_re - - set me "allow_power_isa_3_1_tests" - # Compile a test program containing ISA 3.1 instructions. - set src { - int main() { - asm volatile ("pnop"); // marker + return [allow_target_tests "allow_power_isa_3_1_tests" \ + "Power ISA 3.1 hardware" "Illegal instruction" \ + { + int main() { + asm volatile ("pnop"); // marker asm volatile ("nop"); return 0; } - } - - if {![gdb_simple_compile $me $src executable ]} { - return 0 - } - - # No error message, compilation succeeded so now run it via gdb. - - gdb_exit - gdb_start - gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$obj" - gdb_run_cmd - gdb_expect { - -re ".*Illegal instruction.*${gdb_prompt} $" { - verbose -log "\n$me Power ISA 3.1 hardware not detected" - set allow_power_isa_3_1_tests 0 - } - -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { - verbose -log "\n$me: Power ISA 3.1 hardware detected" - set allow_power_isa_3_1_tests 1 - } - default { - warning "\n$me: default case taken" - set allow_power_isa_3_1_tests 0 - } - } - gdb_exit - remote_file build delete $obj - - verbose "$me: returning $allow_power_isa_3_1_tests" 2 - return $allow_power_isa_3_1_tests + }] } # Run a test on the target to see if it supports vmx hardware. Return 1 if so, # 0 if it does not. Based on 'check_vmx_hw_available' from the GCC testsuite. gdb_caching_proc allow_vsx_tests {} { - global srcdir subdir gdb_prompt inferior_exited_re - set me "allow_vsx_tests" # Some simulators are known to not support Altivec instructions, so @@ -4465,56 +4400,28 @@ gdb_caching_proc allow_vsx_tests {} { # Make sure we have a compiler that understands altivec. if {[test_compiler_info gcc*]} { - set compile_flags "additional_flags=-mvsx" + set flags "-mvsx" } elseif {[test_compiler_info xlc*]} { - set compile_flags "additional_flags=-qasm=gcc" + set flags "-qasm=gcc" } else { verbose "Could not compile with vsx support, returning 0" 2 return 0 } # Compile a test program containing VSX instructions. - set src { - int main() { - double a[2] = { 1.0, 2.0 }; - #ifdef __MACH__ - asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a)); - #else - asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a)); - #endif - return 0; - } - } - if {![gdb_simple_compile $me $src executable $compile_flags]} { - return 0 - } - - # No error message, compilation succeeded so now run it via gdb. - - gdb_exit - gdb_start - gdb_reinitialize_dir $srcdir/$subdir - gdb_load "$obj" - gdb_run_cmd - gdb_expect { - -re ".*Illegal instruction.*${gdb_prompt} $" { - verbose -log "\n$me VSX hardware not detected" - set allow_vsx_tests 0 - } - -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { - verbose -log "\n$me: VSX hardware detected" - set allow_vsx_tests 1 - } - default { - warning "\n$me: default case taken" - set allow_vsx_tests 0 - } - } - gdb_exit - remote_file build delete $obj - - verbose "$me: returning $allow_vsx_tests" 2 - return $allow_vsx_tests + return [allow_target_tests $me "VSX hardware" "Illegal instruction" \ + { + int main() { + double a[2] = { 1.0, 2.0 }; + #ifdef __MACH__ + asm volatile ("lxvd2x v0,v0,%[addr]" : : [addr] "r" (a)); + #else + asm volatile ("lxvd2x 0,0,%[addr]" : : [addr] "r" (a)); + #endif + return 0; + } + } \ + $flags] } # Run a test on the target to see if it supports TSX hardware. Return 1 if so, From patchwork Thu Jul 23 18:52:56 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139856 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0ED634BA798A for ; Thu, 23 Jul 2026 18:53:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0ED634BA798A X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id A6A354BA23EE for ; Thu, 23 Jul 2026 18:52:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A6A354BA23EE 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 A6A354BA23EE 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=1784832776; cv=none; b=kDqA87MjX6nLhdAh7VcBG7h2Q0lJ2fV8bQd5mzYhXnrOAeUQ7oHe9Zi4yBeWIYhPnHGH8j/pqyHTBo0T1ZY8RI9zKCY1m8Zn96JbXOc2wNOrehfR+14Y2lCLcUV/mBANJ+d4UzbWu0ROVBEX8cJ826/3cNzhEjOXq8wK1uiTdAs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832776; c=relaxed/simple; bh=Bg/f1Mq2GVTTSIUdSWlKMDcWR5KgaIbEKpwbS4wcG5U=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=TaHiI60226WAX4OoYaKw/U+3Spl3DKTrMxmJi99ngpoA5lIJF0/JQi8J2me8PJS0hqS7Gw1kxXzrrl7z1USLxYDiyDvkyJIYUyYE5o0STJX4E0t7Z5MdnqmkOncZisvItEvcY7MNT1RmEHUiJYKYZR5BQLS/GvdAFssKD/7W1Gc= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6A354BA23EE Received: by angie.orcam.me.uk (Postfix, from userid 500) id 245E492009D; Thu, 23 Jul 2026 20:52:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 1E93592009B; Thu, 23 Jul 2026 19:52:56 +0100 (BST) Date: Thu, 23 Jul 2026 19:52:56 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 3/7] 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 X-Spam-Status: No, score=-3486.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@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. 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 --- gdb/testsuite/gdb.arch/mips-allow.exp.tcl | 61 ++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips-stepi.exp.tcl | 78 +++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-bal.c | 70 ++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-bal.exp | 30 +++++++++++ gdb/testsuite/gdb.arch/mips1-branch.c | 80 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips1-branch.exp | 30 +++++++++++ 6 files changed, 349 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,78 @@ +# 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 + + 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" { } + } + pass $message + return 1 + } + -re ".*$gdb_prompt" { + send_gdb "set err -= 1\n" + gdb_expect { + -re "$gdb_prompt" { } + } + } + } + } + fail $message + 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,70 @@ +/* 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 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 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), + [any] "r" (any) + : "$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,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 . */ + +/* 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) + : "$31"); + + 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 From patchwork Thu Jul 23 18:53:00 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139853 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC23D4BA23DB for ; Thu, 23 Jul 2026 18:53:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC23D4BA23DB X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [78.133.224.34]) by sourceware.org (Postfix) with ESMTP id 9372F4BA7993 for ; Thu, 23 Jul 2026 18:53:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9372F4BA7993 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 9372F4BA7993 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=78.133.224.34 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832781; cv=none; b=Nt7aW3/NYYx3pwNrQts1vjeZnvTZWjaWFJVeuYud7dvmQiiBEQ+i/jd+B4M1a3+6c48TN+d6E83Ht4DNoKXBfFR42kag7MtIGtHZCP7ieqR2ySlar22tmEgDMA/zX+q+8AUXkSKG8kIYNoTL6VOh2LUklyvGR0wEA85bfnYzutA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832781; c=relaxed/simple; bh=l7PI5TYqsfzuis+r+h5HQPA7c0AF5l+cb87MQQag83w=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=BXYWNpBZXjCGYo+EXfqzGVvhRyWPSS6ONAj4qf4S2ChSneBxADK1As0qf0p35+snkwJbyJj0P1nT/5F3q1MPV0v3LAjlYBN/UCl/qqS60Q8uaGIytqjJ99XCVGlXccdfoexa2Hjz0iF6bFfcVYf0W7ltcwU5fLHVl9UeIqREipM= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9372F4BA7993 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 1A4B19200BB; Thu, 23 Jul 2026 20:53:01 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 13E579200B4; Thu, 23 Jul 2026 19:53:01 +0100 (BST) Date: Thu, 23 Jul 2026 19:53:00 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 4/7] MIPS: Correct BLEZL single-stepping In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-1162.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Correct `mips32_next_pc' and also consider BLEZL taken for the value of zero held in the source register as per the instruction's semantics, restoring `less_zero_branch' label discarded with commit 54f1137d66be and actually matching the comment present in the source. Verification will be provided with the test cases in the next change. 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 --- gdb/mips-tdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) gdb-mips-next-pc-blezl.diff Index: binutils-gdb/gdb/mips-tdep.c =================================================================== --- binutils-gdb.orig/gdb/mips-tdep.c +++ binutils-gdb/gdb/mips-tdep.c @@ -1662,7 +1662,7 @@ mips32_next_pc (struct regcache *regcach case 1: /* BNEL */ goto neq_branch; case 2: /* BLEZL */ - goto less_branch; + goto less_equal_branch; case 3: /* BGTZL */ goto greater_branch; default: @@ -1751,7 +1751,6 @@ mips32_next_pc (struct regcache *regcach case 2: /* BLTZL */ case 16: /* BLTZAL */ case 18: /* BLTZALL */ - less_branch: if (regcache_raw_get_signed (regcache, itype_rs (inst)) < 0) pc += mips32_relative_offset (inst) + 4; else @@ -1817,6 +1816,7 @@ mips32_next_pc (struct regcache *regcach pc += 8; break; case 6: /* BLEZ, BLEZL */ + less_equal_branch: if (regcache_raw_get_signed (regcache, itype_rs (inst)) <= 0) pc += mips32_relative_offset (inst) + 4; else From patchwork Thu Jul 23 18:53:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139857 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D0DE44BA7980 for ; Thu, 23 Jul 2026 18:54:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D0DE44BA7980 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id A75F04BA23D9 for ; Thu, 23 Jul 2026 18:53:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A75F04BA23D9 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 A75F04BA23D9 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=1784832786; cv=none; b=iumlIDV4+NJayG7JP3aAQ6LOASb2LwQaM6DSafOwK2bZ47/Bho0qdGwwEzSl3xiKQ4F+VyHy7roMwvgtk9M4FGLsQMfZMQYHGk25jrIEXskwjJXUirzu73StU0tlcXcuIB2413Fv+Dqnu/b3bovL74KCyRuB1atH6uM9neD0Rw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832786; c=relaxed/simple; bh=GgL7xCou8/mDs5Ecr77fuRNV+/AhY4fJGyJjLamtWnw=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=STdUWfmBniqgZkMCPNMNQnk2uBsHWLR/iYNHCtCyePSFDD63vjW7j6auznFzagKzS0UdvDXhUZR5/vO7KIcDYu21QcGXUlABPs+gf2rvNVX6DjvlYsWExGPx2cvG797JzxzERcIiycL9ml8OXzs/mNvOLHwXOr5hyPY6EBqdv2c= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A75F04BA23D9 Received: by angie.orcam.me.uk (Postfix, from userid 500) id 2C2259200BF; Thu, 23 Jul 2026 20:53:06 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 279A49200BC; Thu, 23 Jul 2026 19:53:06 +0100 (BST) Date: Thu, 23 Jul 2026 19:53:06 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 5/7] MIPS/testsuite: Verify MIPS II CPU branch stepping In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3486.1 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Verify that breakpoints are correctly placed via `mips32_next_pc' while single-stepping through MIPS II CPU branches. Approved-by: Maciej W. Rozycki --- 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 . */ + +/* 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 . + +# 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 From patchwork Thu Jul 23 18:53:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139858 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DFE94BA23CA for ; Thu, 23 Jul 2026 18:54:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DFE94BA23CA X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 2D6794BA7999 for ; Thu, 23 Jul 2026 18:53:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D6794BA7999 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 2D6794BA7999 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=1784832792; cv=none; b=td/djcaqbJ2cP5C2ir4CbGHRc5ggy2M6rc0/60oKvndP6efeY/pvrCG+5E3KpuwgT76gojswDHiwDddy1iYPXLP/EtRorOMx1Q7ardkrznBgPdl/QR/ErNnS0calPXKUyReiHnhrLZ53/lH9QIWRPfdTtLOQQ6+ZfwlmZvsZcOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832792; c=relaxed/simple; bh=/VV1Mac/hokOKHiRUB7ZKV03mx8+sjayKiba8niGqog=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=PWo31WxlliOttnHz+zcJcmWqNC2G0Y94U084I/DYCfe6p0aj1FLoku6evmCobWqKezukrTTHR/eHRCHugyykk0RlMEHeCi40sPFvRWqNGe0ScjdZC4WUeHgR2Ay7xH/Oj3fwnAuo+yjUnmHWq0oTNGpI9Iy5Hhipp7fdpJHv8oY= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D6794BA7999 Received: by angie.orcam.me.uk (Postfix, from userid 500) id A102C9200BC; Thu, 23 Jul 2026 20:53:11 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id 9A0A092009E; Thu, 23 Jul 2026 19:53:11 +0100 (BST) Date: Thu, 23 Jul 2026 19:53:11 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 6/7] MIPS/testsuite: Verify MIPS16 branch stepping In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3486.0 required=5.0 tests=BAYES_00, KAM_ASCII_DIVIDERS, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki 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 --- gdb/testsuite/gdb.arch/mips-allow.exp.tcl | 21 +++++++ gdb/testsuite/gdb.arch/mips16-branch.c | 82 ++++++++++++++++++++++++++++++ gdb/testsuite/gdb.arch/mips16-branch.exp | 30 ++++++++++ 3 files changed, 133 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 @@ -84,3 +84,24 @@ proc allow_mips2_branch_tests {} { {-Wa,-fatal-warnings -mno-mips16 -mno-micromips -minterlink-compressed}] } + +# Check for MIPS16 branch 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_branch_tests {} { + return [allow_target_tests "allow_mips16_branch_tests" \ + "MIPS16 branch 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,82 @@ +/* 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_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 mone = -1; + int zero = 0; + int one = 1; + + 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 . + +# Test single-stepping through MIPS16 branch instructions. + +require {istarget "mips*-*-*"} + +source $srcdir/$subdir/mips-allow.exp.tcl + +require allow_mips16_branch_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 From patchwork Thu Jul 23 18:53:15 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 139854 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D98A4BA79A4 for ; Thu, 23 Jul 2026 18:53:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D98A4BA79A4 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from angie.orcam.me.uk (angie.orcam.me.uk [IPv6:2001:4190:8020::34]) by sourceware.org (Postfix) with ESMTP id 59A084BA23D5 for ; Thu, 23 Jul 2026 18:53:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 59A084BA23D5 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 59A084BA23D5 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=1784832796; cv=none; b=AFDA/HFONoqOVe9NVOvqmgT5MujJK51H13bKZ07GmbhaQ3EzN/JBuQtmpwxge1a25LJ42nrVP0L7zjssV1pAmXz3WlEN90GSAq0yDsrarfzIXislx+IbqCrk5iMaTR5nR95i6RxQ7ujLH6jtS39C39YUptYnmdRWUWJ4VlRZd2A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1784832796; c=relaxed/simple; bh=SZs0/PW2706NnU+oL32s5avk0jJGjn8jfWLkmwNQgeI=; h=Date:From:To:Subject:Message-ID:MIME-Version; b=cC3+zNB0YHSmdLhch7NoSC3Jcsn/u+SyqNxyuz/YHYeleD8MfEhZCqhUDFBt3hExFwUFTU4YEDfRy1jjUpuhGGRT9hu4AHK/W+F/S4QrFTmbdePkjAc6F19d+VsLij57PJqeQkIJTg2HlSoO6Ts3rKNLjp8oJ8bWC5xw+1E5GoE= ARC-Authentication-Results: i=1; sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 59A084BA23D5 Received: by angie.orcam.me.uk (Postfix, from userid 500) id D64839200C0; Thu, 23 Jul 2026 20:53:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by angie.orcam.me.uk (Postfix) with ESMTP id D24DD9200BF; Thu, 23 Jul 2026 19:53:15 +0100 (BST) Date: Thu, 23 Jul 2026 19:53:15 +0100 (BST) From: "Maciej W. Rozycki" To: gdb-patches@sourceware.org cc: Jovan Dmitrovic , Djordje Todorovic , Milica Matic , "Maciej W. Rozycki" Subject: [PATCH 7/7] MIPS: Reorder a reference to "BGTZ, BGTZL" in `mips32_next_pc' In-Reply-To: Message-ID: References: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 X-Spam-Status: No, score=-3486.4 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, KAM_INFOUSMEBIZ, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, TXREP shortcircuit=no autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Maciej W. Rozycki Move a reference to "BGTZ, BGTZL" in `mips32_next_pc' to the leading case label as with the other instructions called out in the function. Approved-by: Maciej W. Rozycki --- gdb/mips-tdep.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) gdb-mips-next-pc-bgtz-comment.diff Index: binutils-gdb/gdb/mips-tdep.c =================================================================== --- binutils-gdb.orig/gdb/mips-tdep.c +++ binutils-gdb/gdb/mips-tdep.c @@ -1822,9 +1822,9 @@ mips32_next_pc (struct regcache *regcach else pc += 8; break; - case 7: + case 7: /* BGTZ, BGTZL */ default: - greater_branch: /* BGTZ, BGTZL */ + greater_branch: if (regcache_raw_get_signed (regcache, itype_rs (inst)) > 0) pc += mips32_relative_offset (inst) + 4; else