summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/break_points.cpp97
-rw-r--r--src/common/break_points.h48
-rw-r--r--src/common/common.vcxproj1
-rw-r--r--src/common/common.vcxproj.filters1
-rw-r--r--src/common/register_set.h163
-rw-r--r--src/common/thread.cpp4
6 files changed, 70 insertions, 244 deletions
diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp
index 25d34a21a..25528b864 100644
--- a/src/common/break_points.cpp
+++ b/src/common/break_points.cpp
@@ -9,32 +9,29 @@
#include <sstream>
#include <algorithm>
-bool BreakPoints::IsAddressBreakPoint(u32 _iAddress)
+bool BreakPoints::IsAddressBreakPoint(u32 iAddress)
{
- for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
- if (i->iAddress == _iAddress)
- return true;
- return false;
+ auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; };
+ auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
+ return it != m_BreakPoints.end();
}
-bool BreakPoints::IsTempBreakPoint(u32 _iAddress)
+bool BreakPoints::IsTempBreakPoint(u32 iAddress)
{
- for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
- if (i->iAddress == _iAddress && i->bTemporary)
- return true;
- return false;
+ auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; };
+ auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
+ return it != m_BreakPoints.end();
}
BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
{
TBreakPointsStr bps;
- for (TBreakPoints::const_iterator i = m_BreakPoints.begin();
- i != m_BreakPoints.end(); ++i)
+ for (auto breakpoint : m_BreakPoints)
{
- if (!i->bTemporary)
+ if (!breakpoint.bTemporary)
{
std::stringstream bp;
- bp << std::hex << i->iAddress << " " << (i->bOn ? "n" : "");
+ bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : "");
bps.push_back(bp.str());
}
}
@@ -44,13 +41,13 @@ BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
{
- for (TBreakPointsStr::const_iterator i = bps.begin(); i != bps.end(); ++i)
+ for (auto bps_item : bps)
{
TBreakPoint bp;
std::stringstream bpstr;
- bpstr << std::hex << *i;
+ bpstr << std::hex << bps_item;
bpstr >> bp.iAddress;
- bp.bOn = i->find("n") != i->npos;
+ bp.bOn = bps_item.find("n") != bps_item.npos;
bp.bTemporary = false;
Add(bp);
}
@@ -84,16 +81,10 @@ void BreakPoints::Add(u32 em_address, bool temp)
void BreakPoints::Remove(u32 em_address)
{
- for (TBreakPoints::iterator i = m_BreakPoints.begin(); i != m_BreakPoints.end(); ++i)
- {
- if (i->iAddress == em_address)
- {
- m_BreakPoints.erase(i);
- //if (jit)
- // jit->GetBlockCache()->InvalidateICache(em_address, 4);
- return;
- }
- }
+ auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; };
+ auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
+ if (it != m_BreakPoints.end())
+ m_BreakPoints.erase(it);
}
void BreakPoints::Clear()
@@ -107,21 +98,23 @@ void BreakPoints::Clear()
// }
// );
//}
-
+
m_BreakPoints.clear();
}
MemChecks::TMemChecksStr MemChecks::GetStrings() const
{
TMemChecksStr mcs;
- for (TMemChecks::const_iterator i = m_MemChecks.begin();
- i != m_MemChecks.end(); ++i)
+ for (auto memcheck : m_MemChecks)
{
std::stringstream mc;
- mc << std::hex << i->StartAddress;
- mc << " " << (i->bRange ? i->EndAddress : i->StartAddress) << " " <<
- (i->bRange ? "n" : "") << (i->OnRead ? "r" : "") <<
- (i->OnWrite ? "w" : "") << (i->Log ? "l" : "") << (i->Break ? "p" : "");
+ mc << std::hex << memcheck.StartAddress;
+ mc << " " << (memcheck.bRange ? memcheck.EndAddress : memcheck.StartAddress) << " "
+ << (memcheck.bRange ? "n" : "")
+ << (memcheck.OnRead ? "r" : "")
+ << (memcheck.OnWrite ? "w" : "")
+ << (memcheck.Log ? "l" : "")
+ << (memcheck.Break ? "p" : "");
mcs.push_back(mc.str());
}
@@ -130,17 +123,17 @@ MemChecks::TMemChecksStr MemChecks::GetStrings() const
void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
{
- for (TMemChecksStr::const_iterator i = mcs.begin(); i != mcs.end(); ++i)
+ for (auto mcs_item : mcs)
{
TMemCheck mc;
std::stringstream mcstr;
- mcstr << std::hex << *i;
+ mcstr << std::hex << mcs_item;
mcstr >> mc.StartAddress;
- mc.bRange = i->find("n") != i->npos;
- mc.OnRead = i->find("r") != i->npos;
- mc.OnWrite = i->find("w") != i->npos;
- mc.Log = i->find("l") != i->npos;
- mc.Break = i->find("p") != i->npos;
+ mc.bRange = mcs_item.find("n") != mcs_item.npos;
+ mc.OnRead = mcs_item.find("r") != mcs_item.npos;
+ mc.OnWrite = mcs_item.find("w") != mcs_item.npos;
+ mc.Log = mcs_item.find("l") != mcs_item.npos;
+ mc.Break = mcs_item.find("p") != mcs_item.npos;
if (mc.bRange)
mcstr >> mc.EndAddress;
else
@@ -149,27 +142,23 @@ void MemChecks::AddFromStrings(const TMemChecksStr& mcs)
}
}
-void MemChecks::Add(const TMemCheck& _rMemoryCheck)
+void MemChecks::Add(const TMemCheck& rMemoryCheck)
{
- if (GetMemCheck(_rMemoryCheck.StartAddress) == 0)
- m_MemChecks.push_back(_rMemoryCheck);
+ if (GetMemCheck(rMemoryCheck.StartAddress) == 0)
+ m_MemChecks.push_back(rMemoryCheck);
}
-void MemChecks::Remove(u32 _Address)
+void MemChecks::Remove(u32 Address)
{
- for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
- {
- if (i->StartAddress == _Address)
- {
- m_MemChecks.erase(i);
- return;
- }
- }
+ auto cond = [&Address](const TMemCheck& mc) { return mc.StartAddress == Address; };
+ auto it = std::find_if(m_MemChecks.begin(), m_MemChecks.end(), cond);
+ if (it != m_MemChecks.end())
+ m_MemChecks.erase(it);
}
TMemCheck *MemChecks::GetMemCheck(u32 address)
{
- for (TMemChecks::iterator i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
+ for (auto i = m_MemChecks.begin(); i != m_MemChecks.end(); ++i)
{
if (i->bRange)
{
diff --git a/src/common/break_points.h b/src/common/break_points.h
index 46df34665..da14ca7f3 100644
--- a/src/common/break_points.h
+++ b/src/common/break_points.h
@@ -14,32 +14,33 @@ class DebugInterface;
struct TBreakPoint
{
- u32 iAddress;
- bool bOn;
- bool bTemporary;
+ u32 iAddress;
+ bool bOn;
+ bool bTemporary;
};
struct TMemCheck
{
- TMemCheck() {
- numHits = 0;
- StartAddress = EndAddress = 0;
- bRange = OnRead = OnWrite = Log = Break = false;
- }
- u32 StartAddress;
- u32 EndAddress;
+ TMemCheck():
+ StartAddress(0), EndAddress(0),
+ bRange(false), OnRead(false), OnWrite(false),
+ Log(false), Break(false), numHits(0)
+ { }
- bool bRange;
+ u32 StartAddress;
+ u32 EndAddress;
- bool OnRead;
- bool OnWrite;
+ bool bRange;
- bool Log;
- bool Break;
+ bool OnRead;
+ bool OnWrite;
- u32 numHits;
+ bool Log;
+ bool Break;
- void Action(DebugInterface *dbg_interface, u32 _iValue, u32 addr,
+ u32 numHits;
+
+ void Action(DebugInterface *dbg_interface, u32 iValue, u32 addr,
bool write, int size, u32 pc);
};
@@ -56,22 +57,22 @@ public:
void AddFromStrings(const TBreakPointsStr& bps);
// is address breakpoint
- bool IsAddressBreakPoint(u32 _iAddress);
- bool IsTempBreakPoint(u32 _iAddress);
+ bool IsAddressBreakPoint(u32 iAddress);
+ bool IsTempBreakPoint(u32 iAddress);
// Add BreakPoint
void Add(u32 em_address, bool temp=false);
void Add(const TBreakPoint& bp);
// Remove Breakpoint
- void Remove(u32 _iAddress);
+ void Remove(u32 iAddress);
void Clear();
- void DeleteByAddress(u32 _Address);
+ void DeleteByAddress(u32 Address);
private:
TBreakPoints m_BreakPoints;
- u32 m_iBreakOnCount;
+ u32 m_iBreakOnCount;
};
@@ -89,7 +90,7 @@ public:
TMemChecksStr GetStrings() const;
void AddFromStrings(const TMemChecksStr& mcs);
- void Add(const TMemCheck& _rMemoryCheck);
+ void Add(const TMemCheck& rMemoryCheck);
// memory breakpoint
TMemCheck *GetMemCheck(u32 address);
@@ -99,4 +100,3 @@ public:
};
#endif
-
diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj
index 1f5c714c3..341d3a813 100644
--- a/src/common/common.vcxproj
+++ b/src/common/common.vcxproj
@@ -182,7 +182,6 @@
<ClInclude Include="mem_arena.h" />
<ClInclude Include="msg_handler.h" />
<ClInclude Include="platform.h" />
- <ClInclude Include="register_set.h" />
<ClInclude Include="scm_rev.h" />
<ClInclude Include="std_condition_variable.h" />
<ClInclude Include="std_mutex.h" />
diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters
index e8c4ce360..59268ce5a 100644
--- a/src/common/common.vcxproj.filters
+++ b/src/common/common.vcxproj.filters
@@ -29,7 +29,6 @@
<ClInclude Include="memory_util.h" />
<ClInclude Include="msg_handler.h" />
<ClInclude Include="platform.h" />
- <ClInclude Include="register_set.h" />
<ClInclude Include="std_condition_variable.h" />
<ClInclude Include="std_mutex.h" />
<ClInclude Include="std_thread.h" />
diff --git a/src/common/register_set.h b/src/common/register_set.h
deleted file mode 100644
index ba19a2614..000000000
--- a/src/common/register_set.h
+++ /dev/null
@@ -1,163 +0,0 @@
-// Copyright 2014 Citra Emulator Project
-// Licensed under GPLv2
-// Refer to the license.txt file included.
-
-#pragma once
-
-// Copyright 2014 Tony Wasserka
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the distribution.
-// * Neither the name of the owner nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-/*
- * Standardized way to define a group of registers and corresponding data structures. To define
- * a new register set, first define struct containing an enumeration called "Id" containing
- * all register IDs and a template struct called "Struct". Specialize the Struct struct for any
- * register ID which needs to be accessed in a specialized way. You can then declare the object
- * containing all register values using the RegisterSet<BaseType, DefiningStruct> type, where
- * BaseType is the underlying type of each register (e.g. u32).
- * Of course, you'll usually want to implement the Struct template such that they are of the same
- * size as BaseType. However, it's also possible to make it larger, e.g. when you want to describe
- * multiple registers with the same structure.
- *
- * Example:
- *
- * struct Regs {
- * enum Id : u32 {
- * Value1 = 0,
- * Value2 = 1,
- * Value3 = 2,
- * NumIds = 3
- * };
- *
- * // declare register definition structures
- * template<Id id>
- * struct Struct;
- * };
- *
- * // Define register set object
- * RegisterSet<u32, CommandIds> registers;
- *
- * // define register definition structures
- * template<>
- * struct Regs::Struct<Regs::Value1> {
- * union {
- * BitField<0, 4, u32> some_field;
- * BitField<4, 3, u32> some_other_field;
- * };
- * };
- *
- * Usage in external code (within SomeNamespace scope):
- *
- * For a register which maps to a single index:
- * registers.Get<Regs::Value1>().some_field = some_value;
- *
- * For a register which maps to different indices, e.g. a group of similar registers
- * registers.Get<Regs::Value1>(index).some_field = some_value;
- *
- *
- * @tparam BaseType Base type used for storing individual registers, e.g. u32
- * @tparam RegDefinition Class defining an enumeration called "Id" and a template<Id id> struct, as described above.
- * @note RegDefinition::Id needs to have an enum value called NumIds defining the number of registers to be allocated.
- */
-template<typename BaseType, typename RegDefinition>
-struct RegisterSet {
- // Register IDs
- using Id = typename RegDefinition::Id;
-
- // type used for *this
- using ThisType = RegisterSet<BaseType, RegDefinition>;
-
- // Register definition structs, defined in RegDefinition
- template<Id id>
- using Struct = typename RegDefinition::template Struct<id>;
-
-
- /*
- * Lookup register with the given id and return it as the corresponding structure type.
- * @note This just forwards the arguments to Get(Id).
- */
- template<Id id>
- const Struct<id>& Get() const {
- return Get<id>(id);
- }
-
- /*
- * Lookup register with the given id and return it as the corresponding structure type.
- * @note This just forwards the arguments to Get(Id).
- */
- template<Id id>
- Struct<id>& Get() {
- return Get<id>(id);
- }
-
- /*
- * Lookup register with the given index and return it as the corresponding structure type.
- * @todo Is this portable with regards to structures larger than BaseType?
- * @note if index==id, you don't need to specify the function parameter.
- */
- template<Id id>
- const Struct<id>& Get(const Id& index) const {
- const int idx = static_cast<size_t>(index);
- return *reinterpret_cast<const Struct<id>*>(&raw[idx]);
- }
-
- /*
- * Lookup register with the given index and return it as the corresponding structure type.
- * @note This just forwards the arguments to the const version of Get(Id).
- * @note if index==id, you don't need to specify the function parameter.
- */
- template<Id id>
- Struct<id>& Get(const Id& index) {
- return const_cast<Struct<id>&>(GetThis().Get<id>(index));
- }
-
- /*
- * Plain array access.
- * @note If you want to have this casted to a register defininition struct, use Get() instead.
- */
- const BaseType& operator[] (const Id& id) const {
- return raw[static_cast<size_t>(id)];
- }
-
- /*
- * Plain array access.
- * @note If you want to have this casted to a register defininition struct, use Get() instead.
- * @note This operator just forwards its argument to the const version.
- */
- BaseType& operator[] (const Id& id) {
- return const_cast<BaseType&>(GetThis()[id]);
- }
-
-private:
- /*
- * Returns a const reference to "this".
- */
- const ThisType& GetThis() const {
- return static_cast<const ThisType&>(*this);
- }
-
- BaseType raw[Id::NumIds];
-};
diff --git a/src/common/thread.cpp b/src/common/thread.cpp
index c70ee37cf..7341035c2 100644
--- a/src/common/thread.cpp
+++ b/src/common/thread.cpp
@@ -7,7 +7,7 @@
#ifdef __APPLE__
#include <mach/mach.h>
-#elif defined BSD4_4
+#elif defined(BSD4_4) || defined(__OpenBSD__)
#include <pthread_np.h>
#endif
@@ -123,6 +123,8 @@ void SetCurrentThreadName(const char* szThreadName)
{
#ifdef __APPLE__
pthread_setname_np(szThreadName);
+#elif defined(__OpenBSD__)
+ pthread_set_name_np(pthread_self(), szThreadName);
#else
pthread_setname_np(pthread_self(), szThreadName);
#endif