Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. exts.c
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the kernel debugger extensions dll.
  8. Environment:
  9. User Mode
  10. --*/
  11. #include "precomp.h"
  12. #include <ntverp.h>
  13. //
  14. // Valid for the lifetime of the debug session.
  15. //
  16. WINDBG_EXTENSION_APIS ExtensionApis;
  17. ULONG TargetMachine;
  18. BOOL Connected;
  19. ULONG g_TargetClass, g_TargetQual;
  20. ULONG g_TargetBuild;
  21. //
  22. // Valid only during an extension API call
  23. //
  24. PDEBUG_ADVANCED g_ExtAdvanced;
  25. PDEBUG_CLIENT g_ExtClient;
  26. PDEBUG_CONTROL g_ExtControl;
  27. PDEBUG_DATA_SPACES g_ExtData;
  28. PDEBUG_REGISTERS g_ExtRegisters;
  29. PDEBUG_SYMBOLS2 g_ExtSymbols;
  30. PDEBUG_SYSTEM_OBJECTS g_ExtSystem;
  31. // Queries for all debugger interfaces.
  32. extern "C" HRESULT
  33. ExtQuery(PDEBUG_CLIENT Client)
  34. {
  35. HRESULT Status;
  36. if ((Status = Client->QueryInterface(__uuidof(IDebugAdvanced),
  37. (void **)&g_ExtAdvanced)) != S_OK)
  38. {
  39. goto Fail;
  40. }
  41. if ((Status = Client->QueryInterface(__uuidof(IDebugControl),
  42. (void **)&g_ExtControl)) != S_OK)
  43. {
  44. goto Fail;
  45. }
  46. if ((Status = Client->QueryInterface(__uuidof(IDebugDataSpaces),
  47. (void **)&g_ExtData)) != S_OK)
  48. {
  49. goto Fail;
  50. }
  51. if ((Status = Client->QueryInterface(__uuidof(IDebugRegisters),
  52. (void **)&g_ExtRegisters)) != S_OK)
  53. {
  54. goto Fail;
  55. }
  56. if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols),
  57. (void **)&g_ExtSymbols)) != S_OK)
  58. {
  59. goto Fail;
  60. }
  61. if ((Status = Client->QueryInterface(__uuidof(IDebugSystemObjects),
  62. (void **)&g_ExtSystem)) != S_OK)
  63. {
  64. goto Fail;
  65. }
  66. g_ExtClient = Client;
  67. return S_OK;
  68. Fail:
  69. ExtRelease();
  70. return Status;
  71. }
  72. // Cleans up all debugger interfaces.
  73. void
  74. ExtRelease(void)
  75. {
  76. g_ExtClient = NULL;
  77. EXT_RELEASE(g_ExtAdvanced);
  78. EXT_RELEASE(g_ExtControl);
  79. EXT_RELEASE(g_ExtData);
  80. EXT_RELEASE(g_ExtRegisters);
  81. EXT_RELEASE(g_ExtSymbols);
  82. EXT_RELEASE(g_ExtSystem);
  83. }
  84. // Normal output.
  85. void __cdecl
  86. ExtOut(PCSTR Format, ...)
  87. {
  88. va_list Args;
  89. va_start(Args, Format);
  90. g_ExtControl->OutputVaList(DEBUG_OUTPUT_NORMAL, Format, Args);
  91. va_end(Args);
  92. }
  93. // Error output.
  94. void __cdecl
  95. ExtErr(PCSTR Format, ...)
  96. {
  97. va_list Args;
  98. va_start(Args, Format);
  99. g_ExtControl->OutputVaList(DEBUG_OUTPUT_ERROR, Format, Args);
  100. va_end(Args);
  101. }
  102. // Warning output.
  103. void __cdecl
  104. ExtWarn(PCSTR Format, ...)
  105. {
  106. va_list Args;
  107. va_start(Args, Format);
  108. g_ExtControl->OutputVaList(DEBUG_OUTPUT_WARNING, Format, Args);
  109. va_end(Args);
  110. }
  111. // Verbose output.
  112. void __cdecl
  113. ExtVerb(PCSTR Format, ...)
  114. {
  115. va_list Args;
  116. va_start(Args, Format);
  117. g_ExtControl->OutputVaList(DEBUG_OUTPUT_VERBOSE, Format, Args);
  118. va_end(Args);
  119. }
  120. extern "C"
  121. HRESULT
  122. CALLBACK
  123. DebugExtensionInitialize(PULONG Version, PULONG Flags)
  124. {
  125. IDebugClient *DebugClient;
  126. PDEBUG_CONTROL DebugControl;
  127. HRESULT Hr;
  128. *Version = DEBUG_EXTENSION_VERSION(1, 0);
  129. *Flags = 0;
  130. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  131. (void **)&DebugClient)) != S_OK)
  132. {
  133. return Hr;
  134. }
  135. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  136. (void **)&DebugControl)) != S_OK)
  137. {
  138. return Hr;
  139. }
  140. ExtensionApis.nSize = sizeof (ExtensionApis);
  141. if ((Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis)) != S_OK) {
  142. return Hr;
  143. }
  144. DebugControl->Release();
  145. DebugClient->Release();
  146. return S_OK;
  147. }
  148. extern "C"
  149. void
  150. CALLBACK
  151. DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
  152. {
  153. //
  154. // The first time we actually connect to a target, get the page size
  155. //
  156. if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
  157. {
  158. IDebugClient *DebugClient;
  159. PDEBUG_DATA_SPACES DebugDataSpaces;
  160. PDEBUG_CONTROL DebugControl;
  161. HRESULT Hr;
  162. ULONG64 Page;
  163. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  164. (void **)&DebugClient)) == S_OK)
  165. {
  166. //
  167. // Get the architecture type.
  168. //
  169. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  170. (void **)&DebugControl)) == S_OK)
  171. {
  172. if ((Hr = DebugControl->GetActualProcessorType(
  173. &TargetMachine)) == S_OK)
  174. {
  175. Connected = TRUE;
  176. }
  177. ULONG MajorVer, Platform, MinorVer, SrvPack;
  178. if ((Hr = DebugControl->GetSystemVersion(&Platform, &MajorVer,
  179. &MinorVer, NULL,
  180. 0, NULL,
  181. &SrvPack, NULL,
  182. 0, NULL)) == S_OK) {
  183. g_TargetBuild = MinorVer;
  184. }
  185. ULONG Qualifier;
  186. if ((Hr = DebugControl->GetDebuggeeType(&g_TargetClass, &g_TargetQual)) == S_OK)
  187. {
  188. }
  189. DebugControl->Release();
  190. }
  191. DebugClient->Release();
  192. }
  193. }
  194. if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
  195. {
  196. Connected = FALSE;
  197. TargetMachine = 0;
  198. }
  199. return;
  200. }
  201. extern "C"
  202. void
  203. CALLBACK
  204. DebugExtensionUninitialize(void)
  205. {
  206. return;
  207. }
  208. DllInit(
  209. HANDLE hModule,
  210. DWORD dwReason,
  211. DWORD dwReserved
  212. )
  213. {
  214. switch (dwReason) {
  215. case DLL_THREAD_ATTACH:
  216. break;
  217. case DLL_THREAD_DETACH:
  218. break;
  219. case DLL_PROCESS_DETACH:
  220. break;
  221. case DLL_PROCESS_ATTACH:
  222. break;
  223. }
  224. return TRUE;
  225. }