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.

183 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. dbgexts.cpp
  5. Abstract:
  6. This file contains the generic routines and initialization code
  7. for the debugger extensions dll.
  8. --*/
  9. #include "tsdbg.h"
  10. PDEBUG_CLIENT g_ExtClient;
  11. PDEBUG_CONTROL g_ExtControl;
  12. PDEBUG_SYMBOLS g_ExtSymbols;
  13. PDEBUG_SYMBOLS2 g_ExtSymbols2;
  14. PDEBUG_SYSTEM_OBJECTS g_ExtSysObjects;
  15. PDEBUG_SYSTEM_OBJECTS2 g_ExtSysObjects2;
  16. WINDBG_EXTENSION_APIS ExtensionApis;
  17. ULONG TargetMachine;
  18. BOOL Connected;
  19. // Queries for all debugger interfaces.
  20. extern "C" HRESULT
  21. ExtQuery(PDEBUG_CLIENT Client)
  22. {
  23. HRESULT Status;
  24. if ((Status = Client->QueryInterface(__uuidof(IDebugControl),
  25. (void **)&g_ExtControl)) != S_OK)
  26. {
  27. goto Fail;
  28. }
  29. if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols),
  30. (void **)&g_ExtSymbols)) != S_OK)
  31. {
  32. goto Fail;
  33. }
  34. if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols2),
  35. (void **)&g_ExtSymbols2)) != S_OK)
  36. {
  37. goto Fail;
  38. }
  39. if ((Status = Client->QueryInterface(__uuidof(IDebugSystemObjects),
  40. (void **)&g_ExtSysObjects)) != S_OK)
  41. {
  42. goto Fail;
  43. }
  44. if ((Status = Client->QueryInterface(__uuidof(IDebugSystemObjects),
  45. (void **)&g_ExtSysObjects2)) != S_OK)
  46. {
  47. goto Fail;
  48. }
  49. g_ExtClient = Client;
  50. return S_OK;
  51. Fail:
  52. ExtRelease();
  53. return Status;
  54. }
  55. // Cleans up all debugger interfaces.
  56. void
  57. ExtRelease(void)
  58. {
  59. g_ExtClient = NULL;
  60. EXT_RELEASE(g_ExtControl);
  61. EXT_RELEASE(g_ExtSymbols);
  62. EXT_RELEASE(g_ExtSymbols2);
  63. EXT_RELEASE(g_ExtSysObjects);
  64. EXT_RELEASE(g_ExtSysObjects2);
  65. }
  66. extern "C"
  67. HRESULT
  68. CALLBACK
  69. DebugExtensionInitialize(PULONG Version, PULONG Flags)
  70. {
  71. IDebugClient *DebugClient;
  72. PDEBUG_CONTROL DebugControl;
  73. HRESULT Hr;
  74. *Version = DEBUG_EXTENSION_VERSION(1, 0);
  75. *Flags = 0;
  76. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  77. (void **)&DebugClient)) != S_OK)
  78. {
  79. return Hr;
  80. }
  81. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  82. (void **)&DebugControl)) == S_OK)
  83. {
  84. //
  85. // Get the windbg-style extension APIS
  86. //
  87. ExtensionApis.nSize = sizeof (ExtensionApis);
  88. if ((Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis)) != S_OK)
  89. return Hr;
  90. DebugControl->Release();
  91. }
  92. DebugClient->Release();
  93. return S_OK;
  94. }
  95. extern "C"
  96. void
  97. CALLBACK
  98. DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
  99. {
  100. UNREFERENCED_PARAMETER(Argument);
  101. //
  102. // The first time we actually connect to a target
  103. //
  104. if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
  105. {
  106. IDebugClient *DebugClient;
  107. HRESULT Hr;
  108. PDEBUG_CONTROL DebugControl;
  109. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  110. (void **)&DebugClient)) == S_OK)
  111. {
  112. //
  113. // Get the architecture type.
  114. //
  115. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  116. (void **)&DebugControl)) == S_OK)
  117. {
  118. if ((Hr = DebugControl->GetActualProcessorType(
  119. &TargetMachine)) == S_OK)
  120. {
  121. Connected = TRUE;
  122. }
  123. NotifyOnTargetAccessible(DebugControl);
  124. DebugControl->Release();
  125. }
  126. DebugClient->Release();
  127. }
  128. }
  129. if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
  130. {
  131. Connected = FALSE;
  132. TargetMachine = 0;
  133. }
  134. return;
  135. }
  136. extern "C"
  137. void
  138. CALLBACK
  139. DebugExtensionUninitialize(void)
  140. {
  141. return;
  142. }