From nobody Tue May 13 07:34:09 2025
Delivered-To: importer@patchew.org
Authentication-Results: mx.zohomail.com;
	dkim=pass;
	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=linaro.org
ARC-Seal: i=1; a=rsa-sha256; t=1734397746; cv=none;
	d=zohomail.com; s=zohoarc;
	b=gCcJcJ5zjm5HOJ9wMGWTYDH5hsNxmPfD8sBpUTpdJc7+wt7ZOfCXrPyrcbE+VrDafXNl5Ldiqi62+FopR8nM09lojY1zA30hTTGhSR9+gRwVXlgBZq73kPvyl2TMGeq3t+O4btNHn7nebcUWfiMPxuFqnWOHxXpqLRTSnbCi868=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1734397746;
 h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To;
	bh=E0X1MlNNMfXe3fyFvrKoslEpzjFsMN2sr/cA5ARxGXA=;
	b=BnesK/C/Sa0M6uff4B6jJQ4+SidDz19rkgo+mFJzDwKOimHK8vJrllR0uRi20s6mfhJ6v1wDxwkxitwQu9OzBbZmTjVaNtTXX+ayVd02dVTmTlC2YQyDOxUwgaIapbw2sU+aIx41t0On+I87mfolcTqt6lKbW6tqD5hDxt7K7q8=
ARC-Authentication-Results: i=1; mx.zohomail.com;
	dkim=pass;
	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=<pierrick.bouvier@linaro.org> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 17343977463261022.733473315771;
 Mon, 16 Dec 2024 17:09:06 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tNM3f-0008Ho-PK; Mon, 16 Dec 2024 20:07:31 -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 <pierrick.bouvier@linaro.org>)
 id 1tNM3b-0008Gp-Fe
 for qemu-devel@nongnu.org; Mon, 16 Dec 2024 20:07:27 -0500
Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <pierrick.bouvier@linaro.org>)
 id 1tNM3Z-0004y4-JU
 for qemu-devel@nongnu.org; Mon, 16 Dec 2024 20:07:27 -0500
Received: by mail-pl1-x62a.google.com with SMTP id
 d9443c01a7336-21636268e43so57918655ad.2
 for <qemu-devel@nongnu.org>; Mon, 16 Dec 2024 17:07:25 -0800 (PST)
Received: from pc.. (216-180-64-156.dyn.novuscom.net. [216.180.64.156])
 by smtp.gmail.com with ESMTPSA id
 d9443c01a7336-218a1e6d0e4sm48746595ad.261.2024.12.16.17.07.23
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 16 Dec 2024 17:07:23 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=linaro.org; s=google; t=1734397644; x=1735002444; darn=nongnu.org;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:from:to:cc:subject:date
 :message-id:reply-to;
 bh=E0X1MlNNMfXe3fyFvrKoslEpzjFsMN2sr/cA5ARxGXA=;
 b=FRmousVrJv+7ygwCpPJyWhExj+Ya0MMjhkJqCzgziL7z+kepRWH3mILOpcw2oxVtu+
 H43pLJAJCCL/sr0fvbd45ZgGsGnGXflvRJ21mWW4D2uqur1yc/MGE3yFF94Oaw6nIHS0
 Q/h1qYHLXKnKP1pID8pgdxyHNCJ++N89LmB5OEbvRKbH3iiT06zJE8Qv4DMEm1eUq6Ox
 QbsvAWIJ5bECXKNn1hh6sKXQ0BchTQWadYuiKbVZeXwAgE1B5DTIJABol7RvKa2Dv2Ro
 PjacZAk1eCvYCrnvyN/AobjZOhpvl8Vk/fwM6H7dUKp3ZxTHO9bbmH0vfuNv17LcyQE7
 fRbA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1734397644; x=1735002444;
 h=content-transfer-encoding:mime-version:references:in-reply-to
 :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc
 :subject:date:message-id:reply-to;
 bh=E0X1MlNNMfXe3fyFvrKoslEpzjFsMN2sr/cA5ARxGXA=;
 b=DJRDEDzrH4ohH9X65S31ySHbFrWuCVlpkdJIUEMKFUJcxtEwGuqfxkyNcndVUy0diV
 12m7M+K30Aj2ViTR1mtAH8JqVmA1jU0Z0iHrCN3b2/NoVuH2A3Rlv1vwlECxj/aVR8sz
 /uBidgpZjwALbRw0HkjlmfhdpZG+gFA1asEh6HYHEV5LaPdiGLL1t7qn2KY25RITL1fE
 wdmc5QvLEj9ZnKgp3HWJD3BKPmG5xIawAebJTqHoKg0Tt04pSq7ZqVLH2ENVkMWl3n/j
 1075SpajaR1rbCaMmnzafcdHoap5/A/L1AnOKWieQmYcVgtd1BDmneZcwybknwV1um03
 ci3g==
X-Gm-Message-State: AOJu0YyQmhjYLNjSRPLl2wqRxRZy2UV6LXr+R7x3B7RpnqiOy3/rUD0b
 uUuuWcOJqUZoMgqgVge4zTHX96lf8yIL5YUs287s3vJTnnWexYiHJwsTmoWnYKufc7qrz/PqQN1
 hLfg=
X-Gm-Gg: ASbGncsF+2nJKN6n54CoqTAPcCoFSRCTxv1YwH2l0NhcRBZ0ryHIDOIczXmaPs8aHyI
 kscQYGAQzcIL468wbV7LX9lEBkh+2bTzOj7KqRzqos7CW0zGQ/Va6hotb/tHvsoNVDXsBygE0h3
 pKPJkk5ETxOZeGMGC3wsboccneEaAGTL3EskHDaxrC7SjLgtyElPxCVcRKnd9mdPbUDWm0YD0uE
 Myvb7Zy5JtqCncdwSrjpkJnNT1dgzfGccgJxYF7Zw/Z24a6xZmDr6DDLgICmNEwaZDTKsQt0vd5
 zm9/WK4Zt/53bGk=
X-Google-Smtp-Source: 
 AGHT+IEf8zli+GR2E5mGKeKZw+rS+mr4jkVdutiv53wWJN7EDEUBzsyV+At6jH+qTZZkYeNiMYCEjQ==
X-Received: by 2002:a17:902:ce01:b0:215:50fb:ae4a with SMTP id
 d9443c01a7336-218928bc06bmr235729535ad.0.1734397644273;
 Mon, 16 Dec 2024 17:07:24 -0800 (PST)
From: Pierrick Bouvier <pierrick.bouvier@linaro.org>
To: qemu-devel@nongnu.org
Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= <alex.bennee@linaro.org>,
 richard.henderson@linaro.org,
 Pierrick Bouvier <pierrick.bouvier@linaro.org>,
 Alexandre Iooss <erdnaxe@crans.org>, Paolo Bonzini <pbonzini@redhat.com>,
 Mahmoud Mandour <ma.mandourr@gmail.com>, Thomas Huth <thuth@redhat.com>,
 philmd@linaro.org
Subject: [PATCH 07/13] contrib/plugins/stoptrigger: fix 32-bit build
Date: Mon, 16 Dec 2024 17:07:01 -0800
Message-Id: <20241217010707.2557258-8-pierrick.bouvier@linaro.org>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20241217010707.2557258-1-pierrick.bouvier@linaro.org>
References: <20241217010707.2557258-1-pierrick.bouvier@linaro.org>
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
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=2607:f8b0:4864:20::62a;
 envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x62a.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-BeenThere: qemu-devel@nongnu.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=subscribe>
Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org
Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org
X-ZohoMail-DKIM: pass (identity @linaro.org)
X-ZM-MESSAGEID: 1734397747965116600
Content-Type: text/plain; charset="utf-8"

Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
 contrib/plugins/stoptrigger.c | 48 ++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/contrib/plugins/stoptrigger.c b/contrib/plugins/stoptrigger.c
index 03ee22f4c6a..b3a6ed66a7b 100644
--- a/contrib/plugins/stoptrigger.c
+++ b/contrib/plugins/stoptrigger.c
@@ -21,9 +21,11 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUG=
IN_VERSION;
 /* Scoreboard to track executed instructions count */
 typedef struct {
     uint64_t insn_count;
+    uint64_t current_pc;
 } InstructionsCount;
 static struct qemu_plugin_scoreboard *insn_count_sb;
 static qemu_plugin_u64 insn_count;
+static qemu_plugin_u64 current_pc;
=20
 static uint64_t icount;
 static int icount_exit_code;
@@ -34,6 +36,11 @@ static bool exit_on_address;
 /* Map trigger addresses to exit code */
 static GHashTable *addrs_ht;
=20
+typedef struct {
+    uint64_t exit_addr;
+    int exit_code;
+} ExitInfo;
+
 static void exit_emulation(int return_code, char *message)
 {
     qemu_plugin_outs(message);
@@ -43,23 +50,18 @@ static void exit_emulation(int return_code, char *messa=
ge)
=20
 static void exit_icount_reached(unsigned int cpu_index, void *udata)
 {
-    uint64_t insn_vaddr =3D GPOINTER_TO_UINT(udata);
+    uint64_t insn_vaddr =3D qemu_plugin_u64_get(current_pc, cpu_index);
     char *msg =3D g_strdup_printf("icount reached at 0x%" PRIx64 ", exitin=
g\n",
                                 insn_vaddr);
-
     exit_emulation(icount_exit_code, msg);
 }
=20
 static void exit_address_reached(unsigned int cpu_index, void *udata)
 {
-    uint64_t insn_vaddr =3D GPOINTER_TO_UINT(udata);
-    char *msg =3D g_strdup_printf("0x%" PRIx64 " reached, exiting\n", insn=
_vaddr);
-    int exit_code;
-
-    exit_code =3D GPOINTER_TO_INT(
-        g_hash_table_lookup(addrs_ht, GUINT_TO_POINTER(insn_vaddr)));
-
-    exit_emulation(exit_code, msg);
+    ExitInfo *ei =3D udata;
+    g_assert(ei);
+    char *msg =3D g_strdup_printf("0x%" PRIx64 " reached, exiting\n", ei->=
exit_addr);
+    exit_emulation(ei->exit_code, msg);
 }
=20
 static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
@@ -67,23 +69,25 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q=
emu_plugin_tb *tb)
     size_t tb_n =3D qemu_plugin_tb_n_insns(tb);
     for (size_t i =3D 0; i < tb_n; i++) {
         struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i);
-        gpointer insn_vaddr =3D GUINT_TO_POINTER(qemu_plugin_insn_vaddr(in=
sn));
+        uint64_t insn_vaddr =3D qemu_plugin_insn_vaddr(insn);
=20
         if (exit_on_icount) {
             /* Increment and check scoreboard for each instruction */
             qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
                 insn, QEMU_PLUGIN_INLINE_ADD_U64, insn_count, 1);
+            qemu_plugin_register_vcpu_insn_exec_inline_per_vcpu(
+                insn, QEMU_PLUGIN_INLINE_STORE_U64, current_pc, insn_vaddr=
);
             qemu_plugin_register_vcpu_insn_exec_cond_cb(
                 insn, exit_icount_reached, QEMU_PLUGIN_CB_NO_REGS,
-                QEMU_PLUGIN_COND_EQ, insn_count, icount + 1, insn_vaddr);
+                QEMU_PLUGIN_COND_EQ, insn_count, icount + 1, NULL);
         }
=20
         if (exit_on_address) {
-            if (g_hash_table_contains(addrs_ht, insn_vaddr)) {
+            ExitInfo *ei =3D g_hash_table_lookup(addrs_ht, &insn_vaddr);
+            if (ei) {
                 /* Exit triggered by address */
                 qemu_plugin_register_vcpu_insn_exec_cb(
-                    insn, exit_address_reached, QEMU_PLUGIN_CB_NO_REGS,
-                    insn_vaddr);
+                    insn, exit_address_reached, QEMU_PLUGIN_CB_NO_REGS, ei=
);
             }
         }
     }
@@ -99,11 +103,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin=
_id_t id,
                                            const qemu_info_t *info, int ar=
gc,
                                            char **argv)
 {
-    addrs_ht =3D g_hash_table_new(NULL, g_direct_equal);
+    addrs_ht =3D g_hash_table_new_full(g_int64_hash, g_int64_equal, NULL, =
g_free);
=20
     insn_count_sb =3D qemu_plugin_scoreboard_new(sizeof(InstructionsCount)=
);
     insn_count =3D qemu_plugin_scoreboard_u64_in_struct(
         insn_count_sb, InstructionsCount, insn_count);
+    current_pc =3D qemu_plugin_scoreboard_u64_in_struct(
+        insn_count_sb, InstructionsCount, current_pc);
=20
     for (int i =3D 0; i < argc; i++) {
         char *opt =3D argv[i];
@@ -124,13 +130,13 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugi=
n_id_t id,
             exit_on_icount =3D true;
         } else if (g_strcmp0(tokens[0], "addr") =3D=3D 0) {
             g_auto(GStrv) addr_tokens =3D g_strsplit(tokens[1], ":", 2);
-            uint64_t exit_addr =3D g_ascii_strtoull(addr_tokens[0], NULL, =
0);
-            int exit_code =3D 0;
+            ExitInfo *ei =3D g_malloc(sizeof(ExitInfo));
+            ei->exit_addr =3D g_ascii_strtoull(addr_tokens[0], NULL, 0);
+            ei->exit_code =3D 0;
             if (addr_tokens[1]) {
-                exit_code =3D g_ascii_strtoull(addr_tokens[1], NULL, 0);
+                ei->exit_code =3D g_ascii_strtoull(addr_tokens[1], NULL, 0=
);
             }
-            g_hash_table_insert(addrs_ht, GUINT_TO_POINTER(exit_addr),
-                                GINT_TO_POINTER(exit_code));
+            g_hash_table_insert(addrs_ht, &ei->exit_addr, ei);
             exit_on_address =3D true;
         } else {
             fprintf(stderr, "option parsing failed: %s\n", opt);
--=20
2.39.5