From patchwork Tue Feb 1 18:20:45 2022 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: 538960 Delivered-To: patch@linaro.org Received: by 2002:a5d:59ac:0:0:0:0:0 with SMTP id p12csp1061511wrr; Tue, 1 Feb 2022 13:07:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6ATeBkUMN/diOXW8BliuRQw6SffaBe8UzKreYMZMWPb8+IFM2PlgGElc/sOTX7hYgArgi X-Received: by 2002:a81:108b:: with SMTP id 133mr99940ywq.549.1643749647761; Tue, 01 Feb 2022 13:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643749647; cv=none; d=google.com; s=arc-20160816; b=PsDys/zm5MH4bVcnsClo7u/DjcEQc8x3F8r1wF3qMLlkSfRNWbU/HEu7BxNDECIFu6 djSq+kW7iDYmjIp4lJjw5sExKFtSzZRK003VJITeZep8NIr6ZqGucoRwgJrZ9PXWS5/B 3Z2ovPqVc78N/UjNhRRijnNPOrSeqcm+TlOrRHRQQUA/7CVzGUMkaH8ftMY9/STFRqsm vkaoCCNqpZk7s7bG/hLwYXLlDFYZzl1hpFPO1iWYjQtxFs+PgvSM0E88pxx0IMxr/ctG wuRuSVbMM/5ntQZBuL+y56eDhTd0V1jZW6sK2OgxlfgDaWjULOelSFQH6jkYRtoHLmxA zdfA== 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=eYKuNqQWbQA6VLRyOfqmdoksIAggzecx1ac/yhIpgTM=; b=0AIwN5fI4ztAvtLgAOL3WzMWibZo45NuF0fYdOvdORYYUKDQtyHHLUsR0h096zitKt qGIEjAf6Lbe5/Hq6vC5sNCznhH7DmrAWjjrbZmOxqbQFIq2ofOkQsjoNKav1nCPP7wMc RHxsYd16lFyhrv/mkuOQgtt0RHK7Ej9dSBj0FrqRlm2Sm86aSNuoQTFw2k/q9FRfCsRI yG1E2WeyzykU38q3aXWfgEMzBaa+bYk0Fg0wcx/LKmFx7FrvEE/AzVUJX7KgNv8opyJD 799HdJQbEDICjGTZVB+AJt9uCrcssG4++S6hj/lBXq5lGC/NKW3LgS5S9EWl4oEn8EnW cUkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=fL1H1kI8; 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 n8si40958230ybc.160.2022.02.01.13.07.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 01 Feb 2022 13:07:27 -0800 (PST) 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=fL1H1kI8; 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]:47414 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nF0N5-0007PV-4A for patch@linaro.org; Tue, 01 Feb 2022 16:07:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nExtz-0002jM-H8 for qemu-devel@nongnu.org; Tue, 01 Feb 2022 13:29:15 -0500 Received: from [2a00:1450:4864:20::331] (port=33345 helo=mail-wm1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nExtx-0001h9-Ol for qemu-devel@nongnu.org; Tue, 01 Feb 2022 13:29:15 -0500 Received: by mail-wm1-x331.google.com with SMTP id n12-20020a05600c3b8c00b0034eb13edb8eso1777499wms.0 for ; Tue, 01 Feb 2022 10:29:12 -0800 (PST) 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=eYKuNqQWbQA6VLRyOfqmdoksIAggzecx1ac/yhIpgTM=; b=fL1H1kI8ftqFuOmJWZ03NTmcd6Ja5YYnqfsu8uq+yY1PWgaHpkuSRFC/kO3Jz6juxt aPXpb+FP7WXf+kY1Me1WlgmlSMKIKRSMppr3YxcPyczhhozk9pkiQE2pnk2nmVQTGRVa oTUX7rUooDL/i+9hpikSgEJOIPbnEMMGKk1fFPg4lwG+8wXq7k6qA3lDeuXsKUb3oHGz LI4znghd9/ZbVk/SgDYRucuK+B6D+Aav84OMbM/T06DBG9VwshfJvzcVnNzufDm3gH7m xHQvBsEKxKCHqOi8m4m2olY4NgDyty0Iow/ud9AKMQMUSkQurmnP3dRIII72hS/6LHE7 ZOig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eYKuNqQWbQA6VLRyOfqmdoksIAggzecx1ac/yhIpgTM=; b=xJI2C+o7p7GKfhVhNb39Qhj0L38t6AwjjIRk1k5oKNg1pVPIFzeJJdDv+9WpS8tcZO Q84GJXhQ2qcWBd6ukxtZtAK6D1kCKUS0E2NPPK0KdADOx59df8kB3nC2UDT9kZxSC3fG iQ7UU9g0KLki5EQmmE9MydV4S6VGBcWfM7aX96U+4sNFViLuy3T/HI0hTMku1MeZa6s8 do+9KPOk/Ev2m+1TOq2faGkyN3xiuTz0440hE37F6sVrI1VJFP72pRj1umfmTKwwjjqZ doWiK/a9v//8crZMk35QB3hobugZAQy9lowWQ35n4Oo6hPebMAZ8FTXk7OWRmC3UYVxm mEKQ== X-Gm-Message-State: AOAM532OqzMisEc71+ixG5zruXDSxAfcKXg234FwJ0Rf50QE04Hsa0qF Oh+M5EHv9GF4lJjbH2EF5zhaZYOri9rCIg== X-Received: by 2002:a05:600c:3583:: with SMTP id p3mr2954025wmq.172.1643740151785; Tue, 01 Feb 2022 10:29:11 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id p17sm15600796wrf.112.2022.02.01.10.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 10:29:06 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id ADB4A1FFB8; Tue, 1 Feb 2022 18:20:52 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 20/25] plugins: add helper functions for coverage plugins Date: Tue, 1 Feb 2022 18:20:45 +0000 Message-Id: <20220201182050.15087-21-alex.bennee@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220201182050.15087-1-alex.bennee@linaro.org> References: <20220201182050.15087-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::331 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 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, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: fam@euphon.net, berrange@redhat.com, stefanha@redhat.com, crosa@redhat.com, aaron@os.amperecomputing.com, robhenry@microsoft.com, f4bug@amsat.org, mahmoudabdalghany@outlook.com, minyihh@uci.edu, cota@braap.org, Ivanov Arkady , Luke.Craig@ll.mit.edu, pbonzini@redhat.com, kuhn.chenqun@huawei.com, ma.mandourr@gmail.com, Alexandre Iooss , =?utf-8?q?Alex_?= =?utf-8?q?Benn=C3=A9e?= , aurelien@aurel32.net Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Ivanov Arkady Which provide information about: - start_code. - end_code. - entry. - path to the executable binary. Signed-off-by: Ivanov Arkady Message-Id: <163491883461.304355.8210754161847179432.stgit@pc-System-Product-Name> [AJB: reword title, better descriptions, defaults, rm export, fix include] Signed-off-by: Alex Bennée Message-Id: <20220124201608.604599-18-alex.bennee@linaro.org> --- include/qemu/qemu-plugin.h | 34 ++++++++++++++++++++++++++ plugins/api.c | 46 ++++++++++++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 4 ++++ 3 files changed, 84 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 5f1017201f..535ddbf0ae 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -590,4 +590,38 @@ void qemu_plugin_outs(const char *string); */ bool qemu_plugin_bool_parse(const char *name, const char *val, bool *ret); +/** + * qemu_plugin_path_to_binary() - path to binary file being executed + * + * Return a string representing the path to the binary. For user-mode + * this is the main executable. For system emulation we currently + * return NULL. The user should g_free() the string once no longer + * needed. + */ +const char *qemu_plugin_path_to_binary(void); + +/** + * qemu_plugin_start_code() - returns start of text segment + * + * Returns the nominal start address of the main text segment in + * user-mode. Currently returns 0 for system emulation. + */ +uint64_t qemu_plugin_start_code(void); + +/** + * qemu_plugin_end_code() - returns end of text segment + * + * Returns the nominal end address of the main text segment in + * user-mode. Currently returns 0 for system emulation. + */ +uint64_t qemu_plugin_end_code(void); + +/** + * qemu_plugin_entry_code() - returns start address for module + * + * Returns the nominal entry address of the main text segment in + * user-mode. Currently returns 0 for system emulation. + */ +uint64_t qemu_plugin_entry_code(void); + #endif /* QEMU_PLUGIN_API_H */ diff --git a/plugins/api.c b/plugins/api.c index b143b09ce9..e6a2c9dde3 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -44,6 +44,9 @@ #ifndef CONFIG_USER_ONLY #include "qemu/plugin-memory.h" #include "hw/boards.h" +#else +#include "qemu.h" +#include "loader.h" #endif /* Uninstall and Reset handlers */ @@ -391,3 +394,46 @@ bool qemu_plugin_bool_parse(const char *name, const char *value, bool *ret) { return name && value && qapi_bool_parse(name, value, ret, NULL); } + +/* + * Binary path, start and end locations + */ +const char *qemu_plugin_path_to_binary(void) +{ + char *path = NULL; +#ifdef CONFIG_USER_ONLY + TaskState *ts = (TaskState *) current_cpu->opaque; + path = g_strdup(ts->bprm->filename); +#endif + return path; +} + +uint64_t qemu_plugin_start_code(void) +{ + uint64_t start = 0; +#ifdef CONFIG_USER_ONLY + TaskState *ts = (TaskState *) current_cpu->opaque; + start = ts->info->start_code; +#endif + return start; +} + +uint64_t qemu_plugin_end_code(void) +{ + uint64_t end = 0; +#ifdef CONFIG_USER_ONLY + TaskState *ts = (TaskState *) current_cpu->opaque; + end = ts->info->end_code; +#endif + return end; +} + +uint64_t qemu_plugin_entry_code(void) +{ + uint64_t entry = 0; +#ifdef CONFIG_USER_ONLY + TaskState *ts = (TaskState *) current_cpu->opaque; + entry = ts->info->entry; +#endif + return entry; +} diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 4834756ba3..71f6c90549 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -1,5 +1,7 @@ { qemu_plugin_bool_parse; + qemu_plugin_end_code; + qemu_plugin_entry_code; qemu_plugin_get_hwaddr; qemu_plugin_hwaddr_device_name; qemu_plugin_hwaddr_is_io; @@ -17,6 +19,7 @@ qemu_plugin_n_max_vcpus; qemu_plugin_n_vcpus; qemu_plugin_outs; + qemu_plugin_path_to_binary; qemu_plugin_register_atexit_cb; qemu_plugin_register_flush_cb; qemu_plugin_register_vcpu_exit_cb; @@ -33,6 +36,7 @@ qemu_plugin_register_vcpu_tb_exec_inline; qemu_plugin_register_vcpu_tb_trans_cb; qemu_plugin_reset; + qemu_plugin_start_code; qemu_plugin_tb_get_insn; qemu_plugin_tb_n_insns; qemu_plugin_tb_vaddr;