From patchwork Wed Jun 26 23:37:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 807525 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp546054wrn; Wed, 26 Jun 2024 16:39:48 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWksdMftbrcSPtPqN2LXetQGAJQXjslh7lIAZQ+4UrpYvNczBUS9nll9Zxswy4qTvUHfQJwNnK9nVvgAHMb+q2I X-Google-Smtp-Source: AGHT+IG6Ldme3k7jVVQ8sTyuP2Wq9p02Q8BmOAitujxgLOehZ1lQEKJSR2e0cXezPrs04yTndcK+ X-Received: by 2002:a05:6808:1b09:b0:3d2:1b3a:d073 with SMTP id 5614622812f47-3d545a88fc3mr13673806b6e.57.1719445187898; Wed, 26 Jun 2024 16:39:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719445187; cv=none; d=google.com; s=arc-20160816; b=oypgGDTdiRZNbt3TKTo9Zt5fqyg2ljofeOk0GfbuyUim8fEwP7/euyUDexGshf/jYF qN17OI5uj7P5IlEJeYo1Ii74GMGFq9L5/9t+vwRF3hnGOPiYJLTViBAUKAtPfYhAAIdJ YSOlaCisRXeexJal/d9p1fbhEfxq8den7CqwrEsx6DFrUpMAFGqODg+Qy+m591drrXG9 yV8QTKWdlYwUfm9B5uxDlrLnGnX/aJbbbD7LRcuLJK2Li4tRxeaO/ZVNwAEMFawSPzaN k2RnilNHsi2Z3uEH+K7CBztGzNjhhgLlLLcXPZCKcjhzGggdUGnhi9h/5mQ7961JuJ8P G2fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jtCGpIl6luQ3ISJAfvlxdEXOg6zayrBpIY7vxCz1GF8=; fh=t+og6vq6PhvWUJH0MmfTYZOEuVFiDGq3dRDviuzY8a8=; b=YpwlMRxy1b5bkhjwlDrFN0XOHAISnmR/z9S8ig6MNCeNBpyl0vOVARitJSXco6dU7v iGLFVrFafJTunqNKRDhDMqAN4SFP8uyNftsN/6ZjYVGIXoUFwi+d9iYzsQO9r6QQGlI7 SqNe9x3W2yPvPs3VYNuA843AOaR+1pY9oKRo2XDRouT9Lpm6Y+8pyGc2AMaqJDKBjFQA R3fqaJHEHcoDjXGAyV1DSirbiuFc1ByW3TKp/RU/tYLeYQaZxg3VDqY30BYpW0tFYFMp uTBsQr+YPFxDR0PjqnJOHfjHqlsQakYoj1tFzr3EDm1k5ucrRT66K38NteQwKJJnwPmF peXA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9ZVyQh1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id af79cd13be357-79d5c8c4961si15240785a.662.2024.06.26.16.39.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Jun 2024 16:39:47 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=C9ZVyQh1; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sMcDj-0007U7-MQ; Wed, 26 Jun 2024 19:38:39 -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 1sMcDO-0007Se-Ql for qemu-devel@nongnu.org; Wed, 26 Jun 2024 19:38:15 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMcDM-0007Ka-Hy for qemu-devel@nongnu.org; Wed, 26 Jun 2024 19:38:14 -0400 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1f9de13d6baso52783615ad.2 for ; Wed, 26 Jun 2024 16:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719445090; x=1720049890; 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=jtCGpIl6luQ3ISJAfvlxdEXOg6zayrBpIY7vxCz1GF8=; b=C9ZVyQh1fFnjDN09RuYGfJwJpcBtqT9MOX9Hi2xAQ1xV7NmOGGjLiFMJVo4ERxebro Bx+uILkFJYDeV1Qdf/SL8vWx4tB2y+mJ5ct/feyEizwg9SdYbS7Vdti0WFN/euhyOvCf zyJXwk9R8izGfLhMAMJWEDGTtwCMS7chK9NZ8MBSq5jz6J6qirY1jyyIGEFy1aawkFUE OnIrIBe5nuwj0Zfk5y1ITMEdGYEjLLIj41b9wlaV6ATEpOQYaTXNT45xpYajpSgvhHZx 4lo7XynKW4Wx9lIAd0lgUMEowd8s3ujz/3BPLL1UHHFmPrmbpQoyoZJg5YjKmHk7y3He vxUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719445090; x=1720049890; 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=jtCGpIl6luQ3ISJAfvlxdEXOg6zayrBpIY7vxCz1GF8=; b=cZceDWudVjeTjtrNH+qpccZxSerP7t01i2XfkcV5mpDCCqptfD8G5KqNJUZ+fVlSpY GJju2HQ8AXyLfR3GmgBOwFiKQXeT+lba2Fh7NriYWkRG7Anl/kl5UAml2an/Ffmm4D/Y l9lTEed0vgwMIzKrqtEU5NMXIOY3544617TLeV3TmakHkbKjVgrtql7zVqHw0BpDIzji 5hOvTDd5G5CSLtIgmvp/whjl52MPiUQjvDFKPBmu9TdxSsP81Ex7niOgNzRhTcgUzxZp YJNba/r0091KKuj4d3GyHZDQSNjzlHROVEP6fG4Z4YcugeC94N8HN6mSZUZUEodY4TgF 2FXw== X-Gm-Message-State: AOJu0YzDS1de0EWJPZxAK8MpmVOBz/X1jzsag2nXagnzgCQrrHMA5dAI NrY01EIvFK2CHNWgov8Ln+QF9JmXy1GRMowAUU3+TkKQcVFgjEv61L+EKXISksctTkid6U5/OFl MwIw= X-Received: by 2002:a17:902:c40e:b0:1f9:f3c6:ed37 with SMTP id d9443c01a7336-1fa23f22771mr139607805ad.14.1719445089760; Wed, 26 Jun 2024 16:38:09 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1faac8df624sm563055ad.29.2024.06.26.16.38.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 16:38:09 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud?= =?utf-8?q?=C3=A9?= , Pierrick Bouvier , Mahmoud Mandour , Paolo Bonzini , Eduardo Habkost , Richard Henderson , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= Subject: [PATCH v2 6/7] tests/plugin/mem: add option to print memory accesses Date: Wed, 26 Jun 2024 16:37:56 -0700 Message-Id: <20240626233757.375083-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626233757.375083-1-pierrick.bouvier@linaro.org> References: <20240626233757.375083-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x631.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: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org By using "print-accesses=true" option, mem plugin will now print every value accessed, with associated size, type (store vs load) and symbol where this happens. Signed-off-by: Pierrick Bouvier --- tests/plugin/mem.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/plugin/mem.c b/tests/plugin/mem.c index b650dddcce1..d897034a044 100644 --- a/tests/plugin/mem.c +++ b/tests/plugin/mem.c @@ -24,7 +24,7 @@ typedef struct { 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 = QEMU_PLUGIN_MEM_RW; @@ -60,6 +60,20 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, } } +static void print_access(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo, + uint64_t vaddr, void *udata) +{ + unsigned size = 8 << qemu_plugin_mem_size_shift(meminfo); + const char *type = qemu_plugin_mem_is_store(meminfo) ? "store" : "load"; + uint64_t upper = qemu_plugin_mem_get_value_upper_bits(meminfo); + uint64_t lower = qemu_plugin_mem_get_value_lower_bits(meminfo); + const char *sym = udata ? udata : ""; + g_autoptr(GString) out = g_string_new(""); + g_string_printf(out, "access: 0x%.0"PRIx64"%"PRIx64",%d,%s,%s\n", + upper, lower, size, type, sym); + qemu_plugin_outs(out->str); +} + static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) { size_t n = qemu_plugin_tb_n_insns(tb); @@ -79,6 +93,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) QEMU_PLUGIN_CB_NO_REGS, rw, NULL); } + if (do_print_accesses) { + const char *sym = qemu_plugin_insn_symbol(insn); + qemu_plugin_register_vcpu_mem_cb(insn, print_access, + QEMU_PLUGIN_CB_NO_REGS, + rw, (void *) sym); + } } } @@ -117,6 +137,12 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, fprintf(stderr, "boolean argument parsing failed: %s\n", opt); return -1; } + } else if (g_strcmp0(tokens[0], "print-accesses") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], + &do_print_accesses)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + return -1; + } } else { fprintf(stderr, "option parsing failed: %s\n", opt); return -1;