From ce6103be30478dda67f8092a8be3bcef92bb11d3 Mon Sep 17 00:00:00 2001 From: chaoticgd <43898262+chaoticgd@users.noreply.github.com> Date: Thu, 14 Nov 2024 23:27:20 +0000 Subject: [PATCH] Debugger: Improve function scanner performance for unmapped addresses --- 3rdparty/ccc/src/ccc/elf.cpp | 14 +++++++------ 3rdparty/ccc/src/ccc/elf.h | 20 ++++++++++-------- pcsx2/DebugTools/DebugInterface.cpp | 32 ++++++++++++++--------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/3rdparty/ccc/src/ccc/elf.cpp b/3rdparty/ccc/src/ccc/elf.cpp index 8c3ed99e57..5bb11dd72c 100644 --- a/3rdparty/ccc/src/ccc/elf.cpp +++ b/3rdparty/ccc/src/ccc/elf.cpp @@ -93,7 +93,7 @@ const ElfProgramHeader* ElfFile::entry_point_segment() const return entry_segment; } -Result> ElfFile::get_virtual(u32 address, u32 size) const +std::optional> ElfFile::get_virtual(u32 address, u32 size) const { u32 end_address = address + size; @@ -109,17 +109,19 @@ Result> ElfFile::get_virtual(u32 address, u32 size) const } } - return CCC_FAILURE("No ELF segment for address range 0x%x to 0x%x.", address, end_address); + return std::nullopt; } -Result ElfFile::copy_virtual(u8* dest, u32 address, u32 size) const +bool ElfFile::copy_virtual(u8* dest, u32 address, u32 size) const { - Result> block = get_virtual(address, size); - CCC_RETURN_IF_ERROR(block); + std::optional> block = get_virtual(address, size); + if(!block.has_value()) { + return false; + } memcpy(dest, block->data(), size); - return Result(); + return true; } } diff --git a/3rdparty/ccc/src/ccc/elf.h b/3rdparty/ccc/src/ccc/elf.h index 33d89e759c..35f6203298 100644 --- a/3rdparty/ccc/src/ccc/elf.h +++ b/3rdparty/ccc/src/ccc/elf.h @@ -125,18 +125,20 @@ struct ElfFile { const ElfProgramHeader* entry_point_segment() const; // Retrieve a block of data in an ELF file given its address and size. - Result> get_virtual(u32 address, u32 size) const; + std::optional> get_virtual(u32 address, u32 size) const; // Copy a block of data in an ELF file to the destination buffer given its // address and size. - Result copy_virtual(u8* dest, u32 address, u32 size) const; + bool copy_virtual(u8* dest, u32 address, u32 size) const; // Retrieve an object of type T from an ELF file given its address. template - Result get_object_virtual(u32 address) const + std::optional get_object_virtual(u32 address) const { - Result> result = get_virtual(address, sizeof(T)); - CCC_RETURN_IF_ERROR(result); + std::optional> result = get_virtual(address, sizeof(T)); + if(!result.has_value()) { + return std::nullopt; + } return *(T*) result->data(); } @@ -144,10 +146,12 @@ struct ElfFile { // Retrieve an array of objects of type T from an ELF file given its // address and element count. template - Result> get_array_virtual(u32 address, u32 element_count) const + std::optional> get_array_virtual(u32 address, u32 element_count) const { - Result> result = get_virtual(address, element_count * sizeof(T)); - CCC_RETURN_IF_ERROR(result); + std::optional> result = get_virtual(address, element_count * sizeof(T)); + if(!result.has_value()) { + return std::nullopt; + } return std::span((T*) result->data(), (T*) (result->data() + result->size())); } diff --git a/pcsx2/DebugTools/DebugInterface.cpp b/pcsx2/DebugTools/DebugInterface.cpp index 5e8a67fb20..db4ac668de 100644 --- a/pcsx2/DebugTools/DebugInterface.cpp +++ b/pcsx2/DebugTools/DebugInterface.cpp @@ -1012,8 +1012,8 @@ ElfMemoryReader::ElfMemoryReader(const ccc::ElfFile& elf) u32 ElfMemoryReader::read8(u32 address) { - ccc::Result result = m_elf.get_object_virtual(address); - if (!result.success()) + std::optional result = m_elf.get_object_virtual(address); + if (!result.has_value()) return 0; return *result; @@ -1021,8 +1021,8 @@ u32 ElfMemoryReader::read8(u32 address) u32 ElfMemoryReader::read8(u32 address, bool& valid) { - ccc::Result result = m_elf.get_object_virtual(address); - valid = result.success(); + std::optional result = m_elf.get_object_virtual(address); + valid = result.has_value(); if (!valid) return 0; @@ -1031,8 +1031,8 @@ u32 ElfMemoryReader::read8(u32 address, bool& valid) u32 ElfMemoryReader::read16(u32 address) { - ccc::Result result = m_elf.get_object_virtual(address); - if (!result.success()) + std::optional result = m_elf.get_object_virtual(address); + if (!result.has_value()) return 0; return *result; @@ -1040,8 +1040,8 @@ u32 ElfMemoryReader::read16(u32 address) u32 ElfMemoryReader::read16(u32 address, bool& valid) { - ccc::Result result = m_elf.get_object_virtual(address); - valid = result.success(); + std::optional result = m_elf.get_object_virtual(address); + valid = result.has_value(); if (!valid) return 0; @@ -1050,8 +1050,8 @@ u32 ElfMemoryReader::read16(u32 address, bool& valid) u32 ElfMemoryReader::read32(u32 address) { - ccc::Result result = m_elf.get_object_virtual(address); - if (!result.success()) + std::optional result = m_elf.get_object_virtual(address); + if (!result.has_value()) return 0; return *result; @@ -1059,8 +1059,8 @@ u32 ElfMemoryReader::read32(u32 address) u32 ElfMemoryReader::read32(u32 address, bool& valid) { - ccc::Result result = m_elf.get_object_virtual(address); - valid = result.success(); + std::optional result = m_elf.get_object_virtual(address); + valid = result.has_value(); if (!valid) return 0; @@ -1069,8 +1069,8 @@ u32 ElfMemoryReader::read32(u32 address, bool& valid) u64 ElfMemoryReader::read64(u32 address) { - ccc::Result result = m_elf.get_object_virtual(address); - if (!result.success()) + std::optional result = m_elf.get_object_virtual(address); + if (!result.has_value()) return 0; return *result; @@ -1078,8 +1078,8 @@ u64 ElfMemoryReader::read64(u32 address) u64 ElfMemoryReader::read64(u32 address, bool& valid) { - ccc::Result result = m_elf.get_object_virtual(address); - valid = result.success(); + std::optional result = m_elf.get_object_virtual(address); + valid = result.has_value(); if (!valid) return 0;