Switch SBWatchpoint::SetEnabled over to using Process::{Enable,Disable}Watchpoint.

We don't have a good story for what happens to watchpoints when you don't
have a process, or if your process exits.  Clearing that up will instruct 
how to fix this for real.

Also added a test to make sure disable->enable works as well.
This resolves llvm.org/pr30789.

llvm-svn: 285742
This commit is contained in:
Jim Ingham 2016-11-01 20:37:02 +00:00
parent f77a9889c0
commit 306b62b4ae
4 changed files with 35 additions and 8 deletions

View File

@ -71,6 +71,10 @@ public:
bool IsEnabled() const;
// This doesn't really enable/disable the watchpoint.
// It is currently just for use in the Process plugin's
// {Enable,Disable}Watchpoint, which should be used instead.
void SetEnabled(bool enabled, bool notify = true);
bool IsHardware() const override;

View File

@ -21,13 +21,21 @@ class TestWatchpointSetEnable(TestBase):
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
@expectedFailureAll(bugnumber="llvm.org/pr30789, <rdar://problem/28944061>")
def test_disable_works (self):
"""Set a watchpoint, disable it, and make sure it doesn't get hit."""
self.build()
self.disable_works()
self.do_test(False)
def disable_works(self):
@expectedFailureAndroid(archs=['arm', 'aarch64'])
@expectedFailureAll(
oslist=["windows"],
bugnumber="llvm.org/pr24446: WINDOWS XFAIL TRIAGE - Watchpoints not supported on Windows")
def test_disable_enable_works (self):
"""Set a watchpoint, disable it, and make sure it doesn't get hit."""
self.build()
self.do_test(True)
def do_test(self, test_enable):
"""Set a watchpoint, disable it and make sure it doesn't get hit."""
exe = 'a.out'
@ -69,7 +77,12 @@ class TestWatchpointSetEnable(TestBase):
stop_reason = thread.GetStopReason()
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint.")
self.assertEqual(stop_reason, lldb.eStopReasonBreakpoint, "We didn't stop at our breakpoint.")
if test_enable:
wp.SetEnabled(True)
self.assertTrue(wp.IsEnabled(), "The watchpoint thinks it is still disabled.")
process.Continue()
stop_reason = thread.GetStopReason()
self.assertEqual(stop_reason, lldb.eStopReasonWatchpoint, "We didn't stop at our watchpoint")

View File

@ -8,5 +8,6 @@ main()
printf("Set a breakpoint here: %d.\n", global_var);
global_var = 20;
printf("We should have stopped on the previous line: %d.\n", global_var);
global_var = 30;
return 0;
}

View File

@ -19,6 +19,7 @@
#include "lldb/Core/Log.h"
#include "lldb/Core/Stream.h"
#include "lldb/Core/StreamFile.h"
#include "lldb/Target/Process.h"
#include "lldb/Target/Target.h"
#include "lldb/lldb-defines.h"
#include "lldb/lldb-types.h"
@ -126,10 +127,18 @@ size_t SBWatchpoint::GetWatchSize() {
void SBWatchpoint::SetEnabled(bool enabled) {
lldb::WatchpointSP watchpoint_sp(GetSP());
if (watchpoint_sp) {
std::lock_guard<std::recursive_mutex> guard(
watchpoint_sp->GetTarget().GetAPIMutex());
Target &target = watchpoint_sp->GetTarget();
std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex());
ProcessSP process_sp = target.GetProcessSP();
if (process_sp) {
if (enabled)
process_sp->EnableWatchpoint(watchpoint_sp.get(), false);
else
process_sp->DisableWatchpoint(watchpoint_sp.get(), false);
} else {
watchpoint_sp->SetEnabled(enabled);
}
}
}
bool SBWatchpoint::IsEnabled() {