From nobody Sun Nov 24 07:49:42 2024 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=1725977346; cv=none; d=zohomail.com; s=zohoarc; b=ch8V2qzG3dBi6yUi8+DaVSSiILqrCKROkMi01a0evrtGFPnhgMMns7aeB3N4d6uMyA5ZOoIHAhyjv8lyhoL/0QvrNwuuuEQjFjT3mkpqA6nSDxIY7eG1zbIBNztd5A+XZnWgdRWTT92Eqa7j7z11o4HJG4yWmj95o7y2acFeu5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725977346; h=Content-Type: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=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; b=bhkou+ry3HERb+voQ7Ls30sBMQ9ZQB0n6DfRZ87mxFxhahigk0coS7IGkpD28uzBZMZHvKUulsjbbN7Odl2mgWfL5pDz/4gma7PWH+DnGRATdW7GRoCzj75h14DtYTEwD9H4QuKrroW/YQtna8xzHb5LthWd+oSeh1VKMzwObcM= 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= (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 1725977346552839.4210160584081; Tue, 10 Sep 2024 07:09:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1so1XB-00005C-85; Tue, 10 Sep 2024 10:07:57 -0400 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 1so1X8-0008GV-3C for qemu-devel@nongnu.org; Tue, 10 Sep 2024 10:07:54 -0400 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1so1X4-0006ZO-O9 for qemu-devel@nongnu.org; Tue, 10 Sep 2024 10:07:53 -0400 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a8a897bd4f1so581114566b.3 for ; Tue, 10 Sep 2024 07:07:50 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25cea3e1sm482516466b.167.2024.09.10.07.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 07:07:42 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id 74CEF5F7B4; Tue, 10 Sep 2024 15:07:35 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725977269; x=1726582069; 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=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; b=bwZPAxUOz8fDk0nuJ8Nw6Ziy6JJ2cUV5PLew3t4woDjflcUzSlB+GA+CJopn2JcNQV kdHmbdGq/YmfXPH08F3Iyymi6NOWvGPH6630p1F6a1I8DGy5XjeTp4KxkEBiJayWGMYj S4pfHwb+iZGokZEvTLBYJN6ALTaZP95Qp0F/7aTt+q7Jb4ng++IoixfDDFzGUZneHz9Z QCUNJjLGuIGGK3PoJvcar5nBc9vnT3mD0L7WX8bebBOVDf79DUndlYTYRpR6Ip+wU64l eenF5XtsuKC8MjjKiHSNtdN/fD97Kho9MGhj2bdIkact0X6JFS2Sn0gJrcVaXm62sM/Z 7jcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725977269; x=1726582069; 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=tNcKpK3gqW5pd0AiX4NmCCbDvgLi1QOfUkQVya3+J3c=; b=n+20q5rLKkGkm+yuGi0RX9wpd7WY+SA+eKfyvkKngzJAzJEzv+ASFN51aoNqfdGLZU zH2BaUMPIJjeSG+5AzdHukIdhHqRdY6oxE3/qBp1vmd/Tw0cgopwqCBWaMsocJNwoaLs aBTT+j1cCqsvfG0ljy0zU3YNp5JDKrXezKXDGM0B4VAIXQkHUKXnWaVPG0WppASfq+yA FZrJ/P2mm9WksR+7hVMRFQhUvHN+lfkeinat4hBs0TrY+jjJNiVa4gaGqA2GFnr1GagO MZwxC5C4i9NFa2gqh8XI18vZ3Zs+2getsAH3Ay8L/AC4pcuoxHnMABYfwKyY+SlzWH+B O+xw== X-Gm-Message-State: AOJu0YzIXrhnO03xMvIwugfQWR7IuKqtZQ202aEwtSIn50rVnNdrqpnX Dcj/iIfkiZpyu3R9Tbh/QOUfvMi+QUt3KQColH64W3Q5cik4TiWntwr02VqBNLM= X-Google-Smtp-Source: AGHT+IF0irRXfjqUTLP0ADVFD7/rZSWwKBMZaLQ/m4gUJjLt0sjcRBJLb/Iyj9rBZ5om/rHGXGJGDw== X-Received: by 2002:a17:907:2684:b0:a72:9d25:8ad3 with SMTP id a640c23a62f3a-a8ffaa93bc5mr95735566b.9.1725977268733; Tue, 10 Sep 2024 07:07:48 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Eduardo Habkost , Zhao Liu , Marcel Apfelbaum , Beraldo Leal , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alexandre Iooss , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Pierrick Bouvier , Yanan Wang , Peter Maydell , Mahmoud Mandour , Thomas Huth , qemu-arm@nongnu.org, devel@lists.libvirt.org, Jiaxun Yang , Paolo Bonzini , Richard Henderson , Wainer dos Santos Moschetta , Xingtao Yao Subject: [PATCH 18/26] tests/plugin/mem: add option to print memory accesses Date: Tue, 10 Sep 2024 15:07:25 +0100 Message-Id: <20240910140733.4007719-19-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240910140733.4007719-1-alex.bennee@linaro.org> References: <20240910140733.4007719-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=2a00:1450:4864:20::630; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x630.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=unavailable 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: , 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: 1725977348770116600 From: Pierrick Bouvier By using "print-accesses=3Dtrue" option, mem plugin will now print every value accessed, with associated size, type (store vs load), symbol, instruction address and phys/virt address accessed. Reviewed-by: Richard Henderson Reviewed-by: Xingtao Yao Signed-off-by: Pierrick Bouvier Message-Id: <20240724194708.1843704-6-pierrick.bouvier@linaro.org> Signed-off-by: Alex Benn=C3=A9e --- tests/tcg/plugins/mem.c | 69 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/tests/tcg/plugins/mem.c b/tests/tcg/plugins/mem.c index b650dddcce..086e6f5bdf 100644 --- a/tests/tcg/plugins/mem.c +++ b/tests/tcg/plugins/mem.c @@ -21,10 +21,15 @@ typedef struct { uint64_t io_count; } CPUCount; =20 +typedef struct { + uint64_t vaddr; + const char *sym; +} InsnInfo; + static struct qemu_plugin_scoreboard *counts; static qemu_plugin_u64 mem_count; static qemu_plugin_u64 io_count; -static bool do_inline, do_callback; +static bool do_inline, do_callback, do_print_accesses; static bool do_haddr; static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; =20 @@ -60,6 +65,44 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin= _meminfo_t meminfo, } } =20 +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t mem= info, + uint64_t vaddr, void *udata) +{ + InsnInfo *insn_info =3D udata; + unsigned size =3D 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type =3D qemu_plugin_mem_is_store(meminfo) ? "store" : "lo= ad"; + qemu_plugin_mem_value value =3D qemu_plugin_mem_get_value(meminfo); + uint64_t hwaddr =3D + qemu_plugin_hwaddr_phys_addr(qemu_plugin_get_hwaddr(meminfo, vaddr= )); + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "0x%"PRIx64",%s,0x%"PRIx64",0x%"PRIx64",%d,%s,", + insn_info->vaddr, insn_info->sym, + vaddr, hwaddr, size, type); + switch (value.type) { + case QEMU_PLUGIN_MEM_VALUE_U8: + g_string_append_printf(out, "0x%02"PRIx8, value.data.u8); + break; + case QEMU_PLUGIN_MEM_VALUE_U16: + g_string_append_printf(out, "0x%04"PRIx16, value.data.u16); + break; + case QEMU_PLUGIN_MEM_VALUE_U32: + g_string_append_printf(out, "0x%08"PRIx32, value.data.u32); + break; + case QEMU_PLUGIN_MEM_VALUE_U64: + g_string_append_printf(out, "0x%016"PRIx64, value.data.u64); + break; + case QEMU_PLUGIN_MEM_VALUE_U128: + g_string_append_printf(out, "0x%016"PRIx64"%016"PRIx64, + value.data.u128.high, value.data.u128.low); + break; + default: + g_assert_not_reached(); + } + g_string_append_printf(out, "\n"); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n =3D qemu_plugin_tb_n_insns(tb); @@ -79,6 +122,16 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct q= emu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + /* we leak this pointer, to avoid locking to keep track of it = */ + InsnInfo *insn_info =3D g_malloc(sizeof(InsnInfo)); + const char *sym =3D qemu_plugin_insn_symbol(insn); + insn_info->sym =3D sym ? sym : ""; + insn_info->vaddr =3D qemu_plugin_insn_vaddr(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) insn_info); + } } } =20 @@ -117,6 +170,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") =3D=3D 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", o= pt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1; @@ -129,6 +188,14 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin= _id_t id, return -1; } =20 + if (do_print_accesses) { + g_autoptr(GString) out =3D g_string_new(""); + g_string_printf(out, + "insn_vaddr,insn_symbol,mem_vaddr,mem_hwaddr," + "access_size,access_type,mem_value\n"); + qemu_plugin_outs(out->str); + } + counts =3D qemu_plugin_scoreboard_new(sizeof(CPUCount)); mem_count =3D qemu_plugin_scoreboard_u64_in_struct( counts, CPUCount, mem_count); --=20 2.39.2