Compare commits

...

111 Commits

Author SHA1 Message Date
Hedges
26d74fefdc Merge 85d02d07fc into 316b933a31 2018-07-12 16:54:02 +00:00
Jarek Syrylak
85d02d07fc This auto should not actually be const 2018-07-12 17:53:47 +01:00
Jarek Syrylak
5a9ba8342f More tidy up as per comments on pull request 2018-07-12 17:41:14 +01:00
Jarek Syrylak
21a2512cfb More tidy up as per comments on pull request 2018-07-12 15:46:31 +01:00
Jarek Syrylak
33ac8e9a85 Tidy up as per comments on pull request 2018-07-12 12:23:12 +01:00
Jarek Syrylak
eca5df2573 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-12 09:38:35 +01:00
Jarek Syrylak
39840bd511 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-11 17:23:37 +01:00
Jarek Syrylak
7b31bed043 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-11 10:04:28 +01:00
Jarek Syrylak
d909d700ce Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-10 17:50:16 +01:00
Jarek Syrylak
198805b0fa Revert bad merge/rebase 2018-07-10 17:22:24 +01:00
Jarek Syrylak
05a019d4ee Merge branch 'master' of https://github.com/Hedges/yuzu 2018-07-10 16:39:04 +01:00
Jarek Syrylak
4b22a64d63 Compile fixes for Linux and macOS 2018-07-10 16:38:24 +01:00
Jarek Syrylak
e652110fda Register all loaded modules with GDBStub 2018-07-10 16:38:23 +01:00
Jarek Syrylak
9cb1f759ca Avoid crash in IsValidVirtualAddress() 2018-07-10 16:38:16 +01:00
Jarek Syrylak
4a657f5fb6 Register module with GDBStub. 2018-07-10 16:38:08 +01:00
Jarek Syrylak
20a3fbcc5a Fix handler for libraries query. 2018-07-10 16:38:01 +01:00
Jarek Syrylak
490893f119 Register NRO module. 2018-07-10 16:38:01 +01:00
Jarek Syrylak
430903a1ba Fix splitpath on Windows. 2018-07-10 16:38:00 +01:00
Jarek Syrylak
f7e6e204da Some cleanup. 2018-07-10 16:38:00 +01:00
Jarek Syrylak
1ffd10ce18 Add support for NSO modules. 2018-07-10 16:38:00 +01:00
Jarek Syrylak
c2ad530279 Initial support for floating point registers (wip). 2018-07-10 16:37:46 +01:00
Jarek Syrylak
625558e7b0 Reload registers from thread context after they have been changed in GDBStub. 2018-07-10 16:37:46 +01:00
Jarek Syrylak
fb8e336e95 Tidy up. 2018-07-10 16:37:45 +01:00
Jarek Syrylak
68e5f369c1 More improvements and diagnostics for GDBStub. 2018-07-10 16:37:45 +01:00
Jarek Syrylak
2f465d7572 More improvements and diagnostics for GDBStub. 2018-07-10 16:37:38 +01:00
Jarek Syrylak
c3ec14616f More improvements and diagnostics for GDBStub. 2018-07-10 16:37:38 +01:00
Jarek Syrylak
7e7f94f559 More improvements and diagnostics for GDBStub. 2018-07-10 16:37:38 +01:00
Jarek Syrylak
6bd605cb61 Work towards improving handling of threads in GDBStub. 2018-07-10 16:37:37 +01:00
Jarek Syrylak
b412594127 Extra diagnostics for multi-threaded breaks. 2018-07-10 16:37:37 +01:00
Jarek Syrylak
7f342ce736 In step mode only signal trap from current thread, in run mode signal always. 2018-07-10 16:37:37 +01:00
Jarek Syrylak
b5e29babc5 Looking for a thread by its id should _not_ set it as a current thread!
Returning proper list of threads for better integration with VS debugger.
2018-07-10 16:37:37 +01:00
Jarek Syrylak
008a2d35d8 Only send traps from GDB's current thread, otherwise we will always be thrown back to main thread when stepping. 2018-07-10 16:37:36 +01:00
Jarek Syrylak
f8f0913e2e Tidy up. 2018-07-10 16:37:36 +01:00
Jarek Syrylak
fdf73c177b Replaced htonll with swap64. 2018-07-10 16:37:36 +01:00
Jarek Syrylak
7212fd5227 Applied clang-format. 2018-07-10 16:37:35 +01:00
Jarek Syrylak
341517a5f2 GDB Stub should work now. 2018-07-10 16:37:35 +01:00
Jarek Syrylak
31bc72dd5b Compile fixes for Linux and macOS 2018-07-10 11:28:36 +01:00
Jarek Syrylak
bee01b8e6c Register all loaded modules with GDBStub 2018-07-10 11:02:34 +01:00
Jarek Syrylak
813fab2046 Avoid crash in IsValidVirtualAddress() 2018-07-10 10:25:34 +01:00
Jarek Syrylak
2b091f642f Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-10 10:21:50 +01:00
Jarek Syrylak
e39769b78a Merge branch 'master' of https://github.com/Hedges/yuzu 2018-07-09 09:52:19 +01:00
Jarek Syrylak
20f6ac28f9 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-08 11:01:43 +01:00
Jarek Syrylak
75767354c6 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-07 22:21:35 +01:00
Jarek Syrylak
35a3eb3467 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-07 10:14:07 +01:00
Jarek Syrylak
cdf1682f79 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-07 10:13:45 +01:00
Jarek Syrylak
7246b03e45 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-06 10:18:00 +01:00
Jarek Syrylak
1ba63bd4d7 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-05 19:33:38 +01:00
Jarek Syrylak
36460b5d58 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-05 17:54:26 +01:00
Jarek Syrylak
732b8305de Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-05 09:53:51 +01:00
Jarek Syrylak
22c008ea20 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-04 22:13:56 +01:00
Jarek Syrylak
c30cf74ef8 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-04 10:02:31 +01:00
Jarek Syrylak
3274826d28 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-03 19:00:24 +01:00
Jarek Syrylak
f69c7d738b Merge branch 'master' of https://github.com/Hedges/yuzu 2018-07-03 19:00:12 +01:00
Jarek Syrylak
c3e39280e6 Register module with GDBStub. 2018-07-03 09:59:38 +01:00
Jarek Syrylak
f18b555c4d Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-03 09:57:20 +01:00
Jarek Syrylak
9e73c92f3e Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-02 18:53:03 +01:00
Jarek Syrylak
ab7567e048 Merge branch 'master' of https://github.com/Hedges/yuzu 2018-07-02 09:55:15 +01:00
Jarek Syrylak
1cb53177cc Fix handler for libraries query. 2018-07-02 00:15:21 +01:00
Jarek Syrylak
38acb2a835 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-07-01 22:08:17 +01:00
Jarek Syrylak
aa020b7a9b Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-30 12:30:22 +01:00
Jarek Syrylak
90539362bc Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-29 00:10:19 +01:00
Jarek Syrylak
99acda51d2 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-28 09:56:31 +01:00
Jarek Syrylak
e7b518e8dd Register NRO module. 2018-06-27 23:47:51 +01:00
Jarek Syrylak
917db5cafe Fix splitpath on Windows. 2018-06-27 23:47:27 +01:00
Jarek Syrylak
1f73848198 Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-27 19:23:23 +01:00
Jarek Syrylak
82058c7275 Some cleanup. 2018-06-27 17:35:57 +01:00
Jarek Syrylak
1a18c59964 Add support for NSO modules. 2018-06-27 16:22:30 +01:00
Jarek Syrylak
f2d69f0dd9 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-27 10:35:09 +01:00
Jarek Syrylak
d4ec24bdbb Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-26 19:30:21 +01:00
Jarek Syrylak
f684b02719 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-26 10:10:05 +01:00
Jarek Syrylak
5c5950bd9e Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-25 10:00:26 +01:00
Jarek Syrylak
538418e4b0 Initial support for floating point registers (wip). 2018-06-24 23:06:07 +01:00
Jarek Syrylak
72fd238ff2 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-24 11:22:59 +01:00
Jarek Syrylak
74e3b223b7 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-23 13:11:42 +01:00
Jarek Syrylak
5d0afdeae6 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-22 22:15:37 +01:00
Jarek Syrylak
b0c05f5e86 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-21 10:05:27 +01:00
Jarek Syrylak
7f6bf91050 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-19 17:33:56 +01:00
Jarek Syrylak
ffa6a3dd5c Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-19 09:46:32 +01:00
Jarek Syrylak
a8026d328f Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-18 15:01:58 +01:00
Jarek Syrylak
b0067bb3e5 Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-12 19:16:27 +01:00
Jarek Syrylak
a35755dab8 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-12 16:41:20 +01:00
Jarek Syrylak
c5445c764d Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-11 17:08:25 +01:00
Jarek Syrylak
c40e897bc0 Reload registers from thread context after they have been changed in GDBStub. 2018-06-11 14:53:47 +01:00
Jarek Syrylak
01c168a460 Tidy up. 2018-06-11 09:50:40 +01:00
Jarek Syrylak
098fb7438e Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-11 09:42:25 +01:00
Jarek Syrylak
1d1646e53f Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-10 23:40:10 +01:00
Jarek Syrylak
4ab40a08ff Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-09 16:59:18 +01:00
Jarek Syrylak
6b37634175 More improvements and diagnostics for GDBStub. 2018-06-09 16:41:41 +01:00
Jarek Syrylak
e0ceb4ed70 More improvements and diagnostics for GDBStub. 2018-06-09 15:16:56 +01:00
Jarek Syrylak
806de51c6a More improvements and diagnostics for GDBStub. 2018-06-09 10:58:18 +01:00
Jarek Syrylak
f21550c836 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-09 10:25:29 +01:00
Jarek Syrylak
2adb30a137 More improvements and diagnostics for GDBStub. 2018-06-09 10:24:55 +01:00
Jarek Syrylak
1c002e1acc Work towards improving handling of threads in GDBStub. 2018-06-08 18:35:34 +01:00
Jarek Syrylak
d0d834ad2d Extra diagnostics for multi-threaded breaks. 2018-06-08 01:03:24 +01:00
Jarek Syrylak
56a5d60276 In step mode only signal trap from current thread, in run mode signal always. 2018-06-07 23:40:03 +01:00
Jarek Syrylak
4346150b6f Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-07 19:45:08 +01:00
Jarek Syrylak
586c14670e Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-07 19:44:48 +01:00
Jarek Syrylak
5ce0d95f1c Looking for a thread by its id should _not_ set it as a current thread!
Returning proper list of threads for better integration with VS debugger.
2018-06-07 18:20:33 +01:00
Jarek Syrylak
f76bceb714 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-07 09:53:34 +01:00
Jarek Syrylak
1615d56d0f Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-06 21:12:27 +01:00
Jarek Syrylak
2f61f8ff13 Only send traps from GDB's current thread, otherwise we will always be thrown back to main thread when stepping. 2018-06-06 15:05:23 +01:00
Jarek Syrylak
cbadda89c1 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-06 14:59:23 +01:00
Jarek Syrylak
ae86329474 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-06 09:45:23 +01:00
Jarek Syrylak
b0d52753c1 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-05 19:22:30 +01:00
Jarek Syrylak
8171771fa8 Merge branch 'master' of https://github.com/Hedges/yuzu 2018-06-05 19:22:05 +01:00
Jarek Syrylak
f3ea3523b2 Tidy up. 2018-06-05 12:56:02 +01:00
Jarek Syrylak
84963f2f20 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-04 23:37:50 +01:00
Jarek Syrylak
33a4892279 Merge branch 'master' of https://github.com/yuzu-emu/yuzu 2018-06-04 22:23:05 +01:00
Jarek Syrylak
f417fbcd47 Replaced htonll with swap64. 2018-06-04 17:05:07 +01:00
Jarek Syrylak
62fd45d040 Applied clang-format. 2018-06-04 16:46:08 +01:00
Jarek Syrylak
a78a5003fa GDB Stub should work now. 2018-06-04 16:03:01 +01:00
9 changed files with 172 additions and 54 deletions

View File

@@ -134,7 +134,7 @@ bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _
size_t dir_end = full_path.find_last_of("/"
// windows needs the : included for something like just "C:" to be considered a directory
#ifdef _WIN32
":"
"\\:"
#endif
);
if (std::string::npos == dir_end)

View File

@@ -193,11 +193,11 @@ void ARM_Unicorn::ExecuteInstructions(int num_instructions) {
}
Kernel::Thread* thread = Kernel::GetCurrentThread();
SaveContext(thread->context);
if (last_bkpt_hit) {
if (last_bkpt_hit || (num_instructions == 1)) {
last_bkpt_hit = false;
GDBStub::Break();
GDBStub::SendTrap(thread, 5);
}
GDBStub::SendTrap(thread, 5);
}
}

View File

@@ -61,10 +61,12 @@ const u32 SIGTERM = 15;
const u32 MSG_WAITALL = 8;
#endif
const u32 X30_REGISTER = 30;
const u32 LR_REGISTER = 30;
const u32 SP_REGISTER = 31;
const u32 PC_REGISTER = 32;
const u32 CPSR_REGISTER = 33;
const u32 UC_ARM64_REG_Q0 = 34;
const u32 FPSCR_REGISTER = 66;
// For sample XML files see the GDB source /gdb/features
// GDB also wants the l character at the start
@@ -130,6 +132,8 @@ static const char* target_xml =
</flags>
<reg name="cpsr" bitsize="32" type="cpsr_flags"/>
</feature>
<feature name="org.gnu.gdb.aarch64.fpu">
</feature>
</target>
)";
@@ -144,6 +148,7 @@ static u32 latest_signal = 0;
static bool memory_break = false;
static Kernel::Thread* current_thread = nullptr;
static u32 current_core = 0;
// Binding to a port within the reserved ports range (0-1023) requires root permissions,
// so default to a port outside of that range.
@@ -171,13 +176,34 @@ static std::map<u64, Breakpoint> breakpoints_execute;
static std::map<u64, Breakpoint> breakpoints_read;
static std::map<u64, Breakpoint> breakpoints_write;
struct Module {
std::string name;
PAddr beg;
PAddr end;
};
static std::vector<Module> modules;
void RegisterModule(std::string name, PAddr beg, PAddr end, bool add_elf_ext) {
Module module;
if (add_elf_ext) {
Common::SplitPath(name, nullptr, &module.name, nullptr);
module.name += ".elf";
} else {
module.name = std::move(name);
}
module.beg = beg;
module.end = end;
modules.push_back(std::move(module));
}
static Kernel::Thread* FindThreadById(int id) {
for (int core = 0; core < Core::NUM_CPU_CORES; core++) {
auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for (auto thread : threads) {
for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for (auto& thread : threads) {
if (thread->GetThreadId() == id) {
current_thread = thread.get();
return current_thread;
current_core = core;
return thread.get();
}
}
}
@@ -197,6 +223,8 @@ static u64 RegRead(int id, Kernel::Thread* thread = nullptr) {
return thread->context.pc;
} else if (id == CPSR_REGISTER) {
return thread->context.cpsr;
} else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) {
return thread->context.fpu_registers[id - UC_ARM64_REG_Q0][0];
} else {
return 0;
}
@@ -215,6 +243,8 @@ static void RegWrite(int id, u64 val, Kernel::Thread* thread = nullptr) {
thread->context.pc = val;
} else if (id == CPSR_REGISTER) {
thread->context.cpsr = val;
} else if (id > CPSR_REGISTER && id < FPSCR_REGISTER) {
thread->context.fpu_registers[id - (CPSR_REGISTER + 1)][0] = val;
}
}
@@ -534,7 +564,11 @@ static void HandleQuery() {
SendReply("T0");
} else if (strncmp(query, "Supported", strlen("Supported")) == 0) {
// PacketSize needs to be large enough for target xml
SendReply("PacketSize=2000;qXfer:features:read+");
std::string buffer = "PacketSize=2000;qXfer:features:read+;qXfer:threads:read+";
if (modules.size()) {
buffer += ";qXfer:libraries:read+";
}
SendReply(buffer.c_str());
} else if (strncmp(query, "Xfer:features:read:target.xml:",
strlen("Xfer:features:read:target.xml:")) == 0) {
SendReply(target_xml);
@@ -543,9 +577,9 @@ static void HandleQuery() {
SendReply(buffer.c_str());
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
std::string val = "m";
for (int core = 0; core < Core::NUM_CPU_CORES; core++) {
auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for (auto thread : threads) {
for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for (const auto& thread : threads) {
val += fmt::format("{:x}", thread->GetThreadId());
val += ",";
}
@@ -554,6 +588,31 @@ static void HandleQuery() {
SendReply(val.c_str());
} else if (strncmp(query, "sThreadInfo", strlen("sThreadInfo")) == 0) {
SendReply("l");
} else if (strncmp(query, "Xfer:threads:read", strlen("Xfer:threads:read")) == 0) {
std::string buffer;
buffer += "l<?xml version=\"1.0\"?>";
buffer += "<threads>";
for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) {
const auto& threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
for (const auto& thread : threads) {
buffer +=
fmt::format(R"*(<thread id="{:x}" core="{:d}" name="Thread {:x}"></thread>)*",
thread->GetThreadId(), core, thread->GetThreadId());
}
}
buffer += "</threads>";
SendReply(buffer.c_str());
} else if (strncmp(query, "Xfer:libraries:read", strlen("Xfer:libraries:read")) == 0) {
std::string buffer;
buffer += "l<?xml version=\"1.0\"?>";
buffer += "<library-list>";
for (const auto& module : modules) {
buffer +=
fmt::format(R"*("<library name = "{}"><segment address = "0x{:x}"/></library>)*",
module.name, module.beg);
}
buffer += "</library-list>";
SendReply(buffer.c_str());
} else {
SendReply("");
}
@@ -561,33 +620,27 @@ static void HandleQuery() {
/// Handle set thread command from gdb client.
static void HandleSetThread() {
if (memcmp(command_buffer, "Hc", 2) == 0 || memcmp(command_buffer, "Hg", 2) == 0) {
int thread_id = -1;
if (command_buffer[2] != '-') {
thread_id = static_cast<int>(HexToInt(
command_buffer + 2,
command_length - 2 /*strlen(reinterpret_cast<char*>(command_buffer) + 2)*/));
}
if (thread_id >= 1) {
current_thread = FindThreadById(thread_id);
}
if (!current_thread) {
thread_id = 1;
current_thread = FindThreadById(thread_id);
}
if (current_thread) {
SendReply("OK");
return;
}
int thread_id = -1;
if (command_buffer[2] != '-') {
thread_id = static_cast<int>(HexToInt(command_buffer + 2, command_length - 2));
}
if (thread_id >= 1) {
current_thread = FindThreadById(thread_id);
}
if (!current_thread) {
thread_id = 1;
current_thread = FindThreadById(thread_id);
}
if (current_thread) {
SendReply("OK");
return;
}
SendReply("E01");
}
/// Handle thread alive command from gdb client.
static void HandleThreadAlive() {
int thread_id = static_cast<int>(
HexToInt(command_buffer + 1,
command_length - 1 /*strlen(reinterpret_cast<char*>(command_buffer) + 1)*/));
int thread_id = static_cast<int>(HexToInt(command_buffer + 1, command_length - 1));
if (thread_id == 0) {
thread_id = 1;
}
@@ -610,16 +663,23 @@ static void SendSignal(Kernel::Thread* thread, u32 signal, bool full = true) {
latest_signal = signal;
std::string buffer;
if (full) {
buffer = fmt::format("T{:02x}{:02x}:{:016x};{:02x}:{:016x};", latest_signal, PC_REGISTER,
Common::swap64(RegRead(PC_REGISTER, thread)), SP_REGISTER,
Common::swap64(RegRead(SP_REGISTER, thread)));
} else {
buffer = fmt::format("T{:02x};", latest_signal);
if (!thread) {
full = false;
}
buffer += fmt::format("thread:{:x};", thread->GetThreadId());
std::string buffer;
if (full) {
buffer = fmt::format("T{:02x}{:02x}:{:016x};{:02x}:{:016x};{:02x}:{:016x}", latest_signal,
PC_REGISTER, Common::swap64(RegRead(PC_REGISTER, thread)), SP_REGISTER,
Common::swap64(RegRead(SP_REGISTER, thread)), LR_REGISTER,
Common::swap64(RegRead(LR_REGISTER, thread)));
} else {
buffer = fmt::format("T{:02x}", latest_signal);
}
if (thread) {
buffer += fmt::format(";thread:{:x};", thread->GetThreadId());
}
SendReply(buffer.c_str());
}
@@ -711,8 +771,13 @@ static void ReadRegister() {
LongToGdbHex(reply, RegRead(id, current_thread));
} else if (id == CPSR_REGISTER) {
IntToGdbHex(reply, (u32)RegRead(id, current_thread));
} else if (id >= UC_ARM64_REG_Q0 && id < FPSCR_REGISTER) {
LongToGdbHex(reply, RegRead(id, current_thread));
} else if (id == FPSCR_REGISTER) {
LongToGdbHex(reply, RegRead(998, current_thread));
} else {
return SendReply("E01");
// return SendReply("E01");
LongToGdbHex(reply, RegRead(997, current_thread));
}
SendReply(reinterpret_cast<char*>(reply));
@@ -729,7 +794,7 @@ static void ReadRegisters() {
LongToGdbHex(bufptr + reg * 16, RegRead(reg, current_thread));
}
bufptr += (32 * 16);
bufptr += 32 * 16;
LongToGdbHex(bufptr, RegRead(PC_REGISTER, current_thread));
@@ -739,6 +804,16 @@ static void ReadRegisters() {
bufptr += 8;
for (int reg = UC_ARM64_REG_Q0; reg <= UC_ARM64_REG_Q0 + 31; reg++) {
LongToGdbHex(bufptr + reg * 16, RegRead(reg, current_thread));
}
bufptr += 32 * 32;
LongToGdbHex(bufptr, RegRead(998, current_thread));
bufptr += 8;
SendReply(reinterpret_cast<char*>(buffer));
}
@@ -759,10 +834,17 @@ static void WriteRegister() {
RegWrite(id, GdbHexToLong(buffer_ptr), current_thread);
} else if (id == CPSR_REGISTER) {
RegWrite(id, GdbHexToInt(buffer_ptr), current_thread);
} else if (id >= UC_ARM64_REG_Q0 && id < FPSCR_REGISTER) {
RegWrite(id, GdbHexToLong(buffer_ptr), current_thread);
} else if (id == FPSCR_REGISTER) {
RegWrite(998, GdbHexToLong(buffer_ptr), current_thread);
} else {
return SendReply("E01");
// return SendReply("E01");
RegWrite(997, GdbHexToLong(buffer_ptr), current_thread);
}
Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context);
SendReply("OK");
}
@@ -773,18 +855,24 @@ static void WriteRegisters() {
if (command_buffer[0] != 'G')
return SendReply("E01");
for (int i = 0, reg = 0; reg <= CPSR_REGISTER; i++, reg++) {
for (int i = 0, reg = 0; reg <= FPSCR_REGISTER; i++, reg++) {
if (reg <= SP_REGISTER) {
RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread);
} else if (reg == PC_REGISTER) {
RegWrite(PC_REGISTER, GdbHexToLong(buffer_ptr + i * 16), current_thread);
} else if (reg == CPSR_REGISTER) {
RegWrite(CPSR_REGISTER, GdbHexToInt(buffer_ptr + i * 16), current_thread);
} else if (reg >= UC_ARM64_REG_Q0 && reg < FPSCR_REGISTER) {
RegWrite(reg, GdbHexToLong(buffer_ptr + i * 16), current_thread);
} else if (reg == FPSCR_REGISTER) {
RegWrite(998, GdbHexToLong(buffer_ptr + i * 16), current_thread);
} else {
UNIMPLEMENTED();
}
}
Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context);
SendReply("OK");
}
@@ -806,6 +894,10 @@ static void ReadMemory() {
SendReply("E01");
}
if (addr < Memory::PROCESS_IMAGE_VADDR || addr >= Memory::MAP_REGION_VADDR_END) {
return SendReply("E00");
}
if (!Memory::IsValidVirtualAddress(addr)) {
return SendReply("E00");
}
@@ -840,16 +932,17 @@ static void WriteMemory() {
}
void Break(bool is_memory_break) {
if (!halt_loop) {
halt_loop = true;
send_trap = true;
}
send_trap = true;
memory_break = is_memory_break;
}
/// Tell the CPU that it should perform a single step.
static void Step() {
if (command_length > 1) {
RegWrite(PC_REGISTER, GdbHexToLong(command_buffer + 1), current_thread);
Core::System::GetInstance().ArmInterface(current_core).LoadContext(current_thread->context);
}
step_loop = true;
halt_loop = true;
send_trap = true;
@@ -1090,6 +1183,8 @@ static void Init(u16 port) {
breakpoints_read.clear();
breakpoints_write.clear();
modules.clear();
// Start gdb server
LOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port);
@@ -1192,8 +1287,12 @@ void SetCpuStepFlag(bool is_step) {
void SendTrap(Kernel::Thread* thread, int trap) {
if (send_trap) {
if (!halt_loop || current_thread == thread) {
current_thread = thread;
SendSignal(thread, trap);
}
halt_loop = true;
send_trap = false;
SendSignal(thread, trap);
}
}
}; // namespace GDBStub

View File

@@ -6,6 +6,7 @@
#pragma once
#include <string>
#include "common/common_types.h"
#include "core/hle/kernel/thread.h"
@@ -51,6 +52,9 @@ bool IsServerEnabled();
/// Returns true if there is an active socket connection.
bool IsConnected();
/// Register module.
void RegisterModule(std::string name, PAddr beg, PAddr end, bool add_elf_ext = true);
/**
* Signal to the gdbstub server that it should halt CPU execution.
*
@@ -80,10 +84,10 @@ BreakpointAddress GetNextBreakpointFromAddress(PAddr addr, GDBStub::BreakpointTy
*/
bool CheckBreakpoint(PAddr addr, GDBStub::BreakpointType type);
// If set to true, the CPU will halt at the beginning of the next CPU loop.
/// If set to true, the CPU will halt at the beginning of the next CPU loop.
bool GetCpuHaltFlag();
// If set to true and the CPU is halted, the CPU will step one instruction.
/// If set to true and the CPU is halted, the CPU will step one instruction.
bool GetCpuStepFlag();
/**

View File

@@ -9,6 +9,7 @@
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/file_sys/romfs_factory.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/hle/service/filesystem/filesystem.h"
@@ -133,6 +134,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr);
if (next_load_addr) {
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
// Register module with GDBStub
GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false);
} else {
next_load_addr = load_addr;
}

View File

@@ -7,10 +7,12 @@
#include "common/common_funcs.h"
#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "common/swap.h"
#include "core/core.h"
#include "core/file_sys/program_metadata.h"
#include "core/file_sys/romfs_factory.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/hle/service/filesystem/filesystem.h"
@@ -259,6 +261,8 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr<Kernel::Process>& process) {
next_load_addr = AppLoader_NSO::LoadModule(module, nca->GetExeFsFile(module), load_addr);
if (next_load_addr) {
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
// Register module with GDBStub
GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false);
} else {
next_load_addr = load_addr;
}

View File

@@ -9,6 +9,7 @@
#include "common/logging/log.h"
#include "common/swap.h"
#include "core/core.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/loader/nro.h"
@@ -115,6 +116,9 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) {
codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image));
Core::CurrentProcess()->LoadModule(codeset, load_base);
// Register module with GDBStub
GDBStub::RegisterModule(codeset->name, load_base, load_base);
return true;
}

View File

@@ -10,6 +10,7 @@
#include "common/logging/log.h"
#include "common/swap.h"
#include "core/core.h"
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/resource_limit.h"
#include "core/loader/nso.h"
@@ -147,6 +148,9 @@ VAddr AppLoader_NSO::LoadModule(const std::string& name, const std::vector<u8>&
codeset->memory = std::make_shared<std::vector<u8>>(std::move(program_image));
Core::CurrentProcess()->LoadModule(codeset, load_base);
// Register module with GDBStub
GDBStub::RegisterModule(codeset->name, load_base, load_base);
return load_base + image_size;
}