-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDebuggerProxy.cs
More file actions
89 lines (76 loc) · 2.26 KB
/
Copy pathDebuggerProxy.cs
File metadata and controls
89 lines (76 loc) · 2.26 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
using System.Collections.Generic;
using System.Dynamic;
using System.Management.Automation;
namespace PSExt
{
/// <summary>
/// Proxy to debugger responsible for invoking the calls from PowerShell on the debugger thread.
/// DynamicDebuggerProxy helper does this and delegates to the real debugger.
/// </summary>
public class DebuggerProxy : IDebugger
{
private readonly dynamic _proxy;
/// <summary>
/// Creates a new instance of the debugger proxy
/// </summary>
/// <param name="debugger">the real native debugger to delegate calls to</param>
/// <param name="debugFunctionDispatch"></param>
public DebuggerProxy(IDebugger debugger, IDebugFunctionDispatch debugFunctionDispatch)
{
_proxy = new DynamicDebuggerProxy(debugger, debugFunctionDispatch);
}
public string ExecuteCommand(string command)
{
return _proxy.ExecuteCommand(command);
}
public string ReadLine()
{
return _proxy.ReadLine();
}
public void Write(string value)
{
_proxy.Write(value);
}
public IList<BreakpointData> GetBreakpoints()
{
return _proxy.GetBreakpoints();
}
public IList<BreakpointData> AddBreakpoints(BreakpointData data)
{
return _proxy.AddBreakpoints(data);
}
public IList<ModuleData> GetModules()
{
return _proxy.GetModules();
}
public IList<DebugThread> GetCallstack(bool all)
{
return _proxy.GetCallstack(all);
}
public IList<SymbolValue> GetVariables(StackFrame frame, int levels)
{
return _proxy.GetStackFrame(frame, levels);
}
private class DynamicDebuggerProxy : DynamicObject
{
private readonly IDebugger _proxy;
private readonly IDebugFunctionDispatch _debugFunctionDispatch;
public DynamicDebuggerProxy(IDebugger proxy, IDebugFunctionDispatch debugFunctionDispatch)
{
_proxy = proxy;
_debugFunctionDispatch = debugFunctionDispatch;
}
public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
{
var mi = typeof (IDebugger).GetMethod(binder.Name);
if (_debugFunctionDispatch.DispatchRequired())
{
result = _debugFunctionDispatch.InvokeFunction(new MethodInvocationInfo(mi, _proxy, args));
return true;
}
result = mi.Invoke(_proxy, args);
return true;
}
}
}
}