diff options
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 2603192fe..500734f2d 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -232,7 +232,7 @@ static u8 HexCharToValue(u8 hex) { | |||
| 232 | return hex - 'A' + 0xA; | 232 | return hex - 'A' + 0xA; |
| 233 | } | 233 | } |
| 234 | 234 | ||
| 235 | NGLOG_ERROR(Debug_GDBStub, "Invalid nibble: {} ({:02X})", hex, hex); | 235 | LOG_ERROR(Debug_GDBStub, "Invalid nibble: {} ({:02X})", hex, hex); |
| 236 | return 0; | 236 | return 0; |
| 237 | } | 237 | } |
| 238 | 238 | ||
| @@ -372,7 +372,7 @@ static u8 ReadByte() { | |||
| 372 | u8 c; | 372 | u8 c; |
| 373 | size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); | 373 | size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); |
| 374 | if (received_size != 1) { | 374 | if (received_size != 1) { |
| 375 | NGLOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); | 375 | LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); |
| 376 | Shutdown(); | 376 | Shutdown(); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| @@ -413,7 +413,7 @@ static void RemoveBreakpoint(BreakpointType type, PAddr addr) { | |||
| 413 | 413 | ||
| 414 | auto bp = p.find(static_cast<u64>(addr)); | 414 | auto bp = p.find(static_cast<u64>(addr)); |
| 415 | if (bp != p.end()) { | 415 | if (bp != p.end()) { |
| 416 | NGLOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}", | 416 | LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: {:016X} bytes at {:016X} of type {}", |
| 417 | bp->second.len, bp->second.addr, static_cast<int>(type)); | 417 | bp->second.len, bp->second.addr, static_cast<int>(type)); |
| 418 | p.erase(static_cast<u64>(addr)); | 418 | p.erase(static_cast<u64>(addr)); |
| 419 | } | 419 | } |
| @@ -459,7 +459,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { | |||
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { | 461 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { |
| 462 | NGLOG_DEBUG(Debug_GDBStub, | 462 | LOG_DEBUG(Debug_GDBStub, |
| 463 | "Found breakpoint type {} @ {:016X}, range: {:016X}" | 463 | "Found breakpoint type {} @ {:016X}, range: {:016X}" |
| 464 | " - {:016X} ({:X} bytes)", | 464 | " - {:016X} ({:X} bytes)", |
| 465 | static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len); | 465 | static_cast<int>(type), addr, bp->second.addr, bp->second.addr + len, len); |
| @@ -478,7 +478,7 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { | |||
| 478 | static void SendPacket(const char packet) { | 478 | static void SendPacket(const char packet) { |
| 479 | size_t sent_size = send(gdbserver_socket, &packet, 1, 0); | 479 | size_t sent_size = send(gdbserver_socket, &packet, 1, 0); |
| 480 | if (sent_size != 1) { | 480 | if (sent_size != 1) { |
| 481 | NGLOG_ERROR(Debug_GDBStub, "send failed"); | 481 | LOG_ERROR(Debug_GDBStub, "send failed"); |
| 482 | } | 482 | } |
| 483 | } | 483 | } |
| 484 | 484 | ||
| @@ -492,13 +492,13 @@ static void SendReply(const char* reply) { | |||
| 492 | return; | 492 | return; |
| 493 | } | 493 | } |
| 494 | 494 | ||
| 495 | NGLOG_DEBUG(Debug_GDBStub, "Reply: {}", reply); | 495 | LOG_DEBUG(Debug_GDBStub, "Reply: {}", reply); |
| 496 | 496 | ||
| 497 | memset(command_buffer, 0, sizeof(command_buffer)); | 497 | memset(command_buffer, 0, sizeof(command_buffer)); |
| 498 | 498 | ||
| 499 | command_length = static_cast<u32>(strlen(reply)); | 499 | command_length = static_cast<u32>(strlen(reply)); |
| 500 | if (command_length + 4 > sizeof(command_buffer)) { | 500 | if (command_length + 4 > sizeof(command_buffer)) { |
| 501 | NGLOG_ERROR(Debug_GDBStub, "command_buffer overflow in SendReply"); | 501 | LOG_ERROR(Debug_GDBStub, "command_buffer overflow in SendReply"); |
| 502 | return; | 502 | return; |
| 503 | } | 503 | } |
| 504 | 504 | ||
| @@ -515,7 +515,7 @@ static void SendReply(const char* reply) { | |||
| 515 | while (left > 0) { | 515 | while (left > 0) { |
| 516 | int sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); | 516 | int sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); |
| 517 | if (sent_size < 0) { | 517 | if (sent_size < 0) { |
| 518 | NGLOG_ERROR(Debug_GDBStub, "gdb: send failed"); | 518 | LOG_ERROR(Debug_GDBStub, "gdb: send failed"); |
| 519 | return Shutdown(); | 519 | return Shutdown(); |
| 520 | } | 520 | } |
| 521 | 521 | ||
| @@ -526,7 +526,7 @@ static void SendReply(const char* reply) { | |||
| 526 | 526 | ||
| 527 | /// Handle query command from gdb client. | 527 | /// Handle query command from gdb client. |
| 528 | static void HandleQuery() { | 528 | static void HandleQuery() { |
| 529 | NGLOG_DEBUG(Debug_GDBStub, "gdb: query '{}'", command_buffer + 1); | 529 | LOG_DEBUG(Debug_GDBStub, "gdb: query '{}'", command_buffer + 1); |
| 530 | 530 | ||
| 531 | const char* query = reinterpret_cast<const char*>(command_buffer + 1); | 531 | const char* query = reinterpret_cast<const char*>(command_buffer + 1); |
| 532 | 532 | ||
| @@ -634,18 +634,18 @@ static void ReadCommand() { | |||
| 634 | // ignore ack | 634 | // ignore ack |
| 635 | return; | 635 | return; |
| 636 | } else if (c == 0x03) { | 636 | } else if (c == 0x03) { |
| 637 | NGLOG_INFO(Debug_GDBStub, "gdb: found break command"); | 637 | LOG_INFO(Debug_GDBStub, "gdb: found break command"); |
| 638 | halt_loop = true; | 638 | halt_loop = true; |
| 639 | SendSignal(current_thread, SIGTRAP); | 639 | SendSignal(current_thread, SIGTRAP); |
| 640 | return; | 640 | return; |
| 641 | } else if (c != GDB_STUB_START) { | 641 | } else if (c != GDB_STUB_START) { |
| 642 | NGLOG_DEBUG(Debug_GDBStub, "gdb: read invalid byte {:02X}", c); | 642 | LOG_DEBUG(Debug_GDBStub, "gdb: read invalid byte {:02X}", c); |
| 643 | return; | 643 | return; |
| 644 | } | 644 | } |
| 645 | 645 | ||
| 646 | while ((c = ReadByte()) != GDB_STUB_END) { | 646 | while ((c = ReadByte()) != GDB_STUB_END) { |
| 647 | if (command_length >= sizeof(command_buffer)) { | 647 | if (command_length >= sizeof(command_buffer)) { |
| 648 | NGLOG_ERROR(Debug_GDBStub, "gdb: command_buffer overflow"); | 648 | LOG_ERROR(Debug_GDBStub, "gdb: command_buffer overflow"); |
| 649 | SendPacket(GDB_STUB_NACK); | 649 | SendPacket(GDB_STUB_NACK); |
| 650 | return; | 650 | return; |
| 651 | } | 651 | } |
| @@ -658,7 +658,7 @@ static void ReadCommand() { | |||
| 658 | u8 checksum_calculated = CalculateChecksum(command_buffer, command_length); | 658 | u8 checksum_calculated = CalculateChecksum(command_buffer, command_length); |
| 659 | 659 | ||
| 660 | if (checksum_received != checksum_calculated) { | 660 | if (checksum_received != checksum_calculated) { |
| 661 | NGLOG_ERROR( | 661 | LOG_ERROR( |
| 662 | Debug_GDBStub, | 662 | Debug_GDBStub, |
| 663 | "gdb: invalid checksum: calculated {:02X} and read {:02X} for ${}# (length: {})", | 663 | "gdb: invalid checksum: calculated {:02X} and read {:02X} for ${}# (length: {})", |
| 664 | checksum_calculated, checksum_received, command_buffer, command_length); | 664 | checksum_calculated, checksum_received, command_buffer, command_length); |
| @@ -688,7 +688,7 @@ static bool IsDataAvailable() { | |||
| 688 | t.tv_usec = 0; | 688 | t.tv_usec = 0; |
| 689 | 689 | ||
| 690 | if (select(gdbserver_socket + 1, &fd_socket, nullptr, nullptr, &t) < 0) { | 690 | if (select(gdbserver_socket + 1, &fd_socket, nullptr, nullptr, &t) < 0) { |
| 691 | NGLOG_ERROR(Debug_GDBStub, "select failed"); | 691 | LOG_ERROR(Debug_GDBStub, "select failed"); |
| 692 | return false; | 692 | return false; |
| 693 | } | 693 | } |
| 694 | 694 | ||
| @@ -801,7 +801,7 @@ static void ReadMemory() { | |||
| 801 | u64 len = | 801 | u64 len = |
| 802 | HexToLong(start_offset, static_cast<u64>((command_buffer + command_length) - start_offset)); | 802 | HexToLong(start_offset, static_cast<u64>((command_buffer + command_length) - start_offset)); |
| 803 | 803 | ||
| 804 | NGLOG_DEBUG(Debug_GDBStub, "gdb: addr: {:016X} len: {:016X}", addr, len); | 804 | LOG_DEBUG(Debug_GDBStub, "gdb: addr: {:016X} len: {:016X}", addr, len); |
| 805 | 805 | ||
| 806 | if (len * 2 > sizeof(reply)) { | 806 | if (len * 2 > sizeof(reply)) { |
| 807 | SendReply("E01"); | 807 | SendReply("E01"); |
| @@ -888,7 +888,7 @@ static bool CommitBreakpoint(BreakpointType type, PAddr addr, u64 len) { | |||
| 888 | breakpoint.len = len; | 888 | breakpoint.len = len; |
| 889 | p.insert({addr, breakpoint}); | 889 | p.insert({addr, breakpoint}); |
| 890 | 890 | ||
| 891 | NGLOG_DEBUG(Debug_GDBStub, "gdb: added {} breakpoint: {:016X} bytes at {:016X}", | 891 | LOG_DEBUG(Debug_GDBStub, "gdb: added {} breakpoint: {:016X} bytes at {:016X}", |
| 892 | static_cast<int>(type), breakpoint.len, breakpoint.addr); | 892 | static_cast<int>(type), breakpoint.len, breakpoint.addr); |
| 893 | 893 | ||
| 894 | return true; | 894 | return true; |
| @@ -996,7 +996,7 @@ void HandlePacket() { | |||
| 996 | return; | 996 | return; |
| 997 | } | 997 | } |
| 998 | 998 | ||
| 999 | NGLOG_DEBUG(Debug_GDBStub, "Packet: {}", command_buffer); | 999 | LOG_DEBUG(Debug_GDBStub, "Packet: {}", command_buffer); |
| 1000 | 1000 | ||
| 1001 | switch (command_buffer[0]) { | 1001 | switch (command_buffer[0]) { |
| 1002 | case 'q': | 1002 | case 'q': |
| @@ -1010,7 +1010,7 @@ void HandlePacket() { | |||
| 1010 | break; | 1010 | break; |
| 1011 | case 'k': | 1011 | case 'k': |
| 1012 | Shutdown(); | 1012 | Shutdown(); |
| 1013 | NGLOG_INFO(Debug_GDBStub, "killed by gdb"); | 1013 | LOG_INFO(Debug_GDBStub, "killed by gdb"); |
| 1014 | return; | 1014 | return; |
| 1015 | case 'g': | 1015 | case 'g': |
| 1016 | ReadRegisters(); | 1016 | ReadRegisters(); |
| @@ -1092,7 +1092,7 @@ static void Init(u16 port) { | |||
| 1092 | breakpoints_write.clear(); | 1092 | breakpoints_write.clear(); |
| 1093 | 1093 | ||
| 1094 | // Start gdb server | 1094 | // Start gdb server |
| 1095 | NGLOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port); | 1095 | LOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port); |
| 1096 | 1096 | ||
| 1097 | sockaddr_in saddr_server = {}; | 1097 | sockaddr_in saddr_server = {}; |
| 1098 | saddr_server.sin_family = AF_INET; | 1098 | saddr_server.sin_family = AF_INET; |
| @@ -1105,28 +1105,28 @@ static void Init(u16 port) { | |||
| 1105 | 1105 | ||
| 1106 | int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); | 1106 | int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); |
| 1107 | if (tmpsock == -1) { | 1107 | if (tmpsock == -1) { |
| 1108 | NGLOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); | 1108 | LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); |
| 1109 | } | 1109 | } |
| 1110 | 1110 | ||
| 1111 | // Set socket to SO_REUSEADDR so it can always bind on the same port | 1111 | // Set socket to SO_REUSEADDR so it can always bind on the same port |
| 1112 | int reuse_enabled = 1; | 1112 | int reuse_enabled = 1; |
| 1113 | if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled, | 1113 | if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled, |
| 1114 | sizeof(reuse_enabled)) < 0) { | 1114 | sizeof(reuse_enabled)) < 0) { |
| 1115 | NGLOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option"); | 1115 | LOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option"); |
| 1116 | } | 1116 | } |
| 1117 | 1117 | ||
| 1118 | const sockaddr* server_addr = reinterpret_cast<const sockaddr*>(&saddr_server); | 1118 | const sockaddr* server_addr = reinterpret_cast<const sockaddr*>(&saddr_server); |
| 1119 | socklen_t server_addrlen = sizeof(saddr_server); | 1119 | socklen_t server_addrlen = sizeof(saddr_server); |
| 1120 | if (bind(tmpsock, server_addr, server_addrlen) < 0) { | 1120 | if (bind(tmpsock, server_addr, server_addrlen) < 0) { |
| 1121 | NGLOG_ERROR(Debug_GDBStub, "Failed to bind gdb socket"); | 1121 | LOG_ERROR(Debug_GDBStub, "Failed to bind gdb socket"); |
| 1122 | } | 1122 | } |
| 1123 | 1123 | ||
| 1124 | if (listen(tmpsock, 1) < 0) { | 1124 | if (listen(tmpsock, 1) < 0) { |
| 1125 | NGLOG_ERROR(Debug_GDBStub, "Failed to listen to gdb socket"); | 1125 | LOG_ERROR(Debug_GDBStub, "Failed to listen to gdb socket"); |
| 1126 | } | 1126 | } |
| 1127 | 1127 | ||
| 1128 | // Wait for gdb to connect | 1128 | // Wait for gdb to connect |
| 1129 | NGLOG_INFO(Debug_GDBStub, "Waiting for gdb to connect..."); | 1129 | LOG_INFO(Debug_GDBStub, "Waiting for gdb to connect..."); |
| 1130 | sockaddr_in saddr_client; | 1130 | sockaddr_in saddr_client; |
| 1131 | sockaddr* client_addr = reinterpret_cast<sockaddr*>(&saddr_client); | 1131 | sockaddr* client_addr = reinterpret_cast<sockaddr*>(&saddr_client); |
| 1132 | socklen_t client_addrlen = sizeof(saddr_client); | 1132 | socklen_t client_addrlen = sizeof(saddr_client); |
| @@ -1137,9 +1137,9 @@ static void Init(u16 port) { | |||
| 1137 | halt_loop = false; | 1137 | halt_loop = false; |
| 1138 | step_loop = false; | 1138 | step_loop = false; |
| 1139 | 1139 | ||
| 1140 | NGLOG_ERROR(Debug_GDBStub, "Failed to accept gdb client"); | 1140 | LOG_ERROR(Debug_GDBStub, "Failed to accept gdb client"); |
| 1141 | } else { | 1141 | } else { |
| 1142 | NGLOG_INFO(Debug_GDBStub, "Client connected."); | 1142 | LOG_INFO(Debug_GDBStub, "Client connected."); |
| 1143 | saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr); | 1143 | saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr); |
| 1144 | } | 1144 | } |
| 1145 | 1145 | ||
| @@ -1158,7 +1158,7 @@ void Shutdown() { | |||
| 1158 | return; | 1158 | return; |
| 1159 | } | 1159 | } |
| 1160 | 1160 | ||
| 1161 | NGLOG_INFO(Debug_GDBStub, "Stopping GDB ..."); | 1161 | LOG_INFO(Debug_GDBStub, "Stopping GDB ..."); |
| 1162 | if (gdbserver_socket != -1) { | 1162 | if (gdbserver_socket != -1) { |
| 1163 | shutdown(gdbserver_socket, SHUT_RDWR); | 1163 | shutdown(gdbserver_socket, SHUT_RDWR); |
| 1164 | gdbserver_socket = -1; | 1164 | gdbserver_socket = -1; |
| @@ -1168,7 +1168,7 @@ void Shutdown() { | |||
| 1168 | WSACleanup(); | 1168 | WSACleanup(); |
| 1169 | #endif | 1169 | #endif |
| 1170 | 1170 | ||
| 1171 | NGLOG_INFO(Debug_GDBStub, "GDB stopped."); | 1171 | LOG_INFO(Debug_GDBStub, "GDB stopped."); |
| 1172 | } | 1172 | } |
| 1173 | 1173 | ||
| 1174 | bool IsServerEnabled() { | 1174 | bool IsServerEnabled() { |