summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Debug
diff options
context:
space:
mode:
authorSepalani <sepalani@hotmail.fr>2018-01-29 17:58:02 +0100
committerSepalani <sepalani@hotmail.fr>2018-04-28 17:46:51 +0400
commit74d4a4478facdbe400def1967abcde07e9f3dde7 (patch)
treebdf172ce3d9afa922239d4f040f9869721af9b5a /Source/Core/Common/Debug
parent28138cfde9d0d59f2e66defca43885821fbdacb3 (diff)
DebugInterface: Watches methods added
Move Watches to Common
Diffstat (limited to 'Source/Core/Common/Debug')
-rw-r--r--Source/Core/Common/Debug/Watches.cpp118
-rw-r--r--Source/Core/Common/Debug/Watches.h51
2 files changed, 169 insertions, 0 deletions
diff --git a/Source/Core/Common/Debug/Watches.cpp b/Source/Core/Common/Debug/Watches.cpp
new file mode 100644
index 0000000000..3668af1626
--- /dev/null
+++ b/Source/Core/Common/Debug/Watches.cpp
@@ -0,0 +1,118 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "Common/Debug/Watches.h"
+
+#include <algorithm>
+#include <sstream>
+
+namespace Common::Debug
+{
+Watch::Watch(u32 address_, const std::string& name_, Watch::State is_enabled_)
+ : address(address_), name(name_), is_enabled(is_enabled_)
+{
+}
+
+std::size_t Watches::SetWatch(u32 address, const std::string& name)
+{
+ const std::size_t size = m_watches.size();
+ for (std::size_t index = 0; index < size; index++)
+ {
+ if (m_watches.at(index).address == address)
+ {
+ UpdateWatch(index, address, name);
+ return index;
+ }
+ }
+ m_watches.emplace_back(address, name, Watch::State::Enabled);
+ return size;
+}
+
+const Watch& Watches::GetWatch(std::size_t index) const
+{
+ return m_watches.at(index);
+}
+
+const std::vector<Watch>& Watches::GetWatches() const
+{
+ return m_watches;
+}
+
+void Watches::UnsetWatch(u32 address)
+{
+ m_watches.erase(std::remove_if(m_watches.begin(), m_watches.end(),
+ [address](const auto& watch) { return watch.address == address; }),
+ m_watches.end());
+}
+
+void Watches::UpdateWatch(std::size_t index, u32 address, const std::string& name)
+{
+ m_watches[index].address = address;
+ m_watches[index].name = name;
+}
+
+void Watches::UpdateWatchAddress(std::size_t index, u32 address)
+{
+ m_watches[index].address = address;
+}
+
+void Watches::UpdateWatchName(std::size_t index, const std::string& name)
+{
+ m_watches[index].name = name;
+}
+
+void Watches::EnableWatch(std::size_t index)
+{
+ m_watches[index].is_enabled = Watch::State::Enabled;
+}
+
+void Watches::DisableWatch(std::size_t index)
+{
+ m_watches[index].is_enabled = Watch::State::Disabled;
+}
+
+bool Watches::HasEnabledWatch(u32 address) const
+{
+ return std::any_of(m_watches.begin(), m_watches.end(), [address](const auto& watch) {
+ return watch.address == address && watch.is_enabled == Watch::State::Enabled;
+ });
+}
+
+void Watches::RemoveWatch(std::size_t index)
+{
+ m_watches.erase(m_watches.begin() + index);
+}
+
+void Watches::LoadFromStrings(const std::vector<std::string>& watches)
+{
+ for (const std::string& watch : watches)
+ {
+ std::stringstream ss;
+ u32 address;
+ std::string name;
+ ss << std::hex << watch;
+ ss >> address;
+ ss >> std::ws;
+ std::getline(ss, name);
+ SetWatch(address, name);
+ }
+}
+
+std::vector<std::string> Watches::SaveToStrings() const
+{
+ std::vector<std::string> watches;
+ for (const auto& watch : m_watches)
+ {
+ std::stringstream ss;
+ ss << std::hex << watch.address << " " << watch.name;
+ watches.push_back(ss.str());
+ }
+ return watches;
+}
+
+void Watches::Clear()
+{
+ m_watches.clear();
+}
+} // namespace Common::Debug
diff --git a/Source/Core/Common/Debug/Watches.h b/Source/Core/Common/Debug/Watches.h
new file mode 100644
index 0000000000..1134f20900
--- /dev/null
+++ b/Source/Core/Common/Debug/Watches.h
@@ -0,0 +1,51 @@
+// Copyright 2018 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <cstddef>
+#include <string>
+#include <vector>
+
+#include "Common/CommonTypes.h"
+
+namespace Common::Debug
+{
+struct Watch
+{
+ enum class State : bool
+ {
+ Enabled = true,
+ Disabled = false
+ };
+
+ u32 address;
+ std::string name;
+ State is_enabled;
+
+ Watch(u32 address, const std::string& name, State is_enabled);
+};
+
+class Watches
+{
+public:
+ std::size_t SetWatch(u32 address, const std::string& name);
+ const Watch& GetWatch(std::size_t index) const;
+ const std::vector<Watch>& GetWatches() const;
+ void UnsetWatch(u32 address);
+ void UpdateWatch(std::size_t index, u32 address, const std::string& name);
+ void UpdateWatchAddress(std::size_t index, u32 address);
+ void UpdateWatchName(std::size_t index, const std::string& name);
+ void EnableWatch(std::size_t index);
+ void DisableWatch(std::size_t index);
+ bool HasEnabledWatch(u32 address) const;
+ void RemoveWatch(std::size_t index);
+ void LoadFromStrings(const std::vector<std::string>& watches);
+ std::vector<std::string> SaveToStrings() const;
+ void Clear();
+
+private:
+ std::vector<Watch> m_watches;
+};
+} // namespace Common::Debug