summaryrefslogtreecommitdiff
path: root/src/core/gdbstub/gdbstub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
-rw-r--r--src/core/gdbstub/gdbstub.cpp47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 97ee65464..28a8a0f49 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -205,7 +205,7 @@ static Kernel::Thread* FindThreadById(s64 id) {
205 const auto& threads = Core::System::GetInstance().GlobalScheduler().GetThreadList(); 205 const auto& threads = Core::System::GetInstance().GlobalScheduler().GetThreadList();
206 for (auto& thread : threads) { 206 for (auto& thread : threads) {
207 if (thread->GetThreadID() == static_cast<u64>(id)) { 207 if (thread->GetThreadID() == static_cast<u64>(id)) {
208 current_core = thread->GetProcessorID(); 208 current_core = static_cast<u32>(thread->GetProcessorID());
209 return thread.get(); 209 return thread.get();
210 } 210 }
211 } 211 }
@@ -457,7 +457,14 @@ static u128 GdbHexToU128(const u8* src) {
457/// Read a byte from the gdb client. 457/// Read a byte from the gdb client.
458static u8 ReadByte() { 458static u8 ReadByte() {
459 u8 c; 459 u8 c;
460 std::size_t received_size = recv(gdbserver_socket, reinterpret_cast<char*>(&c), 1, MSG_WAITALL); 460
461#ifdef WIN32
462 const auto socket_id = static_cast<SOCKET>(gdbserver_socket);
463#else
464 const auto socket_id = gdbserver_socket;
465#endif
466
467 const auto received_size = recv(socket_id, reinterpret_cast<char*>(&c), 1, MSG_WAITALL);
461 if (received_size != 1) { 468 if (received_size != 1) {
462 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size); 469 LOG_ERROR(Debug_GDBStub, "recv failed: {}", received_size);
463 Shutdown(); 470 Shutdown();
@@ -574,7 +581,13 @@ bool CheckBreakpoint(VAddr addr, BreakpointType type) {
574 * @param packet Packet to be sent to client. 581 * @param packet Packet to be sent to client.
575 */ 582 */
576static void SendPacket(const char packet) { 583static void SendPacket(const char packet) {
577 std::size_t sent_size = send(gdbserver_socket, &packet, 1, 0); 584#ifdef WIN32
585 const auto socket_id = static_cast<SOCKET>(gdbserver_socket);
586#else
587 const auto socket_id = gdbserver_socket;
588#endif
589
590 const auto sent_size = send(socket_id, &packet, 1, 0);
578 if (sent_size != 1) { 591 if (sent_size != 1) {
579 LOG_ERROR(Debug_GDBStub, "send failed"); 592 LOG_ERROR(Debug_GDBStub, "send failed");
580 } 593 }
@@ -611,7 +624,13 @@ static void SendReply(const char* reply) {
611 u8* ptr = command_buffer; 624 u8* ptr = command_buffer;
612 u32 left = command_length + 4; 625 u32 left = command_length + 4;
613 while (left > 0) { 626 while (left > 0) {
614 const auto sent_size = send(gdbserver_socket, reinterpret_cast<char*>(ptr), left, 0); 627#ifdef WIN32
628 const auto socket_id = static_cast<SOCKET>(gdbserver_socket);
629#else
630 const auto socket_id = gdbserver_socket;
631#endif
632 const auto sent_size =
633 send(socket_id, reinterpret_cast<char*>(ptr), static_cast<socklen_t>(left), 0);
615 if (sent_size < 0) { 634 if (sent_size < 0) {
616 LOG_ERROR(Debug_GDBStub, "gdb: send failed"); 635 LOG_ERROR(Debug_GDBStub, "gdb: send failed");
617 return Shutdown(); 636 return Shutdown();
@@ -1294,8 +1313,13 @@ static void Init(u16 port) {
1294 WSAStartup(MAKEWORD(2, 2), &InitData); 1313 WSAStartup(MAKEWORD(2, 2), &InitData);
1295#endif 1314#endif
1296 1315
1297 int tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0)); 1316#ifdef WIN32
1298 if (tmpsock == -1) { 1317 using socket_type = SOCKET;
1318#else
1319 using socket_type = int;
1320#endif
1321 const auto tmpsock = static_cast<socket_type>(socket(PF_INET, SOCK_STREAM, 0));
1322 if (tmpsock == static_cast<socket_type>(-1)) {
1299 LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket"); 1323 LOG_ERROR(Debug_GDBStub, "Failed to create gdb socket");
1300 } 1324 }
1301 1325
@@ -1335,7 +1359,7 @@ static void Init(u16 port) {
1335 } 1359 }
1336 1360
1337 // Clean up temporary socket if it's still alive at this point. 1361 // Clean up temporary socket if it's still alive at this point.
1338 if (tmpsock != -1) { 1362 if (tmpsock != static_cast<socket_type>(-1)) {
1339 shutdown(tmpsock, SHUT_RDWR); 1363 shutdown(tmpsock, SHUT_RDWR);
1340 } 1364 }
1341} 1365}
@@ -1352,7 +1376,12 @@ void Shutdown() {
1352 1376
1353 LOG_INFO(Debug_GDBStub, "Stopping GDB ..."); 1377 LOG_INFO(Debug_GDBStub, "Stopping GDB ...");
1354 if (gdbserver_socket != -1) { 1378 if (gdbserver_socket != -1) {
1355 shutdown(gdbserver_socket, SHUT_RDWR); 1379#ifdef WIN32
1380 const auto tmpsock = static_cast<SOCKET>(socket(PF_INET, SOCK_STREAM, 0));
1381#else
1382 const auto tmpsock = static_cast<int>(socket(PF_INET, SOCK_STREAM, 0));
1383#endif
1384 shutdown(tmpsock, SHUT_RDWR);
1356 gdbserver_socket = -1; 1385 gdbserver_socket = -1;
1357 } 1386 }
1358 1387
@@ -1383,7 +1412,7 @@ void SetCpuStepFlag(bool is_step) {
1383 step_loop = is_step; 1412 step_loop = is_step;
1384} 1413}
1385 1414
1386void SendTrap(Kernel::Thread* thread, int trap) { 1415void SendTrap(Kernel::Thread* thread, u32 trap) {
1387 if (!send_trap) { 1416 if (!send_trap) {
1388 return; 1417 return;
1389 } 1418 }