-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmips32_dbg.cpp
108 lines (81 loc) · 2.14 KB
/
mips32_dbg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include <iostream>
#include "mips32_dbg.h"
#include "mips32_sim.h"
using namespace std;
void MIPS32Debugger::showStatus()
{
MRtContext *ctx = sim->runtimeCtx;
MInstruction *inst = instList[ctx->pc];
cout << inst->line << ": " << sourceLines[inst->line - 1] << endl;
}
void MIPS32Debugger::start()
{
sim->runtimeCtx->pc = 0;
sim->runtimeCtx->stop = false;
}
bool MIPS32Debugger::next()
{
MRtContext *ctx = sim->runtimeCtx;
MInstruction *inst = instList[ctx->pc];
unsigned count = instList.size();
ctx->line = inst->line;
ctx->pc ++;
if (!sim->execInstruction(inst)) {
return false;
}
if (ctx->stop || (ctx->pc >= count)) {
finished = true;
}
return true;
}
bool MIPS32Debugger::run()
{
MRtContext *ctx = sim->runtimeCtx;
unsigned count = instList.size();
while (1) {
MInstruction *inst = instList[ctx->pc];
if (breakpoints.find(inst->line) != breakpoints.end()) {
if (inBreakpoint)
inBreakpoint = false;
else {
cout << "Program paused due to breakpoint at line " << inst->line << endl;
inBreakpoint = true;
return false;
}
}
ctx->line = inst->line;
ctx->pc ++;
if (!sim->execInstruction(inst)) {
return false;
}
if (ctx->stop || (ctx->pc >= count)) {
finished = true;
break;
}
}
return true;
}
void MIPS32Debugger::stop()
{
delete mPool; //This releases all the tree nodes
delete sim->runtimeCtx;
delete sim->jumpTable;
sim->runtimeCtx = NULL;
sim->jumpTable = NULL;
sim->dbg = NULL;
delete this;
}
bool MIPS32Debugger::doSimCommand(string cmd)
{
stringstream in;
in.str(cmd);
MParserContext ctx;
if (sim->parseFile(&in, ctx)) {
MInstruction *inst = ctx.instList.front();
sim->execInstruction(inst);
} else {
cout << "Error in command." << endl;
return false;
}
return true;
}