-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakpointCollection.cs
More file actions
99 lines (83 loc) · 3.81 KB
/
BreakpointCollection.cs
File metadata and controls
99 lines (83 loc) · 3.81 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
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
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace DebugNET {
public class BreakpointCollection : IEnumerable<KeyValuePair<IntPtr, Breakpoint>> {
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public ICollection<IntPtr> Keys => Dictionary.Keys;
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public ICollection<Breakpoint> Values => Dictionary.Values;
public int Count => Dictionary.Count;
[DebuggerBrowsable(DebuggerBrowsableState.RootHidden)]
private Dictionary<IntPtr, Breakpoint> Dictionary { get; set; }
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private Debugger Debugger { get; set; }
public BreakpointCollection(Debugger debugger) {
Debugger = debugger;
Dictionary = new Dictionary<IntPtr, Breakpoint>();
}
public BreakpointCollection(Debugger debugger, int capacity) {
Debugger = debugger;
Dictionary = new Dictionary<IntPtr, Breakpoint>(capacity);
}
public BreakpointCollection(Debugger debugger, IDictionary<IntPtr, Breakpoint> dictionary) {
Debugger = debugger;
Dictionary = new Dictionary<IntPtr, Breakpoint>(dictionary);
}
public Breakpoint this[IntPtr key] {
get {
return Dictionary.ContainsKey(key) ? Dictionary[key] : null;
}
set {
if (Dictionary.ContainsKey(key)) Dictionary[key] = value;
else Dictionary.Add(key, value);
}
}
public void Add(IntPtr key, Breakpoint value) {
value.Instruction = Debugger.ReadByte(key);
Dictionary.Add(key, value);
}
public void Add(IntPtr key, EventHandler<BreakpointEventArgs> eventHandler, Func<BreakpointEventArgs, bool> condition = null) {
byte instruction = Debugger.ReadByte(key);
Breakpoint breakpoint = new Breakpoint(instruction);
breakpoint.Hit += eventHandler;
breakpoint.Condition = condition;
breakpoint.Enable(Debugger, key);
Dictionary.Add(key, breakpoint);
}
public void Add(KeyValuePair<IntPtr, Breakpoint> item) => Add(item.Key, item.Value);
public void Clear() {
foreach (var item in Dictionary) {
item.Value.Disable(Debugger, item.Key);
}
Dictionary.Clear();
}
public bool Contains(KeyValuePair<IntPtr, Breakpoint> item) => Dictionary.Contains(item);
public bool ContainsKey(IntPtr key) => Dictionary.ContainsKey(key);
public bool ContainsValue(Breakpoint value) => Dictionary.ContainsValue(value);
public bool Remove(IntPtr key) {
if (Dictionary.ContainsKey(key)) Dictionary[key].Disable(Debugger, key);
return Dictionary.Remove(key);
}
public bool Remove(KeyValuePair<IntPtr, Breakpoint> item) => Remove(item.Key);
public bool TryGetValue(IntPtr key, out Breakpoint value) => Dictionary.TryGetValue(key, out value);
public Breakpoint Get(IntPtr key, bool create = true) {
if (TryGetValue(key, out Breakpoint breakpoint)) return breakpoint;
else if (create) {
byte instruction = Debugger.ReadByte(key);
breakpoint = new Breakpoint(instruction);
breakpoint.Enable(Debugger, key);
Dictionary.Add(key, breakpoint);
}
return breakpoint;
}
public IEnumerator<KeyValuePair<IntPtr, Breakpoint>> GetEnumerator() {
foreach (var item in Dictionary) {
yield return item;
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}