summaryrefslogtreecommitdiffstats
path: root/src/core/debugger/gdbstub.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/debugger/gdbstub.cpp')
-rw-r--r--src/core/debugger/gdbstub.cpp108
1 files changed, 56 insertions, 52 deletions
diff --git a/src/core/debugger/gdbstub.cpp b/src/core/debugger/gdbstub.cpp
index 9c02b7b31..e2a13bbd2 100644
--- a/src/core/debugger/gdbstub.cpp
+++ b/src/core/debugger/gdbstub.cpp
@@ -96,7 +96,7 @@ static std::string EscapeXML(std::string_view data) {
GDBStub::GDBStub(DebuggerBackend& backend_, Core::System& system_)
: DebuggerFrontend(backend_), system{system_} {
- if (system.CurrentProcess()->Is64BitProcess()) {
+ if (system.ApplicationProcess()->Is64BitProcess()) {
arch = std::make_unique<GDBStubA64>();
} else {
arch = std::make_unique<GDBStubA32>();
@@ -118,14 +118,14 @@ void GDBStub::Watchpoint(Kernel::KThread* thread, const Kernel::DebugWatchpoint&
switch (watch.type) {
case Kernel::DebugWatchpointType::Read:
- SendReply(fmt::format("{}rwatch:{:x};", status, watch.start_address));
+ SendReply(fmt::format("{}rwatch:{:x};", status, GetInteger(watch.start_address)));
break;
case Kernel::DebugWatchpointType::Write:
- SendReply(fmt::format("{}watch:{:x};", status, watch.start_address));
+ SendReply(fmt::format("{}watch:{:x};", status, GetInteger(watch.start_address)));
break;
case Kernel::DebugWatchpointType::ReadOrWrite:
default:
- SendReply(fmt::format("{}awatch:{:x};", status, watch.start_address));
+ SendReply(fmt::format("{}awatch:{:x};", status, GetInteger(watch.start_address)));
break;
}
}
@@ -261,9 +261,9 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
const size_t addr{static_cast<size_t>(strtoll(command.data(), nullptr, 16))};
const size_t size{static_cast<size_t>(strtoll(command.data() + sep, nullptr, 16))};
- if (system.Memory().IsValidVirtualAddressRange(addr, size)) {
+ if (system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
std::vector<u8> mem(size);
- system.Memory().ReadBlock(addr, mem.data(), size);
+ system.ApplicationMemory().ReadBlock(addr, mem.data(), size);
SendReply(Common::HexToString(mem));
} else {
@@ -281,8 +281,8 @@ void GDBStub::ExecuteCommand(std::string_view packet, std::vector<DebuggerAction
const auto mem_substr{std::string_view(command).substr(mem_sep)};
const auto mem{Common::HexStringToVector(mem_substr, false)};
- if (system.Memory().IsValidVirtualAddressRange(addr, size)) {
- system.Memory().WriteBlock(addr, mem.data(), size);
+ if (system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
+ system.ApplicationMemory().WriteBlock(addr, mem.data(), size);
system.InvalidateCpuInstructionCacheRange(addr, size);
SendReply(GDB_STUB_REPLY_OK);
} else {
@@ -325,7 +325,7 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
- if (!system.Memory().IsValidVirtualAddressRange(addr, size)) {
+ if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
@@ -334,22 +334,22 @@ void GDBStub::HandleBreakpointInsert(std::string_view command) {
switch (type) {
case BreakpointType::Software:
- replaced_instructions[addr] = system.Memory().Read32(addr);
- system.Memory().Write32(addr, arch->BreakpointInstruction());
+ replaced_instructions[addr] = system.ApplicationMemory().Read32(addr);
+ system.ApplicationMemory().Write32(addr, arch->BreakpointInstruction());
system.InvalidateCpuInstructionCacheRange(addr, sizeof(u32));
success = true;
break;
case BreakpointType::WriteWatch:
- success = system.CurrentProcess()->InsertWatchpoint(system, addr, size,
- Kernel::DebugWatchpointType::Write);
+ success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
+ Kernel::DebugWatchpointType::Write);
break;
case BreakpointType::ReadWatch:
- success = system.CurrentProcess()->InsertWatchpoint(system, addr, size,
- Kernel::DebugWatchpointType::Read);
+ success = system.ApplicationProcess()->InsertWatchpoint(addr, size,
+ Kernel::DebugWatchpointType::Read);
break;
case BreakpointType::AccessWatch:
- success = system.CurrentProcess()->InsertWatchpoint(
- system, addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
+ success = system.ApplicationProcess()->InsertWatchpoint(
+ addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
break;
case BreakpointType::Hardware:
default:
@@ -372,7 +372,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
const size_t addr{static_cast<size_t>(strtoll(command.data() + addr_sep, nullptr, 16))};
const size_t size{static_cast<size_t>(strtoll(command.data() + size_sep, nullptr, 16))};
- if (!system.Memory().IsValidVirtualAddressRange(addr, size)) {
+ if (!system.ApplicationMemory().IsValidVirtualAddressRange(addr, size)) {
SendReply(GDB_STUB_REPLY_ERR);
return;
}
@@ -383,7 +383,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
case BreakpointType::Software: {
const auto orig_insn{replaced_instructions.find(addr)};
if (orig_insn != replaced_instructions.end()) {
- system.Memory().Write32(addr, orig_insn->second);
+ system.ApplicationMemory().Write32(addr, orig_insn->second);
system.InvalidateCpuInstructionCacheRange(addr, sizeof(u32));
replaced_instructions.erase(addr);
success = true;
@@ -391,16 +391,16 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
break;
}
case BreakpointType::WriteWatch:
- success = system.CurrentProcess()->RemoveWatchpoint(system, addr, size,
- Kernel::DebugWatchpointType::Write);
+ success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
+ Kernel::DebugWatchpointType::Write);
break;
case BreakpointType::ReadWatch:
- success = system.CurrentProcess()->RemoveWatchpoint(system, addr, size,
- Kernel::DebugWatchpointType::Read);
+ success = system.ApplicationProcess()->RemoveWatchpoint(addr, size,
+ Kernel::DebugWatchpointType::Read);
break;
case BreakpointType::AccessWatch:
- success = system.CurrentProcess()->RemoveWatchpoint(
- system, addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
+ success = system.ApplicationProcess()->RemoveWatchpoint(
+ addr, size, Kernel::DebugWatchpointType::ReadOrWrite);
break;
case BreakpointType::Hardware:
default:
@@ -421,7 +421,7 @@ void GDBStub::HandleBreakpointRemove(std::string_view command) {
static std::optional<std::string> GetNameFromThreadType32(Core::Memory::Memory& memory,
const Kernel::KThread* thread) {
// Read thread type from TLS
- const VAddr tls_thread_type{memory.Read32(thread->GetTLSAddress() + 0x1fc)};
+ const VAddr tls_thread_type{memory.Read32(thread->GetTlsAddress() + 0x1fc)};
const VAddr argument_thread_type{thread->GetArgument()};
if (argument_thread_type && tls_thread_type != argument_thread_type) {
@@ -452,7 +452,7 @@ static std::optional<std::string> GetNameFromThreadType32(Core::Memory::Memory&
static std::optional<std::string> GetNameFromThreadType64(Core::Memory::Memory& memory,
const Kernel::KThread* thread) {
// Read thread type from TLS
- const VAddr tls_thread_type{memory.Read64(thread->GetTLSAddress() + 0x1f8)};
+ const VAddr tls_thread_type{memory.Read64(thread->GetTlsAddress() + 0x1f8)};
const VAddr argument_thread_type{thread->GetArgument()};
if (argument_thread_type && tls_thread_type != argument_thread_type) {
@@ -482,10 +482,10 @@ static std::optional<std::string> GetNameFromThreadType64(Core::Memory::Memory&
static std::optional<std::string> GetThreadName(Core::System& system,
const Kernel::KThread* thread) {
- if (system.CurrentProcess()->Is64BitProcess()) {
- return GetNameFromThreadType64(system.Memory(), thread);
+ if (system.ApplicationProcess()->Is64BitProcess()) {
+ return GetNameFromThreadType64(system.ApplicationMemory(), thread);
} else {
- return GetNameFromThreadType32(system.Memory(), thread);
+ return GetNameFromThreadType32(system.ApplicationMemory(), thread);
}
}
@@ -554,8 +554,9 @@ void GDBStub::HandleQuery(std::string_view command) {
if (main != modules.end()) {
SendReply(fmt::format("TextSeg={:x}", main->first));
} else {
- SendReply(fmt::format("TextSeg={:x}",
- system.CurrentProcess()->PageTable().GetCodeRegionStart()));
+ SendReply(fmt::format(
+ "TextSeg={:x}",
+ GetInteger(system.ApplicationProcess()->PageTable().GetCodeRegionStart())));
}
} else if (command.starts_with("Xfer:libraries:read::")) {
Loader::AppLoader::Modules modules;
@@ -573,10 +574,10 @@ void GDBStub::HandleQuery(std::string_view command) {
SendReply(PaginateBuffer(buffer, command.substr(21)));
} else if (command.starts_with("fThreadInfo")) {
// beginning of list
- const auto& threads = system.GlobalSchedulerContext().GetThreadList();
+ const auto& threads = system.ApplicationProcess()->GetThreadList();
std::vector<std::string> thread_ids;
for (const auto& thread : threads) {
- thread_ids.push_back(fmt::format("{:x}", thread->GetThreadID()));
+ thread_ids.push_back(fmt::format("{:x}", thread->GetThreadId()));
}
SendReply(fmt::format("m{}", fmt::join(thread_ids, ",")));
} else if (command.starts_with("sThreadInfo")) {
@@ -587,15 +588,15 @@ void GDBStub::HandleQuery(std::string_view command) {
buffer += R"(<?xml version="1.0"?>)";
buffer += "<threads>";
- const auto& threads = system.GlobalSchedulerContext().GetThreadList();
+ const auto& threads = system.ApplicationProcess()->GetThreadList();
for (const auto* thread : threads) {
auto thread_name{GetThreadName(system, thread)};
if (!thread_name) {
- thread_name = fmt::format("Thread {:d}", thread->GetThreadID());
+ thread_name = fmt::format("Thread {:d}", thread->GetThreadId());
}
buffer += fmt::format(R"(<thread id="{:x}" core="{:d}" name="{}">{}</thread>)",
- thread->GetThreadID(), thread->GetActiveCore(),
+ thread->GetThreadId(), thread->GetActiveCore(),
EscapeXML(*thread_name), GetThreadState(thread));
}
@@ -729,7 +730,7 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
std::string_view command_str{reinterpret_cast<const char*>(&command[0]), command.size()};
std::string reply;
- auto* process = system.CurrentProcess();
+ auto* process = system.ApplicationProcess();
auto& page_table = process->PageTable();
const char* commands = "Commands:\n"
@@ -756,18 +757,21 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
reply = fmt::format("Process: {:#x} ({})\n"
"Program Id: {:#018x}\n",
- process->GetProcessID(), process->GetName(), process->GetProgramID());
- reply +=
- fmt::format("Layout:\n"
- " Alias: {:#012x} - {:#012x}\n"
- " Heap: {:#012x} - {:#012x}\n"
- " Aslr: {:#012x} - {:#012x}\n"
- " Stack: {:#012x} - {:#012x}\n"
- "Modules:\n",
- page_table.GetAliasRegionStart(), page_table.GetAliasRegionEnd(),
- page_table.GetHeapRegionStart(), page_table.GetHeapRegionEnd(),
- page_table.GetAliasCodeRegionStart(), page_table.GetAliasCodeRegionEnd(),
- page_table.GetStackRegionStart(), page_table.GetStackRegionEnd());
+ process->GetProcessId(), process->GetName(), process->GetProgramId());
+ reply += fmt::format("Layout:\n"
+ " Alias: {:#012x} - {:#012x}\n"
+ " Heap: {:#012x} - {:#012x}\n"
+ " Aslr: {:#012x} - {:#012x}\n"
+ " Stack: {:#012x} - {:#012x}\n"
+ "Modules:\n",
+ GetInteger(page_table.GetAliasRegionStart()),
+ GetInteger(page_table.GetAliasRegionEnd()),
+ GetInteger(page_table.GetHeapRegionStart()),
+ GetInteger(page_table.GetHeapRegionEnd()),
+ GetInteger(page_table.GetAliasCodeRegionStart()),
+ GetInteger(page_table.GetAliasCodeRegionEnd()),
+ GetInteger(page_table.GetStackRegionStart()),
+ GetInteger(page_table.GetStackRegionEnd()));
for (const auto& [vaddr, name] : modules) {
reply += fmt::format(" {:#012x} - {:#012x} {}\n", vaddr,
@@ -817,9 +821,9 @@ void GDBStub::HandleRcmd(const std::vector<u8>& command) {
}
Kernel::KThread* GDBStub::GetThreadByID(u64 thread_id) {
- const auto& threads{system.GlobalSchedulerContext().GetThreadList()};
+ const auto& threads{system.ApplicationProcess()->GetThreadList()};
for (auto* thread : threads) {
- if (thread->GetThreadID() == thread_id) {
+ if (thread->GetThreadId() == thread_id) {
return thread;
}
}