From nobody Sat Nov 29 10:17:25 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1764317460; cv=none; d=zohomail.com; s=zohoarc; b=Gs1yHtejZ1N3t0+ieq6bb+FmVwlXuxMaRM80m3K7hbyJvlYpMdRTsQLyf7ubNg2K2HcGahETsYO8K8yoHxQcTyhTO7y92HWkOlVEyfrVMBc6JKMD9dzw35Rv58gkfwTzOMkm585TiMlu5FWsAyRo01tJsmZIDDGse/+HNAp5Sw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1764317460; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Sender:Subject:Subject:To:To:Message-Id; bh=1jiIPJ3RlobDveD9b2FYnwWzGO/sZP8XoyNeIAx61oY=; b=SR0r71NSs2G/hGwhRuJgZ9YHnOhwBsD6cjbQhOa3ZRSH8MUcfFhPxJr/W4Mtzl+NI1R/HcMz1HY0CRIwSuUgTgPuiHp82ctEJF2smjQMrzWRdPRrB7AHo2N20gtDFwD3agcq5XK0+L9AMEsXcoK9NtCGJ+u6Xv+RsFknPMwbL7A= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1764317460648359.3367121597174; Fri, 28 Nov 2025 00:11:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vOtYc-00070s-38; Fri, 28 Nov 2025 03:10:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOtYJ-0006sP-4l; Fri, 28 Nov 2025 03:10:04 -0500 Received: from 60-248-80-70.hinet-ip.hinet.net ([60.248.80.70] helo=Atcsqr.andestech.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vOtYG-00035a-5H; Fri, 28 Nov 2025 03:10:02 -0500 Received: from mail.andestech.com (ATCPCS31.andestech.com [10.0.1.89]) by Atcsqr.andestech.com with ESMTPS id 5AS89YGl009063 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 28 Nov 2025 16:09:34 +0800 (+08) (envelope-from alvinga@andestech.com) Received: from swlinux02.andestech.com (10.0.15.183) by ATCPCS31.andestech.com (10.0.1.89) with Microsoft SMTP Server id 14.3.498.0; Fri, 28 Nov 2025 16:09:34 +0800 To: , CC: , , , , , , Alvin Chang , Yu-Ming Chang Subject: [PATCH] target/riscv: Fix index of fired breakpoint and watchpoint Date: Fri, 28 Nov 2025 16:09:28 +0800 Message-ID: <20251128080928.3160155-1-alvinga@andestech.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.0.15.183] X-DKIM-Results: atcpcs31.andestech.com; dkim=none; X-DNSRBL: X-SPAM-SOURCE-CHECK: pass X-MAIL: Atcsqr.andestech.com 5AS89YGl009063 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=60.248.80.70; envelope-from=alvinga@andestech.com; helo=Atcsqr.andestech.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, RDNS_DYNAMIC=0.982, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Alvin Chang From: Alvin Chang via Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1764317464197019200 Content-Type: text/plain; charset="utf-8" The do_trigger_action() receives index of fired trigger as second parameter. However, in current implementation, the argument is hardcoded as DBG_ACTION_BP which is 0. This is a bug because we may match/fire any breakpoints or watchpoints at other index than 0. Fix this bug by iterating cpu_breakpoint[] and cpu_watchpoint[] to compare and match necessary checkpoints. The index of the fired cpu_breakpoint or the cpu_watchpoint is the index of the trigger we want to provide to do_trigger_action(). Signed-off-by: Alvin Chang Reviewed-by: Yu-Ming Chang Reviewed-by: Daniel Henrique Barboza --- target/riscv/debug.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 5664466..f3bca8e 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -929,11 +929,24 @@ void riscv_cpu_debug_excp_handler(CPUState *cs) =20 if (cs->watchpoint_hit) { if (cs->watchpoint_hit->flags & BP_CPU) { - do_trigger_action(env, DBG_ACTION_BP); + /* Search fired trigger and do its action */ + for (int i =3D 0; i < ARRAY_SIZE(env->cpu_watchpoint); i++) { + if (cs->watchpoint_hit =3D=3D env->cpu_watchpoint[i]) { + do_trigger_action(env, i); + break; + } + } } } else { if (cpu_breakpoint_test(cs, env->pc, BP_CPU)) { - do_trigger_action(env, DBG_ACTION_BP); + /* Search fired trigger and do its action */ + for (int i =3D 0; i < ARRAY_SIZE(env->cpu_breakpoint); i++) { + CPUBreakpoint *bp =3D env->cpu_breakpoint[i]; + if (bp && bp->pc =3D=3D env->pc && (bp->flags & BP_CPU)) { + do_trigger_action(env, i); + break; + } + } } } } --=20 2.43.0