From: Brian Norris Date: Sun, 4 Nov 2012 01:16:19 +0000 (-0700) Subject: Merge branch 'master' into pldi13 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=2e067c102b91db06977412388b69d06a0c0b7166;hp=d1fab609e185bf89056da0f88030750d28bc9b32 Merge branch 'master' into pldi13 --- diff --git a/common.cc b/common.cc index b274989f..f4aa7ece 100644 --- a/common.cc +++ b/common.cc @@ -2,6 +2,8 @@ #include #include +#include + #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); + } +} diff --git a/common.h b/common.h index 50410ea7..81b26728 100644 --- 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__) diff --git a/config.h b/config.h index 109e8d86..227c9a9c 100644 --- 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 index 00000000..a091e15f --- /dev/null +++ b/include/model-assert.h @@ -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 8a17a18e..e8d4f9af 100644 --- 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); diff --git a/snapshot-interface.cc b/snapshot-interface.cc index 47fafa5b..51fe2f08 100644 --- a/snapshot-interface.cc +++ b/snapshot-interface.cc @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -13,10 +12,11 @@ #include #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); diff --git a/snapshotimp.h b/snapshotimp.h index 2e4929d0..b03d2852 100644 --- a/snapshotimp.h +++ b/snapshotimp.h @@ -9,7 +9,6 @@ #include #include #include -#include #include #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