diff options
Diffstat (limited to 'util/statetrace/statetrace.cc')
-rw-r--r-- | util/statetrace/statetrace.cc | 82 |
1 files changed, 29 insertions, 53 deletions
diff --git a/util/statetrace/statetrace.cc b/util/statetrace/statetrace.cc index d50c24f59..132e5baa3 100644 --- a/util/statetrace/statetrace.cc +++ b/util/statetrace/statetrace.cc @@ -47,7 +47,8 @@ using namespace std; -void printUsage(const char * execName) +void +printUsage(const char * execName) { cout << execName << " <options> -- <command> <arguments>" << endl; cout << "options:" << endl; @@ -58,7 +59,8 @@ void printUsage(const char * execName) cout << " -nt don't print an instruction trace" << endl; } -int main(int argc, char * argv[], char * envp[]) +int +main(int argc, char * argv[], char * envp[]) { TraceChild * child = genTraceChild(); string args; @@ -73,87 +75,64 @@ int main(int argc, char * argv[], char * envp[]) printUsage(argv[0]); return 0; } - for(int x = 1; x < argc; x++) - { - if(!strcmp(argv[x], "-h")) - { + for (int x = 1; x < argc; x++) { + if (!strcmp(argv[x], "-h")) { printUsage(argv[0]); return 0; } - if(!strcmp(argv[x], "--host")) - { + if (!strcmp(argv[x], "--host")) { x++; - if(x >= argc) - { + if (x >= argc) { cerr << "Incorrect usage.\n" << endl; printUsage(argv[0]); return 1; } host = argv[x]; - } - else if(!strcmp(argv[x], "-r")) - { + } else if (!strcmp(argv[x], "-r")) { cout << "Legal register names:" << endl; int numRegs = child->getNumRegs(); - for(unsigned int x = 0; x < numRegs; x++) - { + for (unsigned int x = 0; x < numRegs; x++) cout << "\t" << child->getRegName(x) << endl; - } return 0; - } - else if(!strcmp(argv[x], "-i")) - { + } else if (!strcmp(argv[x], "-i")) { printInitial = true; - } - else if(!strcmp(argv[x], "-nt")) - { + } else if (!strcmp(argv[x], "-nt")) { printTrace = false; - } - else if(!strcmp(argv[x], "--")) - { + } else if (!strcmp(argv[x], "--")) { x++; - if(x >= argc) - { + if (x >= argc) { cerr << "Incorrect usage.\n" << endl; printUsage(argv[0]); return 1; } startProgramArgs = x; break; - } - else - { + } else { cerr << "Incorrect usage.\n" << endl; printUsage(argv[0]); return 1; } } - if(!child->startTracing(argv[startProgramArgs], - argv + startProgramArgs)) - { + if (!child->startTracing(argv[startProgramArgs], + argv + startProgramArgs)) { cerr << "Couldn't start target program" << endl; return 1; } child->step(); - if(printInitial) - { + if (printInitial) child->outputStartState(cout); - } - if(printTrace) - { + if (printTrace) { // Connect to m5 bool portSet = false; int port; int sock = socket(AF_INET, SOCK_STREAM, 0); - if(sock < 0) - { + if (sock < 0) { cerr << "Error opening socket! " << strerror(errno) << endl; return 1; } struct hostent *server; server = gethostbyname(host.c_str()); - if(!server) - { + if (!server) { cerr << "Couldn't get host ip! " << strerror(errno) << endl; return 1; } @@ -164,22 +143,19 @@ int main(int argc, char * argv[], char * envp[]) (char *)&serv_addr.sin_addr.s_addr, server->h_length); serv_addr.sin_port = htons(8000); - if(connect(sock, (sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) - { + if (connect(sock, (sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { cerr << "Couldn't connect to server! " << strerror(errno) << endl; return 1; } - while(child->isTracing()) - { - if(!child->sendState(sock)) - break; - child->step(); + while (child->isTracing()) { + if (!child->sendState(sock)) + break; + child->step(); } } - if(!child->stopTracing()) - { - cerr << "Couldn't stop child" << endl; - return 1; + if (!child->stopTracing()) { + cerr << "Couldn't stop child" << endl; + return 1; } return 0; } |