[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 12/12] plugins/execlog: add data address match
From: |
Sven Schnelle |
Subject: |
[PATCH v3 12/12] plugins/execlog: add data address match |
Date: |
Fri, 1 Mar 2024 18:46:09 +0100 |
Add a match similar to the afilter address match, but for data
addresses. When an address is specified with '-dfilter=0x12345'
only load/stores to/from address 0x12345 are printed. All other
instructions are hidden.
Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
contrib/plugins/execlog.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/contrib/plugins/execlog.c b/contrib/plugins/execlog.c
index c518797893..c44fd0e593 100644
--- a/contrib/plugins/execlog.c
+++ b/contrib/plugins/execlog.c
@@ -27,6 +27,8 @@ typedef struct CPU {
GString *last_exec;
/* Ptr array of Register */
GPtrArray *registers;
+ /* whether this instruction should be logged */
+ bool log;
} CPU;
QEMU_PLUGIN_EXPORT int qemu_plugin_version = QEMU_PLUGIN_VERSION;
@@ -36,6 +38,7 @@ static GRWLock expand_array_lock;
static GPtrArray *imatches;
static GList *amatches;
+static GList *dmatches;
static GPtrArray *rmatches;
static bool disas_assist;
static GMutex add_reg_name_lock;
@@ -62,6 +65,11 @@ static void vcpu_mem(unsigned int cpu_index,
qemu_plugin_meminfo_t info,
/* Find vCPU in array */
+ if (dmatches && !qemu_plugin_range_list_contains(dmatches, vaddr)) {
+ return;
+ }
+ c->log = true;
+
/* Indicate type of memory access */
if (qemu_plugin_mem_is_store(info)) {
g_string_append(s, ", store");
@@ -121,15 +129,17 @@ static void vcpu_insn_exec_with_regs(unsigned int
cpu_index, void *udata)
if (cpu->registers) {
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");
+ }
}
/* Store new instruction in cache */
/* vcpu_mem will add memory access information to last_exec */
g_string_printf(cpu->last_exec, "%u, ", cpu_index);
g_string_append(cpu->last_exec, (char *)udata);
+ cpu->log = dmatches ? false : true;
}
/* Log last instruction while checking registers, ignore next */
@@ -157,7 +167,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");
}
@@ -166,6 +176,7 @@ static void vcpu_insn_exec(unsigned int cpu_index, void
*udata)
/* vcpu_mem will add memory access information to last_exec */
g_string_printf(cpu->last_exec, "%u, ", cpu_index);
g_string_append(cpu->last_exec, (char *)udata);
+ cpu->log = dmatches ? false : true;
}
/**
@@ -377,7 +388,7 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
g_rw_lock_reader_lock(&expand_array_lock);
for (i = 0; i < cpus->len; i++) {
CPU *c = get_cpu(i);
- if (c->last_exec && c->last_exec->str) {
+ if (c->log && c->last_exec && c->last_exec->str) {
qemu_plugin_outs(c->last_exec->str);
qemu_plugin_outs("\n");
}
@@ -432,6 +443,13 @@ QEMU_PLUGIN_EXPORT int
qemu_plugin_install(qemu_plugin_id_t id,
qemu_plugin_error_print(err);
return -1;
}
+ } else if (g_strcmp0(tokens[0], "dfilter") == 0) {
+ Error *err = NULL;
+ qemu_plugin_range_list_from_string(&dmatches, tokens[1], &err);
+ if (err) {
+ qemu_plugin_error_print(err);
+ return -1;
+ }
} else if (g_strcmp0(tokens[0], "reg") == 0) {
add_regpat(tokens[1]);
} else if (g_strcmp0(tokens[0], "rdisas") == 0) {
--
2.43.2
- Re: [PATCH v3 01/12] util/log: convert debug_regions to GList, (continued)
- [PATCH v3 06/12] util/range: split up range_list_from_string(), Sven Schnelle, 2024/03/01
- [PATCH v3 05/12] util/range: use append_new_range() in range_list_from_string(), Sven Schnelle, 2024/03/01
- [PATCH v3 02/12] util/log: make qemu_set_dfilter_ranges() take a GList, Sven Schnelle, 2024/03/01
- [PATCH v3 03/12] util/range: move range_list_from_string() to range.c, Sven Schnelle, 2024/03/01
- [PATCH v3 07/12] util/range: make range_list_from_string() accept a single number, Sven Schnelle, 2024/03/01
- [PATCH v3 08/12] qemu/range: add range_list_contains() function, Sven Schnelle, 2024/03/01
- [PATCH v3 04/12] util/range: add range_list_free(), Sven Schnelle, 2024/03/01
- [PATCH v3 10/12] plugins: add range list API, Sven Schnelle, 2024/03/01
- [PATCH v3 12/12] plugins/execlog: add data address match,
Sven Schnelle <=
- [PATCH v3 09/12] plugins: add API to print errors, Sven Schnelle, 2024/03/01
- [PATCH v3 11/12] plugins/execlog: use range list api, Sven Schnelle, 2024/03/01