From aa89ed511177e4569115aa90f7fb73d78a33f3ff Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 3 Apr 2021 16:56:31 -0700 Subject: [PATCH] Debugger: Include source tag in memcpys. --- Core/Debugger/MemBlockInfo.cpp | 8 ++++++++ Core/Debugger/MemBlockInfo.h | 2 ++ Core/HLE/ReplaceTables.cpp | 25 +++++++++++++++---------- Core/HLE/sceKernelInterrupt.cpp | 15 +++++++++------ GPU/GPUCommon.cpp | 5 +++-- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index c9d40de1da..37734c232c 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -433,6 +433,14 @@ std::vector FindMemInfoByFlag(MemBlockFlags flags, uint32_t start, return results; } +std::string GetMemWriteTagAt(uint32_t start, uint32_t size) { + std::vector memRangeInfo = FindMemInfoByFlag(MemBlockFlags::WRITE, start, size); + for (auto range : memRangeInfo) { + return range.tag; + } + return "none"; +} + void MemBlockInfoInit() { std::lock_guard guard(pendingMutex); pendingNotifies.reserve(MAX_PENDING_NOTIFIES); diff --git a/Core/Debugger/MemBlockInfo.h b/Core/Debugger/MemBlockInfo.h index e46bea8c87..4e38c8410d 100644 --- a/Core/Debugger/MemBlockInfo.h +++ b/Core/Debugger/MemBlockInfo.h @@ -63,6 +63,8 @@ inline void NotifyMemInfo(MemBlockFlags flags, uint32_t start, uint32_t size, co std::vector FindMemInfo(uint32_t start, uint32_t size); std::vector FindMemInfoByFlag(MemBlockFlags flags, uint32_t start, uint32_t size); +std::string GetMemWriteTagAt(uint32_t start, uint32_t size); + void MemBlockInfoInit(); void MemBlockInfoShutdown(); void MemBlockInfoDoState(PointerWrap &p); diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index 992c893971..efde566c56 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -156,8 +156,9 @@ static int Replace_memcpy() { } RETURN(destPtr); - NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, "ReplaceMemcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, "ReplaceMemcpy"); + const std::string tag = "ReplaceMemcpy/" + GetMemWriteTagAt(srcPtr, bytes); + NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tag.c_str(), tag.size()); return 10 + bytes / 4; // approximation } @@ -198,8 +199,9 @@ static int Replace_memcpy_jak() { currentMIPS->r[MIPS_REG_A3] = destPtr + bytes; RETURN(destPtr); - NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, "ReplaceMemcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, "ReplaceMemcpy"); + const std::string tag = "ReplaceMemcpy/" + GetMemWriteTagAt(srcPtr, bytes); + NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tag.c_str(), tag.size()); return 5 + bytes * 8 + 2; // approximation. This is a slow memcpy - a byte copy loop.. } @@ -226,8 +228,9 @@ static int Replace_memcpy16() { } RETURN(destPtr); - NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, "ReplaceMemcpy16"); - NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, "ReplaceMemcpy16"); + const std::string tag = "ReplaceMemcpy16/" + GetMemWriteTagAt(srcPtr, bytes); + NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tag.c_str(), tag.size()); return 10 + bytes / 4; // approximation } @@ -264,8 +267,9 @@ static int Replace_memcpy_swizzled() { RETURN(0); - NotifyMemInfo(MemBlockFlags::READ, srcPtr, pitch * h, "ReplaceMemcpySwizzle"); - NotifyMemInfo(MemBlockFlags::WRITE, destPtr, pitch * h, "ReplaceMemcpySwizzle"); + const std::string tag = "ReplaceMemcpySwizzle/" + GetMemWriteTagAt(srcPtr, pitch * h); + NotifyMemInfo(MemBlockFlags::READ, srcPtr, pitch * h, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, destPtr, pitch * h, tag.c_str(), tag.size()); return 10 + (pitch * h) / 4; // approximation } @@ -292,8 +296,9 @@ static int Replace_memmove() { } RETURN(destPtr); - NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, "ReplaceMemmove"); - NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, "ReplaceMemmove"); + const std::string tag = "ReplaceMemmove/" + GetMemWriteTagAt(srcPtr, bytes); + NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tag.c_str(), tag.size()); return 10 + bytes / 4; // approximation } diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index adaabd362f..161979a353 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -658,8 +658,9 @@ static u32 sceKernelMemcpy(u32 dst, u32 src, u32 size) } } - NotifyMemInfo(MemBlockFlags::READ, src, size, "KernelMemcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, dst, size, "KernelMemcpy"); + const std::string tag = "KernelMemcpy/" + GetMemWriteTagAt(src, size); + NotifyMemInfo(MemBlockFlags::READ, src, size, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tag.c_str(), tag.size()); return dst; } @@ -690,8 +691,9 @@ static u32 sysclib_memcpy(u32 dst, u32 src, u32 size) { if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) { memcpy(Memory::GetPointer(dst), Memory::GetPointer(src), size); } - NotifyMemInfo(MemBlockFlags::READ, src, size, "KernelMemcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, dst, size, "KernelMemcpy"); + const std::string tag = "KernelMemcpy/" + GetMemWriteTagAt(src, size); + NotifyMemInfo(MemBlockFlags::READ, src, size, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tag.c_str(), tag.size()); return dst; } @@ -790,8 +792,9 @@ static u32 sysclib_memmove(u32 dst, u32 src, u32 size) { if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) { memmove(Memory::GetPointer(dst), Memory::GetPointer(src), size); } - NotifyMemInfo(MemBlockFlags::READ, src, size, "KernelMemmove"); - NotifyMemInfo(MemBlockFlags::WRITE, dst, size, "KernelMemmove"); + const std::string tag = "KernelMemmove/" + GetMemWriteTagAt(src, size); + NotifyMemInfo(MemBlockFlags::READ, src, size, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tag.c_str(), tag.size()); return 0; } diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 4378047067..a6d48c123f 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2742,8 +2742,9 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size) { return true; } - NotifyMemInfo(MemBlockFlags::READ, src, size, "GPUMemcpy"); - NotifyMemInfo(MemBlockFlags::WRITE, dest, size, "GPUMemcpy"); + const std::string tag = "GPUMemcpy/" + GetMemWriteTagAt(src, size); + NotifyMemInfo(MemBlockFlags::READ, src, size, tag.c_str(), tag.size()); + NotifyMemInfo(MemBlockFlags::WRITE, dest, size, tag.c_str(), tag.size()); InvalidateCache(dest, size, GPU_INVALIDATE_HINT); GPURecord::NotifyMemcpy(dest, src, size); return false;