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