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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
|
// BreakEvent.cs
//
// Author:
// Lluis Sanchez Gual <lluis@novell.com>
//
// Copyright (c) 2008 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
//
using System;
using System.Xml;
namespace Mono.Debugging.Client
{
[Serializable]
public class BreakEvent
{
[NonSerialized] BreakpointStore store;
[NonSerialized] bool enabled = true;
HitAction hitAction = HitAction.Break;
string customActionId;
string traceExpression;
int hitCount;
string lastTraceValue;
public BreakEvent ()
{
}
internal BreakEvent (XmlElement elem)
{
string s = elem.GetAttribute ("enabled");
if (s.Length > 0)
bool.TryParse (s, out enabled);
s = elem.GetAttribute ("hitAction");
if (s.Length > 0)
Enum.TryParse<HitAction> (s, out hitAction);
s = elem.GetAttribute ("customActionId");
if (s.Length > 0)
customActionId = s;
s = elem.GetAttribute ("traceExpression");
if (s.Length > 0)
traceExpression = s;
s = elem.GetAttribute ("hitCountMode");
HitCountMode mode;
if (s.Length > 0 && Enum.TryParse<HitCountMode> (s, out mode))
HitCountMode = mode;
s = elem.GetAttribute ("hitCount");
if (s.Length > 0)
int.TryParse (s, out hitCount);
// this is to facilitate backward compatibility
if (hitCount > 0 && HitCountMode == HitCountMode.None)
HitCountMode = HitCountMode.GreaterThan;
}
internal virtual XmlElement ToXml (XmlDocument doc)
{
XmlElement elem = doc.CreateElement (GetType().Name);
if (!enabled)
elem.SetAttribute ("enabled", "false");
if ((hitAction & HitAction.Break) == HitAction.None)
elem.SetAttribute ("hitAction", hitAction.ToString ());
if (!string.IsNullOrEmpty (customActionId))
elem.SetAttribute ("customActionId", customActionId);
if (!string.IsNullOrEmpty (traceExpression))
elem.SetAttribute ("traceExpression", traceExpression);
if (HitCountMode != HitCountMode.None)
elem.SetAttribute ("hitCountMode", HitCountMode.ToString ());
if (hitCount > 0)
elem.SetAttribute ("hitCount", hitCount.ToString ());
return elem;
}
internal static BreakEvent FromXml (XmlElement elem)
{
if (elem.Name == "FunctionBreakpoint")
return new FunctionBreakpoint (elem);
if (elem.Name == "Breakpoint")
return new Breakpoint (elem);
if (elem.Name == "Catchpoint")
return new Catchpoint (elem);
return null;
}
/// <summary>
/// Gets or sets a value indicating whether this <see cref="Mono.Debugging.Client.BreakEvent"/> is enabled.
/// </summary>
/// <value>
/// <c>true</c> if enabled; otherwise, <c>false</c>.
/// </value>
/// <remarks>
/// Changes in this property are automatically applied. There is no need to call CommitChanges().
/// </remarks>
public bool Enabled {
get {
return enabled;
}
set {
if (store != null && store.IsReadOnly)
return;
enabled = value;
if (store != null)
store.EnableBreakEvent (this, value);
}
}
/// <summary>
/// Gets the status of the break event
/// </summary>
/// <returns>
/// The status of the break event for the given debug session
/// </returns>
/// <param name='session'>
/// Session for which to get the status of the break event
/// </param>
public BreakEventStatus GetStatus (DebuggerSession session)
{
if (store == null || session == null)
return BreakEventStatus.Disconnected;
return session.GetBreakEventStatus (this);
}
/// <summary>
/// Gets a message describing the status of the break event
/// </summary>
/// <returns>
/// The status message of the break event for the given debug session
/// </returns>
/// <param name='session'>
/// Session for which to get the status message of the break event
/// </param>
public string GetStatusMessage (DebuggerSession session)
{
if (store == null || session == null)
return string.Empty;
return session.GetBreakEventStatusMessage (this);
}
/// <summary>
/// Gets or sets the expression to be traced when the breakpoint is hit
/// </summary>
/// <remarks>
/// If this break event is hit and the HitAction is TraceExpression, the debugger
/// will evaluate and print the value of this property.
/// The CommitChanges() method has to be called for changes in this
/// property to take effect.
/// </remarks>
public string TraceExpression {
get {
return traceExpression;
}
set {
traceExpression = value;
}
}
/// <summary>
/// Gets the last value traced.
/// </summary>
/// <remarks>
/// This property returns the last evaluation of TraceExpression.
/// </remarks>
public string LastTraceValue {
get {
return lastTraceValue;
}
internal set {
lastTraceValue = value;
}
}
/// <summary>
/// Gets or sets the action to be performed when the breakpoint is hit
/// </summary>
/// <remarks>
/// If the value is Break, the debugger will pause the execution.
/// If the value is PrintExpression, the debugger will evaluate and
/// print the value of the TraceExpression property.
/// If the value is CustomAction, the debugger will execute the
/// CustomBreakEventHitHandler callback specified in DebuggerSession,
/// and will provide the value of CustomActionId as argument.
/// The CommitChanges() method has to be called for changes in this
/// property to take effect.
/// </remarks>
public HitAction HitAction {
get {
return hitAction;
}
set {
hitAction = value;
}
}
/// <summary>
/// Gets or sets the hit count mode.
/// </summary>
/// <remarks>
/// When the break event is hit, the HitCountMode is used to compare the CurrentHitCount
/// with the TargetHitCount to determine if the break event should trigger.
/// </remarks>
public HitCountMode HitCountMode {
get; set;
}
/// <summary>
/// Gets or sets the target hit count.
/// </summary>
/// <remarks>
/// When the break event is hit, if the value of HitCountMode is not None, then
/// the value of CurrentHitCount will be incremented. Execution will immediately
/// resume if it is determined that the CurrentHitCount vs TargetHitCount
/// comparison does not meet the requirements of HitCountMode.
///
/// The CommitChanges() method has to be called for changes in this property
/// to take effect.
/// </remarks>
///
/// FIXME: rename this to TargetHitCount
public int HitCount {
get {
return hitCount;
}
set {
hitCount = value;
}
}
/// <summary>
/// Gets or sets the current hit count.
/// </summary>
/// <remarks>
/// When the break event is hit, the HitCountMode is used to compare the CurrentHitCount
/// with the TargetHitCount to determine if the break event should trigger.
/// </remarks>
public int CurrentHitCount {
get; set;
}
/// <summary>
/// Gets or sets the custom action identifier.
/// </summary>
/// <remarks>
/// If this break event is hit and the value of HitAction is CustomAction,
/// the debugger will execute the CustomBreakEventHitHandler callback
/// specified in DebuggerSession, and will provide the value of this property
/// as argument.
/// The CommitChanges() method has to be called for changes in this
/// property to take effect.
/// </remarks>
public string CustomActionId {
get {
return customActionId;
}
set {
customActionId = value;
}
}
internal BreakpointStore Store {
get {
return store;
}
set {
store = value;
}
}
/// <summary>
/// Commits changes done in the break event properties
/// </summary>
/// <remarks>
/// This method must be called after doing changes in the break event properties.
/// </remarks>
public void CommitChanges ()
{
if (store != null)
store.NotifyBreakEventChanged (this);
}
internal void NotifyUpdate ()
{
if (store != null)
store.NotifyBreakEventUpdated (this);
}
public virtual bool Reset ()
{
bool changed = CurrentHitCount != 0;
CurrentHitCount = 0;
return changed;
}
/// <summary>
/// Clone this instance.
/// </summary>
public BreakEvent Clone ()
{
return (BreakEvent) MemberwiseClone ();
}
/// <summary>
/// Makes a copy of this instance
/// </summary>
/// <param name='ev'>
/// A break event from which to copy the data.
/// </param>
public virtual void CopyFrom (BreakEvent ev)
{
hitAction = ev.hitAction;
customActionId = ev.customActionId;
traceExpression = ev.traceExpression;
hitCount = ev.hitCount;
}
}
}
|