1 /* -*- Mode: C; indent-tabs-mode: t -*- */
3 #define MYBINARYNAME "model"
4 #define MYLIBRARYNAME "libmodel.so"
5 #define MYALLOCNAME "libmymemory.so"
6 #define PROCNAME "/proc/*/maps"
9 #include "snapshot-interface.h"
13 #include <sys/types.h>
18 snapshotStack * snapshotObject;
20 /*This looks like it might leak memory... Subramanian should fix this. */
22 typedef std::basic_stringstream< char, std::char_traits< char >, MyAlloc< char > > MyStringStream;
23 std::vector< MyString, MyAlloc< MyString> > splitString( MyString input, char delim ){
24 std::vector< MyString, MyAlloc< MyString > > splits;
25 MyStringStream ss( input );
27 while( std::getline( ss, item, delim ) ){
28 splits.push_back( item );
33 bool checkPermissions( MyString permStr ){
34 return permStr.find("w") != MyString::npos;
36 static void takeSegmentSnapshot( const MyString & lineText ){
37 std::vector< MyString, MyAlloc< MyString > > firstSplit = splitString( lineText, ' ' );
38 if( checkPermissions( firstSplit[ 1 ] ) ){
39 std::vector< MyString, MyAlloc< MyString > > secondSplit = splitString( firstSplit[ 0 ], '-' );
40 size_t val1 = 0, val2 = 0;
41 sscanf( secondSplit[ 0 ].c_str(), "%zx", &val1 );
42 sscanf( secondSplit[ 1 ].c_str(), "%zx", &val2 );
43 size_t len = ( val2 - val1 ) / PAGESIZE;
45 addMemoryRegionToSnapShot( ( void * )val1, len );
49 void SnapshotGlobalSegments(){
50 MyString fn = PROCNAME;
51 static char sProcessSize[ 12 ] = { 0 };
52 std::pair< const char *, bool > dataSect[ 3 ];
53 dataSect[ 0 ] = std::make_pair( MYBINARYNAME, false );
54 dataSect[ 1 ] = std::make_pair( MYLIBRARYNAME, false );
55 dataSect[ 2 ] = std::make_pair( MYALLOCNAME, false );
56 static pid_t sProcID = 0;
59 sprintf( sProcessSize, "%d", sProcID );
61 fn.replace( REPLACEPOS, 1, sProcessSize );
62 std::ifstream procName( fn.c_str() );
63 if( procName.is_open() ){
65 while( procName.good() ){
66 getline( procName, line );
68 for( i = 0; i < 3; ++i ){
69 if( MyString::npos != line.find( dataSect[ i ].first ) ) break;
71 if( i >= 3 || dataSect[ i ].second == true ) continue;
72 dataSect[ i ].second = true;
73 if( !procName.good() )return;
74 getline( procName, line );
75 takeSegmentSnapshot( line );
80 //class definition of snapshotStack.....
81 //declaration of constructor....
82 snapshotStack::snapshotStack(){
83 SnapshotGlobalSegments();
87 snapshotStack::~snapshotStack(){
90 int snapshotStack::backTrackBeforeStep(int seqindex) {
92 if (stack->index<=seqindex) {
94 rollBack(stack->snapshotid);
97 struct stackEntry *tmp=stack;
103 void snapshotStack::snapshotStep(int seqindex) {
104 struct stackEntry *tmp=(struct stackEntry *)malloc(sizeof(struct stackEntry));
107 tmp->snapshotid=takeSnapshot();