From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=58554 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P9Mth-00023H-Hs for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:03:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P9Mtf-0006T8-PP for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:03:25 -0400 Received: from mailout-de.gmx.net ([213.165.64.22]:44260 helo=mail.gmx.net) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1P9Mtf-0006T2-7x for qemu-devel@nongnu.org; Fri, 22 Oct 2010 15:03:23 -0400 From: xscript@gmx.net (=?utf-8?Q?Llu=C3=ADs?=) In-Reply-To: Date: Thu, 21 Oct 2010 19:42:31 +0200 References: Message-Id: <1b9ab3dcfc7ed8bc555533a10d89848bf8bf652c.1287772676.git.vilanova@ac.upc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH 09/18] instrument: Add initial instrumentation example List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --- .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-helpe= rs.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/dynp= rint/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=3D/path/to/qemu/instrument/exam= ples/dynprint/host/ --with-instrument=3D/path/to/qemu/instrument/examples/d= ynprint/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/exampl= es/dynprint/guest/test diff --git a/instrument/examples/dynprint/guest/Makefile b/instrument/examp= les/dynprint/guest/Makefile new file mode 100644 index 0000000..ea266f2 --- /dev/null +++ b/instrument/examples/dynprint/guest/Makefile @@ -0,0 +1,7 @@ +CFLAGS +=3D -I../../../../ +PROGS =3D test + +all: $(PROGS) + +clean: + rm -f $(PROGS) diff --git a/instrument/examples/dynprint/guest/test.c b/instrument/example= s/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 communicatio= n. + * + * Copyright (c) 2010 Llu=C3=ADs Vilanova + * + * 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 . + */ + +#include + +#define TOTAL_ITERS 100 + + +int +main () +{ + int i; + + printf("start\n"); + + for (i =3D 0; i < TOTAL_ITERS; i++) { + printf("iteration\n"); + } + + printf("stop\n"); + + return 0; +} diff --git a/instrument/examples/dynprint/host/Makefile b/instrument/exampl= es/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/exam= ples/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=C3=ADs Vilanova + * + * 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 . + */ + +#include + +#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/examp= les/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=C3=ADs Vilanova + * + * 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 . + */ + 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=C3=ADs Vilanova + * + * 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 . + */ + diff --git a/instrument/examples/dynprint/host/instrument-host.h b/instrume= nt/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=C3=ADs Vilanova + * + * 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 . + */ + +#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 (mandator= y) */ +} instr_type_t; + +#endif /* INSTRUMENT_HOST_H */ --=20 1.7.1 --=20 "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