Add some notes + use stringstream to build packet
This commit is contained in:
parent
7de1bf3746
commit
874bfebaf9
2 changed files with 26 additions and 29 deletions
|
@ -1035,12 +1035,6 @@ void HandlePacket() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HasHioRequest()) {
|
|
||||||
const auto reply = BuildHioRequestPacket();
|
|
||||||
SendReply(reply.data());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IsDataAvailable()) {
|
if (!IsDataAvailable()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1059,8 +1053,12 @@ void HandlePacket() {
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'C':
|
case 'C':
|
||||||
case 's':
|
case 's':
|
||||||
//
|
if (HasHioRequest()) {
|
||||||
;
|
// Really, this request needs to get sent _after_ the step or continue
|
||||||
|
// began, but not sure how to schedule that...
|
||||||
|
const auto request_packet = BuildHioRequestPacket();
|
||||||
|
SendReply(request_packet.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (command_buffer[0]) {
|
switch (command_buffer[0]) {
|
||||||
|
|
|
@ -36,12 +36,15 @@ void SetHioRequest(const VAddr addr) {
|
||||||
auto& memory = Core::System::GetInstance().Memory();
|
auto& memory = Core::System::GetInstance().Memory();
|
||||||
memory.ReadBlock(*process, addr, ¤t_hio_request, sizeof(PackedGdbHioRequest));
|
memory.ReadBlock(*process, addr, ¤t_hio_request, sizeof(PackedGdbHioRequest));
|
||||||
|
|
||||||
// TODO read + check request magic header
|
if (std::string_view{current_hio_request.magic} != "GDB") {
|
||||||
|
LOG_WARNING(Debug_GDBStub, "Invalid HIO request sent by application");
|
||||||
current_hio_request_addr = addr;
|
current_hio_request_addr = 0;
|
||||||
sent_request = false;
|
current_hio_request = {};
|
||||||
|
} else {
|
||||||
LOG_DEBUG(Debug_GDBStub, "HIO request initiated");
|
current_hio_request_addr = addr;
|
||||||
|
sent_request = false;
|
||||||
|
LOG_DEBUG(Debug_GDBStub, "HIO request initiated");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HandleHioReply(const u8* const command_buffer, const u32 command_length) {
|
bool HandleHioReply(const u8* const command_buffer, const u32 command_length) {
|
||||||
|
@ -132,41 +135,37 @@ bool HasHioRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string BuildHioRequestPacket() {
|
std::string BuildHioRequestPacket() {
|
||||||
char buf[256 + 1];
|
std::stringstream packet;
|
||||||
char tmp[32 + 1];
|
// TODO:use the IntToGdbHex funcs instead std::hex ?
|
||||||
|
packet << "F" << current_hio_request.function_name << std::hex;
|
||||||
|
|
||||||
u32 nStr = 0;
|
u32 nStr = 0;
|
||||||
|
|
||||||
// TODO: c++ify this and use the IntToGdbHex funcs instead of snprintf
|
|
||||||
|
|
||||||
snprintf(buf, 256, "F%s", current_hio_request.function_name);
|
|
||||||
|
|
||||||
for (u32 i = 0; i < 8 && current_hio_request.param_format[i] != 0; i++) {
|
for (u32 i = 0; i < 8 && current_hio_request.param_format[i] != 0; i++) {
|
||||||
switch (current_hio_request.param_format[i]) {
|
switch (current_hio_request.param_format[i]) {
|
||||||
case 'i':
|
case 'i':
|
||||||
case 'I':
|
case 'I':
|
||||||
case 'p':
|
case 'p':
|
||||||
snprintf(tmp, 32, ",%x", (u32)current_hio_request.parameters[i]);
|
packet << "," << (u32)current_hio_request.parameters[i];
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
case 'L':
|
case 'L':
|
||||||
snprintf(tmp, 32, ",%llx", current_hio_request.parameters[i]);
|
packet << "," << current_hio_request.parameters[i];
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
snprintf(tmp, 32, ",%x/%zx", (u32)current_hio_request.parameters[i],
|
packet << "," << (u32)current_hio_request.parameters[i] << "/"
|
||||||
current_hio_request.string_lengths[nStr++]);
|
<< current_hio_request.string_lengths[nStr++];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
tmp[0] = 0;
|
packet << '\0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strcat(buf, tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto packet = std::string{buf, strlen(buf)};
|
LOG_DEBUG(Debug_GDBStub, "HIO request packet: {}", packet.str());
|
||||||
LOG_DEBUG(Debug_GDBStub, "HIO request packet: {}", packet);
|
|
||||||
sent_request = true;
|
sent_request = true;
|
||||||
|
|
||||||
return packet;
|
return packet.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace GDBStub
|
} // namespace GDBStub
|
||||||
|
|
Loading…
Reference in a new issue