2 * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2012, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
7 #include "WatchpointManager.h"
13 #include <AutoLocker.h>
15 #include "DebuggerInterface.h"
20 WatchpointManager::WatchpointManager(Team
* team
,
21 DebuggerInterface
* debuggerInterface
)
23 fLock("watchpoint manager"),
25 fDebuggerInterface(debuggerInterface
)
27 fDebuggerInterface
->AcquireReference();
31 WatchpointManager::~WatchpointManager()
33 fDebuggerInterface
->ReleaseReference();
38 WatchpointManager::Init()
40 return fLock
.InitCheck();
45 WatchpointManager::InstallWatchpoint(Watchpoint
* watchpoint
,
48 status_t error
= B_OK
;
49 TRACE_CONTROL("WatchpointManager::InstallUserWatchpoint(%p, %d)\n",
52 AutoLocker
<BLocker
> installLocker(fLock
);
53 AutoLocker
<Team
> teamLocker(fTeam
);
55 bool oldEnabled
= watchpoint
->IsEnabled();
56 if (enabled
== oldEnabled
) {
57 TRACE_CONTROL(" watchpoint already valid and with same enabled "
62 watchpoint
->SetEnabled(enabled
);
64 if (watchpoint
->ShouldBeInstalled()) {
65 error
= fDebuggerInterface
->InstallWatchpoint(watchpoint
->Address(),
66 watchpoint
->Type(), watchpoint
->Length());
69 watchpoint
->SetInstalled(true);
71 error
= fDebuggerInterface
->UninstallWatchpoint(watchpoint
->Address());
74 watchpoint
->SetInstalled(false);
78 if (fTeam
->WatchpointAtAddress(watchpoint
->Address()) == NULL
)
79 fTeam
->AddWatchpoint(watchpoint
);
80 fTeam
->NotifyWatchpointChanged(watchpoint
);
88 WatchpointManager::UninstallWatchpoint(Watchpoint
* watchpoint
)
90 AutoLocker
<BLocker
> installLocker(fLock
);
91 AutoLocker
<Team
> teamLocker(fTeam
);
93 fTeam
->RemoveWatchpoint(watchpoint
);
95 if (!watchpoint
->IsInstalled())
98 status_t error
= fDebuggerInterface
->UninstallWatchpoint(
99 watchpoint
->Address());
102 watchpoint
->SetInstalled(false);
103 fTeam
->NotifyWatchpointChanged(watchpoint
);