Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Commit

Permalink
add values to HardwareBreakpointManager's locations map
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSB committed Aug 15, 2017
1 parent 9fc0179 commit 9de7bad
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
8 changes: 7 additions & 1 deletion Headers/DebugServer2/Core/HardwareBreakpointManager.h
Expand Up @@ -67,7 +67,13 @@ class HardwareBreakpointManager : public BreakpointManager {
std::vector<uint64_t> &regs) const;

protected:
std::vector<uint64_t> _locations;
struct Location {
Location()
:address(0) value(0){}
uint64_t address;
uint64_t value;
};
std::vector<Location> _locations;
std::unordered_set<ThreadId> _enabled;

#if defined(ARCH_X86) || defined(ARCH_X86_64)
Expand Down
26 changes: 19 additions & 7 deletions Sources/Core/HardwareBreakpointManager.cpp
Expand Up @@ -20,7 +20,7 @@ namespace ds2 {

HardwareBreakpointManager::HardwareBreakpointManager(
Target::ProcessBase *process)
: super(process), _locations(maxWatchpoints(), 0) {}
: super(process), _locations(maxWatchpoints()) {}

HardwareBreakpointManager::~HardwareBreakpointManager() {}

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -70,7 +76,7 @@ ErrorCode HardwareBreakpointManager::enableLocation(Site const &site,
});

if (error == kSuccess) {
_locations[idx] = site.address;
_locations[idx].address = site.address;
}
return error;
}
Expand All @@ -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;
}
Expand All @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/X86/HardwareBreakpointManager.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit 9de7bad

Please sign in to comment.