qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC PATCH v2 6/7] plugin: add instruction execution lo


From: Alex Bennée
Subject: Re: [Qemu-devel] [RFC PATCH v2 6/7] plugin: add instruction execution logger
Date: Fri, 07 Sep 2018 14:59:33 +0100
User-agent: mu4e 1.1.0; emacs 26.1.50

Pavel Dovgalyuk <address@hidden> writes:

> From: Pavel Dovgalyuk <address@hidden>
>
> 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 <address@hidden>
> ---
>  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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]