snapshot: read from /proc/self/maps
[model-checker.git] / snapshot-interface.cc
index 072c1f959ac07c256129248174665a33fb5e7b30..c22b8712b32937cbd415fb9f2ab7d1039e8c97a8 100644 (file)
@@ -3,7 +3,6 @@
 #include <iostream>
 #include <fstream>
 #include <unistd.h>
-#include <sys/types.h>
 #include <sstream>
 #include <cstring>
 #include <string>
@@ -16,7 +15,7 @@
 
 #define MYBINARYNAME "model"
 #define MYLIBRARYNAME "libmodel.so"
-#define MAPFILE_FORMAT "/proc/%d/maps"
+#define MAPFILE "/proc/self/maps"
 
 SnapshotStack * snapshotObject;
 
@@ -73,12 +72,10 @@ static void SnapshotGlobalSegments(){
  *     library to snapshot them.
  */
 static void SnapshotGlobalSegments(){
-       int pid = getpid();
-       char buf[9000], filename[100];
+       char buf[9000];
        FILE *map;
 
-       sprintf(filename, MAPFILE_FORMAT, pid);
-       map = fopen(filename, "r");
+       map = fopen(MAPFILE, "r");
        if (!map) {
                perror("fopen");
                exit(EXIT_FAILURE);
@@ -93,7 +90,7 @@ static void SnapshotGlobalSegments(){
                        size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
                        if (len != 0)
                                addMemoryRegionToSnapShot(begin, len);
-                       DEBUG("%45s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
+                       DEBUG("%55s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
                }
        }
        fclose(map);
@@ -124,13 +121,13 @@ int SnapshotStack::backTrackBeforeStep(int seqindex) {
                }
                struct stackEntry *tmp=stack;
                stack=stack->next;
-               MYFREE(tmp);
+               model_free(tmp);
        }
 }
 
 /** This method takes a snapshot at the given sequence number. */
 void SnapshotStack::snapshotStep(int seqindex) {
-       struct stackEntry *tmp=(struct stackEntry *)MYMALLOC(sizeof(struct stackEntry));
+       struct stackEntry *tmp=(struct stackEntry *)model_malloc(sizeof(struct stackEntry));
        tmp->next=stack;
        tmp->index=seqindex;
        tmp->snapshotid=takeSnapshot();