aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/video_core/debug_utils/debug_utils.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-10-25 18:02:26 +0200
committerGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-12-09 16:37:34 +0100
commit2c71ec70527abd091d69f1fdd30aaf95d815214a (patch)
treed0e1f48b048f6d3ef801d0562bfcfe0fa11de6f1 /src/video_core/debug_utils/debug_utils.cpp
parent706f9c5574f74b018958477813495dd6e15bd00d (diff)
Pica/DebugUtils: Add breakpoint functionality.
Diffstat (limited to 'src/video_core/debug_utils/debug_utils.cpp')
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
index 8a5f1142..11f87d98 100644
--- a/src/video_core/debug_utils/debug_utils.cpp
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -3,6 +3,8 @@
// Refer to the license.txt file included.
#include <algorithm>
+#include <condition_variable>
+#include <list>
#include <map>
#include <fstream>
#include <mutex>
@@ -12,6 +14,7 @@
#include <png.h>
#endif
+#include "common/log.h"
#include "common/file_util.h"
#include "video_core/pica.h"
@@ -20,6 +23,46 @@
namespace Pica {
+void DebugContext::OnEvent(Event event, void* data) {
+ if (!breakpoints[event].enabled)
+ return;
+
+ {
+ std::unique_lock<std::mutex> lock(breakpoint_mutex);
+
+ // TODO: Should stop the CPU thread here once we multithread emulation.
+
+ active_breakpoint = event;
+ at_breakpoint = true;
+
+ // Tell all observers that we hit a breakpoint
+ for (auto& breakpoint_observer : breakpoint_observers) {
+ breakpoint_observer->OnPicaBreakPointHit(event, data);
+ }
+
+ // Wait until another thread tells us to Resume()
+ resume_from_breakpoint.wait(lock, [&]{ return !at_breakpoint; });
+ }
+}
+
+void DebugContext::Resume() {
+ {
+ std::unique_lock<std::mutex> lock(breakpoint_mutex);
+
+ // Tell all observers that we are about to resume
+ for (auto& breakpoint_observer : breakpoint_observers) {
+ breakpoint_observer->OnPicaResume();
+ }
+
+ // Resume the waiting thread (i.e. OnEvent())
+ at_breakpoint = false;
+ }
+
+ resume_from_breakpoint.notify_one();
+}
+
+std::shared_ptr<DebugContext> g_debug_context; // TODO: Get rid of this global
+
namespace DebugUtils {
void GeometryDumper::AddTriangle(Vertex& v0, Vertex& v1, Vertex& v2) {