@@ -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 GArray *amatches;
+static GArray *dmatches;
static GPtrArray *rmatches;
static bool disas_assist;
static GMutex add_reg_name_lock;
@@ -51,6 +54,17 @@ static CPU *get_cpu(int vcpu_index)
return c;
}
+static bool match_vaddr(uint64_t vaddr)
+{
+ for (int i = 0; i < dmatches->len; i++) {
+ uint64_t v = g_array_index(dmatches, uint64_t, i);
+ if (v == vaddr) {
+ return true;
+ }
+ }
+ return false;
+}
+
/**
* Add memory read or write information to current instruction log
*/
@@ -62,6 +76,11 @@ static void vcpu_mem(unsigned int cpu_index, qemu_plugin_meminfo_t info,
/* Find vCPU in array */
+ if (dmatches && !match_vaddr(vaddr)) {
+ return;
+ }
+ c->log = true;
+
/* Indicate type of memory access */
if (qemu_plugin_mem_is_store(info)) {
g_string_append(s, ", store");
@@ -121,15 +140,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 */
@@ -166,6 +187,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;
}
/**
@@ -381,7 +403,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");
}
@@ -441,6 +463,8 @@ QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id,
parse_insn_match(tokens[1]);
} else if (g_strcmp0(tokens[0], "afilter") == 0) {
parse_vaddr_match(&amatches, tokens[1]);
+ } else if (g_strcmp0(tokens[0], "dfilter") == 0) {
+ parse_vaddr_match(&dmatches, tokens[1]);
} else if (g_strcmp0(tokens[0], "reg") == 0) {
add_regpat(tokens[1]);
} else if (g_strcmp0(tokens[0], "rdisas") == 0) {
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 | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-)