Add support for NSO modules.
This commit is contained in:
@@ -172,6 +172,22 @@ static std::map<u64, Breakpoint> breakpoints_execute;
|
|||||||
static std::map<u64, Breakpoint> breakpoints_read;
|
static std::map<u64, Breakpoint> breakpoints_read;
|
||||||
static std::map<u64, Breakpoint> breakpoints_write;
|
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) {
|
static Kernel::Thread* FindThreadById(int id) {
|
||||||
for (unsigned core = 0; core < Core::NUM_CPU_CORES; core++) {
|
for (unsigned core = 0; core < Core::NUM_CPU_CORES; core++) {
|
||||||
auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
|
auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList();
|
||||||
@@ -535,12 +551,28 @@ static void HandleQuery() {
|
|||||||
SendReply("T0");
|
SendReply("T0");
|
||||||
} else if (strncmp(query, "Supported", strlen("Supported")) == 0) {
|
} else if (strncmp(query, "Supported", strlen("Supported")) == 0) {
|
||||||
// PacketSize needs to be large enough for target xml
|
// 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:",
|
} else if (strncmp(query, "Xfer:features:read:target.xml:",
|
||||||
strlen("Xfer:features:read:target.xml:")) == 0) {
|
strlen("Xfer:features:read:target.xml:")) == 0) {
|
||||||
SendReply(target_xml);
|
SendReply(target_xml);
|
||||||
} else if (strncmp(query, "Offsets", strlen("Offsets")) == 0) {
|
} 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());
|
SendReply(buffer.c_str());
|
||||||
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
|
} else if (strncmp(query, "fThreadInfo", strlen("fThreadInfo")) == 0) {
|
||||||
std::string val = "m";
|
std::string val = "m";
|
||||||
@@ -569,6 +601,17 @@ static void HandleQuery() {
|
|||||||
}
|
}
|
||||||
buffer += "</threads>";
|
buffer += "</threads>";
|
||||||
SendReply(buffer.c_str());
|
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 {
|
} else {
|
||||||
SendReply("");
|
SendReply("");
|
||||||
}
|
}
|
||||||
@@ -827,7 +870,7 @@ static void ReadMemory() {
|
|||||||
SendReply("E01");
|
SendReply("E01");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Memory::IsValidVirtualAddress(addr)) {
|
if (!Memory::IsValidVirtualAddress(addr) && (addr < Memory::STACK_AREA_VADDR)) {
|
||||||
return SendReply("E00");
|
return SendReply("E00");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1112,6 +1155,8 @@ static void Init(u16 port) {
|
|||||||
breakpoints_read.clear();
|
breakpoints_read.clear();
|
||||||
breakpoints_write.clear();
|
breakpoints_write.clear();
|
||||||
|
|
||||||
|
modules.clear();
|
||||||
|
|
||||||
// Start gdb server
|
// Start gdb server
|
||||||
NGLOG_INFO(Debug_GDBStub, "Starting GDB server on port {}...", port);
|
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.
|
/// Returns true if there is an active socket connection.
|
||||||
bool IsConnected();
|
bool IsConnected();
|
||||||
|
|
||||||
|
/// Register module.
|
||||||
|
void RegisterModule(const char* name, PAddr beg, PAddr end);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signal to the gdbstub server that it should halt CPU execution.
|
* Signal to the gdbstub server that it should halt CPU execution.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "common/string_util.h"
|
#include "common/string_util.h"
|
||||||
#include "core/file_sys/romfs_factory.h"
|
#include "core/file_sys/romfs_factory.h"
|
||||||
|
#include "core/gdbstub/gdbstub.h"
|
||||||
#include "core/hle/kernel/process.h"
|
#include "core/hle/kernel/process.h"
|
||||||
#include "core/hle/kernel/resource_limit.h"
|
#include "core/hle/kernel/resource_limit.h"
|
||||||
#include "core/hle/service/filesystem/filesystem.h"
|
#include "core/hle/service/filesystem/filesystem.h"
|
||||||
@@ -133,6 +134,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load(
|
|||||||
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr);
|
next_load_addr = AppLoader_NSO::LoadModule(path, load_addr);
|
||||||
if (next_load_addr) {
|
if (next_load_addr) {
|
||||||
NGLOG_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 {
|
} else {
|
||||||
next_load_addr = load_addr;
|
next_load_addr = load_addr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user