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

Fix Memory Breakpoints (MBP) Debugging #184

Open
wants to merge 6 commits into
base: slippi
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
4 changes: 2 additions & 2 deletions Externals/SlippiLib/SlippiLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand All @@ -92,7 +92,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Externals/nlohmann/nlohmann.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand All @@ -91,7 +91,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Externals/open-vcdiff/open-vcdiff.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand All @@ -134,7 +134,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Externals/semver/semver.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
Expand All @@ -93,7 +93,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugFast|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
Expand Down
55 changes: 40 additions & 15 deletions Source/Core/Common/BreakPoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "Common/BreakPoints.h"
#include "Common/CommonTypes.h"
#include "Common/DebugInterface.h"
#include "Core/Core.h"

#include "Core/PowerPC/JitCommon/JitBase.h"
#include "Core/PowerPC/JitCommon/JitCache.h"

Expand Down Expand Up @@ -168,29 +170,52 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mcstrs)
}
}

bool MemChecks::OverlapsMemcheck(u32 address, u32 length) const
{
if (!HasAny())
return false;

const u32 page_end_suffix = length - 1;
const u32 page_end_address = address | page_end_suffix;

return std::any_of(m_MemChecks.cbegin(), m_MemChecks.cend(), [&](const auto &mc) {
return ((mc.StartAddress | page_end_suffix) == page_end_address ||
(mc.EndAddress | page_end_suffix) == page_end_address) ||
((mc.StartAddress | page_end_suffix) < page_end_address &&
(mc.EndAddress | page_end_suffix) > page_end_address);
});
}

void MemChecks::Add(const TMemCheck& _rMemoryCheck)
{

if (GetMemCheck(_rMemoryCheck.StartAddress) != nullptr)
return;

bool had_any = HasAny();
if (GetMemCheck(_rMemoryCheck.StartAddress) == nullptr)
Core::RunAsCPUThread([&] {
m_MemChecks.push_back(_rMemoryCheck);
// If this is the first one, clear the JIT cache so it can switch to
// watchpoint-compatible code.
if (!had_any && jit)
jit->ClearCache();
// If this is the first one, clear the JIT cache so it can switch to
// watchpoint-compatible code.
if (!had_any && jit)
jit->ClearCache();
});

}

void MemChecks::Remove(u32 _Address)
{
for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
{
if (i->StartAddress == _Address)
{
m_MemChecks.erase(i);
return;
}
}
if (!HasAny() && jit)
jit->ClearCache();
const auto iter = std::find_if(m_MemChecks.cbegin(), m_MemChecks.cend(),
[_Address](const auto &check) { return check.StartAddress == _Address; });

if (iter == m_MemChecks.cend())
return;

Core::RunAsCPUThread([&] {
m_MemChecks.erase(iter);
if (!HasAny())
jit->ClearCache();
});
}

TMemCheck* MemChecks::GetMemCheck(u32 address)
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Common/BreakPoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class MemChecks
void Add(const TMemCheck& _rMemoryCheck);

// memory breakpoint
bool OverlapsMemcheck(u32 address, u32 length) const;

TMemCheck* GetMemCheck(u32 address);
void Remove(u32 _Address);

Expand Down
13 changes: 13 additions & 0 deletions Source/Core/Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,19 @@ bool PauseAndLock(bool do_lock, bool unpause_on_unlock)
return was_unpaused;
}

void RunAsCPUThread(std::function<void()> function)
{
const bool is_cpu_thread = IsCPUThread();
bool was_unpaused = false;
if (!is_cpu_thread)
was_unpaused = PauseAndLock(true, true);

function();

if (!is_cpu_thread)
PauseAndLock(false, was_unpaused);
}

// Display FPS info
// This should only be called from VI
void VideoThrottle()
Expand Down
9 changes: 9 additions & 0 deletions Source/Core/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ void RequestRefreshInfo();

void UpdateTitle();

// Run a function as the CPU thread.
//
// If called from the Host thread, the CPU thread is paused and the current thread temporarily
// becomes the CPU thread while running the function.
// If called from the CPU thread, the function will be run directly.
//
// This should only be called from the CPU thread or the host thread.
void RunAsCPUThread(std::function<void()> function);

// waits until all systems are paused and fully idle, and acquires a lock on that state.
// or, if doLock is false, releases a lock on that state and optionally unpauses.
// calls must be balanced (once with doLock true, then once with doLock false) but may be recursive.
Expand Down
Loading