diff mbox series

[RFC,v2,5/7] plugins: add plugin template

Message ID 152819518295.30857.8519946393746431063.stgit@pasha-ThinkPad-T60
State New
Headers show
Series QEMU binary instrumentation prototype | expand

Commit Message

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

This is a template of the QEMU plugin. It includes empty functions that
plugins may implement.

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

Comments

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

> From: Pavel Dovgalyuk <pavel.dovgaluk@ispras.ru>
>
> This is a template of the QEMU plugin. It includes empty functions that
> plugins may implement.
>

I'm not sure it's worth having a null-template plugin if we can have one
or two well documented example plugins. It just runs the risk of
bitrot....

> Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
> ---
>  plugins/template/Makefile   |   19 +++++++++++++++++++
>  plugins/template/template.c |   19 +++++++++++++++++++
>  2 files changed, 38 insertions(+)
>  create mode 100644 plugins/template/Makefile
>  create mode 100644 plugins/template/template.c
>
> diff --git a/plugins/template/Makefile b/plugins/template/Makefile
> new file mode 100644
> index 0000000..b9d10da
> --- /dev/null
> +++ b/plugins/template/Makefile
> @@ -0,0 +1,19 @@
> +CFLAGS += -I../include -fno-PIE -fPIC -O3
> +LDFLAGS += -shared
> +# TODO: Windows
> +DSOSUF := .so
> +
> +NAME:= template
> +BIN := $(NAME)$(DSOSUF)
> +
> +FILES := template.o
> +
> +%.o: %.c
> +	$(CC) -c -o $@ $< $(CFLAGS)
> +
> +all: $(FILES)
> +	$(CC) $(LDFLAGS) -o $(BIN) $(FILES)
> +
> +clean:
> +	rm $(FILES)
> +	rm $(BIN)
> diff --git a/plugins/template/template.c b/plugins/template/template.c
> new file mode 100644
> index 0000000..fed1053
> --- /dev/null
> +++ b/plugins/template/template.c
> @@ -0,0 +1,19 @@
> +#include <stdint.h>
> +#include <stdio.h>
> +#include "plugins.h"
> +
> +bool plugin_init(const char *args)
> +{
> +    printf("template plugin loaded successfully\n");
> +    return true;
> +}
> +
> +bool plugin_needs_before_insn(uint64_t pc, void *cpu)
> +{
> +    return true;
> +}
> +
> +void plugin_before_insn(uint64_t pc, void *cpu)
> +{
> +    printf("executing instruction at %lx\n", pc);
> +}


--
Alex Bennée
diff mbox series

Patch

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