Statetrace: Get rid of explicit register name handling.

This commit is contained in:
Gabe Black 2011-03-02 22:53:10 -08:00
parent 3c19e45a68
commit 43eda1f285
11 changed files with 0 additions and 224 deletions

View file

@ -39,44 +39,6 @@
using namespace std; using namespace std;
const char * AMD64TraceChild::regNames[numregs] = {
//GPRs
"rax", "rbx", "rcx", "rdx",
//Index registers
"rsi", "rdi",
//Base pointer and stack pointer
"rbp", "rsp",
//New 64 bit mode registers
"r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
//Segmentation registers
"cs", "ds", "es", "fs", "gs", "ss", "fs_base", "gs_base",
//PC
"rip",
//Flags
"eflags",
//MMX
"mmx0_0", "mmx0_1", "mmx1_0", "mmx1_1",
"mmx2_0", "mmx2_1", "mmx3_0", "mmx3_1",
"mmx4_0", "mmx4_1", "mmx5_0", "mmx5_1",
"mmx6_0", "mmx6_1", "mmx7_0", "mmx7_1",
//XMM
"xmm0_0", "xmm0_1", "xmm0_2", "xmm0_3",
"xmm1_0", "xmm1_1", "xmm1_2", "xmm1_3",
"xmm2_0", "xmm2_1", "xmm2_2", "xmm2_3",
"xmm3_0", "xmm3_1", "xmm3_2", "xmm3_3",
"xmm4_0", "xmm4_1", "xmm4_2", "xmm4_3",
"xmm5_0", "xmm5_1", "xmm5_2", "xmm5_3",
"xmm6_0", "xmm6_1", "xmm6_2", "xmm6_3",
"xmm7_0", "xmm7_1", "xmm7_2", "xmm7_3",
"xmm8_0", "xmm8_1", "xmm8_2", "xmm8_3",
"xmm9_0", "xmm9_1", "xmm9_2", "xmm9_3",
"xmm10_0", "xmm10_1", "xmm10_2", "xmm10_3",
"xmm11_0", "xmm11_1", "xmm11_2", "xmm11_3",
"xmm12_0", "xmm12_1", "xmm12_2", "xmm12_3",
"xmm13_0", "xmm13_1", "xmm13_2", "xmm13_3",
"xmm14_0", "xmm14_1", "xmm14_2", "xmm14_3",
"xmm15_0", "xmm15_1", "xmm15_2", "xmm15_3"};
bool bool
AMD64TraceChild::sendState(int socket) AMD64TraceChild::sendState(int socket)
{ {
@ -278,13 +240,6 @@ AMD64TraceChild::getOldRegVal(int num)
return getRegs(oldregs, oldfpregs, num); return getRegs(oldregs, oldfpregs, num);
} }
char *
AMD64TraceChild::printReg(int num)
{
sprintf(printBuffer, "0x%016lX", getRegVal(num));
return printBuffer;
}
ostream & ostream &
AMD64TraceChild::outputStartState(ostream & os) AMD64TraceChild::outputStartState(ostream & os)
{ {

View file

@ -87,8 +87,6 @@ class AMD64TraceChild : public TraceChild
numregs numregs
}; };
private: private:
char printBuffer [256];
static const char * regNames[numregs];
int64_t getRegs(user_regs_struct & myregs, int64_t getRegs(user_regs_struct & myregs,
user_fpregs_struct &myfpregs,int num); user_fpregs_struct &myfpregs,int num);
user_regs_struct regs; user_regs_struct regs;
@ -108,34 +106,12 @@ class AMD64TraceChild : public TraceChild
bool sendState(int socket); bool sendState(int socket);
int
getNumRegs()
{
return numregs;
}
bool
diffSinceUpdate(int num)
{
assert(num < numregs && num >= 0);
return regDiffSinceUpdate[num];
}
std::string
getRegName(int num)
{
assert(num < numregs && num >= 0);
return regNames[num];
}
int64_t getRegVal(int num); int64_t getRegVal(int num);
int64_t getOldRegVal(int num); int64_t getOldRegVal(int num);
uint64_t getPC() {return getRegVal(RIP);} uint64_t getPC() {return getRegVal(RIP);}
uint64_t getSP() {return getRegVal(RSP);} uint64_t getSP() {return getRegVal(RSP);}
std::ostream & outputStartState(std::ostream & output); std::ostream & outputStartState(std::ostream & output);
char * printReg(int num);
bool step(); bool step();
}; };

View file

@ -51,12 +51,6 @@
using namespace std; using namespace std;
const char* ARMTraceChild::regNames[numregs] = {
"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
"r8", "r9", "r10", "fp", "r12", "sp", "lr", "pc",
"cpsr" };
ARMTraceChild::ARMTraceChild() ARMTraceChild::ARMTraceChild()
{ {
foundMvn = false; foundMvn = false;
@ -132,13 +126,6 @@ ARMTraceChild::getOldRegVal(int num)
return getRegs(oldregs, num); return getRegs(oldregs, num);
} }
char *
ARMTraceChild::printReg(int num)
{
sprintf(printBuffer, "0x%08X", (uint32_t)getRegVal(num));
return printBuffer;
}
ostream & ostream &
ARMTraceChild::outputStartState(ostream & os) ARMTraceChild::outputStartState(ostream & os)
{ {

View file

@ -69,8 +69,6 @@ class ARMTraceChild : public TraceChild
numregs numregs
}; };
private: private:
char printBuffer[256];
static const char *regNames[numregs];
uint32_t getRegs(user_regs& myregs, int num); uint32_t getRegs(user_regs& myregs, int num);
user_regs regs; user_regs regs;
user_regs oldregs; user_regs oldregs;
@ -84,26 +82,6 @@ class ARMTraceChild : public TraceChild
ARMTraceChild(); ARMTraceChild();
bool sendState(int socket); bool sendState(int socket);
int
getNumRegs()
{
return numregs;
}
bool
diffSinceUpdate(int num)
{
assert(num < numregs && num >= 0);
return regDiffSinceUpdate[num];
}
std::string
getRegName(int num)
{
assert(num < numregs && num >= 0);
return regNames[num];
}
int64_t getRegVal(int num); int64_t getRegVal(int num);
int64_t getOldRegVal(int num); int64_t getOldRegVal(int num);
@ -121,8 +99,6 @@ class ARMTraceChild : public TraceChild
return getRegVal(SP); return getRegVal(SP);
} }
char * printReg(int num);
std::ostream & outputStartState(std::ostream & os); std::ostream & outputStartState(std::ostream & os);
}; };

View file

@ -37,18 +37,6 @@
using namespace std; using namespace std;
char * I386TraceChild::regNames[numregs] = {
//GPRs
"eax", "ebx", "ecx", "edx",
//Index registers
"esi", "edi",
//Base pointer and stack pointer
"ebp", "esp",
//Segmentation registers
"cs", "ds", "es", "fs", "gs", "ss",
//PC
"eip"};
int64_t int64_t
I386TraceChild::getRegs(user_regs_struct & myregs, int num) I386TraceChild::getRegs(user_regs_struct & myregs, int num)
{ {
@ -109,13 +97,6 @@ I386TraceChild::getOldRegVal(int num)
return getRegs(oldregs, num); return getRegs(oldregs, num);
} }
char *
I386TraceChild::printReg(int num)
{
sprintf(printBuffer, "0x%08X", getRegVal(num));
return printBuffer;
}
TraceChild * TraceChild *
genTraceChild() genTraceChild()
{ {

View file

@ -57,8 +57,6 @@ class I386TraceChild : public TraceChild
numregs numregs
}; };
private: private:
char printBuffer [256];
static char * regNames[numregs];
int64_t getRegs(user_regs_struct & myregs, int num); int64_t getRegs(user_regs_struct & myregs, int num);
user_regs_struct regs; user_regs_struct regs;
user_regs_struct oldregs; user_regs_struct oldregs;
@ -71,26 +69,6 @@ class I386TraceChild : public TraceChild
I386TraceChild(); I386TraceChild();
int
getNumRegs()
{
return numregs;
}
bool
diffSinceUpdate(int num)
{
assert(num < numregs && num >= 0);
return regDiffSinceUpdate[num];
}
std::string
getRegName(int num)
{
assert(num < numregs && num >= 0);
return regNames[num];
}
int64_t getRegVal(int num); int64_t getRegVal(int num);
int64_t getOldRegVal(int num); int64_t getOldRegVal(int num);
uint64_t getPC() {return getRegVal(EIP);} uint64_t getPC() {return getRegVal(EIP);}
@ -102,8 +80,6 @@ class I386TraceChild : public TraceChild
<< std::endl; << std::endl;
return output; return output;
} }
char * printReg(int num);
}; };
#endif #endif

View file

@ -37,23 +37,6 @@
using namespace std; using namespace std;
string SparcTraceChild::regNames[numregs] = {
//Global registers
"g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
//Output registers
"o0", "o1", "o2", "o3", "o4", "o5", "o6", "o7",
//Local registers
"l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
//Input registers
"i0", "i1", "i2", "i3", "i4", "i5", "i6", "i7",
//Floating point
"f0", "f2", "f4", "f6", "f8", "f10", "f12", "f14",
"f16", "f18", "f20", "f22", "f24", "f26", "f28", "f30",
"f32", "f34", "f36", "f38", "f40", "f42", "f44", "f46",
"f48", "f50", "f52", "f54", "f56", "f58", "f60", "f62",
//Miscelaneous
"fsr", "fprs", "pc", "npc", "y", "cwp", "pstate", "asi", "ccr"};
bool bool
SparcTraceChild::sendState(int socket) SparcTraceChild::sendState(int socket)
{ {
@ -385,13 +368,6 @@ SparcTraceChild::getOldRegVal(int num)
return getRegs(oldregs, oldfpregs, oldLocals, oldInputs, num); return getRegs(oldregs, oldfpregs, oldLocals, oldInputs, num);
} }
char *
SparcTraceChild::printReg(int num)
{
sprintf(printBuffer, "0x%016llx", getRegVal(num));
return printBuffer;
}
ostream & ostream &
SparcTraceChild::outputStartState(ostream & os) SparcTraceChild::outputStartState(ostream & os)
{ {

View file

@ -66,8 +66,6 @@ class SparcTraceChild : public TraceChild
numregs numregs
}; };
private: private:
char printBuffer[256];
static std::string regNames[numregs];
regs theregs; regs theregs;
regs oldregs; regs oldregs;
fpu thefpregs; fpu thefpregs;
@ -92,26 +90,6 @@ class SparcTraceChild : public TraceChild
bool sendState(int socket); bool sendState(int socket);
int
getNumRegs()
{
return numregs;
}
bool
diffSinceUpdate(int num)
{
assert(num < numregs && num >= 0);
return regDiffSinceUpdate[num];
}
std::string
getRegName(int num)
{
assert(num < numregs && num >= 0);
return regNames[num];
}
int64_t getRegVal(int num); int64_t getRegVal(int num);
int64_t getOldRegVal(int num); int64_t getOldRegVal(int num);
@ -130,8 +108,6 @@ class SparcTraceChild : public TraceChild
return getRegVal(O6); return getRegVal(O6);
} }
char * printReg(int num);
std::ostream & outputStartState(std::ostream & os); std::ostream & outputStartState(std::ostream & os);
}; };

View file

@ -39,21 +39,8 @@ class RegState
protected: protected:
virtual bool update(int pid) = 0; virtual bool update(int pid) = 0;
public: public:
virtual int getNumRegs() = 0;
virtual bool diffSinceUpdate(int num) = 0;
virtual std::string getRegName(int num) = 0;
virtual int
getRegNum(std::string name)
{
int numregs = getNumRegs();
for (unsigned int x = 0; x < numregs; x++)
if(getRegName(x) == name)
return x;
return -1;
}
virtual int64_t getRegVal(int num) = 0; virtual int64_t getRegVal(int num) = 0;
virtual int64_t getOldRegVal(int num) = 0; virtual int64_t getOldRegVal(int num) = 0;
virtual char * printReg(int num) = 0;
}; };
#endif #endif

View file

@ -53,7 +53,6 @@ printUsage(const char * execName)
cout << "options:" << endl; cout << "options:" << endl;
cout << " -h print this help" << endl; cout << " -h print this help" << endl;
cout << " --host remote m5 host to connect to" << endl; cout << " --host remote m5 host to connect to" << endl;
cout << " -r print register names" << endl;
cout << " -i print initial stack state" << endl; cout << " -i print initial stack state" << endl;
cout << " -nt don't print an instruction trace" << endl; cout << " -nt don't print an instruction trace" << endl;
} }
@ -87,12 +86,6 @@ main(int argc, char * argv[], char * envp[])
return 1; return 1;
} }
host = argv[x]; host = argv[x];
} 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;
} else if (!strcmp(argv[x], "-i")) { } else if (!strcmp(argv[x], "-i")) {
printInitial = true; printInitial = true;
} else if (!strcmp(argv[x], "-nt")) { } else if (!strcmp(argv[x], "-nt")) {

View file

@ -46,14 +46,7 @@ class TraceChild : public RegState
virtual bool startTracing(const char * pathToFile, char * const argv[]); virtual bool startTracing(const char * pathToFile, char * const argv[]);
virtual bool stopTracing(); virtual bool stopTracing();
virtual bool step(); virtual bool step();
virtual uint64_t getPC() = 0;
virtual uint64_t getSP() = 0;
virtual std::ostream & outputStartState(std::ostream & os) = 0; virtual std::ostream & outputStartState(std::ostream & os) = 0;
int
getPid()
{
return pid;
}
bool bool
isTracing() isTracing()
{ {