diff options
Diffstat (limited to 'util/statetrace')
-rw-r--r-- | util/statetrace/Makefile | 4 | ||||
-rw-r--r-- | util/statetrace/arch/tracechild_sparc.cc | 58 | ||||
-rw-r--r-- | util/statetrace/arch/tracechild_sparc.hh | 10 | ||||
-rw-r--r-- | util/statetrace/statetrace.cc | 114 | ||||
-rw-r--r-- | util/statetrace/tracechild.cc | 15 | ||||
-rw-r--r-- | util/statetrace/tracechild.hh | 1 |
6 files changed, 114 insertions, 88 deletions
diff --git a/util/statetrace/Makefile b/util/statetrace/Makefile index c59748163..2abc06d8e 100644 --- a/util/statetrace/Makefile +++ b/util/statetrace/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2006 The Regents of The University of Michigan +# Copyright (c) 2006-2007 The Regents of The University of Michigan # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -34,4 +34,4 @@ statetrace-native: statetrace.cc tracechild.cc tracechild_arch.cc printer.cc pri g++ statetrace.cc tracechild.cc tracechild_arch.cc printer.cc -I ./ -I ./arch/ -O3 --static -o statetrace statetrace-sparc: statetrace.cc tracechild.cc tracechild_arch.cc printer.cc printer.hh refcnt.hh regstate.hh tracechild.hh - sparc64-unknown-linux-gnu-g++ statetrace.cc tracechild.cc tracechild_arch.cc printer.cc -I ./ -I ./arch/ -O3 --static -o statetrace + sparc64-unknown-linux-gnu-g++ statetrace.cc tracechild.cc tracechild_arch.cc printer.cc -g -I ./ -I ./arch/ -O3 --static -o statetrace diff --git a/util/statetrace/arch/tracechild_sparc.cc b/util/statetrace/arch/tracechild_sparc.cc index 2f42330e4..f60f9916b 100644 --- a/util/statetrace/arch/tracechild_sparc.cc +++ b/util/statetrace/arch/tracechild_sparc.cc @@ -54,8 +54,45 @@ string SparcTraceChild::regNames[numregs] = { //Miscelaneous "fsr", "fprs", "pc", "npc", "y", "cwp", "pstate", "asi", "ccr"}; +bool SparcTraceChild::sendState(int socket) +{ + uint64_t regVal = 0; + for(int x = 0; x <= I7; x++) + { + regVal = getRegVal(x); + if(write(socket, ®Val, sizeof(regVal)) == -1) + { + cerr << "Write failed! " << strerror(errno) << endl; + tracing = false; + return false; + } + } + regVal = getRegVal(PC); + if(write(socket, ®Val, sizeof(regVal)) == -1) + { + cerr << "Write failed! " << strerror(errno) << endl; + tracing = false; + return false; + } + regVal = getRegVal(NPC); + if(write(socket, ®Val, sizeof(regVal)) == -1) + { + cerr << "Write failed! " << strerror(errno) << endl; + tracing = false; + return false; + } + regVal = getRegVal(CCR); + if(write(socket, ®Val, sizeof(regVal)) == -1) + { + cerr << "Write failed! " << strerror(errno) << endl; + tracing = false; + return false; + } + return true; +} + int64_t getRegs(regs & myregs, fpu & myfpu, - int64_t * locals, int64_t * inputs, int num) + uint64_t * locals, uint64_t * inputs, int num) { assert(num < SparcTraceChild::numregs && num >= 0); switch(num) @@ -160,14 +197,19 @@ bool SparcTraceChild::update(int pid) cerr << "Update failed" << endl; return false; } - uint64_t StackPointer = getSP(); - const int stackBias = (StackPointer % 1) ? 2047 : 0; + uint64_t stackPointer = getSP(); + uint64_t stackBias = 2047; + bool v9 = stackPointer % 2; for(unsigned int x = 0; x < 8; x++) { - locals[x] = ptrace(PTRACE_PEEKTEXT, pid, - StackPointer + stackBias + x * 8, 0); - inputs[x] = ptrace(PTRACE_PEEKTEXT, pid, - StackPointer + stackBias + x * 8 + (8 * 8), 0); + uint64_t localAddr = stackPointer + + (v9 ? (stackBias + x * 8) : (x * 4)); + locals[x] = ptrace(PTRACE_PEEKTEXT, pid, localAddr, 0); + if(!v9) locals[x] >>= 32; + uint64_t inputAddr = stackPointer + + (v9 ? (stackBias + x * 8 + (8 * 8)) : (x * 4 + 8 * 4)); + inputs[x] = ptrace(PTRACE_PEEKTEXT, pid, inputAddr, 0); + if(!v9) inputs[x] >>= 32; } if(ptrace(PTRACE_GETFPREGS, pid, &thefpregs, 0) != 0) return false; @@ -366,7 +408,7 @@ ostream & SparcTraceChild::outputStartState(ostream & os) { bool v8 = false; uint64_t sp = getSP(); - if(sp % 1) + if(sp % 2) { os << "Detected a 64 bit executable.\n"; v8 = false; diff --git a/util/statetrace/arch/tracechild_sparc.hh b/util/statetrace/arch/tracechild_sparc.hh index 8b4ff9aae..0284fb82e 100644 --- a/util/statetrace/arch/tracechild_sparc.hh +++ b/util/statetrace/arch/tracechild_sparc.hh @@ -72,10 +72,10 @@ private: regs oldregs; fpu thefpregs; fpu oldfpregs; - int64_t locals[8]; - int64_t oldLocals[8]; - int64_t inputs[8]; - int64_t oldInputs[8]; + uint64_t locals[8]; + uint64_t oldLocals[8]; + uint64_t inputs[8]; + uint64_t oldInputs[8]; bool regDiffSinceUpdate[numregs]; //This calculates where the pc might go after the current instruction. @@ -90,6 +90,8 @@ protected: public: SparcTraceChild(); + bool sendState(int socket); + int getNumRegs() { return numregs; diff --git a/util/statetrace/statetrace.cc b/util/statetrace/statetrace.cc index e5baee395..4fe47dc02 100644 --- a/util/statetrace/statetrace.cc +++ b/util/statetrace/statetrace.cc @@ -35,88 +35,48 @@ #include <sys/wait.h> #include <sys/ptrace.h> #include <unistd.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <errno.h> -#include "tracechild.hh" #include "printer.hh" +#include "tracechild.hh" using namespace std; void printUsage(const char * execName) { - cout << execName << " -f <output format file> | -h | -r -- <command> <arguments>" << endl; + cout << execName << " -h | -r -- <command> <arguments>" << endl; } int main(int argc, char * argv[], char * envp[]) { TraceChild * child = genTraceChild(); - NestingPrinter printer(child); string args; int startProgramArgs; //Parse the command line arguments - bool formatStringSet = false; bool printInitial = false; bool printTrace = true; - string format; for(int x = 1; x < argc; x++) { - if(!strcmp(argv[x], "-f")) - { - if(formatStringSet) - { - cerr << "Attempted to set format twice!" - << endl; - printUsage(argv[0]); - return 1; - } - formatStringSet = true; - x++; - if(x >= argc) - { - cerr << "Incorrect usage.\n" << endl; - printUsage(argv[0]); - return 1; - } - ifstream formatFile(argv[x]); - if(!formatFile) - { - cerr << "Problem opening file " - << argv[x] << "." << endl; - return 1; - } - format = ""; - while(formatFile) - { - string line; - getline(formatFile, line); - if(formatFile.eof()) - { - format += line; - break; - } - if(!formatFile) - { - cerr << "Problem reading from file " - << argv[x] << "." << endl; - return 1; - } - format += line + '\n'; - } - } - else if(!strcmp(argv[x], "-h")) + if(!strcmp(argv[x], "-h")) { printUsage(argv[0]); return 0; } else if(!strcmp(argv[x], "-r")) { - cout << "Legal register names:" << endl; - int numRegs = child->getNumRegs(); - for(unsigned int x = 0; x < numRegs; x++) - { - cout << "\t" << child->getRegName(x) << endl; - } - return 0; + cout << "Legal register names:" << endl; + int numRegs = child->getNumRegs(); + for(unsigned int x = 0; x < numRegs; x++) + { + cout << "\t" << child->getRegName(x) << endl; + } + return 0; } else if(!strcmp(argv[x], "-i")) { @@ -145,11 +105,6 @@ int main(int argc, char * argv[], char * envp[]) return 1; } } - /*for(unsigned int x = startProgramArgs; x < argc; x++) - { - cout << "Adding argument " << argv[x]; - args += string(" ") + argv[x]; - }*/ if(!child->startTracing(argv[startProgramArgs], argv + startProgramArgs)) { @@ -162,26 +117,41 @@ int main(int argc, char * argv[], char * envp[]) } if(printTrace) { - if(!formatStringSet) + // Connect to m5 + bool portSet = false; + int port; + int sock = socket(AF_INET, SOCK_STREAM, 0); + if(sock < 0) { - cerr << "No output format set!" << endl; - child->stopTracing(); - printUsage(argv[0]); - return 1; + cerr << "Error opening socket! " << strerror(errno) << endl; + return 1; } - if(!printer.configure(format)) + struct hostent *server; + server = gethostbyname("zower.eecs.umich.edu"); + if(!server) { - cerr << "Problem in the output format" << endl; - child->stopTracing(); - return 1; + cerr << "Couldn't get host ip! " << strerror(errno) << endl; + return 1; + } + struct sockaddr_in serv_addr; + bzero((char *)&serv_addr, sizeof(serv_addr)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, + (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) + { + cerr << "Couldn't connect to server! " << strerror(errno) << endl; + return 1; } child->step(); while(child->isTracing()) { - cout << printer; + if(!child->sendState(sock)) + break; child->step(); } - cout << printer; } if(!child->stopTracing()) { diff --git a/util/statetrace/tracechild.cc b/util/statetrace/tracechild.cc index 130f9690f..603429829 100644 --- a/util/statetrace/tracechild.cc +++ b/util/statetrace/tracechild.cc @@ -51,12 +51,23 @@ bool TraceChild::startTracing(const char * pathToFile, char * const argv[]) //program to trace. //Let our parent trace us - ptrace(PTRACE_TRACEME, 0, 0, 0); + if(ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) + { + cout << "Failure calling TRACEME\n"; + cout << strerror(errno) << endl; + return false; + } + + //Set up an empty environment for the child... + //We would want to specify this somehow at some point + char * env[] = {NULL}; //Start the program to trace - execv(pathToFile, argv); + execve(pathToFile, argv, env); //We should never get here, so this is an error! + cout << "Exec failed\n"; + cout << strerror(errno) << endl; return false; } diff --git a/util/statetrace/tracechild.hh b/util/statetrace/tracechild.hh index 84fa595d8..24712f816 100644 --- a/util/statetrace/tracechild.hh +++ b/util/statetrace/tracechild.hh @@ -42,6 +42,7 @@ protected: public: TraceChild() : tracing(false), instructions(0) {;} + virtual bool sendState(int socket) = 0; virtual bool startTracing(const char * pathToFile, char * const argv[]); virtual bool stopTracing(); |