gdb rsp: minor changes
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
@@ -129,14 +129,6 @@ Cpu::step() {
|
||||
// word align
|
||||
rst_bit(pc, 1);
|
||||
|
||||
#ifdef GDB_DEBUG
|
||||
if (breakpoints.contains(pc - 2 * arm::INSTRUCTION_SIZE)) {
|
||||
glogger.info_bold("CPU halted");
|
||||
halted = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
arm::Instruction instruction(opcodes[0]);
|
||||
|
||||
opcodes[0] = opcodes[1];
|
||||
@@ -156,15 +148,6 @@ Cpu::step() {
|
||||
} else
|
||||
advance_pc_arm();
|
||||
} else {
|
||||
|
||||
#ifdef GDB_DEBUG
|
||||
if (breakpoints.contains(pc - 2 * thumb::INSTRUCTION_SIZE)) {
|
||||
glogger.info_bold("CPU halted");
|
||||
halted = true;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
thumb::Instruction instruction(opcodes[0]);
|
||||
|
||||
opcodes[0] = opcodes[1];
|
||||
|
@@ -46,8 +46,20 @@ GdbRsp::start(const uint port) {
|
||||
server.start(port);
|
||||
server.run();
|
||||
|
||||
attach();
|
||||
|
||||
// attaching is not enough, we continue, until the last GDB communication
|
||||
// happens for ARMv4t i.e, fetching of the CPSR
|
||||
std::string msg;
|
||||
|
||||
while (msg != "$p19") {
|
||||
msg = receive();
|
||||
step(msg); // 25th (0x19) register is cpsr
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GdbRsp::attach() {
|
||||
while (!attached) {
|
||||
step();
|
||||
}
|
||||
@@ -63,7 +75,11 @@ GdbRsp::satisfy_client() {
|
||||
void
|
||||
GdbRsp::step() {
|
||||
std::string msg = receive();
|
||||
step(msg);
|
||||
}
|
||||
|
||||
void
|
||||
GdbRsp::step(std::string msg) {
|
||||
switch (msg[0]) {
|
||||
case '+':
|
||||
break;
|
||||
@@ -81,49 +97,39 @@ GdbRsp::step() {
|
||||
acknowledge();
|
||||
cmd_attached();
|
||||
} else {
|
||||
acknowledge();
|
||||
switch (msg[1]) {
|
||||
case '?':
|
||||
acknowledge();
|
||||
cmd_halted();
|
||||
break;
|
||||
case 'g':
|
||||
acknowledge();
|
||||
cmd_read_registers();
|
||||
break;
|
||||
case 'G':
|
||||
acknowledge();
|
||||
cmd_write_registers(msg);
|
||||
break;
|
||||
case 'p':
|
||||
acknowledge();
|
||||
cmd_read_register(msg);
|
||||
break;
|
||||
case 'P':
|
||||
acknowledge();
|
||||
cmd_write_register(msg);
|
||||
break;
|
||||
case 'm':
|
||||
acknowledge();
|
||||
cmd_read_memory(msg);
|
||||
break;
|
||||
case 'M':
|
||||
acknowledge();
|
||||
cmd_write_memory(msg);
|
||||
break;
|
||||
case 'z':
|
||||
acknowledge();
|
||||
cmd_rm_breakpoint(msg);
|
||||
break;
|
||||
case 'Z':
|
||||
acknowledge();
|
||||
cmd_add_breakpoint(msg);
|
||||
break;
|
||||
case 'c':
|
||||
acknowledge();
|
||||
cmd_continue();
|
||||
break;
|
||||
case 'D':
|
||||
acknowledge();
|
||||
cmd_detach();
|
||||
break;
|
||||
default:
|
||||
@@ -177,10 +183,15 @@ GdbRsp::acknowledge() {
|
||||
|
||||
void
|
||||
GdbRsp::send_empty() {
|
||||
acknowledge();
|
||||
server.send(make_packet(""));
|
||||
}
|
||||
|
||||
void
|
||||
GdbRsp::send_ok() {
|
||||
acknowledge();
|
||||
server.send(make_packet("OK"));
|
||||
}
|
||||
|
||||
void
|
||||
GdbRsp::notify_breakpoint_reached() {
|
||||
gdb_log("reached breakpoint, sending signal");
|
||||
@@ -252,7 +263,7 @@ GdbRsp::cmd_write_registers(std::string msg) {
|
||||
}
|
||||
|
||||
gdb_log("register values written");
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
} catch (const std::exception& e) {
|
||||
gdb_log("{}", e.what());
|
||||
send_empty();
|
||||
@@ -305,7 +316,7 @@ GdbRsp::cmd_write_register(std::string msg) {
|
||||
cpu->gpr[reg] = value;
|
||||
|
||||
gdb_log("single register value written");
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
} catch (const std::exception& e) {
|
||||
gdb_log("{}", e.what());
|
||||
send_empty();
|
||||
@@ -380,7 +391,7 @@ GdbRsp::cmd_write_memory(std::string msg) {
|
||||
|
||||
cpu->sequential = false;
|
||||
gdb_log("register values written");
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
} catch (const std::exception& e) {
|
||||
gdb_log("{}", e.what());
|
||||
send_empty();
|
||||
@@ -416,7 +427,7 @@ GdbRsp::cmd_rm_breakpoint(std::string msg) {
|
||||
|
||||
cpu->breakpoints.erase(address);
|
||||
gdb_log("breakpoint {:#08x} removed", address);
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
} catch (const std::exception& e) {
|
||||
gdb_log("{}", e.what());
|
||||
send_empty();
|
||||
@@ -454,7 +465,7 @@ GdbRsp::cmd_add_breakpoint(std::string msg) {
|
||||
|
||||
cpu->breakpoints.insert(address);
|
||||
gdb_log("breakpoint {:#08x} added", address);
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
} catch (const std::exception& e) {
|
||||
gdb_log("{}", e.what());
|
||||
send_empty();
|
||||
@@ -464,18 +475,14 @@ GdbRsp::cmd_add_breakpoint(std::string msg) {
|
||||
void
|
||||
GdbRsp::cmd_detach() {
|
||||
attached = false;
|
||||
cpu->resume();
|
||||
gdb_log("detached");
|
||||
server.send(OK_MSG);
|
||||
send_ok();
|
||||
}
|
||||
|
||||
void
|
||||
GdbRsp::cmd_continue() {
|
||||
cpu->resume();
|
||||
gdb_log("continued");
|
||||
server.send(OK_MSG);
|
||||
while (true) {
|
||||
cpu->step();
|
||||
}
|
||||
// what to do?
|
||||
gdb_log("cpu continued");
|
||||
send_ok();
|
||||
}
|
||||
}
|
||||
|
@@ -5,9 +5,14 @@ namespace matar {
|
||||
class GdbRsp {
|
||||
public:
|
||||
GdbRsp(std::shared_ptr<Cpu> cpu);
|
||||
~GdbRsp() = default;
|
||||
void start(const uint port);
|
||||
void attach();
|
||||
void satisfy_client();
|
||||
void step();
|
||||
void step(std::string msg);
|
||||
void notify_breakpoint_reached();
|
||||
inline bool is_attached() { return attached; }
|
||||
|
||||
private:
|
||||
bool attached = false;
|
||||
@@ -18,7 +23,7 @@ class GdbRsp {
|
||||
std::string make_packet(std::string raw);
|
||||
void acknowledge();
|
||||
void send_empty();
|
||||
void notify_breakpoint_reached();
|
||||
void send_ok();
|
||||
|
||||
// Commands
|
||||
void cmd_attached();
|
||||
@@ -35,9 +40,6 @@ class GdbRsp {
|
||||
void cmd_detach();
|
||||
void cmd_continue();
|
||||
|
||||
static constexpr std::string ATTACHED_MSG = "$qAttached#8f";
|
||||
static constexpr std::string OK_MSG = "+$OK#9a";
|
||||
|
||||
static constexpr uint MAX_MSG_LEN = 4096;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user