-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathx86_dbg.cpp
108 lines (82 loc) · 2.14 KB
/
x86_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 "x86_dbg.h"
#include "x86_tree.h"
//X86 debugger functions
void X86Debugger::showStatus()
{
XRtContext *ctx = sim->runtimeCtx;
XInstruction *inst = instList[ctx->ip];
cout << inst->line << ": " << sourceLines[inst->line - 1] << endl;
}
void X86Debugger::start()
{
sim->runtimeCtx->ip = 0;
sim->runtimeCtx->stop = false;
}
bool X86Debugger::next()
{
XRtContext *ctx = sim->runtimeCtx;
XInstruction *inst = instList[ctx->ip];
int count = instList.size();
ctx->line = inst->line;
ctx->ip ++;
if (!inst->exec(sim, sim->lastResult)) {
return false;
}
if (ctx->stop || (ctx->ip >= count)) {
finished = true;
}
return true;
}
bool X86Debugger::run()
{
XRtContext *ctx = sim->runtimeCtx;
int count = instList.size();
while (1) {
XInstruction *inst = instList[ctx->ip];
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->ip ++;
if (!inst->exec(sim, sim->lastResult)) {
return false;
}
if (ctx->stop || (ctx->ip >= count)) {
finished = true;
break;
}
}
return true;
}
void X86Debugger::stop()
{
delete mPool; //This releases all the tree nodes
delete sim->runtimeCtx;
delete sim->jumpTbl;
sim->runtimeCtx = NULL;
sim->jumpTbl = NULL;
sim->dbg = NULL;
delete this;
}
bool X86Debugger::doSimCommand(string cmd)
{
stringstream in;
in.str(cmd);
XParserContext ctx;
if (sim->parseFile(&in, ctx)) {
XInstruction *inst = ctx.instList.front();
XReference result;
inst->exec(sim, result);
} else {
cout << "Error in command." << endl;
return false;
}
return true;
}