about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorCristian Cadar <c.cadar@imperial.ac.uk>2019-08-09 16:01:18 +0100
committerMartinNowack <martin.nowack@gmail.com>2019-08-14 16:26:48 +0100
commit5b1214aa066b1ead91ed6df5f17eae244b932736 (patch)
tree90ed3059f506f2f2a50a2644aaf571cce7d19783
parent88bb205e422ee2aaf75594e4e314b21f77f219e3 (diff)
downloadklee-5b1214aa066b1ead91ed6df5f17eae244b932736.tar.gz
Added an option to klee-replay to keep replay directory
-rw-r--r--tools/klee-replay/file-creator.c3
-rw-r--r--tools/klee-replay/klee-replay.c62
-rw-r--r--tools/klee-replay/klee-replay.h3
3 files changed, 41 insertions, 27 deletions
diff --git a/tools/klee-replay/file-creator.c b/tools/klee-replay/file-creator.c
index 6440b414..f6a077c2 100644
--- a/tools/klee-replay/file-creator.c
+++ b/tools/klee-replay/file-creator.c
@@ -478,6 +478,9 @@ int remove_callback(const char *fpath,
 }
 
 void replay_delete_files() {
+  if (keep_temps)
+    return;
+
   fprintf(stderr, "KLEE-REPLAY: NOTE: removing %s\n", replay_dir);
 
   if (nftw(replay_dir, remove_callback, FOPEN_MAX,
diff --git a/tools/klee-replay/klee-replay.c b/tools/klee-replay/klee-replay.c
index 9f5acef8..33c28d22 100644
--- a/tools/klee-replay/klee-replay.c
+++ b/tools/klee-replay/klee-replay.c
@@ -48,6 +48,7 @@ static struct option long_options[] = {
   {"create-files-only", required_argument, 0, 'f'},
   {"chroot-to-dir", required_argument, 0, 'r'},
   {"help", no_argument, 0, 'h'},
+  {"keep-replay-dir", no_argument, 0, 'k'},
   {0, 0, 0, 0},
 };
 
@@ -257,12 +258,16 @@ static void usage(void) {
   fprintf(stderr, "   or: %s --create-files-only <ktest-file>\n", progname);
   fprintf(stderr, "\n");
   fprintf(stderr, "-r, --chroot-to-dir=DIR  use chroot jail, requires CAP_SYS_CHROOT\n");
+  fprintf(stderr, "-k, --keep-replay-dir    do not delete replay directory\n");
   fprintf(stderr, "-h, --help               display this help and exit\n");
   fprintf(stderr, "\n");
   fprintf(stderr, "Use KLEE_REPLAY_TIMEOUT environment variable to set a timeout (in seconds).\n");
   exit(1);
 }
 
+
+int keep_temps = 0;
+
 int main(int argc, char** argv) {
   int prg_argc;
   char ** prg_argv;
@@ -273,35 +278,38 @@ int main(int argc, char** argv) {
     usage();
 
   int c, opt_index;
-  while ((c = getopt_long(argc, argv, "f:r:", long_options, &opt_index)) != -1) {
+  while ((c = getopt_long(argc, argv, "f:r:k", long_options, &opt_index)) != -1) {
     switch (c) {
-      case 'f': {
-        /* Special case hack for only creating files and not actually executing
-        * the program.
-         */
-        if (argc != 3)
-          usage();
-
-        char* input_fname = optarg;
-
-        input = kTest_fromFile(input_fname);
-        if (!input) {
-          fprintf(stderr, "KLEE-REPLAY: ERROR: input file %s not valid.\n",
-                  input_fname);
-          exit(1);
-        }
-
-        prg_argc = input->numArgs;
-        prg_argv = input->args;
-        prg_argv[0] = argv[1];
-        klee_init_env(&prg_argc, &prg_argv);
-
-        replay_create_files(&__exe_fs);
-        return 0;
+    case 'f': {
+      /* Special case hack for only creating files and not actually executing
+       * the program. */
+      if (argc != 3)
+        usage();
+
+      char *input_fname = optarg;
+
+      input = kTest_fromFile(input_fname);
+      if (!input) {
+        fprintf(stderr, "KLEE-REPLAY: ERROR: input file %s not valid.\n", input_fname);
+        exit(1);
       }
-      case 'r':
-        rootdir = optarg;
-        break;
+
+      prg_argc = input->numArgs;
+      prg_argv = input->args;
+      prg_argv[0] = argv[1];
+      klee_init_env(&prg_argc, &prg_argv);
+
+      replay_create_files(&__exe_fs);
+      return 0;
+    }
+
+    case 'r':
+      rootdir = optarg;
+      break;
+
+    case 'k':
+      keep_temps = 1;
+      break;
     }
   }
 
diff --git a/tools/klee-replay/klee-replay.h b/tools/klee-replay/klee-replay.h
index 8dc3b872..5701caa5 100644
--- a/tools/klee-replay/klee-replay.h
+++ b/tools/klee-replay/klee-replay.h
@@ -21,6 +21,9 @@
 // temporary directory used for replay
 extern char replay_dir[];
 
+// whether to keep the replay directory or delete it
+extern int keep_temps;
+
 void replay_create_files(exe_file_system_t *exe_fs);
 void replay_delete_files();