From patchwork Wed Sep 18 21:07:11 2024 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: 829425 Delivered-To: patch@linaro.org Received: by 2002:adf:ebcc:0:b0:367:895a:4699 with SMTP id v12csp36187wrn; Wed, 18 Sep 2024 14:09:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVG7IE6RbUFdBHXeIVnITHHcqeePC9QVJxrNA0nAiM/1Xg5CqmqWrXvrwwrx63Y39txVTEATA==@linaro.org X-Google-Smtp-Source: AGHT+IFSpLAL4TX/8DEHjLqnhqaCiIizf/dlrIDY8byJH6oxRIKzuWXiF3NH0VpwgdKopz2/yeNW X-Received: by 2002:a05:622a:1a1d:b0:458:1d6c:e35d with SMTP id d75a77b69052e-4599d29c4c9mr331841451cf.48.1726693744236; Wed, 18 Sep 2024 14:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1726693744; cv=none; d=google.com; s=arc-20240605; b=Q1Il9HYgvEDDHdmawx6GBZt/pQUaYkhD6fwOTrQm3Dax2dJ9cmEjRuVg2Lw6funhiz R2flx1rOJ6m8oglk1p1qU4k71DV/mipzFPWqLChgtQUKT6lziQtv/OMpIwcneuxi4eKr z25WNTuKGGkLLurNdC8VaEOKfKPRZ51vT2anwUy3qmRpl/fJZKZFwUZG5PSTEtlMcRKu JYLhBiQIEaA/4y+FcIV/KqAgUpY6femYKZe6qWWoinZFx981bCSLjuF/8q4OdO9uQqjM CL3R/KEd8Ix0UeYVJNmNVlVMVY8FBsZ2d9w4Ueu/vMsFMowdFpH/BMx1ToN5amjMVF+G RihQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; fh=c3aJPtZsmWzRKYZf6XiqryCmquXGTEYhQ1ePVCcFYK8=; b=hwndI+BLZejBtSRf7FcFRtfjq8VcZSRGF82tjU9sBi/fX1spH3i7VJFwaV6SDko++F ZnRzmcHtod7LgUb3+QyOZ4WFsoyCmaX7asrtD0smSNNCfN8rWn8SZww/+FZZ3nNLBRTt bTjjelUC/qBjikBmNEDvYnKCOPgzEPNYkCb2e66S2BS7iAIVwg/iqk/aUKwstNQpnoS9 chaWnX+a32cqL7AnPf+oledukaqeJnCueVCYAxW6DEpncOgPJtjcHs5RI0azxgn8PmwR H4wC5FS3AsEeBKGu1qY3Y+6yYhT6UDNV3tnWMQnYz81O0uBD/asYWEN6fneH3wo6uo5Z Iejg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=c2u37rs4; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-45b178ed4adsi2911031cf.369.2024.09.18.14.09.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Sep 2024 14:09:04 -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=c2u37rs4; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sr1tZ-0005Qy-IM; Wed, 18 Sep 2024 17:07:29 -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 1sr1tX-0005IQ-Cq for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sr1tV-0001eW-It for qemu-devel@nongnu.org; Wed, 18 Sep 2024 17:07:27 -0400 Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a90188ae58eso13144666b.1 for ; Wed, 18 Sep 2024 14:07:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1726693644; x=1727298444; 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=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; b=c2u37rs4nXIJnCtXY8PIbob/NWyIwhU2yxXlGXWC/fPArJIs1uyiNqhopkaIBuxFy4 10quSNi3ld7Tw1n4b974y8GCXAffLi46UcjX/yUYxJQcDI32lKy3AyOfMUzSCwnrYcl+ MikMdNG0ZNouInssYKo65518+ZvTiRtHCbDuLWm/Y+wkHo9KatHlNlD7sY6PTk67NWGJ DAGWHx6rzRsY5ESTYeKeE5IHEaxuVSmTlCAtJGkrukitYNH4GIl3AbTX/XOD+iUP3309 2oAP0DBHqqYnqlJHNa6UxZaavK+tywa0h3r4n3FpmFTUTxvm5NJvWDjwAtYbvFMxhvC2 pSQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726693644; x=1727298444; 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=O2qjDyra0c4+qL6NzNT5YzyZzRtZBLugi4bg2B/w4/Q=; b=Z2W7umhnLrosqjlxpBcN5HzEoLo2Gzbnq30ZmtCWKIfEyQSir1gP0iZJCbQhZPk80L pFAGuahtZ7NgkD7qRFl959wJXsjYJbWKQtyrWHxxSfWp3kO+NPQIJ5FlT0dhXGobc7Hl tIFjv6qUnPvkDyLMPMFr/ft3dj/K5IfYL9OeNzf7P2HliSkJcRZO87mynT/FSHxkf3TM LB/9bxLAmA0KMhYVkWA5+3Nl3JCLyZ7sw59ZVg6Mv1N/GvTQ1Ho4L9v5d2KRxgeUCOL4 d0OyxTSJHgPxXiXZUhaLXGQZObKvOqimmlleb6RB3xi/Ega3O8gu7XGqTBDzAFEw1uUp Eerw== X-Gm-Message-State: AOJu0YxxHZJd2Bi14UOg3gYkE795ukEmMakZZwIGUXrgWdUBsEh65jWl ZHtBrwG9+wBnspD4pGadSGWezzUpeHHWmoVgr6HILnZwCqabczfxxAj6Zi9kICE= X-Received: by 2002:a17:907:f1c6:b0:a86:a30f:4aef with SMTP id a640c23a62f3a-a9029446fdbmr2146689866b.22.1726693643917; Wed, 18 Sep 2024 14:07:23 -0700 (PDT) Received: from draig.lan ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9061116d67sm638576166b.94.2024.09.18.14.07.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Sep 2024 14:07:22 -0700 (PDT) Received: from draig.lan (localhost [IPv6:::1]) by draig.lan (Postfix) with ESMTP id E40185F8C8; Wed, 18 Sep 2024 22:07:13 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Rowan Hart , Pierrick Bouvier , =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 17/18] plugins: add option to dump write argument to syscall plugin Date: Wed, 18 Sep 2024 22:07:11 +0100 Message-Id: <20240918210712.2336854-18-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240918210712.2336854-1-alex.bennee@linaro.org> References: <20240918210712.2336854-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x633.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 From: Rowan Hart Signed-off-by: Rowan Hart Reviewed-by: Pierrick Bouvier Tested-by: Pierrick Bouvier Message-Id: <20240827215329.248434-3-rowanbhart@gmail.com> [AJB: tweak fmt string for vaddr] Signed-off-by: Alex Bennée Message-Id: <20240916085400.1046925-18-alex.bennee@linaro.org> diff --git a/docs/about/emulation.rst b/docs/about/emulation.rst index ee59c2fa9b..3028d5fff7 100644 --- a/docs/about/emulation.rst +++ b/docs/about/emulation.rst @@ -414,6 +414,19 @@ run:: 160 1 0 135 1 0 +Behaviour can be tweaked with the following arguments: + +.. list-table:: Syscall plugin arguments + :widths: 20 80 + :header-rows: 1 + + * - Option + - Description + * - print=true|false + - Print the number of times each syscall is called + * - log_writes=true|false + - Log the buffer of each write syscall in hexdump format + Test inline operations ...................... @@ -803,4 +816,3 @@ Other emulation features When running system emulation you can also enable deterministic execution which allows for repeatable record/replay debugging. See :ref:`Record/Replay` for more details. - diff --git a/tests/tcg/plugins/syscall.c b/tests/tcg/plugins/syscall.c index 72e1a5bf90..89dc7f49b1 100644 --- a/tests/tcg/plugins/syscall.c +++ b/tests/tcg/plugins/syscall.c @@ -22,8 +22,57 @@ typedef struct { int64_t errors; } SyscallStats; +struct SyscallInfo { + const char *name; + int64_t write_sysno; +}; + +static const struct SyscallInfo arch_syscall_info[] = { + { "aarch64", 64 }, + { "aarch64_be", 64 }, + { "alpha", 4 }, + { "arm", 4 }, + { "armeb", 4 }, + { "avr", -1 }, + { "cris", -1 }, + { "hexagon", 64 }, + { "hppa", -1 }, + { "i386", 4 }, + { "loongarch64", -1 }, + { "m68k", 4 }, + { "microblaze", 4 }, + { "microblazeel", 4 }, + { "mips", 1 }, + { "mips64", 1 }, + { "mips64el", 1 }, + { "mipsel", 1 }, + { "mipsn32", 1 }, + { "mipsn32el", 1 }, + { "or1k", -1 }, + { "ppc", 4 }, + { "ppc64", 4 }, + { "ppc64le", 4 }, + { "riscv32", 64 }, + { "riscv64", 64 }, + { "rx", -1 }, + { "s390x", -1 }, + { "sh4", -1 }, + { "sh4eb", -1 }, + { "sparc", 4 }, + { "sparc32plus", 4 }, + { "sparc64", 4 }, + { "tricore", -1 }, + { "x86_64", 1 }, + { "xtensa", 13 }, + { "xtensaeb", 13 }, + { NULL, -1 }, +}; + static GMutex lock; static GHashTable *statistics; +static GByteArray *memory_buffer; +static bool do_log_writes; +static int64_t write_sysno = -1; static SyscallStats *get_or_create_entry(int64_t num) { @@ -39,6 +88,44 @@ static SyscallStats *get_or_create_entry(int64_t num) return entry; } +/* + * Hex-dump a GByteArray to the QEMU plugin output in the format: + * 61 63 63 65 6c 09 09 20 20 20 66 70 75 09 09 09 | accel.....fpu... + * 20 6d 6f 64 75 6c 65 2d 63 6f 6d 6d 6f 6e 2e 63 | .module-common.c + */ +static void hexdump(const GByteArray *data) +{ + g_autoptr(GString) out = g_string_new(""); + + for (guint index = 0; index < data->len; index += 16) { + for (guint col = 0; col < 16; col++) { + if (index + col < data->len) { + g_string_append_printf(out, "%02x ", data->data[index + col]); + } else { + g_string_append(out, " "); + } + } + + g_string_append(out, " | "); + + for (guint col = 0; col < 16; col++) { + if (index + col >= data->len) { + break; + } + + if (g_ascii_isgraph(data->data[index + col])) { + g_string_append_printf(out, "%c", data->data[index + col]); + } else { + g_string_append(out, "."); + } + } + + g_string_append(out, "\n"); + } + + qemu_plugin_outs(out->str); +} + static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, @@ -54,6 +141,14 @@ static void vcpu_syscall(qemu_plugin_id_t id, unsigned int vcpu_index, g_autofree gchar *out = g_strdup_printf("syscall #%" PRIi64 "\n", num); qemu_plugin_outs(out); } + + if (do_log_writes && num == write_sysno) { + if (qemu_plugin_read_memory_vaddr(a2, memory_buffer, a3)) { + hexdump(memory_buffer); + } else { + fprintf(stderr, "Error reading memory from vaddr %"PRIu64"\n", a2); + } + } } static void vcpu_syscall_ret(qemu_plugin_id_t id, unsigned int vcpu_idx, @@ -127,6 +222,10 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_print)) { fprintf(stderr, "boolean argument parsing failed: %s\n", opt); } + } else if (g_strcmp0(tokens[0], "log_writes") == 0) { + if (!qemu_plugin_bool_parse(tokens[0], tokens[1], &do_log_writes)) { + fprintf(stderr, "boolean argument parsing failed: %s\n", opt); + } } else { fprintf(stderr, "unsupported argument: %s\n", argv[i]); return -1; @@ -137,6 +236,24 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, statistics = g_hash_table_new_full(NULL, g_direct_equal, NULL, g_free); } + if (do_log_writes) { + for (const struct SyscallInfo *syscall_info = arch_syscall_info; + syscall_info->name != NULL; syscall_info++) { + + if (g_strcmp0(syscall_info->name, info->target_name) == 0) { + write_sysno = syscall_info->write_sysno; + break; + } + } + + if (write_sysno == -1) { + fprintf(stderr, "write syscall number not found\n"); + return -1; + } + + memory_buffer = g_byte_array_new(); + } + qemu_plugin_register_vcpu_syscall_cb(id, vcpu_syscall); qemu_plugin_register_vcpu_syscall_ret_cb(id, vcpu_syscall_ret); qemu_plugin_register_atexit_cb(id, plugin_exit, NULL);