1 #include "snapshot-interface.h"
17 #define MYBINARYNAME "model"
18 #define MYLIBRARYNAME "libmodel.so"
19 #define MAPFILE_FORMAT "/proc/%d/maps"
21 SnapshotStack * snapshotObject;
24 void SnapshotGlobalSegments(){
26 char buf[9000], execname[100];
29 sprintf(execname, "vmmap -interleaved %d", pid);
30 map=popen(execname, "r");
37 /* Wait for correct part */
38 while (fgets(buf, sizeof(buf), map)) {
39 if (strstr(buf, "==== regions for process"))
43 while (fgets(buf, sizeof(buf), map)) {
44 char regionname[200] = "";
52 //Skip out at the end of the section
56 sscanf(buf, "%22s %p-%p [%5dK] %c%c%c/%c%c%c SM=%3s %200s\n", &type, &begin, &end, &size, &r, &w, &x, &mr, &mw, &mx, smstr, regionname);
58 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
61 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
63 addMemoryRegionToSnapShot(begin, len);
64 DEBUG("%45s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
70 void SnapshotGlobalSegments(){
72 char buf[9000], filename[100];
75 sprintf(filename, MAPFILE_FORMAT, pid);
76 map = fopen(filename, "r");
81 while (fgets(buf, sizeof(buf), map)) {
82 char regionname[200] = "";
86 sscanf(buf, "%p-%p %c%c%c%c %*x %*x:%*x %*u %200s\n", &begin, &end, &r, &w, &x, &p, regionname);
87 if (w == 'w' && (strstr(regionname, MYBINARYNAME) || strstr(regionname, MYLIBRARYNAME))) {
88 size_t len = ((uintptr_t)end - (uintptr_t)begin) / PAGESIZE;
90 addMemoryRegionToSnapShot(begin, len);
91 DEBUG("%45s: %18p - %18p\t%c%c%c%c\n", regionname, begin, end, r, w, x, p);
98 //class definition of SnapshotStack.....
99 //declaration of constructor....
100 SnapshotStack::SnapshotStack(){
101 SnapshotGlobalSegments();
105 SnapshotStack::~SnapshotStack(){
108 int SnapshotStack::backTrackBeforeStep(int seqindex) {
110 if (stack->index<=seqindex) {
112 rollBack(stack->snapshotid);
115 struct stackEntry *tmp=stack;
121 void SnapshotStack::snapshotStep(int seqindex) {
122 struct stackEntry *tmp=(struct stackEntry *)MYMALLOC(sizeof(struct stackEntry));
125 tmp->snapshotid=takeSnapshot();