break_points.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <algorithm>
  5. #include <sstream>
  6. #include "common/break_points.h"
  7. #include "common/logging/log.h"
  8. bool BreakPoints::IsAddressBreakPoint(u32 iAddress) const {
  9. auto cond = [&iAddress](const TBreakPoint& bp) { return bp.iAddress == iAddress; };
  10. auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
  11. return it != m_BreakPoints.end();
  12. }
  13. bool BreakPoints::IsTempBreakPoint(u32 iAddress) const {
  14. auto cond = [&iAddress](const TBreakPoint& bp) {
  15. return bp.iAddress == iAddress && bp.bTemporary;
  16. };
  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. TBreakPointsStr bps;
  22. for (auto breakpoint : m_BreakPoints) {
  23. if (!breakpoint.bTemporary) {
  24. std::stringstream bp;
  25. bp << std::hex << breakpoint.iAddress << " " << (breakpoint.bOn ? "n" : "");
  26. bps.push_back(bp.str());
  27. }
  28. }
  29. return bps;
  30. }
  31. void BreakPoints::AddFromStrings(const TBreakPointsStr& bps) {
  32. for (auto bps_item : bps) {
  33. TBreakPoint bp;
  34. std::stringstream bpstr;
  35. bpstr << std::hex << bps_item;
  36. bpstr >> bp.iAddress;
  37. bp.bOn = bps_item.find("n") != bps_item.npos;
  38. bp.bTemporary = false;
  39. Add(bp);
  40. }
  41. }
  42. void BreakPoints::Add(const TBreakPoint& bp) {
  43. if (!IsAddressBreakPoint(bp.iAddress)) {
  44. m_BreakPoints.push_back(bp);
  45. // if (jit)
  46. // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
  47. }
  48. }
  49. void BreakPoints::Add(u32 em_address, bool temp) {
  50. if (!IsAddressBreakPoint(em_address)) // only add new addresses
  51. {
  52. TBreakPoint pt; // breakpoint settings
  53. pt.bOn = true;
  54. pt.bTemporary = temp;
  55. pt.iAddress = em_address;
  56. m_BreakPoints.push_back(pt);
  57. // if (jit)
  58. // jit->GetBlockCache()->InvalidateICache(em_address, 4);
  59. }
  60. }
  61. void BreakPoints::Remove(u32 em_address) {
  62. auto cond = [&em_address](const TBreakPoint& bp) { return bp.iAddress == em_address; };
  63. auto it = std::find_if(m_BreakPoints.begin(), m_BreakPoints.end(), cond);
  64. if (it != m_BreakPoints.end())
  65. m_BreakPoints.erase(it);
  66. }
  67. void BreakPoints::Clear() {
  68. // if (jit)
  69. //{
  70. // std::for_each(m_BreakPoints.begin(), m_BreakPoints.end(),
  71. // [](const TBreakPoint& bp)
  72. // {
  73. // jit->GetBlockCache()->InvalidateICache(bp.iAddress, 4);
  74. // }
  75. // );
  76. //}
  77. m_BreakPoints.clear();
  78. }