break_points.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/break_points.h"
  5. #include "common/logging/log.h"
  6. #include <sstream>
  7. #include <algorithm>
  8. bool BreakPoints::IsAddressBreakPoint(u32 iAddress) const
  9. {
  10. auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; };
  11. auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
  12. return it != m_BreakPoints.end();
  13. }
  14. bool BreakPoints::IsTempBreakPoint(u32 iAddress) const
  15. {
  16. auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress && bp.bTemporary; };
  17. auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
  18. return it != m_BreakPoints.end();
  19. }
  20. BreakPoints::TBreakPointsStr BreakPoints::GetStrings() const
  21. {
  22. TBreakPointsStr bps;
  23. for (auto breakpoint : m_BreakPoints)
  24. {
  25. if (!breakpoint.bTemporary)
  26. {
  27. std::stringstream bp;
  28. bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : "");
  29. bps.push_back(bp.str());
  30. }
  31. }
  32. return bps;
  33. }
  34. void BreakPoints::AddFromStrings(const TBreakPointsStr& bps)
  35. {
  36. for (auto bps_item : bps)
  37. {
  38. TBreakPoint bp;
  39. std::stringstream bpstr;
  40. bpstr << std::hex << bps_item;
  41. bpstr >> bp.iAddress;
  42. bp.bOn = bps_item.find("n") != bps_item.npos;
  43. bp.bTemporary = false;
  44. Add(bp);
  45. }
  46. }
  47. void BreakPoints::Add(const TBreakPoint& bp)
  48. {
  49. if (!IsAddressBreakPoint(bp.iAddress))
  50. {
  51. m_BreakPoints.push_back(bp);
  52. //if (jit)
  53. // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
  54. }
  55. }
  56. void BreakPoints::Add(u32 em_address, bool temp)
  57. {
  58. if (!IsAddressBreakPoint(em_address)) // only add new addresses
  59. {
  60. TBreakPoint pt; // breakpoint settings
  61. pt.bOn = true;
  62. pt.bTemporary = temp;
  63. pt.iAddress = em_address;
  64. m_BreakPoints.push_back(pt);
  65. //if (jit)
  66. // jit->GetBlockCache()->InvalidateICache(em_address, 4);
  67. }
  68. }
  69. void BreakPoints::Remove(u32 em_address)
  70. {
  71. auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; };
  72. auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
  73. if (it != m_BreakPoints.end())
  74. m_BreakPoints.erase(it);
  75. }
  76. void BreakPoints::Clear()
  77. {
  78. //if (jit)
  79. //{
  80. // std::for_each(m_BreakPoints.begin(), m_BreakPoints.end(),
  81. // [](const TBreakPoint& bp)
  82. // {
  83. // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
  84. // }
  85. // );
  86. //}
  87. m_BreakPoints.clear();
  88. }