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.cpp71
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
44const int GDB_BUFFER_SIZE = 10000; 44namespace GDBStub {
45namespace {
46constexpr int GDB_BUFFER_SIZE = 10000;
45 47
46const char GDB_STUB_START = '$'; 48constexpr char GDB_STUB_START = '$';
47const char GDB_STUB_END = '#'; 49constexpr char GDB_STUB_END = '#';
48const char GDB_STUB_ACK = '+'; 50constexpr char GDB_STUB_ACK = '+';
49const char GDB_STUB_NACK = '-'; 51constexpr char GDB_STUB_NACK = '-';
50 52
51#ifndef SIGTRAP 53#ifndef SIGTRAP
52const u32 SIGTRAP = 5; 54constexpr u32 SIGTRAP = 5;
53#endif 55#endif
54 56
55#ifndef SIGTERM 57#ifndef SIGTERM
56const u32 SIGTERM = 15; 58constexpr u32 SIGTERM = 15;
57#endif 59#endif
58 60
59#ifndef MSG_WAITALL 61#ifndef MSG_WAITALL
60const u32 MSG_WAITALL = 8; 62constexpr u32 MSG_WAITALL = 8;
61#endif 63#endif
62 64
63const u32 LR_REGISTER = 30; 65constexpr u32 LR_REGISTER = 30;
64const u32 SP_REGISTER = 31; 66constexpr u32 SP_REGISTER = 31;
65const u32 PC_REGISTER = 32; 67constexpr u32 PC_REGISTER = 32;
66const u32 CPSR_REGISTER = 33; 68constexpr u32 CPSR_REGISTER = 33;
67const u32 UC_ARM64_REG_Q0 = 34; 69constexpr u32 UC_ARM64_REG_Q0 = 34;
68const u32 FPSCR_REGISTER = 66; 70constexpr 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
71const u32 TODO_DUMMY_REG_997 = 997; 73constexpr u32 TODO_DUMMY_REG_997 = 997;
72const u32 TODO_DUMMY_REG_998 = 998; 74constexpr 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
77static const char* target_xml = 79constexpr 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
143namespace GDBStub { 145int gdbserver_socket = -1;
144
145static int gdbserver_socket = -1;
146 146
147static u8 command_buffer[GDB_BUFFER_SIZE]; 147u8 command_buffer[GDB_BUFFER_SIZE];
148static u32 command_length; 148u32 command_length;
149 149
150static u32 latest_signal = 0; 150u32 latest_signal = 0;
151static bool memory_break = false; 151bool memory_break = false;
152 152
153static Kernel::Thread* current_thread = nullptr; 153Kernel::Thread* current_thread = nullptr;
154static u32 current_core = 0; 154u32 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.
158static u16 gdbstub_port = 24689; 158u16 gdbstub_port = 24689;
159 159
160static bool halt_loop = true; 160bool halt_loop = true;
161static bool step_loop = false; 161bool step_loop = false;
162static bool send_trap = false; 162bool 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.
166static std::atomic<bool> server_enabled(false); 166std::atomic<bool> server_enabled(false);
167 167
168#ifdef _WIN32 168#ifdef _WIN32
169WSADATA InitData; 169WSADATA InitData;
@@ -175,9 +175,9 @@ struct Breakpoint {
175 u64 len; 175 u64 len;
176}; 176};
177 177
178static std::map<u64, Breakpoint> breakpoints_execute; 178std::map<u64, Breakpoint> breakpoints_execute;
179static std::map<u64, Breakpoint> breakpoints_read; 179std::map<u64, Breakpoint> breakpoints_read;
180static std::map<u64, Breakpoint> breakpoints_write; 180std::map<u64, Breakpoint> breakpoints_write;
181 181
182struct Module { 182struct 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
188static std::vector<Module> modules; 188std::vector<Module> modules;
189} // Anonymous namespace
189 190
190void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) { 191void RegisterModule(std::string name, VAddr beg, VAddr end, bool add_elf_ext) {
191 Module module; 192 Module module;