diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp index 4d4176ff2f..31764ef1c5 100644 --- a/src/core/gdbstub/gdbstub.cpp +++ b/src/core/gdbstub/gdbstub.cpp @@ -133,39 +133,6 @@ static const char* target_xml = - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - )"; @@ -181,7 +148,7 @@ static u32 latest_signal = 0; static bool memory_break = false; static Kernel::Thread* current_thread = nullptr; -static unsigned current_core = 0; +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. @@ -210,23 +177,28 @@ static std::map breakpoints_read; static std::map breakpoints_write; struct Module { - char name[128]; + std::string name; PAddr beg; PAddr end; }; static std::vector modules; -void RegisterModule(const char* name, PAddr beg, PAddr end) { +void RegisterModule(std::string name, PAddr beg, PAddr end, bool add_elf_ext) { Module module; - strncpy(module.name, name, sizeof(module.name)); + 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(module); + modules.push_back(std::move(module)); } static Kernel::Thread* FindThreadById(int id) { - for (unsigned core = 0; core < Core::NUM_CPU_CORES; core++) { + for (u32 core = 0; core < Core::NUM_CPU_CORES; core++) { auto threads = Core::System::GetInstance().Scheduler(core)->GetThreadList(); for (auto thread : threads) { if (thread->GetThreadId() == id) { @@ -393,21 +365,6 @@ static void LongToGdbHex(u8* dest, u64 v) { } } -/** - * Convert a u128 into a gdb-formatted hex string. - * - * @param dest Pointer to buffer to store output hex string characters. - * @param v Value to convert. - */ -// static void LongLongToGdbHex(u8* dest, u128 v) -//{ -// for(int i = 0; i < 32; i += 2) -// { -// dest[i + 1] = NibbleToHex(static_cast(v >> (4 * i))); -// dest[i] = NibbleToHex(static_cast(v >> (4 * (i + 1)))); -// } -//} - /** * Convert a gdb-formatted hex string into a u32. * @@ -440,24 +397,6 @@ static u64 GdbHexToLong(const u8* src) { return output; } -/** - * Convert a gdb-formatted hex string into a u128. - * - * @param src Pointer to hex string. - */ -// static u128 GdbHexToLong(const u8* src) -//{ -// u128 output = 0; -// -// for(int i = 0; i < 32; i += 2) -// { -// output = (output << 4) | HexCharToValue(src[15 - i - 1]); -// output = (output << 4) | HexCharToValue(src[15 - i]); -// } -// -// return output; -//} - /// Read a byte from the gdb client. static u8 ReadByte() { u8 c; @@ -634,8 +573,7 @@ static void HandleQuery() { strlen("Xfer:features:read:target.xml:")) == 0) { SendReply(target_xml); } else if (strncmp(query, "Offsets", strlen("Offsets")) == 0) { - std::string buffer; - buffer = fmt::format("TextSeg={:0x}", Memory::PROCESS_IMAGE_VADDR); + std::string 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"; @@ -856,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)); @@ -870,7 +808,7 @@ static void ReadRegisters() { LongToGdbHex(bufptr + reg * 16, RegRead(reg, current_thread)); } - bufptr += (32 * 32); + bufptr += 32 * 32; LongToGdbHex(bufptr, RegRead(998, current_thread)); @@ -956,7 +894,7 @@ static void ReadMemory() { SendReply("E01"); } - if ((addr < Memory::PROCESS_IMAGE_VADDR) || (addr >= Memory::MAP_REGION_VADDR_END)) { + if (addr < Memory::PROCESS_IMAGE_VADDR || addr >= Memory::MAP_REGION_VADDR_END) { return SendReply("E00"); } @@ -1349,7 +1287,7 @@ void SetCpuStepFlag(bool is_step) { void SendTrap(Kernel::Thread* thread, int trap) { if (send_trap) { - if (!halt_loop || (current_thread == thread)) { + if (!halt_loop || current_thread == thread) { current_thread = thread; SendSignal(thread, trap); } diff --git a/src/core/gdbstub/gdbstub.h b/src/core/gdbstub/gdbstub.h index 2c17a7275b..a6b50c26cf 100644 --- a/src/core/gdbstub/gdbstub.h +++ b/src/core/gdbstub/gdbstub.h @@ -6,6 +6,7 @@ #pragma once +#include #include "common/common_types.h" #include "core/hle/kernel/thread.h" @@ -52,7 +53,7 @@ bool IsServerEnabled(); bool IsConnected(); /// Register module. -void RegisterModule(const char* name, PAddr beg, PAddr end); +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. diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 68f2f30073..5fdb1d2893 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -135,7 +135,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( 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); + GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); } else { next_load_addr = load_addr; } diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index baa448956d..0fd930ae20 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp @@ -262,7 +262,7 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr& process) { 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); + GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); } else { next_load_addr = load_addr; } diff --git a/src/core/loader/nro.cpp b/src/core/loader/nro.cpp index 01c2138ae1..4d7c69a228 100644 --- a/src/core/loader/nro.cpp +++ b/src/core/loader/nro.cpp @@ -7,7 +7,6 @@ #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/gdbstub/gdbstub.h" @@ -118,9 +117,7 @@ bool AppLoader_NRO::LoadNro(const std::string& path, VAddr load_base) { Core::CurrentProcess()->LoadModule(codeset, load_base); // Register module with GDBStub - std::string filename; - Common::SplitPath(codeset->name, nullptr, &filename, nullptr); - GDBStub::RegisterModule((filename + ".elf").c_str(), load_base, load_base); + GDBStub::RegisterModule(codeset->name, load_base, load_base); return true; } diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 82d3c93a57..1c629e21f3 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -8,7 +8,6 @@ #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/gdbstub/gdbstub.h" @@ -150,9 +149,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& name, const std::vector& Core::CurrentProcess()->LoadModule(codeset, load_base); // Register module with GDBStub - std::string filename; - Common::SplitPath(codeset->name, nullptr, &filename, nullptr); - GDBStub::RegisterModule((filename + ".elf").c_str(), load_base, load_base); + GDBStub::RegisterModule(codeset->name, load_base, load_base); return load_base + image_size; }