PageRenderTime 69ms CodeModel.GetById 22ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

/Debugger/Debugger.Core/ManagedCallbackProxy.cs

http://github.com/icsharpcode/ILSpy
C# | 420 lines | 362 code | 46 blank | 12 comment | 0 complexity | 393a1831d28b2fac0aecf6fa3ea519e1 MD5 | raw file
  1// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
  2// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
  3
  4using System;
  5using System.Windows.Forms;
  6using Debugger.Interop;
  7using Debugger.Interop.CorDebug;
  8
  9// Regular expresion:
 10// ^{\t*}{(:Ll| )*{:i} *\(((.# {:i}, |\))|())^6\)*}\n\t*\{(.|\n)@\t\}
 11// Output: \1 - intention   \2 - declaration \3 - function name  \4-9 parameters
 12
 13// Replace with:
 14// \1\2\n\1{\n\1\tCallbackReceived("\3", new object[] {\4, \5, \6, \7, \8, \9});\n\1}
 15// \1\2\n\1{\n\1\tCall(delegate {\n\1\t     \trealCallback.\3(\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\4),\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\5),\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\6),\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\7),\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\8),\n\1\t     \t\tMTA2STA.MarshalIntPtrTo(\9),\n\1\t     \t);\n\1\t     });\n\1}
 16
 17namespace Debugger
 18{
 19	/// <summary>
 20	/// This proxy marshals the callback to the appropriate thread
 21	/// </summary>
 22	class ManagedCallbackProxy : ICorDebugManagedCallback, ICorDebugManagedCallback2
 23	{
 24		NDebugger debugger;
 25		ManagedCallbackSwitch callbackSwitch;
 26		
 27		public NDebugger Debugger {
 28			get {
 29				return debugger;
 30			}
 31		}
 32		
 33		public ManagedCallbackProxy(NDebugger debugger, ManagedCallbackSwitch callbackSwitch)
 34		{
 35			this.debugger = debugger;
 36			this.callbackSwitch = callbackSwitch;
 37		}
 38		
 39		void Call(MethodInvoker callback)
 40		{
 41			debugger.MTA2STA.Call(callback);
 42		}
 43			
 44		public void StepComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pStepper, CorDebugStepReason reason)
 45		{
 46			Call(delegate {
 47			     	callbackSwitch.StepComplete(
 48			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
 49			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
 50			     		MTA2STA.MarshalIntPtrTo<ICorDebugStepper>(pStepper),
 51			     		reason
 52			     	);
 53			     });
 54		}
 55		
 56		public void Break(System.IntPtr pAppDomain, System.IntPtr pThread)
 57		{
 58			Call(delegate {
 59			     	callbackSwitch.Break(
 60			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
 61			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
 62			     	);
 63			     });
 64		}
 65		
 66		public void ControlCTrap(System.IntPtr pProcess)
 67		{
 68			Call(delegate {
 69			     	callbackSwitch.ControlCTrap(
 70			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
 71			     	);
 72			     });
 73		}
 74		
 75		public void Exception(System.IntPtr pAppDomain, System.IntPtr pThread, int unhandled)
 76		{
 77			Call(delegate {
 78			     	callbackSwitch.Exception(
 79			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
 80			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
 81			     		unhandled
 82			     	);
 83			     });
 84		}
 85		
 86		public void Breakpoint(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint)
 87		{
 88			Call(delegate {
 89			     	callbackSwitch.Breakpoint(
 90			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
 91			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
 92			     		// This fails in .NET 1.1:
 93			     		MTA2STA.MarshalIntPtrTo<ICorDebugBreakpoint>(pBreakpoint)
 94			     	);
 95			     });
 96		}
 97		
 98		public void CreateProcess(System.IntPtr pProcess)
 99		{
100			Call(delegate {
101			     	callbackSwitch.CreateProcess(
102			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
103			     	);
104			     });
105		}
106		
107		public void CreateAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain)
108		{
109			Call(delegate {
110			     	callbackSwitch.CreateAppDomain(
111			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
112			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain)
113			     	);
114			     });
115		}
116		
117		public void CreateThread(System.IntPtr pAppDomain, System.IntPtr pThread)
118		{
119			Call(delegate {
120			     	callbackSwitch.CreateThread(
121			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
122			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
123			     	);
124			     });
125		}
126		
127		public void LoadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly)
128		{
129			Call(delegate {
130			     	callbackSwitch.LoadAssembly(
131			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
132			     		MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly)
133			     	);
134			     });
135		}
136		
137		public void LoadModule(System.IntPtr pAppDomain, System.IntPtr pModule)
138		{
139			Call(delegate {
140			     	callbackSwitch.LoadModule(
141			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
142			     		MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule)
143			     	);
144			     });
145		}
146		
147		public void NameChange(System.IntPtr pAppDomain, System.IntPtr pThread)
148		{
149			Call(delegate {
150			     	callbackSwitch.NameChange(
151			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
152			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
153			     	);
154			     });
155		}
156		
157		public void LoadClass(System.IntPtr pAppDomain, System.IntPtr c)
158		{
159			Call(delegate {
160			     	callbackSwitch.LoadClass(
161			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
162			     		MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c)
163			     	);
164			     });
165		}
166		
167		public void UnloadClass(System.IntPtr pAppDomain, System.IntPtr c)
168		{
169			Call(delegate {
170			     	callbackSwitch.UnloadClass(
171			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
172			     		MTA2STA.MarshalIntPtrTo<ICorDebugClass>(c)
173			     	);
174			     });
175		}
176		
177		public void ExitThread(System.IntPtr pAppDomain, System.IntPtr pThread)
178		{
179			Call(delegate {
180			     	callbackSwitch.ExitThread(
181			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
182			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread)
183			     	);
184			     });
185		}
186		
187		public void UnloadModule(System.IntPtr pAppDomain, System.IntPtr pModule)
188		{
189			Call(delegate {
190			     	callbackSwitch.UnloadModule(
191			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
192			     		MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule)
193			     	);
194			     });
195		}
196		
197		public void UnloadAssembly(System.IntPtr pAppDomain, System.IntPtr pAssembly)
198		{
199			Call(delegate {
200			     	callbackSwitch.UnloadAssembly(
201			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
202			     		MTA2STA.MarshalIntPtrTo<ICorDebugAssembly>(pAssembly)
203			     	);
204			     });
205		}
206		
207		public void ExitAppDomain(System.IntPtr pProcess, System.IntPtr pAppDomain)
208		{
209			Call(delegate {
210			     	callbackSwitch.ExitAppDomain(
211			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
212			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain)
213			     	);
214			     });
215		}
216		
217		public void ExitProcess(System.IntPtr pProcess)
218		{
219			Call(delegate {
220			     	callbackSwitch.ExitProcess(
221			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess)
222			     	);
223			     });
224		}
225		
226		public void BreakpointSetError(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pBreakpoint, uint dwError)
227		{
228			Call(delegate {
229			     	callbackSwitch.BreakpointSetError(
230			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
231			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
232			     		MTA2STA.MarshalIntPtrTo<ICorDebugBreakpoint>(pBreakpoint),
233			     		dwError
234			     	);
235			     });
236		}
237		
238		public void LogSwitch(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, uint ulReason, System.IntPtr pLogSwitchName, System.IntPtr pParentName)
239		{
240			Call(delegate {
241			     	callbackSwitch.LogSwitch(
242			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
243			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
244			     		lLevel,
245			     		ulReason,
246			     		MTA2STA.MarshalIntPtrTo<string>(pLogSwitchName),
247			     		MTA2STA.MarshalIntPtrTo<string>(pParentName)
248			     	);
249			     });
250		}
251		
252		public void EvalException(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval)
253		{
254			Call(delegate {
255			     	callbackSwitch.EvalException(
256			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
257			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
258			     		MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval)
259			     	);
260			     });
261		}
262		
263		public void LogMessage(System.IntPtr pAppDomain, System.IntPtr pThread, int lLevel, System.IntPtr pLogSwitchName, System.IntPtr pMessage)
264		{
265			Call(delegate {
266			     	callbackSwitch.LogMessage(
267			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
268			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
269			     		lLevel,
270			     		MTA2STA.MarshalIntPtrTo<string>(pLogSwitchName),
271			     		MTA2STA.MarshalIntPtrTo<string>(pMessage)
272			     	);
273			     });
274		}
275		
276		public void EditAndContinueRemap(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pFunction, int fAccurate)
277		{
278			Call(delegate {
279			     	callbackSwitch.EditAndContinueRemap(
280			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
281			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
282			     		MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction),
283			     		fAccurate
284			     	);
285			     });
286		}
287		
288		public void EvalComplete(System.IntPtr pAppDomain, System.IntPtr pThread, System.IntPtr pEval)
289		{
290			Call(delegate {
291			     	callbackSwitch.EvalComplete(
292			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
293			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
294			     		MTA2STA.MarshalIntPtrTo<ICorDebugEval>(pEval)
295			     	);
296			     });
297		}
298		
299		public void DebuggerError(System.IntPtr pProcess, int errorHR, uint errorCode)
300		{
301			Call(delegate {
302			     	callbackSwitch.DebuggerError(
303			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
304			     		errorHR,
305			     		errorCode
306			     	);
307			     });
308		}
309		
310		public void UpdateModuleSymbols(System.IntPtr pAppDomain, System.IntPtr pModule, System.IntPtr pSymbolStream)
311		{
312			Call(delegate {
313			     	callbackSwitch.UpdateModuleSymbols(
314			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
315			     		MTA2STA.MarshalIntPtrTo<ICorDebugModule>(pModule),
316			     		MTA2STA.MarshalIntPtrTo<IStream>(pSymbolStream)
317			     	);
318			     });
319		}
320
321
322
323		#region ICorDebugManagedCallback2 Members
324
325		public void ChangeConnection(IntPtr pProcess, uint dwConnectionId)
326		{
327			Call(delegate {
328			     	callbackSwitch.ChangeConnection(
329			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
330			     		dwConnectionId
331			     	);
332			     });
333		}
334		
335		public void CreateConnection(IntPtr pProcess, uint dwConnectionId, IntPtr pConnName)
336		{
337			Call(delegate {
338			     	callbackSwitch.CreateConnection(
339			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
340			     		dwConnectionId,
341			     		pConnName
342			     	);
343			     });
344		}
345		
346		public void DestroyConnection(IntPtr pProcess, uint dwConnectionId)
347		{
348			Call(delegate {
349			     	callbackSwitch.DestroyConnection(
350			     		MTA2STA.MarshalIntPtrTo<ICorDebugProcess>(pProcess),
351			     		dwConnectionId
352			     	);
353			     });
354		}
355		
356		public void Exception(IntPtr pAppDomain, IntPtr pThread, IntPtr pFrame, uint nOffset, CorDebugExceptionCallbackType dwEventType, uint dwFlags)
357		{
358			Call(delegate {
359			     	callbackSwitch.Exception2(
360			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
361			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
362			     		MTA2STA.MarshalIntPtrTo<ICorDebugFrame>(pFrame),
363			     		nOffset,
364			     		dwEventType,
365			     		dwFlags
366			     	);
367			     });
368		}
369		
370		public void ExceptionUnwind(IntPtr pAppDomain, IntPtr pThread, CorDebugExceptionUnwindCallbackType dwEventType, uint dwFlags)
371		{
372			Call(delegate {
373			     	callbackSwitch.ExceptionUnwind(
374			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
375			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
376			     		dwEventType,
377			     		dwFlags
378			     	);
379			     });
380		}
381		
382		public void FunctionRemapComplete(IntPtr pAppDomain, IntPtr pThread, IntPtr pFunction)
383		{
384			Call(delegate {
385			     	callbackSwitch.FunctionRemapComplete(
386			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
387			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
388			     		MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pFunction)
389			     	);
390			     });
391		}
392		
393		public void FunctionRemapOpportunity(IntPtr pAppDomain, IntPtr pThread, IntPtr pOldFunction, IntPtr pNewFunction, uint oldILOffset)
394		{
395			Call(delegate {
396			     	callbackSwitch.FunctionRemapOpportunity(
397			     		MTA2STA.MarshalIntPtrTo<ICorDebugAppDomain>(pAppDomain),
398			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
399			     		MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pOldFunction),
400			     		MTA2STA.MarshalIntPtrTo<ICorDebugFunction>(pNewFunction),
401			     		oldILOffset
402			     	);
403			     });
404		}
405		
406		public void MDANotification(IntPtr pController, IntPtr pThread, IntPtr pMDA)
407		{
408			Call(delegate {
409			     	callbackSwitch.MDANotification(
410			     		MTA2STA.MarshalIntPtrTo<ICorDebugController>(pController),
411			     		MTA2STA.MarshalIntPtrTo<ICorDebugThread>(pThread),
412			     		MTA2STA.MarshalIntPtrTo<ICorDebugMDA>(pMDA)
413			     	);
414			     });
415		}
416		
417		#endregion
418	}
419
420}