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.

289 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. exts.cpp
  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. #pragma hdrstop
  13. #include <ntverp.h>
  14. //
  15. // Valid for the lifetime of the debug session.
  16. //
  17. WINDBG_EXTENSION_APIS ExtensionApis;
  18. ULONG TargetMachine;
  19. BOOL Connected;
  20. ULONG g_TargetClass;
  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_SPACES2 g_ExtData;
  28. PDEBUG_REGISTERS g_ExtRegisters;
  29. PDEBUG_SYMBOLS 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(IDebugDataSpaces2),
  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 Qualifier;
  178. if ((Hr = DebugControl->GetDebuggeeType(&g_TargetClass, &Qualifier)) == S_OK)
  179. {
  180. }
  181. DebugControl->Release();
  182. }
  183. DebugClient->Release();
  184. }
  185. }
  186. if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
  187. {
  188. Connected = FALSE;
  189. TargetMachine = 0;
  190. }
  191. return;
  192. }
  193. extern "C"
  194. void
  195. CALLBACK
  196. DebugExtensionUninitialize(void)
  197. {
  198. return;
  199. }
  200. DllInit(
  201. HANDLE hModule,
  202. DWORD dwReason,
  203. DWORD dwReserved
  204. )
  205. {
  206. switch (dwReason) {
  207. case DLL_THREAD_ATTACH:
  208. break;
  209. case DLL_THREAD_DETACH:
  210. break;
  211. case DLL_PROCESS_DETACH:
  212. break;
  213. case DLL_PROCESS_ATTACH:
  214. break;
  215. }
  216. return TRUE;
  217. }
  218. DECLARE_API( help )
  219. {
  220. dprintf("evlog [Option [-?]] - Allows operations on the host event log\n");
  221. dprintf("handle [Handle [UMFlags [TypeName]]] - Display info about open handles\n");
  222. dprintf("help - Show this help\n");
  223. dprintf("vadump [-v] - Display all virtual memory allocation ranges\n");
  224. dprintf(" and their corresponding protection info\n");
  225. dprintf("vprot [Address] - Display virtual memory protection info\n");
  226. //dprintf("uniqstack [b,v,p,n] - Like debugger's built-in ~* k [b,v,p,n], but\n"
  227. // " this will exclude stacks that look like other\n"
  228. // " stacks already printed.\n");
  229. dprintf("\nType \".hh [command]\" for more detailed help\n");
  230. return S_OK;
  231. }