From nobody Sun May 19 04:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1634292066; cv=none; d=zohomail.com; s=zohoarc; b=Zo3jeID/WfbieyyiRIpEJij5w3uxHFqolAIejLQFngLot7GDK6oxQn+DwwO61pXH4xXl9HQrC8CEPykzAKJrrxsm8jZBdo+n+ZukytLDRc4ezMDbX/B/Mwyksbd8YDouw99bQN8KiB70/A3q59QdgUbHxYbtt68py4CMk4rZxl8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634292066; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=37IIrG3CP7WtvnIT1tpjSOBrnhxIDoe6tnGmofgKBK4=; b=gyfVYVkPuxgpB1CA0z/s9KIwJMATxk7Vh0F76AdK8yRJ1ptNZyKBj/jd/ppYRak1rYnpjuck7uKo4+MzSCN03GhG09PNVGm0Q1rhONUH1PS7hUGTYz0dbx6X4N+8X8zYqWec2Qpna86ctyn7VZYmYgv0F9LiIgo3ll4dag4XBiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634292065996391.55231576276503; Fri, 15 Oct 2021 03:01:05 -0700 (PDT) Received: from localhost ([::1]:48372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbK1Q-0000iL-Sm for importer@patchew.org; Fri, 15 Oct 2021 06:01:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbJvx-00033h-SX for qemu-devel@nongnu.org; Fri, 15 Oct 2021 05:55:26 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]:33356) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbJvw-0005VN-BF for qemu-devel@nongnu.org; Fri, 15 Oct 2021 05:55:25 -0400 Received: by mail-lf1-x131.google.com with SMTP id j21so39821858lfe.0 for ; Fri, 15 Oct 2021 02:55:22 -0700 (PDT) Received: from pc-System-Product-Name.intra.ispras.ru ([85.142.117.226]) by smtp.gmail.com with ESMTPSA id r128sm456515lff.284.2021.10.15.02.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 02:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=37IIrG3CP7WtvnIT1tpjSOBrnhxIDoe6tnGmofgKBK4=; b=Ew9Mk+cUJHR+lr+wzPKV1xgawRL2j+zwqJVru6KAJ922ZaJra9/xE7HNaPEMs7cRdl HhGnys6aKU7PCFgFq7Uz0UQQF6Ty9+e8LDraNXdJiPQf+klmhb8WwVxnNi3yo5KS8Hjt JguLLo+nnVQAeZUq0PWHnh03YfMz+5VO/W4SsBzdoBI+FV6t09ahGmLNh65MsjhXHki7 2s2i4E0drlhzUJiFZaktNnxQk5a4jGA+dKpVpDE/wUY5lKW0XSCznLGbjeZz3CqFaoKo qgBWlu33+MKuqb2YkET9ACVOnrMhwYyvJNizVzIRNUL8hdBohzDBy5ZdosDU1/IZA81W ZksA== 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:user-agent:mime-version:content-transfer-encoding; bh=37IIrG3CP7WtvnIT1tpjSOBrnhxIDoe6tnGmofgKBK4=; b=WOffLBMhFq3x7BRjtpKDr5unFtbOmj/AausHaPuHL98rccD/2ZlvJKDYlSPD4XGHad ccJqKLqgQIhxLEKTKKDnT/5csZUPyB2xY70RNz1Y1ZJ4bwoSEZnDMaeXv8dBou87c9d7 1TNboJzW8EgGi28+/k82X06CYqO3qFERmyriK3yqy0UU09flswKUa7YU6fTVzGLzKRHD xOXrGK0NveC1UjmvQJICdT2b03slMOnwgPbROTGh0sE3ruzRMF9Okee/79fr8iShbLwx F/Di+Rt2oxZUrsOIFDKMzKoQxTeeGujPJJ6E8/YWqNl0L4mxf5VrEzgKmDhW5HRHDNP5 QUUg== X-Gm-Message-State: AOAM533ioeDafbWrGZodqjvocwziWDDr7vO9rF/8gvSjRHq3MqORY1Bn mOCVu9WRzsSZmqpcNs56mSnUk3Td/bKR2A== X-Google-Smtp-Source: ABdhPJyNQhxEkvyfZPly/Uvv1tqvfu2vB5V+ARrSetB1CnxEvadEL4HpySww77F2SxRpN6jfN8N3DA== X-Received: by 2002:a2e:5858:: with SMTP id x24mr11572363ljd.50.1634291720823; Fri, 15 Oct 2021 02:55:20 -0700 (PDT) From: NDNF To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] src/plugins: add helper functions for drcov Date: Fri, 15 Oct 2021 12:55:16 +0300 Message-Id: <163429171602.439576.8875867021199772041.stgit@pc-System-Product-Name> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163429165642.439576.16356288759891202632.stgit@pc-System-Product-Name> References: <163429165642.439576.16356288759891202632.stgit@pc-System-Product-Name> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::131; envelope-from=arkaisp2021@gmail.com; helo=mail-lf1-x131.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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: alex.bennee@linaro.org, pavel.dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1634292068065100003 This patch adds helper functions to the drcov plugin. Which provide information about: - start_code. - end_code. - entry. - path to the executable binary. Signed-off-by: Ivanov Arkady --- include/qemu/qemu-plugin.h | 5 +++++ plugins/api.c | 27 +++++++++++++++++++++++++++ plugins/qemu-plugins.symbols | 4 ++++ 3 files changed, 36 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index 5775e82c4e..807d932e02 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -405,4 +405,9 @@ int qemu_plugin_n_max_vcpus(void); */ void qemu_plugin_outs(const char *string); =20 +QEMU_PLUGIN_EXPORT const char *qemu_plugin_path_to_binary(void); +QEMU_PLUGIN_EXPORT uint64_t qemu_plugin_start_code(void); +QEMU_PLUGIN_EXPORT uint64_t qemu_plugin_end_code(void); +QEMU_PLUGIN_EXPORT uint64_t qemu_plugin_entry_code(void); + #endif /* QEMU_PLUGIN_API_H */ diff --git a/plugins/api.c b/plugins/api.c index bbdc5a4eb4..4e8a582d58 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -340,3 +340,30 @@ void qemu_plugin_outs(const char *string) { qemu_log_mask(CPU_LOG_PLUGIN, "%s", string); } + +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +const char *qemu_plugin_path_to_binary(void) +{ + TaskState *ts =3D (TaskState *) current_cpu->opaque; + return ts->bprm->filename; +} + +uint64_t qemu_plugin_start_code(void) +{ + TaskState *ts =3D (TaskState *) current_cpu->opaque; + return ts->info->start_code; +} + +uint64_t qemu_plugin_end_code(void) +{ + TaskState *ts =3D (TaskState *) current_cpu->opaque; + return ts->info->end_code; +} + +uint64_t qemu_plugin_entry_code(void) +{ + TaskState *ts =3D (TaskState *) current_cpu->opaque; + return ts->info->entry; +} +#endif diff --git a/plugins/qemu-plugins.symbols b/plugins/qemu-plugins.symbols index 4bdb381f48..021851fb7d 100644 --- a/plugins/qemu-plugins.symbols +++ b/plugins/qemu-plugins.symbols @@ -37,4 +37,8 @@ qemu_plugin_n_vcpus; qemu_plugin_n_max_vcpus; qemu_plugin_outs; + qemu_plugin_path_to_binary; + qemu_plugin_start_code; + qemu_plugin_end_code; + qemu_plugin_entry_code; }; From nobody Sun May 19 04:05:33 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1634291991; cv=none; d=zohomail.com; s=zohoarc; b=nbpxFEMyo5BNKC3wArlnG2kQRlJlvKGR5VVS3rWt52JUJOM5b8wHEH5ZirIhpeHUQ7JEN/jIi0AqcQ5bsNbYbmGCwVzK9q54lHtq1yJ9QoK+TpUnd0kxWYGmyc3tux46SW5qq9HLrN7hFCrR11hjPyPDXVGKms+B5vsHG8XtAfg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634291991; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Qoo1pPiEdbI5MtHJboYvyS1XIILlXI1+9H+BWKPa5BU=; b=ETdXjOVoXRIICRHYUhvorK7dh6sD124iZwNym95JGFPtj8I+Vpf3UOMwxnSsCv3S8vMCP/Bzyy4R+n+GIIAdaspOYLWKuXh249tXRCALGpeJ83GUqoOFWG3qwReegZK4Q0G2GLqISYwDTh7/XZfNidQdigNNdTSOphzURjoD2SI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1634291991434899.4658145767113; Fri, 15 Oct 2021 02:59:51 -0700 (PDT) Received: from localhost ([::1]:46774 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbK0E-000823-1w for importer@patchew.org; Fri, 15 Oct 2021 05:59:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbJw6-000390-3t for qemu-devel@nongnu.org; Fri, 15 Oct 2021 05:55:34 -0400 Received: from mail-lf1-x12e.google.com ([2a00:1450:4864:20::12e]:34566) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbJw4-0005i4-Cn for qemu-devel@nongnu.org; Fri, 15 Oct 2021 05:55:33 -0400 Received: by mail-lf1-x12e.google.com with SMTP id t9so38620487lfd.1 for ; Fri, 15 Oct 2021 02:55:32 -0700 (PDT) Received: from pc-System-Product-Name.intra.ispras.ru ([85.142.117.226]) by smtp.gmail.com with ESMTPSA id s11sm459737lfd.95.2021.10.15.02.55.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Oct 2021 02:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Qoo1pPiEdbI5MtHJboYvyS1XIILlXI1+9H+BWKPa5BU=; b=ZgtnXPaxYQLoTs+lKC+PmURjTNIcLrBX4VPLL7m3VbAWzz25RTREl7P4lrx8IlRZka Us46abWrJ0KpVJseYCEad5sfnEqrlg+UIyS9NLpE5tEiFD/QPxAWkJS6Fs5HYtq3ysC6 AQn5ooe00dZbwBqjSUjMM0jqNqD6lVFeAAe8XzjbynyI7A9L/Dme+XvK205uf+Y9L1nA c6EDBzdYITjHFHvdTtVdOBMaxvmDzbm98UWOLrmTBQYn/PRJNya6OglBfPHfePh2oC3Q BQ4naQBNXHAdcCb+TPxOrYimiiESiNoh4lHfkfAPT0ROvKUOb5a5UaMK9o0TWL+Elf8v T6dg== 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:user-agent:mime-version:content-transfer-encoding; bh=Qoo1pPiEdbI5MtHJboYvyS1XIILlXI1+9H+BWKPa5BU=; b=IP6+QgOY58fd2XBH0KUFk0v6DXnW+9xo/zWYrkOlsA889jdWT4a5di1NQKAoZmQBuh 8hWjNzUsdgdrn4U0/4Zvk1bWgoTu+4dpKHGRioehwV20lH4sy8okmCVwDtyUfOw+4RXW 56Qstfd0to7aYXY7SGKuxAkGR7uXgPPsg+qRIABVXpj3GvWrNc/u2SiuCnMoqgjEfZxv EfWOQTRXmJamVUPw/xMdLGz+cuvxDaW+YAhpeNmFoa8SMtTlCdUAi23PoVzjWYJtnrJt OQ7u8K1u7MkPgcNqUamkEMG1xUQzAJ3Lg5Y9uNcgp1q9DjvNdTyu4Wh2+GalLnSnt9U6 jmcw== X-Gm-Message-State: AOAM530Hv5yUM/w4BwgeYvu32Imjr6DBML6i9KFhIwgsJPc/DViWTDgT 4QAyCJOrXnls0aYF0nBJ8+yjYqNWjO9pzg== X-Google-Smtp-Source: ABdhPJw++NfAA4QoNDv6LERiolZ9jgPQWtQceTPlw5kqKWBJD2ei7UMYFj2JG0SQC4FoEE6ZIq5Vhw== X-Received: by 2002:a2e:3902:: with SMTP id g2mr11827841lja.321.1634291730557; Fri, 15 Oct 2021 02:55:30 -0700 (PDT) From: NDNF To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] contrib/plugins: add a drcov plugin Date: Fri, 15 Oct 2021 12:55:26 +0300 Message-Id: <163429172593.439576.18239997817704146254.stgit@pc-System-Product-Name> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163429165642.439576.16356288759891202632.stgit@pc-System-Product-Name> References: <163429165642.439576.16356288759891202632.stgit@pc-System-Product-Name> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::12e; envelope-from=arkaisp2021@gmail.com; helo=mail-lf1-x12e.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, 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: alex.bennee@linaro.org, pavel.dovgaluk@ispras.ru Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1634291992938100001 This patch adds the ability to generate files in drcov format. Primary goal this script is to have coverage logfiles thatwork in Lighthouse. Signed-off-by: Ivanov Arkady --- contrib/plugins/Makefile | 1=20 contrib/plugins/drcov.c | 148 ++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 149 insertions(+) create mode 100644 contrib/plugins/drcov.c diff --git a/contrib/plugins/Makefile b/contrib/plugins/Makefile index 7801b08b0d..0a681efeec 100644 --- a/contrib/plugins/Makefile +++ b/contrib/plugins/Makefile @@ -17,6 +17,7 @@ NAMES +=3D hotblocks NAMES +=3D hotpages NAMES +=3D howvec NAMES +=3D lockstep +NAMES +=3D drcov =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 diff --git a/contrib/plugins/drcov.c b/contrib/plugins/drcov.c new file mode 100644 index 0000000000..f94b52ff64 --- /dev/null +++ b/contrib/plugins/drcov.c @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2021, Ivanov Arkady + * + * Drcov - a DynamoRIO-based tool that collects coverage information + * from a binary. Primary goal this script is to have coverage log + * files that work in Lighthouse. + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +static char header[] =3D "DRCOV VERSION: 2\n" + "DRCOV FLAVOR: drcov-64\n" + "Module Table: version 2, count 1\n" + "Columns: id, base, end, entry, path\n"; + +static FILE *fp; +static char *file_name; +static GMutex lock; + +typedef struct { + uint32_t start; + uint16_t size; + uint16_t mod_id; +} bb_entry_t; + +static GSList *bbs; + +static void printf_header(void) +{ + g_autoptr(GString) head =3D g_string_new(header); + const char *path =3D qemu_plugin_path_to_binary(); + uint64_t start_code =3D qemu_plugin_start_code(); + uint64_t end_code =3D qemu_plugin_end_code(); + uint64_t entry =3D qemu_plugin_entry_code(); + g_string_append_printf(head, "0, 0x%lx, 0x%lx, 0x%lx, %s\n", + start_code, end_code, entry, path); + g_string_append_printf(head, "BB Table: %d bbs\n", g_slist_length(bbs)= ); + fwrite(head->str, sizeof(char), head->len, fp); +} + +static void printf_char_array32(uint32_t data) +{ + const uint8_t *bytes =3D (const uint8_t *)(&data); + fwrite(bytes, sizeof(char), sizeof(data), fp); +} + +static void printf_char_array16(uint16_t data) +{ + const uint8_t *bytes =3D (const uint8_t *)(&data); + fwrite(bytes, sizeof(char), sizeof(data), fp); +} + + +static void printf_el(gpointer data, gpointer user_data) +{ + g_mutex_lock(&lock); + + bb_entry_t *bb =3D (bb_entry_t *)data; + printf_char_array32(bb->start); + printf_char_array16(bb->size); + printf_char_array16(bb->mod_id); + + g_mutex_unlock(&lock); +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + /* Print function */ + printf_header(); + g_slist_foreach(bbs, printf_el, NULL); + + /* Clear */ + g_slist_free_full(bbs, &g_free); + g_free(file_name); + fclose(fp); +} + +static void plugin_init(void) +{ + fp =3D fopen(file_name, "wb"); +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + bb_entry_t *bb =3D g_malloc0(sizeof(bb_entry_t)); + memcpy(bb, udata, sizeof(bb_entry_t)); + + g_mutex_lock(&lock); + bbs =3D g_slist_append(bbs, bb); + g_mutex_unlock(&lock); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + bb_entry_t *bb =3D g_new0(bb_entry_t, 1); + uint64_t pc =3D qemu_plugin_tb_vaddr(tb); + + size_t n =3D qemu_plugin_tb_n_insns(tb); + for (int i =3D 0; i < n; i++) { + bb->size +=3D qemu_plugin_insn_size(qemu_plugin_tb_get_insn(tb, i)= ); + } + + bb->start =3D pc; + bb->mod_id =3D 0; + + qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, + (void *)bb); + +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + + if (!argc) { + file_name =3D "file.drcov.trace"; + } else { + if (g_str_has_prefix(argv[0], "filename=3D")) { + size_t size =3D strlen(argv[0]) - 9; + file_name =3D g_malloc0(size + 1); + strncpy(file_name, argv[0] + 9, size); + file_name[size] =3D '\0'; + } + } + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + + return 0; +}