--- .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 <vilan...@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 <vilan...@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 <vilan...@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 <vilan...@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 <vilan...@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