-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakpoint.cs
More file actions
54 lines (37 loc) · 1.5 KB
/
Breakpoint.cs
File metadata and controls
54 lines (37 loc) · 1.5 KB
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
using System;
namespace DebugNET {
public class Breakpoint {
public event EventHandler<BreakpointEventArgs> Hit;
private const byte BreakPointInstruction = 0xCC;
public Func<BreakpointEventArgs, bool> Condition { get; set; }
public bool Enabled { get; internal set; }
public byte Instruction { get; internal set; }
internal Breakpoint(byte instruction) {
Instruction = instruction;
}
/// <summary>
/// Enables the breakpoint.
/// </summary>
public bool Enable(Debugger debugger, IntPtr address) {
debugger.WaitHandle.WaitOne(250);
if (Enabled || !debugger.IsAttached) return false;
//if (!debugger.IsAttached) throw new AttachException("The debugger is not attached. Setting this breakpoint could crash the program.");
debugger.WriteByte(address, BreakPointInstruction);
Enabled = true;
return true;
}
/// <summary>
/// Disables the breakpoint.
/// </summary>
public bool Disable(Debugger debugger, IntPtr address) {
if (!Enabled) return false;
debugger.WriteByte(address, Instruction);
Enabled = false;
return true;
}
internal protected virtual void OnHit(BreakpointEventArgs e) {
Hit?.Invoke(this, e);
}
public override string ToString() => Instruction.ToString("X2");
}
}