diff mbox

[RFC,v2,6/7] plugin: add instruction execution logger

Message ID 152819518838.30857.7489579122481731984.stgit@pasha-ThinkPad-T60 (mailing list archive)
State New, archived
Headers show

Commit Message

Pavel Dovgalyuk June 5, 2018, 10:39 a.m. UTC
From: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>

This patch adds a plugin for logging addresses of all executed instructions,
making a complete instruction-level trace.

Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
---
 plugins/exec-log/Makefile   |   19 +++++++++++++++++++
 plugins/exec-log/exec-log.c |   18 ++++++++++++++++++
 2 files changed, 37 insertions(+)
 create mode 100644 plugins/exec-log/Makefile
 create mode 100644 plugins/exec-log/exec-log.c

Comments

Alex Bennée Sept. 7, 2018, 1:59 p.m. UTC | #1
Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru> writes:

> From: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
>
> This patch adds a plugin for logging addresses of all executed instructions,
> making a complete instruction-level trace.

This isn't a good example. You can do this now with a much simpler:

  ${QEMU} -singlestep -d nochain,trace:exec_tb -D $trace ${BINARY}

Or even with a binary log:

  ${QEMU} -singlestep -d nochain -trace enable=exec_tb,file=$trace ${BINARY}

Which is all currently built-in. For the example to be worthwhile we
need to show how we can do something we currently can't do with the
existing infrastructure.

Perhaps a better example would be logging each PC execution to a hash
table so we can compute the hottest PC?

However that is going to require another API to allow information to be
exported from the plugin itself to report it's results.

>
> Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
> ---
>  plugins/exec-log/Makefile   |   19 +++++++++++++++++++
>  plugins/exec-log/exec-log.c |   18 ++++++++++++++++++
>  2 files changed, 37 insertions(+)
>  create mode 100644 plugins/exec-log/Makefile
>  create mode 100644 plugins/exec-log/exec-log.c
>
> diff --git a/plugins/exec-log/Makefile b/plugins/exec-log/Makefile
> new file mode 100644
> index 0000000..86374f4
> --- /dev/null
> +++ b/plugins/exec-log/Makefile
> @@ -0,0 +1,19 @@
> +CFLAGS += -I../include -fno-PIE -fPIC -O3

I would have:

QEMU_SRC=../..
CFLAGS += -I$(QEMU_SRC)/include -fno-PIE -fPIC -O3

to make it clearer for out of tree plugins.

> +LDFLAGS += -shared
> +# TODO: Windows
> +DSOSUF := .so
> +
> +NAME:= exec-log
> +BIN := $(NAME)$(DSOSUF)
> +
> +FILES := exec-log.o
> +
> +%.o: %.c
> +	$(CC) -c -o $@ $< $(CFLAGS)
> +
> +all: $(FILES)
> +	$(CC) $(LDFLAGS) -o $(BIN) $(FILES)
> +
> +clean:
> +	rm $(FILES)
> +	rm $(BIN)

If the example plugins are going to sit in the main tree we should build
them (and ideally test they load/work during make check/tcg-check).

> diff --git a/plugins/exec-log/exec-log.c b/plugins/exec-log/exec-log.c
> new file mode 100644
> index 0000000..7fc7975
> --- /dev/null
> +++ b/plugins/exec-log/exec-log.c
> @@ -0,0 +1,18 @@
> +#include <stdint.h>
> +#include <stdio.h>
> +#include "plugins.h"
> +
> +bool plugin_init(const char *args)
> +{
> +    return true;
> +}
> +
> +bool plugin_needs_before_insn(uint64_t pc, void *cpu)
> +{
> +    return true;
> +}
> +
> +void plugin_before_insn(uint64_t pc, void *cpu)
> +{
> +    qemulib_log("executing instruction at %lx\n", pc);
> +}


--
Alex Bennée
diff mbox

Patch

diff --git a/plugins/exec-log/Makefile b/plugins/exec-log/Makefile
new file mode 100644
index 0000000..86374f4
--- /dev/null
+++ b/plugins/exec-log/Makefile
@@ -0,0 +1,19 @@ 
+CFLAGS += -I../include -fno-PIE -fPIC -O3
+LDFLAGS += -shared
+# TODO: Windows
+DSOSUF := .so
+
+NAME:= exec-log
+BIN := $(NAME)$(DSOSUF)
+
+FILES := exec-log.o
+
+%.o: %.c
+	$(CC) -c -o $@ $< $(CFLAGS)
+
+all: $(FILES)
+	$(CC) $(LDFLAGS) -o $(BIN) $(FILES)
+
+clean:
+	rm $(FILES)
+	rm $(BIN)
diff --git a/plugins/exec-log/exec-log.c b/plugins/exec-log/exec-log.c
new file mode 100644
index 0000000..7fc7975
--- /dev/null
+++ b/plugins/exec-log/exec-log.c
@@ -0,0 +1,18 @@ 
+#include <stdint.h>
+#include <stdio.h>
+#include "plugins.h"
+
+bool plugin_init(const char *args)
+{
+    return true;
+}
+
+bool plugin_needs_before_insn(uint64_t pc, void *cpu)
+{
+    return true;
+}
+
+void plugin_before_insn(uint64_t pc, void *cpu)
+{
+    qemulib_log("executing instruction at %lx\n", pc);
+}