-
-
Notifications
You must be signed in to change notification settings - Fork 340
/
WatchpointManager.cpp
105 lines (78 loc) · 2.14 KB
/
WatchpointManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2012, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "WatchpointManager.h"
#include <stdio.h>
#include <new>
#include <AutoLocker.h>
#include "DebuggerInterface.h"
#include "Team.h"
#include "Tracing.h"
WatchpointManager::WatchpointManager(Team* team,
DebuggerInterface* debuggerInterface)
:
fLock("watchpoint manager"),
fTeam(team),
fDebuggerInterface(debuggerInterface)
{
fDebuggerInterface->AcquireReference();
}
WatchpointManager::~WatchpointManager()
{
fDebuggerInterface->ReleaseReference();
}
status_t
WatchpointManager::Init()
{
return fLock.InitCheck();
}
status_t
WatchpointManager::InstallWatchpoint(Watchpoint* watchpoint,
bool enabled)
{
status_t error = B_OK;
TRACE_CONTROL("WatchpointManager::InstallUserWatchpoint(%p, %d)\n",
watchpoint, enabled);
AutoLocker<BLocker> installLocker(fLock);
AutoLocker<Team> teamLocker(fTeam);
bool oldEnabled = watchpoint->IsEnabled();
if (enabled == oldEnabled) {
TRACE_CONTROL(" watchpoint already valid and with same enabled "
"state\n");
return B_OK;
}
watchpoint->SetEnabled(enabled);
if (watchpoint->ShouldBeInstalled()) {
error = fDebuggerInterface->InstallWatchpoint(watchpoint->Address(),
watchpoint->Type(), watchpoint->Length());
if (error == B_OK)
watchpoint->SetInstalled(true);
} else {
error = fDebuggerInterface->UninstallWatchpoint(watchpoint->Address());
if (error == B_OK)
watchpoint->SetInstalled(false);
}
if (error == B_OK) {
if (fTeam->WatchpointAtAddress(watchpoint->Address()) == NULL)
fTeam->AddWatchpoint(watchpoint);
fTeam->NotifyWatchpointChanged(watchpoint);
}
return error;
}
void
WatchpointManager::UninstallWatchpoint(Watchpoint* watchpoint)
{
AutoLocker<BLocker> installLocker(fLock);
AutoLocker<Team> teamLocker(fTeam);
fTeam->RemoveWatchpoint(watchpoint);
if (!watchpoint->IsInstalled())
return;
status_t error = fDebuggerInterface->UninstallWatchpoint(
watchpoint->Address());
if (error == B_OK) {
watchpoint->SetInstalled(false);
fTeam->NotifyWatchpointChanged(watchpoint);
}
}