[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/18] instrument: Add initial instrumentation examp
From: |
Lluís |
Subject: |
[Qemu-devel] [PATCH 09/18] instrument: Add initial instrumentation example |
Date: |
Thu, 21 Oct 2010 19:42:31 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
---
.gitignore | 1 +
instrument/examples/dynprint/README | 16 +++++++
instrument/examples/dynprint/guest/Makefile | 7 +++
instrument/examples/dynprint/guest/test.c | 39 +++++++++++++++++
instrument/examples/dynprint/host/Makefile | 14 ++++++
instrument/examples/dynprint/host/backdoor.c | 44 ++++++++++++++++++++
instrument/examples/dynprint/host/helpers.c | 19 ++++++++
.../dynprint/host/instrument-host-helpers.h | 19 ++++++++
.../examples/dynprint/host/instrument-host.h | 30 +++++++++++++
9 files changed, 189 insertions(+), 0 deletions(-)
create mode 100644 instrument/examples/dynprint/README
create mode 100644 instrument/examples/dynprint/guest/Makefile
create mode 100644 instrument/examples/dynprint/guest/test.c
create mode 100644 instrument/examples/dynprint/host/Makefile
create mode 100644 instrument/examples/dynprint/host/backdoor.c
create mode 100644 instrument/examples/dynprint/host/helpers.c
create mode 100644 instrument/examples/dynprint/host/instrument-host-helpers.h
create mode 100644 instrument/examples/dynprint/host/instrument-host.h
diff --git a/.gitignore b/.gitignore
index e4a351d..7fd5e88 100644
--- a/.gitignore
+++ b/.gitignore
@@ -59,3 +59,4 @@ pc-bios/optionrom/multiboot.raw
.stgit-*
cscope.*
backdoor/examples/print/guest/test
+instrument/examples/dynprint/guest/test
diff --git a/instrument/examples/dynprint/README
b/instrument/examples/dynprint/README
new file mode 100644
index 0000000..a1aa7f1
--- /dev/null
+++ b/instrument/examples/dynprint/README
@@ -0,0 +1,16 @@
+This example defines two instrumentation states:
+ * one printing the address of each fetched instruction
+ * one printing all the available information of each fetched instruction
+
+along with an instruction-based backdoor to dynamically (de)activate such
+states.
+
+To compile the host (quemu) run:
+ /path/to/qemu/configure
--with-backdoor=/path/to/qemu/instrument/examples/dynprint/host/
--with-instrument=/path/to/qemu/instrument/examples/dynprint/host/
+ make
+
+To compile the guest program run:
+ make -C /path/to/qemu/instrument/examples/dynprint/guest/
+
+Now you can run it with:
+ /path/to/qemu/i386-linux-user/qemu-i386
/path/to/qemu/instrument/examples/dynprint/guest/test
diff --git a/instrument/examples/dynprint/guest/Makefile
b/instrument/examples/dynprint/guest/Makefile
new file mode 100644
index 0000000..ea266f2
--- /dev/null
+++ b/instrument/examples/dynprint/guest/Makefile
@@ -0,0 +1,7 @@
+CFLAGS += -I../../../../
+PROGS = test
+
+all: $(PROGS)
+
+clean:
+ rm -f $(PROGS)
diff --git a/instrument/examples/dynprint/guest/test.c
b/instrument/examples/dynprint/guest/test.c
new file mode 100644
index 0000000..254ebcf
--- /dev/null
+++ b/instrument/examples/dynprint/guest/test.c
@@ -0,0 +1,39 @@
+/*
+ * Sample guest program exercising instruction-based backdoor communication.
+ *
+ * Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#define TOTAL_ITERS 100
+
+
+int
+main ()
+{
+ int i;
+
+ printf("start\n");
+
+ for (i = 0; i < TOTAL_ITERS; i++) {
+ printf("iteration\n");
+ }
+
+ printf("stop\n");
+
+ return 0;
+}
diff --git a/instrument/examples/dynprint/host/Makefile
b/instrument/examples/dynprint/host/Makefile
new file mode 100644
index 0000000..45213d1
--- /dev/null
+++ b/instrument/examples/dynprint/host/Makefile
@@ -0,0 +1,14 @@
+# Makefile for user-provided backdoor and instrumentation code
+
+include $(SRC_PATH)/config-host.mak
+include $(SRC_PATH)/rules.mak
+include $(SRC_PATH)/Makefile.objs
+
+libbackdoor.a: backdoor.o
+ $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR
$(TARGET_DIR)$@")
+
+libinstrument.a: helpers.o
+ $(call quiet-command,rm -f $@ && $(AR) rcs $@ $^," AR
$(TARGET_DIR)$@")
+
+clean:
+ rm -f libinstrument.a $(objs)
diff --git a/instrument/examples/dynprint/host/backdoor.c
b/instrument/examples/dynprint/host/backdoor.c
new file mode 100644
index 0000000..7b4e883
--- /dev/null
+++ b/instrument/examples/dynprint/host/backdoor.c
@@ -0,0 +1,44 @@
+/*
+ * Example of dynamic control of instrumentation states.
+ *
+ * Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "cpu.h"
+#include "helper.h"
+
+
+void
+helper_backdoor_i8 (uint32_t imm)
+{
+ switch (imm) {
+ default:
+ printf("Unexpected use of instrumentation backdoor\n");
+ abort();
+ }
+}
+
+void
+helper_backdoor_i8_v (uint32_t imm, target_ulong value)
+{
+ switch (imm) {
+ default:
+ printf("Unexpected use of instrumentation backdoor\n");
+ abort();
+ }
+}
diff --git a/instrument/examples/dynprint/host/helpers.c
b/instrument/examples/dynprint/host/helpers.c
new file mode 100644
index 0000000..656b716
--- /dev/null
+++ b/instrument/examples/dynprint/host/helpers.c
@@ -0,0 +1,19 @@
+/*
+ * Example of static instrumentation point callbacks.
+ *
+ * Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
diff --git a/instrument/examples/dynprint/host/instrument-host-helpers.h
b/instrument/examples/dynprint/host/instrument-host-helpers.h
new file mode 100644
index 0000000..e88738d
--- /dev/null
+++ b/instrument/examples/dynprint/host/instrument-host-helpers.h
@@ -0,0 +1,19 @@
+/*
+ * Example of static instrumentation point callback definitions.
+ *
+ * Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
diff --git a/instrument/examples/dynprint/host/instrument-host.h
b/instrument/examples/dynprint/host/instrument-host.h
new file mode 100644
index 0000000..9ede6af
--- /dev/null
+++ b/instrument/examples/dynprint/host/instrument-host.h
@@ -0,0 +1,30 @@
+/*
+ * Example of static instrumentation points.
+ *
+ * Copyright (c) 2010 Lluís Vilanova <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INSTRUMENT_HOST_H
+#define INSTRUMENT_HOST_H
+
+/* See "instrument/host-stub.h" for a description of macro arguments. */
+
+/* Instrumentation types */
+typedef enum {
+ INSTR_TYPE_COUNT /* Total number of instrumentation types (mandatory) */
+} instr_type_t;
+
+#endif /* INSTRUMENT_HOST_H */
--
1.7.1
--
"And it's much the same thing with knowledge, for whenever you learn
something new, the whole world becomes that much richer."
-- The Princess of Pure Reason, as told by Norton Juster in The Phantom
Tollbooth
- [Qemu-devel] [PATCH 17/18] instrument: Add PLVL point, (continued)
- [Qemu-devel] [PATCH 17/18] instrument: Add PLVL point, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 18/18] instrument: [i386] Call PLVL point, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 03/18] backdoor: [all] Include backdoor helper declarations, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 04/18] backdoor: Declare guest-side interface macros, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 08/18] instrument: Handle config-time activation, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 12/18] instrument: [all] Include instrumentation helper declarations, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 07/18] backdoor: Add a simple example, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 11/18] instrument: Code-generation macros, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 05/18] backdoor: [i386] Decode backdoor instructions, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 06/18] backdoor: [i386] Declare guest-side interface macros, Lluís, 2010/10/22
- [Qemu-devel] [PATCH 09/18] instrument: Add initial instrumentation example,
Lluís <=
- [Qemu-devel] [PATCH 10/18] instrument: Dynamic per-CPU state of static instrumentation points, Lluís, 2010/10/22
- Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation, Blue Swirl, 2010/10/23
- backdoor [Was: Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation], Lluís, 2010/10/25
- [Qemu-devel] Re: backdoor [Was: Re: [PATCH 00/17] [RFC] static instrumentation], Paolo Bonzini, 2010/10/25
- Re: [Qemu-devel] Re: backdoor, Lluís, 2010/10/25
- Re: [Qemu-devel] Re: backdoor, Anthony Liguori, 2010/10/25
- Re: [Qemu-devel] Re: backdoor, Lluís, 2010/10/25
- Re: [Qemu-devel] Re: backdoor, Anthony Liguori, 2010/10/25
- Re: [Qemu-devel] Re: backdoor, Lluís, 2010/10/26
- Re: backdoor [Was: Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation], Blue Swirl, 2010/10/25