qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: xscript@gmx.net (Lluís)
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 09/18] instrument: Add initial instrumentation example
Date: Thu, 21 Oct 2010 19:42:31 +0200	[thread overview]
Message-ID: <1b9ab3dcfc7ed8bc555533a10d89848bf8bf652c.1287772676.git.vilanova@ac.upc.edu> (raw)
In-Reply-To: <cover.1287772676.git.vilanova@ac.upc.edu>


---
 .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 <vilanova@ac.upc.edu>
+ *
+ * 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 <vilanova@ac.upc.edu>
+ *
+ * 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 <vilanova@ac.upc.edu>
+ *
+ * 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 <vilanova@ac.upc.edu>
+ *
+ * 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 <vilanova@ac.upc.edu>
+ *
+ * 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

  parent reply	other threads:[~2010-10-22 19:03 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-22 18:32 [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation Lluís
2010-10-22 18:53 ` Lluís
2010-10-18 17:24   ` [Qemu-devel] [PATCH 01/18] backdoor: Handle config-time activation Lluís
2010-10-18 17:40   ` [Qemu-devel] [PATCH 04/18] backdoor: Declare guest-side interface macros Lluís
2010-10-18 18:08   ` [Qemu-devel] [PATCH 06/18] backdoor: [i386] " Lluís
2010-10-18 18:27   ` [Qemu-devel] [PATCH 08/18] instrument: Handle config-time activation Lluís
2010-10-19 19:14   ` [Qemu-devel] [PATCH 05/18] backdoor: [i386] Decode backdoor instructions Lluís
2010-10-19 19:22   ` [Qemu-devel] [PATCH 02/18] backdoor: Declare host-side backdoor helpers Lluís
2010-10-19 19:33   ` [Qemu-devel] [PATCH 03/18] backdoor: [all] Include backdoor helper declarations Lluís
2010-10-19 20:05   ` [Qemu-devel] [PATCH 07/18] backdoor: Add a simple example Lluís
2010-10-19 21:11   ` [Qemu-devel] [PATCH 13/18] instrument: Add FETCH point Lluís
2010-10-19 21:12   ` [Qemu-devel] [PATCH 15/18] instrument: Add VMEM point Lluís
2010-10-19 21:36   ` [Qemu-devel] [PATCH 18/18] instrument: [i386] Call PLVL point Lluís
2010-10-19 21:36   ` [Qemu-devel] [PATCH 17/18] instrument: Add " Lluís
2010-10-19 21:37   ` [Qemu-devel] [PATCH 10/18] instrument: Dynamic per-CPU state of static instrumentation points Lluís
2010-10-19 21:40   ` [Qemu-devel] [PATCH 14/18] instrument: [i386] Call FETCH point Lluís
2010-10-21 14:36   ` [Qemu-devel] [PATCH 11/18] instrument: Code-generation macros Lluís
2010-10-21 17:42   ` Lluís [this message]
2010-10-21 20:55   ` [Qemu-devel] [PATCH 12/18] instrument: [all] Include instrumentation helper declarations Lluís
2010-10-22 14:00   ` [Qemu-devel] [PATCH 16/18] instrument: [all] Call VMEM point Lluís
2010-10-23 12:40 ` [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation Blue Swirl
2010-10-25 10:54   ` backdoor [Was: Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation] Lluís
2010-10-25 12:29     ` [Qemu-devel] Re: backdoor [Was: " Paolo Bonzini
2010-10-25 13:37       ` [Qemu-devel] Re: backdoor Lluís
2010-10-25 21:20         ` Anthony Liguori
2010-10-25 22:48           ` Lluís
2010-10-25 23:06             ` Anthony Liguori
2010-10-26 20:03               ` Lluís
2010-10-25 17:27     ` backdoor [Was: Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation] Blue Swirl
2010-10-25 20:54       ` [Qemu-devel] Re: backdoor Lluís
2010-10-25 11:13   ` instrument [Was: Re: [Qemu-devel] [PATCH 00/17] [RFC] static instrumentation] Lluís
2010-10-25 18:31     ` Blue Swirl
2010-10-25 21:48       ` [Qemu-devel] Re: instrument Lluís

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1b9ab3dcfc7ed8bc555533a10d89848bf8bf652c.1287772676.git.vilanova@ac.upc.edu \
    --to=xscript@gmx.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).