// When changing existing watchpoint, VS creates a new watchpoint and deletes the // previous one. But LLDB doesn't create a new watchpoint if it points to the same // address. This may result in several DebugWatchpoint objects holding the same // watchpoint, and if one of the instances deletes it all the related DebugWatchpoint // become invalid. So we need to keep tracking of who actually using the watchpoint // by calling RegisterWatchpoint / UnregisterWatchpoint methods. public int Delete() { if (_deleted) { return(VSConstants.S_OK); } _deleted = true; _breakpointManager.UnregisterWatchpoint(Self); if (_lldbWatchpoint != null && _breakpointManager.GetWatchpointRefCount(Self) == 0) { _target.DeleteWatchpoint(_lldbWatchpoint.GetId()); } return(VSConstants.S_OK); }