diff options
Diffstat (limited to 'src/core/gdbstub/gdbstub.cpp')
| -rw-r--r-- | src/core/gdbstub/gdbstub.cpp | 71 |
1 files changed, 36 insertions, 35 deletions
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index ac53ba752..22ea53e22 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp | |||
| @@ -41,40 +41,42 @@ | |||
| 41 | #include "core/loader/loader.h" | 41 | #include "core/loader/loader.h" |
| 42 | #include "core/memory.h" | 42 | #include "core/memory.h" |
| 43 | 43 | ||
| 44 | const int GDB_BUFFER_SIZE = 10000; | 44 | namespace GDBStub { |
| 45 | namespace { | ||
| 46 | constexpr int GDB_BUFFER_SIZE = 10000; | ||
| 45 | 47 | ||
| 46 | const char GDB_STUB_START = '$'; | 48 | constexpr char GDB_STUB_START = '$'; |
| 47 | const char GDB_STUB_END = '#'; | 49 | constexpr char GDB_STUB_END = '#'; |
| 48 | const char GDB_STUB_ACK = '+'; | 50 | constexpr char GDB_STUB_ACK = '+'; |
| 49 | const char GDB_STUB_NACK = '-'; | 51 | constexpr char GDB_STUB_NACK = '-'; |
| 50 | 52 | ||
| 51 | #ifndef SIGTRAP | 53 | #ifndef SIGTRAP |
| 52 | const u32 SIGTRAP = 5; | 54 | constexpr u32 SIGTRAP = 5; |
| 53 | #endif | 55 | #endif |
| 54 | 56 | ||
| 55 | #ifndef SIGTERM | 57 | #ifndef SIGTERM |
| 56 | const u32 SIGTERM = 15; | 58 | constexpr u32 SIGTERM = 15; |
| 57 | #endif | 59 | #endif |
| 58 | 60 | ||
| 59 | #ifndef MSG_WAITALL | 61 | #ifndef MSG_WAITALL |
| 60 | const u32 MSG_WAITALL = 8; | 62 | constexpr u32 MSG_WAITALL = 8; |
| 61 | #endif | 63 | #endif |
| 62 | 64 | ||
| 63 | const u32 LR_REGISTER = 30; | 65 | constexpr u32 LR_REGISTER = 30; |
| 64 | const u32 SP_REGISTER = 31; | 66 | constexpr u32 SP_REGISTER = 31; |
| 65 | const u32 PC_REGISTER = 32; | 67 | constexpr u32 PC_REGISTER = 32; |
| 66 | const u32 CPSR_REGISTER = 33; | 68 | constexpr u32 CPSR_REGISTER = 33; |
| 67 | const u32 UC_ARM64_REG_Q0 = 34; | 69 | constexpr u32 UC_ARM64_REG_Q0 = 34; |
| 68 | const u32 FPSCR_REGISTER = 66; | 70 | constexpr u32 FPSCR_REGISTER = 66; |
| 69 | 71 | ||
| 70 | // TODO/WiP - Used while working on support for FPU | 72 | // TODO/WiP - Used while working on support for FPU |
| 71 | const u32 TODO_DUMMY_REG_997 = 997; | 73 | constexpr u32 TODO_DUMMY_REG_997 = 997; |
| 72 | const u32 TODO_DUMMY_REG_998 = 998; | 74 | constexpr u32 TODO_DUMMY_REG_998 = 998; |
| 73 | 75 | ||
| 74 | // For sample XML files see the GDB source /gdb/features | 76 | // For sample XML files see the GDB source /gdb/features |
| 75 | // GDB also wants the l character at the start | 77 | // GDB also wants the l character at the start |
| 76 | // This XML defines what the registers are for this specific ARM device | 78 | // This XML defines what the registers are for this specific ARM device |
| 77 | static const char* target_xml = | 79 | constexpr char target_xml[] = |
| 78 | R"(l<?xml version="1.0"?> | 80 | R"(l<?xml version="1.0"?> |
| 79 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> | 81 | <!DOCTYPE target SYSTEM "gdb-target.dtd"> |
| 80 | <target version="1.0"> | 82 | <target version="1.0"> |
| @@ -140,30 +142,28 @@ static const char* target_xml = | |||
| 140 | </target> | 142 | </target> |
| 141 | )"; | 143 | )"; |
| 142 | 144 | ||
| 143 | namespace GDBStub { | 145 | int gdbserver_socket = -1; |
| 144 | |||
| 145 | static int gdbserver_socket = -1; | ||
| 146 | 146 | ||
| 147 | static u8 command_buffer[GDB_BUFFER_SIZE]; | 147 | u8 command_buffer[GDB_BUFFER_SIZE]; |
| 148 | static u32 command_length; | 148 | u32 command_length; |
| 149 | 149 | ||
| 150 | static u32 latest_signal = 0; | 150 | u32 latest_signal = 0; |
| 151 | static bool memory_break = false; | 151 | bool memory_break = false; |
| 152 | 152 | ||
| 153 | static Kernel::Thread* current_thread = nullptr; | 153 | Kernel::Thread* current_thread = nullptr; |
| 154 | static u32 current_core = 0; | 154 | u32 current_core = 0; |
| 155 | 155 | ||
| 156 | // Binding to a port within the reserved ports range (0-1023) requires root permissions, | 156 | // Binding to a port within the reserved ports range (0-1023) requires root permissions, |
| 157 | // so default to a port outside of that range. | 157 | // so default to a port outside of that range. |
| 158 | static u16 gdbstub_port = 24689; | 158 | u16 gdbstub_port = 24689; |
| 159 | 159 | ||
| 160 | static bool halt_loop = true; | 160 | bool halt_loop = true; |
| 161 | static bool step_loop = false; | 161 | bool step_loop = false; |
| 162 | static bool send_trap = false; | 162 | bool send_trap = false; |
| 163 | 163 | ||
| 164 | // If set to false, the server will never be started and no | 164 | // If set to false, the server will never be started and no |
| 165 | // gdbstub-related functions will be executed. | 165 | // gdbstub-related functions will be executed. |
| 166 | static std::atomic<bool> server_enabled(false); | 166 | std::atomic<bool> server_enabled(false); |
| 167 | 167 | ||
| 168 | #ifdef _WIN32 | 168 | #ifdef _WIN32 |
| 169 | WSADATA InitData; | 169 | WSADATA InitData; |
| @@ -175,9 +175,9 @@ struct Breakpoint { | |||
| 175 | u64 len; | 175 | u64 len; |
| 176 | }; | 176 | }; |
| 177 | 177 | ||
| 178 | static std::map<u64, Breakpoint> breakpoints_execute; | 178 | std::map<u64, Breakpoint> breakpoints_execute; |
| 179 | static std::map<u64, Breakpoint> breakpoints_read; | 179 | std::map<u64, Breakpoint> breakpoints_read; |
| 180 | static std::map<u64, Breakpoint> breakpoints_write; | 180 | std::map<u64, Breakpoint> breakpoints_write; |
| 181 | 181 | ||
| 182 | struct Module { | 182 | struct Module { |
| 183 | std::string name; | 183 | std::string name; |
| @@ -185,7 +185,8 @@ struct Module { | |||
| 185 | VAddr end; | 185 | VAddr end; |
| 186 | }; | 186 | }; |
| 187 | 187 | ||
| 188 | static std::vector<Module> modules; | 188 | std::vector<Module> modules; |
| 189 | } // Anonymous namespace | ||
| 189 | 190 | ||
| 190 | void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) { | 191 | void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) { |
| 191 | Module module; | 192 | Module module; |