From: Sven Schnelle <svens@stackframe.org>
To: "Alex Bennée" <alex.bennee@linaro.org>,
"Alexandre Iooss" <erdnaxe@crans.org>,
"Mahmoud Mandour" <ma.mandourr@gmail.com>,
"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Cc: qemu-devel@nongnu.org, deller@gmx.de,
Sven Schnelle <svens@stackframe.org>
Subject: [PATCH 3/3] plugins/execlog: add address range matching
Date: Thu, 29 Feb 2024 16:07:29 +0100 [thread overview]
Message-ID: <20240229150729.1620410-4-svens@stackframe.org> (raw)
In-Reply-To: <20240229150729.1620410-1-svens@stackframe.org>
Allow to match memory ranges with the address matches. This
allows to give a range of adresses like '-dfilter=0-0x400'
which would only log memory accesses between 0 and 400.
Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
contrib/plugins/execlog.c | 73 ++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 17 deletions(-)
diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index c89ebc08b6..b1b2a7baf1 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -44,6 +44,11 @@ static bool disas_assist;
static GMutex add_reg_name_lock;
static GPtrArray *all_reg_names;
+struct address_match {
+ uint64_t low;
+ uint64_t high;
+};
+
static CPU *get_cpu(int vcpu_index)
{
CPU *c;
@@ -54,11 +59,12 @@ static CPU *get_cpu(int vcpu_index)
return c;
}
-static bool match_vaddr(uint64_t vaddr)
+static bool match_address_range(GArray *match, uint64_t vaddr)
{
- for (int i = 0; i < dmatches->len; i++) {
- uint64_t v = g_array_index(dmatches, uint64_t, i);
- if (v == vaddr) {
+ for (int i = 0; i < match->len; i++) {
+ struct address_match *m =
+ g_array_index(match, struct address_match *, i);
+ if (vaddr >= m->low && vaddr <= m->high) {
return true;
}
}
@@ -74,9 +80,7 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info,
CPU *c = get_cpu(cpu_index);
GString *s = c->last_exec;
- /* Find vCPU in array */
-
- if (dmatches && !match_vaddr(vaddr)) {
+ if (dmatches && !match_address_range(dmatches, vaddr)) {
return;
}
c->log = true;
@@ -164,8 +168,10 @@ static void vcpu_insn_exec_only_regs(unsigned int cpu_index, void *udata)
insn_check_regs(cpu);
}
- qemu_plugin_outs(cpu->last_exec->str);
- qemu_plugin_outs("\n");
+ if (cpu->log) {
+ qemu_plugin_outs(cpu->last_exec->str);
+ qemu_plugin_outs("\n");
+ }
}
/* reset */
@@ -178,7 +184,7 @@ static void vcpu_insn_exec(unsigned int cpu_index, void *udata)
CPU *cpu = get_cpu(cpu_index);
/* Print previous instruction in cache */
- if (cpu->last_exec->len) {
+ if (cpu->log && cpu->last_exec->len) {
qemu_plugin_outs(cpu->last_exec->str);
qemu_plugin_outs("\n");
}
@@ -239,8 +245,7 @@ static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb)
if (skip && amatches) {
int j;
for (j = 0; j < amatches->len && skip; j++) {
- uint64_t v = g_array_index(amatches, uint64_t, j);
- if (v == insn_vaddr) {
+ if (match_address_range(amatches, insn_vaddr)) {
skip = false;
}
}
@@ -394,6 +399,17 @@ static void vcpu_init(qemu_plugin_id_t id, unsigned int vcpu_index)
c->registers = registers_init(vcpu_index);
}
+static void free_matches(GArray *matches)
+{
+ if (!matches) {
+ return;
+ }
+
+ for (int i = 0; i < matches->len; i++) {
+ g_free(g_array_index(matches, struct address_match *, i));
+ }
+}
+
/**
* On plugin exit, print last instruction in cache
*/
@@ -409,6 +425,9 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
}
}
g_rw_lock_reader_unlock(&expand_array_lock);
+
+ free_matches(amatches);
+ free_matches(dmatches);
}
/* Add a match to the array of matches */
@@ -420,14 +439,34 @@ static void parse_insn_match(char *match)
g_ptr_array_add(imatches, g_strdup(match));
}
-static void parse_vaddr_match(GArray **matches, char *match)
+static void parse_vaddr_match(GArray **matches, char *token)
{
- uint64_t v = g_ascii_strtoull(match, NULL, 16);
+ uint64_t low, high;
+ gchar *endp;
- if (!matches) {
- *matches = g_array_new(false, true, sizeof(uint64_t));
+ low = g_ascii_strtoull(token, &endp, 16);
+ if (endp == token) {
+ fprintf(stderr, "Invalid address(range) specified: %s\n", token);
+ return;
+ }
+
+ if (*endp != '-') {
+ high = low;
+ } else {
+ high = g_ascii_strtoull(endp + 1, &endp, 16);
+ if (endp == token) {
+ fprintf(stderr, "Invalid address(range) specified: %s\n", token);
+ return;
+ }
+ }
+
+ if (!*matches) {
+ *matches = g_array_new(false, true, sizeof(struct address_match));
}
- g_array_append_val(*matches, v);
+ struct address_match *match = g_new(struct address_match, 1);
+ match->low = low;
+ match->high = high;
+ g_array_append_val(*matches, match);
}
/*
--
2.43.2
next prev parent reply other threads:[~2024-02-29 15:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-29 15:07 [PATCH 0/3] plugins/execlog: add data address match and address range support Sven Schnelle
2024-02-29 15:07 ` [PATCH 2/3] plugins/execlog: add data address match Sven Schnelle
2024-02-29 15:07 ` Sven Schnelle [this message]
2024-02-29 17:12 ` [PATCH 3/3] plugins/execlog: add address range matching Alex Bennée
2024-02-29 18:04 ` Sven Schnelle
2024-02-29 17:08 ` [PATCH 0/3] plugins/execlog: add data address match and address range support Alex Bennée
2024-02-29 19:40 ` Sven Schnelle
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=20240229150729.1620410-4-svens@stackframe.org \
--to=svens@stackframe.org \
--cc=alex.bennee@linaro.org \
--cc=deller@gmx.de \
--cc=erdnaxe@crans.org \
--cc=ma.mandourr@gmail.com \
--cc=pierrick.bouvier@linaro.org \
--cc=qemu-devel@nongnu.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).