Add support for NSO modules.
This commit is contained in:
@@ -209,6 +209,22 @@ static std::map<u64, Breakpoint> breakpoints_execute;
|
||||
static std::map<u64, Breakpoint> breakpoints_read;
|
||||
static std::map<u64, Breakpoint> breakpoints_write;
|
||||
|
||||
struct Module {
|
||||
char name[128];
|
||||
PAddr beg;
|
||||
PAddr end;
|
||||
};
|
||||
|
||||
static std::vector<Module> modules;
|
||||
|
||||
void RegisterModule(const char* name, PAddr beg, PAddr end) {
|
||||
Module module;
|
||||
strncpy(module.name, name, sizeof(module.name));
|
||||
module.beg = beg;
|
||||
module.end = end;
|
||||
modules.push_back(module);
|
||||
}
|
||||
|
||||
static Kernel::Thread* FindThreadById(int id) {
|
||||
for (unsigned core = 0; core < Core::NUM_CPU_CORES; core++) {
|
||||
auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
|
||||
@@ -609,12 +625,28 @@ 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+;qXfer:threads: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);
|
||||
} else if (strncmp(query, "Offsets", strlen("Offsets")) == 0) {
|
||||
std::string buffer = fmt::format("TextSeg={:0x}", Memory::PROCESS_IMAGE_VADDR);
|
||||
std::string buffer;
|
||||
// if(modules.size())
|
||||
//{
|
||||
// for(auto module : modules)
|
||||
// {
|
||||
// if(stricmp(module.name, "main") == 0)
|
||||
// {
|
||||
// buffer = fmt::format("TextSeg={:0x}", module.beg);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
// else
|
||||
{ buffer = fmt::format("TextSeg={:0x}", Memory::PROCESS_IMAGE_VADDR); }
|
||||
SendReply(buffer.c_str());
|
||||
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
|
||||
std::string val = "m";
|
||||
@@ -643,6 +675,17 @@ static void HandleQuery() {
|
||||
}
|
||||
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 (auto module : modules) {
|
||||
buffer +=
|
||||
fmt::format(R"*("<library name = "{}"><section address = "0x{:x}"/></library>)*",
|
||||
module.name, module.beg);
|
||||
}
|
||||
buffer += "</library-list>";
|
||||
SendReply(buffer.c_str());
|
||||
} else {
|
||||
SendReply("");
|
||||
}
|
||||
@@ -925,7 +968,7 @@ static void ReadMemory() {
|
||||
SendReply("E01");
|
||||
}
|
||||
|
||||
if (!Memory::IsValidVirtualAddress(addr)) {
|
||||
if (!Memory::IsValidVirtualAddress(addr) && (addr < Memory::STACK_AREA_VADDR)) {
|
||||
return SendReply("E00");
|
||||
}
|
||||
|
||||
@@ -1210,6 +1253,8 @@ static void Init(u16 port) {
|
||||
breakpoints_read.clear();
|
||||
breakpoints_write.clear();
|
||||
|
||||
modules.clear();
|
||||
|
||||
// Start gdb server
|
||||
NGLOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port);
|
||||
|
||||
|
||||
@@ -51,6 +51,9 @@ bool IsServerEnabled();
|
||||
/// Returns true if there is an active socket connection.
|
||||
bool IsConnected();
|
||||
|
||||
/// Register module.
|
||||
void RegisterModule(const char* name, PAddr beg, PAddr end);
|
||||
|
||||
/**
|
||||
* Signal to the gdbstub server that it should halt CPU execution.
|
||||
*
|
||||
|
||||
@@ -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"
|
||||
@@ -132,7 +133,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
||||
const VAddr load_addr = next_load_addr;
|
||||
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr);
|
||||
if (next_load_addr) {
|
||||
LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
|
||||
NGLOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr);
|
||||
GDBStub::RegisterModule(module, load_addr, next_load_addr);
|
||||
} else {
|
||||
next_load_addr = load_addr;
|
||||
}
|
||||
@@ -163,7 +165,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(
|
||||
std::shared_ptr<FileUtil::IOFile>& romfs_file, u64& offset, u64& size) {
|
||||
|
||||
if (filepath_romfs.empty()) {
|
||||
LOG_DEBUG(Loader, "No RomFS available");
|
||||
NGLOG_DEBUG(Loader, "No RomFS available");
|
||||
return ResultStatus::ErrorNotUsed;
|
||||
}
|
||||
|
||||
@@ -176,8 +178,8 @@ ResultStatus AppLoader_DeconstructedRomDirectory::ReadRomFS(
|
||||
offset = 0;
|
||||
size = romfs_file->GetSize();
|
||||
|
||||
LOG_DEBUG(Loader, "RomFS offset: 0x{:016X}", offset);
|
||||
LOG_DEBUG(Loader, "RomFS size: 0x{:016X}", size);
|
||||
NGLOG_DEBUG(Loader, "RomFS offset: 0x{:016X}", offset);
|
||||
NGLOG_DEBUG(Loader, "RomFS size: 0x{:016X}", size);
|
||||
|
||||
// Reset read pointer
|
||||
file.Seek(0, SEEK_SET);
|
||||
|
||||
Reference in New Issue
Block a user