-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCLIDebuggerInputController.cpp
More file actions
54 lines (52 loc) · 1.7 KB
/
CLIDebuggerInputController.cpp
File metadata and controls
54 lines (52 loc) · 1.7 KB
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
#include "CLIDebuggerInputController.h"
#include "DebugDispatcher.h"
#include <iostream>
void CLIDebuggerInputController::setInitialBreakpoints(DebugDispatcher *d){
while(true){
printf("Enter a positive number to set a new breakpoint, 0 or negative to continue\n");
int n = 0;
std::cin >> n;
if(n > 0)
d->addBreakpoint(n);
else
break;
}
}
void CLIDebuggerInputController::handleInput(DebugDispatcher *d){
std::string command;
printf("Paused at line %d. Waiting for input...\n", d->getCurrLine());
std::cin >> command;
if(command == "c")
d->setExecutionMode(DebugDispatcher::ExecutionModes::NORMAL);
else if(command == "si")
d->setExecutionMode(DebugDispatcher::ExecutionModes::STEP_IN);
else if(command == "so")
d->setExecutionMode(DebugDispatcher::ExecutionModes::STEP_OVER);
else if(command == "sb"){
unsigned lineNo;
std::cin >> lineNo;
d->addBreakpoint(lineNo);
}
else if(command == "rb"){
unsigned lineNo;
std::cin >> lineNo;
d->removeBreakpoint(lineNo);
}
else if(command == "pr"){
std::string varName;
std::cin >> varName;
const Value *var = d->getVarByName(varName);
if(var != nullptr)
std::cout<<var->makeString()<<"\n";
else
std::cout<<"Variable not found\n";
}
else if(command == "st"){
auto stackTrace = d->getStackTrace();
for(unsigned i = 0; i < stackTrace.size(); i++)
printf("%d->", stackTrace[i].first);
printf("%d\n", d->getCurrLine());
}
else
printf("Unknown command \"%s\"\n", command.c_str());
}