diff options
| author | 2016-09-18 09:38:01 +0900 | |
|---|---|---|
| committer | 2016-09-18 09:38:01 +0900 | |
| commit | dc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch) | |
| tree | 569a7f13128450bbab973236615587ff00bced5f /src/core/gdbstub/gdbstub.cpp | |
| parent | Travis: Import Dolphin’s clang-format hook. (diff) | |
| download | yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip | |
Sources: Run clang-format on everything.
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 101 |
1 files changed, 56 insertions, 45 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 28d403158..6d709bd15 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -16,25 +16,25 @@ | |||
| 16 | 16 | ||
| 17 | #ifdef _MSC_VER | 17 | #ifdef _MSC_VER |
| 18 | #include <WinSock2.h> | 18 | #include <WinSock2.h> |
| 19 | #include <ws2tcpip.h> | ||
| 20 | #include <common/x64/abi.h> | 19 | #include <common/x64/abi.h> |
| 21 | #include <io.h> | 20 | #include <io.h> |
| 22 | #include <iphlpapi.h> | 21 | #include <iphlpapi.h> |
| 22 | #include <ws2tcpip.h> | ||
| 23 | #define SHUT_RDWR 2 | 23 | #define SHUT_RDWR 2 |
| 24 | #else | 24 | #else |
| 25 | #include <unistd.h> | 25 | #include <netinet/in.h> |
| 26 | #include <sys/select.h> | 26 | #include <sys/select.h> |
| 27 | #include <sys/socket.h> | 27 | #include <sys/socket.h> |
| 28 | #include <sys/un.h> | 28 | #include <sys/un.h> |
| 29 | #include <netinet/in.h> | 29 | #include <unistd.h> |
| 30 | #endif | 30 | #endif |
| 31 | 31 | ||
| 32 | #include "common/logging/log.h" | 32 | #include "common/logging/log.h" |
| 33 | #include "common/string_util.h" | 33 | #include "common/string_util.h" |
| 34 | #include "core/core.h" | ||
| 35 | #include "core/memory.h" | ||
| 36 | #include "core/arm/arm_interface.h" | 34 | #include "core/arm/arm_interface.h" |
| 35 | #include "core/core.h" | ||
| 37 | #include "core/gdbstub/gdbstub.h" | 36 | #include "core/gdbstub/gdbstub.h" |
| 37 | #include "core/memory.h" | ||
| 38 | 38 | ||
| 39 | const int GDB_BUFFER_SIZE = 10000; | 39 | const int GDB_BUFFER_SIZE = 10000; |
| 40 | 40 | ||
| @@ -64,7 +64,7 @@ const u32 FPSCR_REGISTER = 58; | |||
| 64 | // GDB also wants the l character at the start | 64 | // GDB also wants the l character at the start |
| 65 | // This XML defines what the registers are for this specific ARM device | 65 | // This XML defines what the registers are for this specific ARM device |
| 66 | static const char* target_xml = | 66 | static const char* target_xml = |
| 67 | R"(l<?xml version="1.0"?> | 67 | R"(l<?xml version="1.0"?> |
| 68 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> | 68 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> |
| 69 | <target version="1.0"> | 69 | <target version="1.0"> |
| 70 | <feature name="org.gnu.gdb.arm.core"> | 70 | <feature name="org.gnu.gdb.arm.core"> |
| @@ -297,7 +297,8 @@ static void RemoveBreakpoint(BreakpointType type, PAddr addr) { | |||
| 297 | 297 | ||
| 298 | auto bp = p.find(addr); | 298 | auto bp = p.find(addr); |
| 299 | if (bp != p.end()) { | 299 | if (bp != p.end()) { |
| 300 | LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n", bp->second.len, bp->second.addr, type); | 300 | LOG_DEBUG(Debug_GDBStub, "gdb: removed a breakpoint: %08x bytes at %08x of type %d\n", |
| 301 | bp->second.len, bp->second.addr, type); | ||
| 301 | p.erase(addr); | 302 | p.erase(addr); |
| 302 | } | 303 | } |
| 303 | } | 304 | } |
| @@ -342,7 +343,9 @@ bool CheckBreakpoint(PAddr addr, BreakpointType type) { | |||
| 342 | } | 343 | } |
| 343 | 344 | ||
| 344 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { | 345 | if (bp->second.active && (addr >= bp->second.addr && addr < bp->second.addr + len)) { |
| 345 | LOG_DEBUG(Debug_GDBStub, "Found breakpoint type %d @ %08x, range: %08x - %08x (%d bytes)\n", type, addr, bp->second.addr, bp->second.addr + len, len); | 346 | LOG_DEBUG(Debug_GDBStub, |
| 347 | "Found breakpoint type %d @ %08x, range: %08x - %08x (%d bytes)\n", type, | ||
| 348 | addr, bp->second.addr, bp->second.addr + len, len); | ||
| 346 | return true; | 349 | return true; |
| 347 | } | 350 | } |
| 348 | } | 351 | } |
| @@ -408,12 +411,13 @@ static void HandleQuery() { | |||
| 408 | 411 | ||
| 409 | const char* query = reinterpret_cast<const char*>(command_buffer + 1); | 412 | const char* query = reinterpret_cast<const char*>(command_buffer + 1); |
| 410 | 413 | ||
| 411 | if (strcmp(query, "TStatus") == 0 ) { | 414 | if (strcmp(query, "TStatus") == 0) { |
| 412 | SendReply("T0"); | 415 | SendReply("T0"); |
| 413 | } else if (strncmp(query, "Supported:", strlen("Supported:")) == 0) { | 416 | } else if (strncmp(query, "Supported:", strlen("Supported:")) == 0) { |
| 414 | // PacketSize needs to be large enough for target xml | 417 | // PacketSize needs to be large enough for target xml |
| 415 | SendReply("PacketSize=800;qXfer:features:read+"); | 418 | SendReply("PacketSize=800;qXfer:features:read+"); |
| 416 | } else if (strncmp(query, "Xfer:features:read:target.xml:", strlen("Xfer:features:read:target.xml:")) == 0) { | 419 | } else if (strncmp(query, "Xfer:features:read:target.xml:", |
| 420 | strlen("Xfer:features:read:target.xml:")) == 0) { | ||
| 417 | SendReply(target_xml); | 421 | SendReply(target_xml); |
| 418 | } else { | 422 | } else { |
| 419 | SendReply(""); | 423 | SendReply(""); |
| @@ -422,10 +426,8 @@ static void HandleQuery() { | |||
| 422 | 426 | ||
| 423 | /// Handle set thread command from gdb client. | 427 | /// Handle set thread command from gdb client. |
| 424 | static void HandleSetThread() { | 428 | static void HandleSetThread() { |
| 425 | if (memcmp(command_buffer, "Hg0", 3) == 0 || | 429 | if (memcmp(command_buffer, "Hg0", 3) == 0 || memcmp(command_buffer, "Hc-1", 4) == 0 || |
| 426 | memcmp(command_buffer, "Hc-1", 4) == 0 || | 430 | memcmp(command_buffer, "Hc0", 4) == 0 || memcmp(command_buffer, "Hc1", 4) == 0) { |
| 427 | memcmp(command_buffer, "Hc0", 4) == 0 || | ||
| 428 | memcmp(command_buffer, "Hc1", 4) == 0) { | ||
| 429 | return SendReply("OK"); | 431 | return SendReply("OK"); |
| 430 | } | 432 | } |
| 431 | 433 | ||
| @@ -444,7 +446,9 @@ static void SendSignal(u32 signal) { | |||
| 444 | 446 | ||
| 445 | latest_signal = signal; | 447 | latest_signal = signal; |
| 446 | 448 | ||
| 447 | std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, htonl(Core::g_app_core->GetPC()), 13, htonl(Core::g_app_core->GetReg(13))); | 449 | std::string buffer = Common::StringFromFormat("T%02x%02x:%08x;%02x:%08x;", latest_signal, 15, |
| 450 | htonl(Core::g_app_core->GetPC()), 13, | ||
| 451 | htonl(Core::g_app_core->GetReg(13))); | ||
| 448 | LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); | 452 | LOG_DEBUG(Debug_GDBStub, "Response: %s", buffer.c_str()); |
| 449 | SendReply(buffer.c_str()); | 453 | SendReply(buffer.c_str()); |
| 450 | } | 454 | } |
| @@ -456,7 +460,7 @@ static void ReadCommand() { | |||
| 456 | 460 | ||
| 457 | u8 c = ReadByte(); | 461 | u8 c = ReadByte(); |
| 458 | if (c == '+') { | 462 | if (c == '+') { |
| 459 | //ignore ack | 463 | // ignore ack |
| 460 | return; | 464 | return; |
| 461 | } else if (c == 0x03) { | 465 | } else if (c == 0x03) { |
| 462 | LOG_INFO(Debug_GDBStub, "gdb: found break command\n"); | 466 | LOG_INFO(Debug_GDBStub, "gdb: found break command\n"); |
| @@ -483,8 +487,9 @@ static void ReadCommand() { | |||
| 483 | u8 checksum_calculated = CalculateChecksum(command_buffer, command_length); | 487 | u8 checksum_calculated = CalculateChecksum(command_buffer, command_length); |
| 484 | 488 | ||
| 485 | if (checksum_received != checksum_calculated) { | 489 | if (checksum_received != checksum_calculated) { |
| 486 | LOG_ERROR(Debug_GDBStub, "gdb: invalid checksum: calculated %02x and read %02x for $%s# (length: %d)\n", | 490 | LOG_ERROR(Debug_GDBStub, |
| 487 | checksum_calculated, checksum_received, command_buffer, command_length); | 491 | "gdb: invalid checksum: calculated %02x and read %02x for $%s# (length: %d)\n", |
| 492 | checksum_calculated, checksum_received, command_buffer, command_length); | ||
| 488 | 493 | ||
| 489 | command_length = 0; | 494 | command_length = 0; |
| 490 | 495 | ||
| @@ -534,7 +539,9 @@ static void ReadRegister() { | |||
| 534 | } else if (id == CPSR_REGISTER) { | 539 | } else if (id == CPSR_REGISTER) { |
| 535 | IntToGdbHex(reply, Core::g_app_core->GetCPSR()); | 540 | IntToGdbHex(reply, Core::g_app_core->GetCPSR()); |
| 536 | } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { | 541 | } else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) { |
| 537 | IntToGdbHex(reply, Core::g_app_core->GetVFPReg(id - CPSR_REGISTER - 1)); // VFP registers should start at 26, so one after CSPR_REGISTER | 542 | IntToGdbHex(reply, Core::g_app_core->GetVFPReg( |
| 543 | id - CPSR_REGISTER - | ||
| 544 | 1)); // VFP registers should start at 26, so one after CSPR_REGISTER | ||
| 538 | } else if (id == FPSCR_REGISTER) { | 545 | } else if (id == FPSCR_REGISTER) { |
| 539 | IntToGdbHex(reply, Core::g_app_core->GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR | 546 | IntToGdbHex(reply, Core::g_app_core->GetVFPSystemReg(VFP_FPSCR)); // Get FPSCR |
| 540 | IntToGdbHex(reply + 8, 0); | 547 | IntToGdbHex(reply + 8, 0); |
| @@ -617,7 +624,8 @@ static void WriteRegisters() { | |||
| 617 | // Dummy FPA registers, ignore | 624 | // Dummy FPA registers, ignore |
| 618 | i += 2; | 625 | i += 2; |
| 619 | } else if (reg > CPSR_REGISTER && reg < FPSCR_REGISTER) { | 626 | } else if (reg > CPSR_REGISTER && reg < FPSCR_REGISTER) { |
| 620 | Core::g_app_core->SetVFPReg(reg - CPSR_REGISTER - 1, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); | 627 | Core::g_app_core->SetVFPReg(reg - CPSR_REGISTER - 1, |
| 628 | GdbHexToInt(buffer_ptr + i * CHAR_BIT)); | ||
| 621 | i++; // Skip padding | 629 | i++; // Skip padding |
| 622 | } else if (reg == FPSCR_REGISTER) { | 630 | } else if (reg == FPSCR_REGISTER) { |
| 623 | Core::g_app_core->SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); | 631 | Core::g_app_core->SetVFPSystemReg(VFP_FPSCR, GdbHexToInt(buffer_ptr + i * CHAR_BIT)); |
| @@ -631,12 +639,13 @@ static void WriteRegisters() { | |||
| 631 | static void ReadMemory() { | 639 | static void ReadMemory() { |
| 632 | static u8 reply[GDB_BUFFER_SIZE - 4]; | 640 | static u8 reply[GDB_BUFFER_SIZE - 4]; |
| 633 | 641 | ||
| 634 | auto start_offset = command_buffer+1; | 642 | auto start_offset = command_buffer + 1; |
| 635 | auto addr_pos = std::find(start_offset, command_buffer+command_length, ','); | 643 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 636 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); | 644 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); |
| 637 | 645 | ||
| 638 | start_offset = addr_pos+1; | 646 | start_offset = addr_pos + 1; |
| 639 | u32 len = HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | 647 | u32 len = |
| 648 | HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | ||
| 640 | 649 | ||
| 641 | LOG_DEBUG(Debug_GDBStub, "gdb: addr: %08x len: %08x\n", addr, len); | 650 | LOG_DEBUG(Debug_GDBStub, "gdb: addr: %08x len: %08x\n", addr, len); |
| 642 | 651 | ||
| @@ -656,12 +665,12 @@ static void ReadMemory() { | |||
| 656 | 665 | ||
| 657 | /// Modify location in memory with data received from the gdb client. | 666 | /// Modify location in memory with data received from the gdb client. |
| 658 | static void WriteMemory() { | 667 | static void WriteMemory() { |
| 659 | auto start_offset = command_buffer+1; | 668 | auto start_offset = command_buffer + 1; |
| 660 | auto addr_pos = std::find(start_offset, command_buffer+command_length, ','); | 669 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 661 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); | 670 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); |
| 662 | 671 | ||
| 663 | start_offset = addr_pos+1; | 672 | start_offset = addr_pos + 1; |
| 664 | auto len_pos = std::find(start_offset, command_buffer+command_length, ':'); | 673 | auto len_pos = std::find(start_offset, command_buffer + command_length, ':'); |
| 665 | u32 len = HexToInt(start_offset, static_cast<u32>(len_pos - start_offset)); | 674 | u32 len = HexToInt(start_offset, static_cast<u32>(len_pos - start_offset)); |
| 666 | 675 | ||
| 667 | u8* dst = Memory::GetPointer(addr); | 676 | u8* dst = Memory::GetPointer(addr); |
| @@ -720,9 +729,10 @@ static bool CommitBreakpoint(BreakpointType type, PAddr addr, u32 len) { | |||
| 720 | breakpoint.active = true; | 729 | breakpoint.active = true; |
| 721 | breakpoint.addr = addr; | 730 | breakpoint.addr = addr; |
| 722 | breakpoint.len = len; | 731 | breakpoint.len = len; |
| 723 | p.insert({ addr, breakpoint }); | 732 | p.insert({addr, breakpoint}); |
| 724 | 733 | ||
| 725 | LOG_DEBUG(Debug_GDBStub, "gdb: added %d breakpoint: %08x bytes at %08x\n", type, breakpoint.len, breakpoint.addr); | 734 | LOG_DEBUG(Debug_GDBStub, "gdb: added %d breakpoint: %08x bytes at %08x\n", type, breakpoint.len, |
| 735 | breakpoint.addr); | ||
| 726 | 736 | ||
| 727 | return true; | 737 | return true; |
| 728 | } | 738 | } |
| @@ -750,12 +760,13 @@ static void AddBreakpoint() { | |||
| 750 | return SendReply("E01"); | 760 | return SendReply("E01"); |
| 751 | } | 761 | } |
| 752 | 762 | ||
| 753 | auto start_offset = command_buffer+3; | 763 | auto start_offset = command_buffer + 3; |
| 754 | auto addr_pos = std::find(start_offset, command_buffer+command_length, ','); | 764 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 755 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); | 765 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); |
| 756 | 766 | ||
| 757 | start_offset = addr_pos+1; | 767 | start_offset = addr_pos + 1; |
| 758 | u32 len = HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | 768 | u32 len = |
| 769 | HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | ||
| 759 | 770 | ||
| 760 | if (type == BreakpointType::Access) { | 771 | if (type == BreakpointType::Access) { |
| 761 | // Access is made up of Read and Write types, so add both breakpoints | 772 | // Access is made up of Read and Write types, so add both breakpoints |
| @@ -798,12 +809,13 @@ static void RemoveBreakpoint() { | |||
| 798 | return SendReply("E01"); | 809 | return SendReply("E01"); |
| 799 | } | 810 | } |
| 800 | 811 | ||
| 801 | auto start_offset = command_buffer+3; | 812 | auto start_offset = command_buffer + 3; |
| 802 | auto addr_pos = std::find(start_offset, command_buffer+command_length, ','); | 813 | auto addr_pos = std::find(start_offset, command_buffer + command_length, ','); |
| 803 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); | 814 | PAddr addr = HexToInt(start_offset, static_cast<u32>(addr_pos - start_offset)); |
| 804 | 815 | ||
| 805 | start_offset = addr_pos+1; | 816 | start_offset = addr_pos + 1; |
| 806 | u32 len = HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | 817 | u32 len = |
| 818 | HexToInt(start_offset, static_cast<u32>((command_buffer + command_length) - start_offset)); | ||
| 807 | 819 | ||
| 808 | if (type == BreakpointType::Access) { | 820 | if (type == BreakpointType::Access) { |
| 809 | // Access is made up of Read and Write types, so add both breakpoints | 821 | // Access is made up of Read and Write types, so add both breakpoints |
| @@ -896,8 +908,7 @@ void ToggleServer(bool status) { | |||
| 896 | if (!IsConnected() && Core::g_sys_core != nullptr) { | 908 | if (!IsConnected() && Core::g_sys_core != nullptr) { |
| 897 | Init(); | 909 | Init(); |
| 898 | } | 910 | } |
| 899 | } | 911 | } else { |
| 900 | else { | ||
| 901 | // Stop server | 912 | // Stop server |
| 902 | if (IsConnected()) { | 913 | if (IsConnected()) { |
| 903 | Shutdown(); | 914 | Shutdown(); |
| @@ -943,7 +954,8 @@ static void Init(u16 port) { | |||
| 943 | 954 | ||
| 944 | // Set socket to SO_REUSEADDR so it can always bind on the same port | 955 | // Set socket to SO_REUSEADDR so it can always bind on the same port |
| 945 | int reuse_enabled = 1; | 956 | int reuse_enabled = 1; |
| 946 | if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled, sizeof(reuse_enabled)) < 0) { | 957 | if (setsockopt(tmpsock, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuse_enabled, |
| 958 | sizeof(reuse_enabled)) < 0) { | ||
| 947 | LOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option"); | 959 | LOG_ERROR(Debug_GDBStub, "Failed to set gdb socket option"); |
| 948 | } | 960 | } |
| 949 | 961 | ||
| @@ -964,13 +976,13 @@ static void Init(u16 port) { | |||
| 964 | socklen_t client_addrlen = sizeof(saddr_client); | 976 | socklen_t client_addrlen = sizeof(saddr_client); |
| 965 | gdbserver_socket = accept(tmpsock, client_addr, &client_addrlen); | 977 | gdbserver_socket = accept(tmpsock, client_addr, &client_addrlen); |
| 966 | if (gdbserver_socket < 0) { | 978 | if (gdbserver_socket < 0) { |
| 967 | // In the case that we couldn't start the server for whatever reason, just start CPU execution like normal. | 979 | // In the case that we couldn't start the server for whatever reason, just start CPU |
| 980 | // execution like normal. | ||
| 968 | halt_loop = false; | 981 | halt_loop = false; |
| 969 | step_loop = false; | 982 | step_loop = false; |
| 970 | 983 | ||
| 971 | LOG_ERROR(Debug_GDBStub, "Failed to accept gdb client"); | 984 | LOG_ERROR(Debug_GDBStub, "Failed to accept gdb client"); |
| 972 | } | 985 | } else { |
| 973 | else { | ||
| 974 | LOG_INFO(Debug_GDBStub, "Client connected.\n"); | 986 | LOG_INFO(Debug_GDBStub, "Client connected.\n"); |
| 975 | saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr); | 987 | saddr_client.sin_addr.s_addr = ntohl(saddr_client.sin_addr.s_addr); |
| 976 | } | 988 | } |
| @@ -1018,5 +1030,4 @@ bool GetCpuStepFlag() { | |||
| 1018 | void SetCpuStepFlag(bool is_step) { | 1030 | void SetCpuStepFlag(bool is_step) { |
| 1019 | step_loop = is_step; | 1031 | step_loop = is_step; |
| 1020 | } | 1032 | } |
| 1021 | |||
| 1022 | }; | 1033 | }; |