Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track memory allocations and writes for debug info #14056

Merged
merged 29 commits into from
Feb 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8e6a438
Mpeg: Correct incorrect upload size return.
unknownbrackets Feb 2, 2021
f7740ed
Debugger: Add more metadata for memory usage.
unknownbrackets Feb 2, 2021
44a0c54
Debugger: Log access reason on memory breakpoint.
unknownbrackets Feb 2, 2021
ca7d127
Debugger: Notate more cases of memory clears.
unknownbrackets Feb 2, 2021
9ead436
Debugger: Specifically tag relocations.
unknownbrackets Feb 2, 2021
ca2f7df
Debugger: Track memory allocations and writes.
unknownbrackets Feb 3, 2021
88e2b9b
Debugger: Notate memset tags directly.
unknownbrackets Feb 3, 2021
e7b968b
Debugger: Notate Memcpys directly as well.
unknownbrackets Feb 3, 2021
76ae1b4
Debugger: Mark framebuffers as VRAM allocations.
unknownbrackets Feb 4, 2021
10a77d2
Debugger: Track texture usage too.
unknownbrackets Feb 4, 2021
c128df5
Debugger: Track ticks of allocation/write/etc.
unknownbrackets Feb 4, 2021
a590671
GPU: Cleanup comment.
unknownbrackets Feb 6, 2021
a62aa47
Debugger: Speed up lookup using an index.
unknownbrackets Feb 6, 2021
7ccb432
Debugger: Defer memory map calculations.
unknownbrackets Feb 6, 2021
53b8b87
Debugger: Track slabs by end, not size.
unknownbrackets Feb 6, 2021
f95fdf3
Debugger: Optimize linear marking.
unknownbrackets Feb 6, 2021
616f5dd
Debugger: Correct search by empty string.
unknownbrackets Feb 7, 2021
6168506
Debugger: Add initial UI for mem info type.
unknownbrackets Feb 7, 2021
595a17e
Debugger: Ignore unmarked mem block info in find.
unknownbrackets Feb 7, 2021
d806552
Debugger: Reorganize memory view painting.
unknownbrackets Feb 7, 2021
c044e6f
Debugger: Highlight memory ranges in memory view.
unknownbrackets Feb 7, 2021
b1a2090
Debugger: Extend tag background on select too.
unknownbrackets Feb 7, 2021
d48bb7e
Debugger: Show memory tag info in status bar.
unknownbrackets Feb 7, 2021
a4ed6eb
Debugger: Fix memory lookup in mirrors/uncached.
unknownbrackets Feb 8, 2021
de72190
Debugger: Update status on scroll down.
unknownbrackets Feb 8, 2021
8d58bbb
Debugger: Correct merging fragmented blocks.
unknownbrackets Feb 8, 2021
cc1b4e6
Debugger: Correct crash with no alloc tag.
unknownbrackets Feb 8, 2021
07de2e5
Debugger: Prevent thread errors on mem alloc info.
unknownbrackets Feb 8, 2021
ee71ef9
Debugger: Keep char *s for memchecks.
unknownbrackets Feb 21, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,8 @@ add_library(${CoreLibName} ${CoreLinkType}
Core/Debugger/Breakpoints.cpp
Core/Debugger/Breakpoints.h
Core/Debugger/DebugInterface.h
Core/Debugger/MemBlockInfo.cpp
Core/Debugger/MemBlockInfo.h
Core/Debugger/SymbolMap.cpp
Core/Debugger/SymbolMap.h
Core/Debugger/DisassemblyManager.cpp
Expand Down
2 changes: 2 additions & 0 deletions Core/Core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@
<ClCompile Include="..\ext\udis86\syn.c" />
<ClCompile Include="..\ext\udis86\udis86.c" />
<ClCompile Include="AVIDump.cpp" />
<ClCompile Include="Debugger\MemBlockInfo.cpp" />
<ClCompile Include="Debugger\WebSocket.cpp" />
<ClCompile Include="Debugger\WebSocket\BreakpointSubscriber.cpp" />
<ClCompile Include="Debugger\WebSocket\CPUCoreSubscriber.cpp" />
Expand Down Expand Up @@ -977,6 +978,7 @@
<ClInclude Include="..\ext\udis86\udis86.h" />
<ClInclude Include="AVIDump.h" />
<ClInclude Include="ConfigValues.h" />
<ClInclude Include="Debugger\MemBlockInfo.h" />
<ClInclude Include="Debugger\WebSocket.h" />
<ClInclude Include="Debugger\WebSocket\BreakpointSubscriber.h" />
<ClInclude Include="Debugger\WebSocket\GameSubscriber.h" />
Expand Down
6 changes: 6 additions & 0 deletions Core/Core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,9 @@
<ClCompile Include="MIPS\fake\FakeJit.cpp">
<Filter>MIPS\fake</Filter>
</ClCompile>
<ClCompile Include="Debugger\MemBlockInfo.cpp">
<Filter>Debugger</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ELF\ElfReader.h">
Expand Down Expand Up @@ -1670,6 +1673,9 @@
<ClInclude Include="MIPS\fake\FakeJit.h">
<Filter>MIPS\fake</Filter>
</ClInclude>
<ClInclude Include="Debugger\MemBlockInfo.h">
<Filter>Debugger</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />
Expand Down
5 changes: 3 additions & 2 deletions Core/CwCheat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Core/CwCheat.h"
#include "Core/Config.h"
#include "Core/Host.h"
#include "Core/MemMapHelpers.h"
#include "Core/MIPS/MIPS.h"
#include "Core/ELF/ParamSFO.h"
#include "Core/System.h"
Expand Down Expand Up @@ -924,7 +925,7 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat,
InvalidateICache(op.addr, op.val);
InvalidateICache(op.copyBytesFrom.destAddr, op.val);

Memory::MemcpyUnchecked(op.copyBytesFrom.destAddr, op.addr, op.val);
Memory::Memcpy(op.copyBytesFrom.destAddr, op.addr, op.val, "CwCheat");
}
break;

Expand Down Expand Up @@ -1106,7 +1107,7 @@ void CWCheatEngine::ExecuteOp(const CheatOperation &op, const CheatCode &cheat,
if (Memory::IsValidRange(dstAddr, val) && Memory::IsValidRange(srcAddr, val)) {
InvalidateICache(dstAddr, val);
InvalidateICache(srcAddr, val);
Memory::MemcpyUnchecked(dstAddr, srcAddr, val);
Memory::Memcpy(dstAddr, srcAddr, val, "CwCheat");
}
// Don't perform any further action.
type = -1;
Expand Down
21 changes: 11 additions & 10 deletions Core/Debugger/Breakpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ static std::mutex memCheckMutex_;
std::vector<MemCheck> CBreakPoints::memChecks_;
std::vector<MemCheck *> CBreakPoints::cleanupMemChecks_;

void MemCheck::Log(u32 addr, bool write, int size, u32 pc) {
void MemCheck::Log(u32 addr, bool write, int size, u32 pc, const char *reason) {
if (result & BREAK_ACTION_LOG) {
const char *type = write ? "Write" : "Read";
if (logFormat.empty()) {
NOTICE_LOG(MEMMAP, "CHK %s%i at %08x (%s), PC=%08x (%s)", write ? "Write" : "Read", size * 8, addr, g_symbolMap->GetDescription(addr).c_str(), pc, g_symbolMap->GetDescription(pc).c_str());
NOTICE_LOG(MEMMAP, "CHK %s%i(%s) at %08x (%s), PC=%08x (%s)", type, size * 8, reason, addr, g_symbolMap->GetDescription(addr).c_str(), pc, g_symbolMap->GetDescription(pc).c_str());
} else {
std::string formatted;
CBreakPoints::EvaluateLogFormat(currentDebugMIPS, logFormat, formatted);
NOTICE_LOG(MEMMAP, "CHK %s%i at %08x: %s", write ? "Write" : "Read", size * 8, addr, formatted.c_str());
NOTICE_LOG(MEMMAP, "CHK %s%i(%s) at %08x: %s", type, size * 8, reason, addr, formatted.c_str());
}
}
}
Expand All @@ -62,10 +63,10 @@ BreakAction MemCheck::Apply(u32 addr, bool write, int size, u32 pc) {
return BREAK_ACTION_IGNORE;
}

BreakAction MemCheck::Action(u32 addr, bool write, int size, u32 pc) {
BreakAction MemCheck::Action(u32 addr, bool write, int size, u32 pc, const char *reason) {
int mask = write ? MEMCHECK_WRITE : MEMCHECK_READ;
if (cond & mask) {
Log(addr, write, size, pc);
Log(addr, write, size, pc, reason);
if ((result & BREAK_ACTION_PAUSE) && coreState != CORE_POWERUP) {
Core_EnableStepping(true);
host->SetDebugMode(true);
Expand Down Expand Up @@ -94,7 +95,7 @@ void MemCheck::JitBeforeAction(u32 addr, bool write, int size, u32 pc) {
// We have to break to find out if it changed.
Core_EnableStepping(true);
} else {
Action(addr, write, size, pc);
Action(addr, write, size, pc, "CPU");
}
}

Expand All @@ -116,7 +117,7 @@ void MemCheck::JitCleanup(bool changed)
return;

if (changed)
Log(lastAddr, true, lastSize, lastPC);
Log(lastAddr, true, lastSize, lastPC, "CPU");

// Resume if it should not have gone to stepping, or if it did not change.
if ((!(result & BREAK_ACTION_PAUSE) || !changed) && coreState == CORE_STEPPING)
Expand Down Expand Up @@ -504,7 +505,7 @@ MemCheck *CBreakPoints::GetMemCheckLocked(u32 address, int size) {
return 0;
}

BreakAction CBreakPoints::ExecMemCheck(u32 address, bool write, int size, u32 pc)
BreakAction CBreakPoints::ExecMemCheck(u32 address, bool write, int size, u32 pc, const char *reason)
{
if (!anyMemChecks_)
return BREAK_ACTION_IGNORE;
Expand All @@ -514,7 +515,7 @@ BreakAction CBreakPoints::ExecMemCheck(u32 address, bool write, int size, u32 pc
check->Apply(address, write, size, pc);
auto copy = *check;
guard.unlock();
return copy.Action(address, write, size, pc);
return copy.Action(address, write, size, pc, reason);
}
return BREAK_ACTION_IGNORE;
}
Expand Down Expand Up @@ -547,7 +548,7 @@ BreakAction CBreakPoints::ExecOpMemCheck(u32 address, u32 pc)
check->Apply(address, write, size, pc);
auto copy = *check;
guard.unlock();
return copy.Action(address, write, size, pc);
return copy.Action(address, write, size, pc, "CPU");
}
}
return BREAK_ACTION_IGNORE;
Expand Down
6 changes: 3 additions & 3 deletions Core/Debugger/Breakpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ struct MemCheck {
// Called on the stored memcheck (affects numHits, etc.)
BreakAction Apply(u32 addr, bool write, int size, u32 pc);
// Called on a copy.
BreakAction Action(u32 addr, bool write, int size, u32 pc);
BreakAction Action(u32 addr, bool write, int size, u32 pc, const char *reason);
void JitBeforeApply(u32 addr, bool write, int size, u32 pc);
void JitBeforeAction(u32 addr, bool write, int size, u32 pc);
bool JitApplyChanged();
void JitCleanup(bool changed);

void Log(u32 addr, bool write, int size, u32 pc);
void Log(u32 addr, bool write, int size, u32 pc, const char *reason);

bool IsEnabled() const {
return (result & BREAK_ACTION_PAUSE) != 0;
Expand Down Expand Up @@ -151,7 +151,7 @@ class CBreakPoints

static bool GetMemCheck(u32 start, u32 end, MemCheck *check);
static bool GetMemCheckInRange(u32 address, int size, MemCheck *check);
static BreakAction ExecMemCheck(u32 address, bool write, int size, u32 pc);
static BreakAction ExecMemCheck(u32 address, bool write, int size, u32 pc, const char *reason);
static BreakAction ExecOpMemCheck(u32 address, u32 pc);

// Executes memchecks but used by the jit. Cleanup finalizes after jit is done.
Expand Down
Loading