From 9de7bad68a3fc44cb43ecb6bc7ce393bd9d109b4 Mon Sep 17 00:00:00 2001 From: Andrew Breckenridge Date: Tue, 15 Aug 2017 16:04:00 -0700 Subject: [PATCH] add values to HardwareBreakpointManager's locations map --- .../Core/HardwareBreakpointManager.h | 8 +++++- Sources/Core/HardwareBreakpointManager.cpp | 26 ++++++++++++++----- .../Core/X86/HardwareBreakpointManager.cpp | 4 +-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Headers/DebugServer2/Core/HardwareBreakpointManager.h b/Headers/DebugServer2/Core/HardwareBreakpointManager.h index 0968d5537..9da018bb4 100644 --- a/Headers/DebugServer2/Core/HardwareBreakpointManager.h +++ b/Headers/DebugServer2/Core/HardwareBreakpointManager.h @@ -67,7 +67,13 @@ class HardwareBreakpointManager : public BreakpointManager { std::vector ®s) const; protected: - std::vector _locations; + struct Location { + Location() + :address(0) value(0){} + uint64_t address; + uint64_t value; + }; + std::vector _locations; std::unordered_set _enabled; #if defined(ARCH_X86) || defined(ARCH_X86_64) diff --git a/Sources/Core/HardwareBreakpointManager.cpp b/Sources/Core/HardwareBreakpointManager.cpp index 96472ffe4..3435cb25a 100644 --- a/Sources/Core/HardwareBreakpointManager.cpp +++ b/Sources/Core/HardwareBreakpointManager.cpp @@ -20,7 +20,7 @@ namespace ds2 { HardwareBreakpointManager::HardwareBreakpointManager( Target::ProcessBase *process) - : super(process), _locations(maxWatchpoints(), 0) {} + : super(process), _locations(maxWatchpoints()) {} HardwareBreakpointManager::~HardwareBreakpointManager() {} @@ -40,9 +40,12 @@ ErrorCode HardwareBreakpointManager::add(Address const &address, Type type, } ErrorCode HardwareBreakpointManager::remove(Address const &address) { - auto loc = std::find(_locations.begin(), _locations.end(), address); + auto loc = std::find_if(_locations.begin(), _locations.end(), + [address](const Location &l){ + return l.address == address; + }); if (loc != _locations.end()) { - _locations[loc - _locations.begin()] = 0; + _locations[loc - _locations.begin()].address = 0; } return super::remove(address); @@ -53,7 +56,10 @@ ErrorCode HardwareBreakpointManager::enableLocation(Site const &site, ErrorCode error; int idx; - auto loc = std::find(_locations.begin(), _locations.end(), site.address); + auto loc = std::find_if(_locations.begin(), _locations.end(), + [site](const Location &l){ + return l.address == site.address; + }); if (loc == _locations.end()) { idx = getAvailableLocation(); if (idx < 0) { @@ -70,7 +76,7 @@ ErrorCode HardwareBreakpointManager::enableLocation(Site const &site, }); if (error == kSuccess) { - _locations[idx] = site.address; + _locations[idx].address = site.address; } return error; } @@ -79,7 +85,10 @@ ErrorCode HardwareBreakpointManager::disableLocation(Site const &site, Target::Thread *thread) { ErrorCode error; - auto loc = std::find(_locations.begin(), _locations.end(), site.address); + auto loc = std::find_if(_locations.begin(), _locations.end(), + [site](const Location &l){ + return l.address == site.address; + }); if (loc == _locations.end()) { return kErrorInvalidArgument; } @@ -100,7 +109,10 @@ int HardwareBreakpointManager::getAvailableLocation() { return -1; } - auto it = std::find(_locations.begin(), _locations.end(), 0); + auto loc = std::find_if(_locations.begin(), _locations.end(), + [](const Location &l){ + return l.address == 0; + }); DS2ASSERT(it != _locations.end()); return (it - _locations.begin()); diff --git a/Sources/Core/X86/HardwareBreakpointManager.cpp b/Sources/Core/X86/HardwareBreakpointManager.cpp index 351a06d86..5156cf788 100644 --- a/Sources/Core/X86/HardwareBreakpointManager.cpp +++ b/Sources/Core/X86/HardwareBreakpointManager.cpp @@ -178,8 +178,8 @@ int HardwareBreakpointManager::hit(Target::Thread *thread, Site &site) { int regIdx = -1; for (size_t i = 0; i < maxWatchpoints(); ++i) { if (debugRegs[kStatusRegIdx] & (1 << i)) { - DS2ASSERT(_locations[i] != 0); - site = _sites.find(_locations[i])->second; + DS2ASSERT(_locations[i].address != 0); + site = _sites.find(_locations[i].address)->second; regIdx = i; break; }