From patchwork Tue Jun 1 14:58:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 451375 Delivered-To: patch@linaro.org Received: by 2002:a02:c735:0:0:0:0:0 with SMTP id h21csp1860010jao; Tue, 1 Jun 2021 07:58:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzO4/y370/i4cp+z+aCDRoQqdeqhR34LU4HmqT8XqktqaNib0uJxV2L9LVX7oe5WOddHLD X-Received: by 2002:a1f:9a04:: with SMTP id c4mr7120303vke.5.1622559527130; Tue, 01 Jun 2021 07:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622559527; cv=none; d=google.com; s=arc-20160816; b=khpkoKEvza2NsEpSUQXAAzHFQY4lKWC7jTZUMNOvFNA8+WDN0/vcyjDNOScQryM3+6 EGmWM2N7JBBZwdZA6VOnNDxDX6PomjK9Fklk475wGTUjMzIMO0OUOnWrPj0NS15EZCp2 kGOWi1Y5zO1Cj+QL80x0VOjYndUFCb4bI1Jq5Xs/79qtlI+Qx+gaH+BO1pUNwPFPf6Vw 9WZ+1G2kxcL607x2BSxkei3aGWXgX9Nelu68LUrShcm2S8M34lTZoLiObIEVdXl5sf3C C2cECNquNsJ7EzPKD/NJYAbnaQexvwrlaqYlheqTUdXJhrHo056sDDawV3kfXr1st2k3 0bIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=0c7U9YSGHoDKB0a+mdBVqHKkv/WspMF3GKbrs2/yiWs=; b=x0BmNZRPh0155AmNJOpXmd4f9Vr24Zqnuhw0V0hf2OxbCzu8cmI9Gwp+Y8vq5ZqsuC KPH9WVgPmqvK8aJVdm5mnakXfaoEmzbBIYFk1BIAho4+p85DyM3g+7SXZku6SFJCkggF WvCBYQCw5f2U7TlAuXdVGw+OKQV1jtdYla5Frv6sKiw/ib7QdhLjtHMdELPGgxIIqlJN 3egrALZV4CuXK+h6JWdk2RBPNl44UcXICkxDtlQLBa0icUMUyonHxDsKSghpAxbl1rqG iya6msZTNXOWuutj6yxBhx6SmAmD+chwB5VPmgbwpAZxaqn/Uufzz5mNlBbddjd+3cMK pnnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=mjfRk8FE; 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=fail (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 z4si7719045uai.4.2021.06.01.07.58.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Jun 2021 07:58: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=fail header.i=@linaro.org header.s=google header.b=mjfRk8FE; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lo5qw-0007W8-Id for patch@linaro.org; Tue, 01 Jun 2021 10:58:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lo5qn-0007Vn-5X for qemu-devel@nongnu.org; Tue, 01 Jun 2021 10:58:37 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:43760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lo5ql-0000ee-7d for qemu-devel@nongnu.org; Tue, 01 Jun 2021 10:58:36 -0400 Received: by mail-wm1-x330.google.com with SMTP id 3-20020a05600c0243b029019f2f9b2b8aso1027743wmj.2 for ; Tue, 01 Jun 2021 07:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0c7U9YSGHoDKB0a+mdBVqHKkv/WspMF3GKbrs2/yiWs=; b=mjfRk8FE985nf+zUr1tlNMdYQWLJ+ITj6eU6qFmNk13acGqpmMKmiaOhHGGIRoGcED OR6Ne/Bfd0fCHGiSNu4NLpSntaDwnvcRKh2v8ghUe9LyNDjaFB4BNtgPUCC1BnehOtMF wFUB+DNxotRcMtDpPKICES/iYkF+aBzDGFRHY/dqgfpTYIlU1VMQYzFXYufURk5aYeKN vRXvMYtn9TijRmgDfBNzRIpHPHY78GiwA9tJRH4LuYSyCP5ALhwxPdrfVMy8UWRhiGkN WeANu2f/7smWKqL0Kjol1dpuZF4UklS/2J4fechDQeRxhOPiAJCQfj4Toe37brNfCb+B ib9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0c7U9YSGHoDKB0a+mdBVqHKkv/WspMF3GKbrs2/yiWs=; b=jc8zqTclUDvR+YYF2LKWkOUN3NfJ/+HNCQjdpXiZYE7BkB9EPYQFsarYP/rHqmBnXt 29D54R2PJ44DJeSWgEiDnJJSpldgPe2sMFICzdVKFabKL1afhhsgfK8tfm7AaGYNwkzc w3Z50ZD0/Sz8z/foxhgSY1elrpOeo3+3T4VD0zZr//DyvC0hikbxGrPZgOpBdwRhMOr9 q2zGJSZB3Fxzh2gh7XlgS+81koIQyKU6zCFlZDjVU3WPlnhieD90EW1gAD0lvzfIfWec AJrBv/l+kc++3pcUZoDS0EmpxYFygVyPyS2IiosP3RljCU1P8z9YahUmNQUDt+Ytwfwd OZ5w== X-Gm-Message-State: AOAM531+X+F7D6z8R353QyhsBTNpVSO9/mxlmdIRkTTn9HMvwfQ9AzwL fO0B9Z2totKI36fHnNUpAjde6A== X-Received: by 2002:a1c:1b93:: with SMTP id b141mr16036263wmb.8.1622559513192; Tue, 01 Jun 2021 07:58:33 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 89sm4127457wrq.14.2021.06.01.07.58.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Jun 2021 07:58:32 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 757091FF7E; Tue, 1 Jun 2021 15:58:31 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] plugins/api: expose symbol lookup to plugins Date: Tue, 1 Jun 2021 15:58:24 +0100 Message-Id: <20210601145824.3849-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x330.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: minyihh@uci.edu, robhenry@microsoft.com, mahmoudabdalghany@outlook.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a quality of life helper for plugins so they don't need to re-implement symbol lookup when dumping an address. The strings are constant so don't need to be duplicated. One minor tweak is to return NULL instead of a zero length string to show lookup failed. Based-on: 20210530063712.6832-4-ma.mandourr@gmail.com Signed-off-by: Alex Bennée --- include/qemu/qemu-plugin.h | 9 +++++++++ contrib/plugins/cache.c | 10 ++++++++-- plugins/api.c | 6 ++++++ 3 files changed, 23 insertions(+), 2 deletions(-) -- 2.20.1 Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 97cdfd7761..dc3496f36c 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -525,6 +525,15 @@ qemu_plugin_register_vcpu_syscall_ret_cb(qemu_plugin_id_t id, char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn); +/** + * qemu_plugin_insn_symbol() - best effort symbol lookup + * @insn: instruction reference + * + * Return a static string referring to the symbol. This is dependent + * on the binary QEMU is running having provided a symbol table. + */ +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn); + /** * qemu_plugin_vcpu_for_each() - iterate over the existing vCPU * @id: plugin ID diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 1e323494bf..afaa3d9db5 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -46,6 +46,7 @@ enum AccessResult { struct InsnData { char *disas_str; + const char *symbol; uint64_t addr; uint64_t misses; }; @@ -377,10 +378,12 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) struct InsnData *idata = g_new(struct InsnData, 1); ddata->disas_str = qemu_plugin_insn_disas(insn); + ddata->symbol = qemu_plugin_insn_symbol(insn); ddata->misses = 0; ddata->addr = effective_addr; idata->disas_str = g_strdup(ddata->disas_str); + idata->symbol = qemu_plugin_insn_symbol(insn); idata->misses = 0; idata->addr = effective_addr; @@ -397,8 +400,11 @@ static void print_entry(gpointer data) { struct InsnData *insn = (struct InsnData *) data; g_autoptr(GString) xx = g_string_new(""); - g_string_append_printf(xx, "0x%" PRIx64 ": %s - misses: %lu\n", - insn->addr, insn->disas_str, insn->misses); + g_string_append_printf(xx, "0x%" PRIx64, insn->addr); + if (insn->symbol) { + g_string_append_printf(xx, " (%s)", insn->symbol); + } + g_string_append_printf(xx, ", %lu, %s\n", insn->misses, insn->disas_str); qemu_plugin_outs(xx->str); } diff --git a/plugins/api.c b/plugins/api.c index 817c9b6b69..332e2c60e2 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -233,6 +233,12 @@ char *qemu_plugin_insn_disas(const struct qemu_plugin_insn *insn) return plugin_disas(cpu, insn->vaddr, insn->data->len); } +const char *qemu_plugin_insn_symbol(const struct qemu_plugin_insn *insn) +{ + const char *sym = lookup_symbol(insn->vaddr); + return sym[0] != 0 ? sym : NULL; +} + /* * The memory queries allow the plugin to query information about a * memory access.