From patchwork Wed Jun 23 10:27:48 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: 465898 Delivered-To: patch@linaro.org Received: by 2002:a02:c94a:0:0:0:0:0 with SMTP id u10csp1604951jao; Wed, 23 Jun 2021 03:35:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy8X077/qDRJUJdnbRNizhJUwIhV0tERy4IYJPB+8kOWEEj2IwVAcXYWs04AmcEs7MKOYj X-Received: by 2002:ae9:ef41:: with SMTP id d62mr4568504qkg.264.1624444533979; Wed, 23 Jun 2021 03:35:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624444533; cv=none; d=google.com; s=arc-20160816; b=b21Z+m82r5whHY16pDjlH0abt9ZgZnr+eJ5OmgKVzI+oLnzZ0lmqLC3aMk65IeNhKw G1VF9PnrMW0x5jjJ0wU/kAU8dfnIeZNlTXfOGmTYb0Z0NbI+NQmx7jTBcu2HGAt8LpUr 4jq0dxgZtbwyNbX6VytGJz0lMCyO0KekCpuHp68nfpt/QTYcGDJOi77sRS2P+BJx3cKU 0zF1kuC9/2SxNtd2vk2q9+mberIM82ma5ifta39RwvN9EhZbamUBTkAZeglEwkaDgFd7 agKHoyQIE/oc/wlFtgsI7MLP0AAAG1e7k0MzBneA98UFXIkw4H+WF0HHT+7MZ8Sd3Qvj IV2A== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=7Csq3L73UZfDLRhp+50fvannHlui5uKUq6fhdlJrVjY=; b=LxluOvcJorYfGZPH9MUt3nEEDDbp5xvbz2cuTvSdI/Q75zCqmqj3TvQDNTOyZGlAxi yhyPSMweQ23lG54e9qGxe50TAerZzIRm61U5RwgfQRbol5BotIjGiRnyQE8BCs1NV4l2 HLmPBgbOs83HIl6GyI7DEKVvv/xWroRnd9nKm9VTvLEJdqhOfvn9kks559PWO1MWpy05 Pjr72bR6OK7AJ7C9EEfpJ/MZLSQEA1GBWMrrcBHjO4OjwpYclVHRDMcjzABs263dK1vk YjFBxFEPrtKbeuJj4aWOqr/+uGLi5TBiG1SC6/GtMB/D9u+HL7R+Pxue2S6kdJeoWxbZ 3iZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=HCpNtft9; 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 f6si3921558qth.90.2021.06.23.03.35.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 23 Jun 2021 03:35:33 -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=HCpNtft9; 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]:56280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lw0EH-000520-4E for patch@linaro.org; Wed, 23 Jun 2021 06:35:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lw0Dz-0004yB-Md for qemu-devel@nongnu.org; Wed, 23 Jun 2021 06:35:15 -0400 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:37863) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lw0Dx-0005wc-5g for qemu-devel@nongnu.org; Wed, 23 Jun 2021 06:35:15 -0400 Received: by mail-wr1-x432.google.com with SMTP id i94so2068830wri.4 for ; Wed, 23 Jun 2021 03:35:12 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Csq3L73UZfDLRhp+50fvannHlui5uKUq6fhdlJrVjY=; b=HCpNtft9zPqrED1fFB0ToTHOqNcWI9rTNtctgcjnMGo6rnJN6H+JBkoYL59V/2p+9g fBHEQfLUj3gLksSZ+7+8szyMWr7a6UtYGGivUl0byslB3KleXek717wQ3TdDtOISKok3 pR9GI5oQUgsFZ6QF0FTL5BbAhzGkIu/iZQiz02osIboIZ7WSJUErTywMFDbguo6JoI6d cOjhfwmgZVJ1b6QVHdavQ/6HqDdnSRaKVG24b+LUM2rSWDwskCqOhUKtqF8RpLAtymfd aRivyBzVKAqHgKcEf9eFlMYUcQvorkQBAA2owffiTUztTOgu6/KOJe/Qf8yjjsnRjgRr SiPg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Csq3L73UZfDLRhp+50fvannHlui5uKUq6fhdlJrVjY=; b=cRmIaOvGbPGdQMWOOOesEyGG3hljN8RxqbCob+8qe3PRxKvJgNUgUdfNzRirPlMxlB NhD3Phgh9T+8CgYEJofECurkoh6jG9QtHRDHdRn/6zdJx0jfMzwM6Qmi95JUtMUdkNSQ 7UmlkxHFMXsBDKQ2VD0l67GURnfYsC7VJckZ0FheNIk0Y7c/z1OUWA9sv0nctzka62Me Fyhd0ls/vsDmov59WeQ67vnOe/r6EcR0QUYMP+d1Br4x0LxkE9GgpB+fr9QOd5JFjnF/ xS0gZOrPACdySUZnoW9ms7ZHCD3harUqPtQwWHRRJ4sjpAbmB07yYCGthZqq2vUMaNyS wcsw== X-Gm-Message-State: AOAM530ETRfx+7xtbwLehNIKp//kTaz8rALCWmvI/eu1GJoU68hQAx1S TvXp7Wdq9v7gSKIdGXYMOKaLVI6ZcsYQ8g== X-Received: by 2002:adf:f088:: with SMTP id n8mr10584374wro.227.1624444511857; Wed, 23 Jun 2021 03:35:11 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n18sm5492764wmq.41.2021.06.23.03.35.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:35:10 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 557771FF93; Wed, 23 Jun 2021 11:27:50 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 7/8] plugins/api: expose symbol lookup to plugins Date: Wed, 23 Jun 2021 11:27:48 +0100 Message-Id: <20210623102749.25686-8-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210623102749.25686-1-alex.bennee@linaro.org> References: <20210623102749.25686-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x432.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: Mahmoud Mandour , =?utf-8?q?Alex_Benn=C3=A9e?= 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. Signed-off-by: Alex Bennée Message-Id: <20210601145824.3849-1-alex.bennee@linaro.org> Signed-off-by: Mahmoud Mandour Message-Id: <20210608040532.56449-2-ma.mandourr@gmail.com> --- include/qemu/qemu-plugin.h | 9 +++++++++ plugins/api.c | 6 ++++++ 2 files changed, 15 insertions(+) -- 2.20.1 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/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.