From: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>, qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Philippe Mathieu-Daudé " <philmd@linaro.org>,
"rowan Hart" <rowanbhart@gmail.com>,
"Gustavo Romero" <gustavo.romero@linaro.org>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>
Subject: Re: [PATCH v5 1/9] contrib/plugins/uftrace: skeleton file
Date: Fri, 08 Aug 2025 11:14:27 +0300 [thread overview]
Message-ID: <t0o24e.37nl0tbfod6ih@linaro.org> (raw)
In-Reply-To: <20250808020702.410109-2-pierrick.bouvier@linaro.org>
On Fri, 08 Aug 2025 05:06, Pierrick Bouvier <pierrick.bouvier@linaro.org> wrote:
>We define a scoreboard that will hold our data per cpu. As well, we
>define a buffer per cpu that will be used to read registers and memories
>in a thread-safe way.
>
>For now, we just instrument all instructions with an empty callback.
>
>Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>---
> contrib/plugins/uftrace.c | 74 +++++++++++++++++++++++++++++++++++++
> contrib/plugins/meson.build | 3 +-
> 2 files changed, 76 insertions(+), 1 deletion(-)
> create mode 100644 contrib/plugins/uftrace.c
>
>diff --git a/contrib/plugins/uftrace.c b/contrib/plugins/uftrace.c
>new file mode 100644
>index 00000000000..d60c1077496
>--- /dev/null
>+++ b/contrib/plugins/uftrace.c
>@@ -0,0 +1,74 @@
>+/*
>+ * Copyright (C) 2025, Pierrick Bouvier <pierrick.bouvier@linaro.org>
>+ *
>+ * Generates a trace compatible with uftrace (similar to uftrace record).
>+ * https://github.com/namhyung/uftrace
>+ *
>+ * See docs/about/emulation.rst|Uftrace for details and examples.
>+ *
>+ * SPDX-License-Identifier: GPL-2.0-or-later
>+ */
>+
>+#include <qemu-plugin.h>
>+#include <glib.h>
>+
>+QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
>+
>+typedef struct Cpu {
>+ GByteArray *buf;
>+} Cpu;
>+
>+static struct qemu_plugin_scoreboard *score;
>+
>+static void track_callstack(unsigned int cpu_index, void *udata)
>+{
>+}
>+
>+static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
>+{
>+ size_t n_insns = qemu_plugin_tb_n_insns(tb);
>+
>+ for (int i = 0; i < n_insns; i++) {
s/int i/size_t i/
>+ struct qemu_plugin_insn *insn = qemu_plugin_tb_get_insn(tb, i);
This can return NULL,
>+
>+ uintptr_t pc = qemu_plugin_insn_vaddr(insn);
And this would lead to a NULL dereference (it performs insn->vaddr
access)
>+ qemu_plugin_register_vcpu_insn_exec_cb(insn, track_callstack,
>+ QEMU_PLUGIN_CB_R_REGS,
>+ (void *) pc);
Hm indentation got broken here, should be
+ qemu_plugin_register_vcpu_insn_exec_cb(insn, track_callstack,
+ QEMU_PLUGIN_CB_R_REGS,
+ (void *)pc);
>+
>+ }
>+}
>+
>+static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index)
>+{
>+ Cpu *cpu = qemu_plugin_scoreboard_find(score, vcpu_index);
>+ cpu->buf = g_byte_array_new();
>+}
>+
>+static void vcpu_end(unsigned int vcpu_index)
>+{
>+ Cpu *cpu = qemu_plugin_scoreboard_find(score, vcpu_index);
>+ g_byte_array_free(cpu->buf, true);
>+ memset(cpu, 0, sizeof(Cpu));
Nitpick, cpu->buf = NULL; is easier to understand (suggestion)
>+}
>+
>+static void at_exit(qemu_plugin_id_t id, void *data)
>+{
>+ for (size_t i = 0; i < qemu_plugin_num_vcpus(); ++i) {
>+ vcpu_end(i);
>+ }
>+
>+ qemu_plugin_scoreboard_free(score);
>+}
>+
>+QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
>+ const qemu_info_t *info,
>+ int argc, char **argv)
>+{
>+ score = qemu_plugin_scoreboard_new(sizeof(Cpu));
>+ qemu_plugin_register_vcpu_init_cb(id, vcpu_init);
>+ qemu_plugin_register_atexit_cb(id, at_exit, NULL);
>+ qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans);
>+
>+ return 0;
>+}
>diff --git a/contrib/plugins/meson.build b/contrib/plugins/meson.build
>index 1876bc78438..7eb3629c95d 100644
>--- a/contrib/plugins/meson.build
>+++ b/contrib/plugins/meson.build
>@@ -1,5 +1,6 @@
> contrib_plugins = ['bbv', 'cache', 'cflow', 'drcov', 'execlog', 'hotblocks',
>- 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger']
>+ 'hotpages', 'howvec', 'hwprofile', 'ips', 'stoptrigger',
>+ 'uftrace']
> if host_os != 'windows'
> # lockstep uses socket.h
> contrib_plugins += 'lockstep'
>--
>2.47.2
>
If no other comments rise for this patch, you can add my r-b after
fixing the NULL check:
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
next prev parent reply other threads:[~2025-08-08 8:27 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 2:06 [PATCH v5 0/9] contrib/plugins: uftrace Pierrick Bouvier
2025-08-08 2:06 ` [PATCH v5 1/9] contrib/plugins/uftrace: skeleton file Pierrick Bouvier
2025-08-08 8:14 ` Manos Pitsidianakis [this message]
2025-08-08 16:19 ` Pierrick Bouvier
2025-08-08 16:34 ` Manos Pitsidianakis
2025-08-08 17:28 ` Pierrick Bouvier
2025-08-08 2:06 ` [PATCH v5 2/9] contrib/plugins/uftrace: define cpu operations and implement aarch64 Pierrick Bouvier
2025-08-08 8:28 ` Manos Pitsidianakis
2025-08-08 16:27 ` Pierrick Bouvier
2025-08-08 16:36 ` Manos Pitsidianakis
2025-08-08 2:06 ` [PATCH v5 3/9] contrib/plugins/uftrace: track callstack Pierrick Bouvier
2025-08-08 8:49 ` Manos Pitsidianakis
2025-08-08 16:36 ` Pierrick Bouvier
2025-08-08 2:06 ` [PATCH v5 4/9] contrib/plugins/uftrace: implement tracing Pierrick Bouvier
2025-08-08 9:11 ` Manos Pitsidianakis
2025-08-08 16:38 ` Pierrick Bouvier
2025-08-08 18:03 ` Pierrick Bouvier
2025-08-08 18:13 ` Manos Pitsidianakis
2025-08-08 18:23 ` Pierrick Bouvier
2025-08-08 18:29 ` Manos Pitsidianakis
2025-08-08 18:24 ` Pierrick Bouvier
2025-08-08 2:06 ` [PATCH v5 5/9] contrib/plugins/uftrace: implement privilege level tracing Pierrick Bouvier
2025-08-08 9:26 ` Manos Pitsidianakis
2025-08-08 16:41 ` Pierrick Bouvier
2025-08-08 2:06 ` [PATCH v5 6/9] contrib/plugins/uftrace: generate additional files for uftrace Pierrick Bouvier
2025-08-08 9:37 ` Manos Pitsidianakis
2025-08-08 16:42 ` Pierrick Bouvier
2025-08-08 2:07 ` [PATCH v5 7/9] contrib/plugins/uftrace: implement x64 support Pierrick Bouvier
2025-08-08 9:42 ` Manos Pitsidianakis
2025-08-08 16:52 ` Pierrick Bouvier
2025-08-08 2:07 ` [PATCH v5 8/9] contrib/plugins/uftrace_symbols.py Pierrick Bouvier
2025-08-08 2:07 ` [PATCH v5 9/9] contrib/plugins/uftrace: add documentation Pierrick Bouvier
2025-08-08 9:46 ` Manos Pitsidianakis
2025-08-08 16:59 ` Pierrick Bouvier
2025-08-08 20:45 ` [PATCH v5 0/9] contrib/plugins: uftrace Pierrick Bouvier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=t0o24e.37nl0tbfod6ih@linaro.org \
--to=manos.pitsidianakis@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=erdnaxe@crans.org \
--cc=gustavo.romero@linaro.org \
--cc=ma.mandourr@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=rowanbhart@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.