Merge branch 'master' into pldi13
authorBrian Norris <banorris@uci.edu>
Sun, 4 Nov 2012 01:16:19 +0000 (18:16 -0700)
committerBrian Norris <banorris@uci.edu>
Sun, 4 Nov 2012 01:16:19 +0000 (18:16 -0700)
common.cc
common.h
config.h
include/model-assert.h [new file with mode: 0644]
main.cc
snapshot-interface.cc
snapshotimp.h

index b274989f48bc4d885f6976b596139b1e5bde42ed..f4aa7ecefa023417c7eec4680e38e1c25a5cc13b 100644 (file)
--- a/common.cc
+++ b/common.cc
@@ -2,6 +2,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#include <model-assert.h>
+
 #include "common.h"
 #include "model.h"
 #include "stacktrace.h"
@@ -40,3 +42,13 @@ void assert_hook(void)
 {
        printf("Add breakpoint to line %u in file %s.\n",__LINE__,__FILE__);
 }
+
+void model_assert(bool expr, const char *file, int line)
+{
+       if (!expr) {
+               printf("  [BUG] Program has hit assertion in file %s at line %d\n",
+                               file, line);
+               model->set_assert();
+               model->switch_to_master(NULL);
+       }
+}
index 50410ea7e0a1bce920a2bb3ce3b968d602f929de..81b26728d917c0af8c1b26e9d0fa2d28cccb8a5a 100644 (file)
--- a/common.h
+++ b/common.h
@@ -20,6 +20,7 @@
 
 void assert_hook(void);
 
+#ifdef CONFIG_ASSERT
 #define ASSERT(expr) \
 do { \
        if (!(expr)) { \
@@ -30,6 +31,10 @@ do { \
                exit(EXIT_FAILURE); \
        } \
 } while (0)
+#else
+#define ASSERT(expr) \
+       do { } while (0)
+#endif /* CONFIG_ASSERT */
 
 #define error_msg(...) fprintf(stderr, "Error: " __VA_ARGS__)
 
index 109e8d86097ab55c545705f0059c544bb01b9738..227c9a9c7a5df0586b84c254eaab5f431bd58559 100644 (file)
--- a/config.h
+++ b/config.h
@@ -9,6 +9,10 @@
 /*             #ifndef CONFIG_DEBUG
                #define CONFIG_DEBUG
                #endif
+
+               #ifndef CONFIG_ASSERT
+               #define CONFIG_ASSERT
+               #endif
 */
 
 /** Turn on support for dumping cyclegraphs as dot files at each
diff --git a/include/model-assert.h b/include/model-assert.h
new file mode 100644 (file)
index 0000000..a091e15
--- /dev/null
@@ -0,0 +1,15 @@
+#ifndef __MODEL_ASSERT_H__
+#define __MODEL_ASSERT_H__
+
+#if __cplusplus
+extern "C" {
+#endif
+
+void model_assert(bool expr, const char *file, int line);
+#define MODEL_ASSERT(expr) model_assert((expr), __FILE__, __LINE__)
+
+#if __cplusplus
+}
+#endif
+
+#endif /* __MODEL_ASSERT_H__ */
diff --git a/main.cc b/main.cc
index 8a17a18e50d718324662e178f6496dec58fbbe00..e8d4f9af356f4ac6a59ab21f69fc26d6bd2d12bb 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -75,8 +75,10 @@ static void parse_options(struct model_params *params, int *argc, char ***argv)
                        break;
                }
        }
-       (*argc) -= optind;
-       (*argv) += optind;
+       (*argv)[optind - 1] = (*argv)[0];
+       (*argc) -= (optind - 1);
+       (*argv) += (optind - 1);
+       optind = 1;
 
        if (error)
                print_usage(params);
index 47fafa5b0641f8865cb279c47f08531e9cbfd4f1..51fe2f08de1392dd6fe40cd3757edcf675367c60 100644 (file)
@@ -3,7 +3,6 @@
 #include <iostream>
 #include <fstream>
 #include <unistd.h>
-#include <sys/types.h>
 #include <sstream>
 #include <cstring>
 #include <string>
 #include <inttypes.h>
 #include "common.h"
 
-
+/* MYBINARYNAME only works because our pathname usually includes 'model' (e.g.,
+ * /.../model-checker/test/userprog.o) */
 #define MYBINARYNAME "model"
 #define MYLIBRARYNAME "libmodel.so"
-#define MAPFILE_FORMAT "/proc/%d/maps"
+#define MAPFILE "/proc/self/maps"
 
 SnapshotStack * snapshotObject;
 
@@ -68,28 +68,37 @@ static void SnapshotGlobalSegments(){
        pclose(map);
 }
 #else
+
+static void get_binary_name(char *buf, size_t len)
+{
+       if (readlink("/proc/self/exe", buf, len) == -1) {
+               perror("readlink");
+               exit(EXIT_FAILURE);
+       }
+}
+
 /** The SnapshotGlobalSegments function computes the memory regions
  *     that may contain globals and then configures the snapshotting
  *     library to snapshot them.
  */
 static void SnapshotGlobalSegments(){
-       int pid = getpid();
-       char buf[9000], filename[100];
+       char buf[9000];
+       char binary_name[800];
        FILE *map;
 
-       sprintf(filename, MAPFILE_FORMAT, pid);
-       map = fopen(filename, "r");
+       map = fopen(MAPFILE, "r");
        if (!map) {
                perror("fopen");
                exit(EXIT_FAILURE);
        }
+       get_binary_name(binary_name, sizeof(binary_name));
        while (fgets(buf, sizeof(buf), map)) {
                char regionname[200] = "";
                char r, w, x, p;
                void *begin, *end;
 
                sscanf(buf, "%p-%p %c%c%c%c %*x %*x:%*x %*u %200s\n", &begin, &end, &r, &w, &x, &p, regionname);
-               if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
+               if (w == 'w' && (strstr(regionname, binary_name) || strstr(regionname, MYLIBRARYNAME))) {
                        size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
                        if (len != 0)
                                addMemoryRegionToSnapShot(begin, len);
index 2e4929d0477e4605cd5363fb86266cd054d1f3fe..b03d28527e3efe69257cbf48ac1311776dbec5ee 100644 (file)
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <sys/mman.h>
-#include <sys/types.h>
 #include <csignal>
 #define SHARED_MEMORY_DEFAULT  (100 * ((size_t)1 << 20)) // 100mb for the shared memory
 #define STACK_SIZE_DEFAULT      (((size_t)1 << 20) * 20)  // 20 mb out of the above 100 mb for my stack