From patchwork Wed Jun 26 23:12:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierrick Bouvier X-Patchwork-Id: 807514 Delivered-To: patch@linaro.org Received: by 2002:adf:e842:0:b0:362:4979:7f74 with SMTP id d2csp539217wrn; Wed, 26 Jun 2024 16:14:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVYOcUTXRMq4QiGrUvWUW+Bun0BfuBxLmaOQ/qHiDxe+Waj04wNRds7VNH2pLpBOCX2Ol70q8NiPE09XqWECfrU X-Google-Smtp-Source: AGHT+IFx6ZyX4/93WFYmYB9wlXWu+4BXbKlusyw5JatSQQERaDgY9s1yKPRaJV5iXLSNYguF/N4a X-Received: by 2002:a05:6214:57d0:b0:6b5:4435:fe4f with SMTP id 6a1803df08f44-6b544360a71mr103507936d6.64.1719443649832; Wed, 26 Jun 2024 16:14:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1719443649; cv=none; d=google.com; s=arc-20160816; b=e3DnjAuqGh/+5p7HvQJFpxCSRmRX31VHXZwFKXxptKX5o8nuEQ5owtVBhSaPl4q/kS AeX+JVORrKK2e9vNJQoIY8M0bBGvumBfRcknoFtLGTkZkarMb4GrOcNH3d0f3HSon5V8 7o/7jJN+tHl0wWYlhi3YtwA6242N5rukbQKWCSz6CcTejDmfmIEMXhJvemRk7XkSR2hF 2xjNs/ap/Jm1oZSOsGBUrybuRHL6IgpCX9zrI0kujLzPAfzWpaWM0znVHExsQ5e0K/Am vOorDTL2Da3kpvCkEScE9K8bX+y6iAUwZM5ou1N+GzNOOLxjNvz7Bl/7qXfPThD9jvGN 0+1g== 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=WQ0fQ4sUzgT0xo1UK8NVSlSI80y+/XkhC1sdM3re38s=; b=P4CdkNYonflfBeFl4OP2JHUNK2C6p/vljuEOHC6WLYw5q7XkaI+BgVoJC1JiunGnWJ kKPFRlezUc+grR2hwKb++3lJgcWZTrkZs6js15Vt7ydcv6f9gmvfzjf8dQyjZYjyNtR0 GeQZzz3Nu0PLg9RJhxg985W5oFF5Mx9cr75AwkMFE+zjQEJnDesrLOWKwWmhjQl8eRFx JZL6U/x8W509UCr53EjLkEnyTWVlEkSca99//+0/AmuNWl2KNfnKYL4rmtfltO/xRvm9 Uy1QfQQmxAnmec4HGftGfoLSgjgBAoK11VNlERelmdsJZ09y1cd3RzjkjYwa7nzgxva+ KlWw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=btot52pc; 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 6a1803df08f44-6b592416826si839966d6.63.2024.06.26.16.14.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 26 Jun 2024 16:14:09 -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=btot52pc; 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 1sMbpF-0003Bn-Fy; Wed, 26 Jun 2024 19:13:17 -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 1sMbp9-00039S-DF for qemu-devel@nongnu.org; Wed, 26 Jun 2024 19:13:12 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sMbp6-0000PB-KQ for qemu-devel@nongnu.org; Wed, 26 Jun 2024 19:13:10 -0400 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1f9fb3ca81bso34335585ad.3 for ; Wed, 26 Jun 2024 16:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1719443587; x=1720048387; 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=btot52pcmJkIttEQiOHpjsvXZgZeLdvJvW/PGfbaalpnfVuvtuTZA1OdQim7tqqkUw d4b3hIRenCs5HhHoBA+GpGqiMP9hcjiMaGJJKGiJPHn0qmfjHgZxCukceOUXw1DulIvJ dDJr983aIQ/71n81+rhsnvK36o0zJK/fuWvMcDiF56dqYw7EesVHYu8bqJdKaM/fKLWR Osqke8HzkzjV7W8eCEOyHR3ZQ+Fqwz8EHX1rYXg6phxwhmZWzpsS+1CUvdNx+/f9pBrb YicZXq8chXivr7Sro4c62+7cErznxjMjaxvibqEC01A4DFllo8uuBzBVfITNigaquIu6 QtOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719443587; x=1720048387; 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=vQOZoynIBmeh8xf1+wJHQpAafPBUClMf0XiQTK5K5HISs6SynYaQw4OLcQk7BI5qPd 78r38LmG9y4xlOH6D/gNPeVk5RprSuAlbuCo4N1avM9fWHKdfWlm79qY/F0jl98+H4pA 2JX0qH7e9aWY7O75WQYNCBS9q+ZeSvoPcC65Lmk5qpddulAu/wgetm15GuHvFXgNhfCL kz0kvSWAF55v9K3vAgwe8bpCzPDXrcGYsKNiTaku6vkUfwDGcd+RuCEFdTn/aW2PdGW/ cLM0rOgCNki817Bw993EknuMcSS5vd24F4Jq/G1+gdnTrfUWfP7hYJUIv3nO6xqGNzL+ RIZg== X-Gm-Message-State: AOJu0Yx+FwUxwCVKu6tmhvPM02369/pWqo18Oe9yurVEwRP/ZNVOEr0W R0RDpG67pUkNZci0RdKIiiueI4hydXiK4BckSZcCQ2AZbPryaSgDsfubJBsKd3tHbwD653YPXcN AU8I= X-Received: by 2002:a17:902:f54c:b0:1f6:225e:67a1 with SMTP id d9443c01a7336-1fa2413cddemr139393005ad.56.1719443586759; Wed, 26 Jun 2024 16:13:06 -0700 (PDT) Received: from linaro.vn.shawcable.net ([2604:3d08:9384:1d00::2193]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1faac82cd3bsm478215ad.0.2024.06.26.16.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jun 2024 16:13:06 -0700 (PDT) From: Pierrick Bouvier To: qemu-devel@nongnu.org Cc: Pierrick Bouvier , Mahmoud Mandour , Paolo Bonzini , Eduardo Habkost , Richard Henderson , Alexandre Iooss , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , =?utf-8?q?Alex?= =?utf-8?q?_Benn=C3=A9e?= Subject: [PATCH 6/7] tests/plugin/mem: add option to print memory accesses Date: Wed, 26 Jun 2024 16:12:54 -0700 Message-Id: <20240626231255.339353-7-pierrick.bouvier@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240626231255.339353-1-pierrick.bouvier@linaro.org> References: <20240626231255.339353-1-pierrick.bouvier@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::632; envelope-from=pierrick.bouvier@linaro.org; helo=mail-pl1-x632.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;