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.

164 lines
3.5 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 "dbgexts.h"
  10. PDEBUG_CLIENT g_ExtClient;
  11. PDEBUG_CONTROL g_ExtControl;
  12. PDEBUG_SYMBOLS g_ExtSymbols;
  13. PDEBUG_SYMBOLS2 g_ExtSymbols2;
  14. WINDBG_EXTENSION_APIS ExtensionApis;
  15. ULONG TargetMachine;
  16. BOOL Connected;
  17. // Queries for all debugger interfaces.
  18. extern "C" HRESULT
  19. ExtQuery(PDEBUG_CLIENT Client)
  20. {
  21. HRESULT Status;
  22. if ((Status = Client->QueryInterface(__uuidof(IDebugControl),
  23. (void **)&g_ExtControl)) != S_OK)
  24. {
  25. goto Fail;
  26. }
  27. if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols),
  28. (void **)&g_ExtSymbols)) != S_OK)
  29. {
  30. goto Fail;
  31. }
  32. if ((Status = Client->QueryInterface(__uuidof(IDebugSymbols2),
  33. (void **)&g_ExtSymbols2)) != S_OK)
  34. {
  35. goto Fail;
  36. }
  37. g_ExtClient = Client;
  38. return S_OK;
  39. Fail:
  40. ExtRelease();
  41. return Status;
  42. }
  43. // Cleans up all debugger interfaces.
  44. void
  45. ExtRelease(void)
  46. {
  47. g_ExtClient = NULL;
  48. EXT_RELEASE(g_ExtControl);
  49. EXT_RELEASE(g_ExtSymbols);
  50. EXT_RELEASE(g_ExtSymbols2);
  51. }
  52. extern "C"
  53. HRESULT
  54. CALLBACK
  55. DebugExtensionInitialize(PULONG Version, PULONG Flags)
  56. {
  57. IDebugClient *DebugClient;
  58. PDEBUG_CONTROL DebugControl;
  59. HRESULT Hr;
  60. *Version = DEBUG_EXTENSION_VERSION(1, 0);
  61. *Flags = 0;
  62. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  63. (void **)&DebugClient)) != S_OK)
  64. {
  65. return Hr;
  66. }
  67. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  68. (void **)&DebugControl)) == S_OK)
  69. {
  70. //
  71. // Get the windbg-style extension APIS
  72. //
  73. ExtensionApis.nSize = sizeof (ExtensionApis);
  74. if ((Hr = DebugControl->GetWindbgExtensionApis64(&ExtensionApis)) != S_OK)
  75. return Hr;
  76. DebugControl->Release();
  77. }
  78. DebugClient->Release();
  79. return S_OK;
  80. }
  81. extern "C"
  82. void
  83. CALLBACK
  84. DebugExtensionNotify(ULONG Notify, ULONG64 Argument)
  85. {
  86. //
  87. // The first time we actually connect to a target
  88. //
  89. if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
  90. {
  91. IDebugClient *DebugClient;
  92. HRESULT Hr;
  93. PDEBUG_CONTROL DebugControl;
  94. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  95. (void **)&DebugClient)) == S_OK)
  96. {
  97. //
  98. // Get the architecture type.
  99. //
  100. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  101. (void **)&DebugControl)) == S_OK)
  102. {
  103. if ((Hr = DebugControl->GetActualProcessorType(
  104. &TargetMachine)) == S_OK)
  105. {
  106. Connected = TRUE;
  107. }
  108. NotifyOnTargetAccessible(DebugControl);
  109. DebugControl->Release();
  110. }
  111. DebugClient->Release();
  112. }
  113. }
  114. if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
  115. {
  116. Connected = FALSE;
  117. TargetMachine = 0;
  118. }
  119. return;
  120. }
  121. extern "C"
  122. void
  123. CALLBACK
  124. DebugExtensionUninitialize(void)
  125. {
  126. return;
  127. }