Source code of Windows XP (NT5)
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.

165 lines
3.4 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. UNREFERENCED_PARAMETER(Argument);
  87. //
  88. // The first time we actually connect to a target
  89. //
  90. if ((Notify == DEBUG_NOTIFY_SESSION_ACCESSIBLE) && (!Connected))
  91. {
  92. IDebugClient *DebugClient;
  93. HRESULT Hr;
  94. PDEBUG_CONTROL DebugControl;
  95. if ((Hr = DebugCreate(__uuidof(IDebugClient),
  96. (void **)&DebugClient)) == S_OK)
  97. {
  98. //
  99. // Get the architecture type.
  100. //
  101. if ((Hr = DebugClient->QueryInterface(__uuidof(IDebugControl),
  102. (void **)&DebugControl)) == S_OK)
  103. {
  104. if ((Hr = DebugControl->GetActualProcessorType(
  105. &TargetMachine)) == S_OK)
  106. {
  107. Connected = TRUE;
  108. }
  109. NotifyOnTargetAccessible(DebugControl);
  110. DebugControl->Release();
  111. }
  112. DebugClient->Release();
  113. }
  114. }
  115. if (Notify == DEBUG_NOTIFY_SESSION_INACTIVE)
  116. {
  117. Connected = FALSE;
  118. TargetMachine = 0;
  119. }
  120. return;
  121. }
  122. extern "C"
  123. void
  124. CALLBACK
  125. DebugExtensionUninitialize(void)
  126. {
  127. return;
  128. }