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.

160 lines
5.0 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows NT **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. w3dbg.c
  7. This is the main module for the W3 Server debugger extension DLL.
  8. This module contains the DLL initialization/termination code and a
  9. few utility functions.
  10. FILE HISTORY:
  11. KeithMo 18-May-1993 Created.
  12. */
  13. #include "w3dbg.h"
  14. //
  15. // Globals shared by all extension commands.
  16. //
  17. PNTSD_OUTPUT_ROUTINE DebugPrint;
  18. PNTSD_GET_EXPRESSION DebugEval;
  19. PNTSD_GET_SYMBOL DebugGetSymbol;
  20. PNTSD_DISASM DebugDisassem;
  21. PNTSD_CHECK_CONTROL_C DebugCheckCtrlC;
  22. /*******************************************************************
  23. NAME: W3DbgDllInitialize
  24. SYNOPSIS: This DLL entry point is called when processes & threads
  25. are initialized and terminated, or upon calls to
  26. LoadLibrary() and FreeLibrary().
  27. ENTRY: hDll - A handle to the DLL.
  28. nReason - Indicates why the DLL entry
  29. point is being called.
  30. pReserved - Reserved.
  31. RETURNS: BOOLEAN - TRUE = DLL init was successful.
  32. FALSE = DLL init failed.
  33. NOTES: The return value is only relevant during processing of
  34. DLL_PROCESS_ATTACH notifications.
  35. HISTORY:
  36. KeithMo 18-May-1993 Created.
  37. ********************************************************************/
  38. BOOLEAN W3DbgDllInitialize( HANDLE hDll,
  39. DWORD nReason,
  40. LPVOID pReserved )
  41. {
  42. BOOLEAN fResult = TRUE;
  43. switch( nReason )
  44. {
  45. case DLL_PROCESS_ATTACH:
  46. //
  47. // This notification indicates that the DLL is attaching to
  48. // the address space of the current process. This is either
  49. // the result of the process starting up, or after a call to
  50. // LoadLibrary(). The DLL should us this as a hook to
  51. // initialize any instance data or to allocate a TLS index.
  52. //
  53. // This call is made in the context of the thread that
  54. // caused the process address space to change.
  55. //
  56. break;
  57. case DLL_PROCESS_DETACH:
  58. //
  59. // This notification indicates that the calling process is
  60. // detaching the DLL from its address space. This is either
  61. // due to a clean process exit or from a FreeLibrary() call.
  62. // The DLL should use this opportunity to return any TLS
  63. // indexes allocated and to free any thread local data.
  64. //
  65. // Note that this notification is posted only once per
  66. // process. Individual threads do not invoke the
  67. // DLL_THREAD_DETACH notification.
  68. //
  69. break;
  70. case DLL_THREAD_ATTACH:
  71. //
  72. // This notfication indicates that a new thread is being
  73. // created in the current process. All DLLs attached to
  74. // the process at the time the thread starts will be
  75. // notified. The DLL should use this opportunity to
  76. // initialize a TLS slot for the thread.
  77. //
  78. // Note that the thread that posts the DLL_PROCESS_ATTACH
  79. // notification will not post a DLL_THREAD_ATTACH.
  80. //
  81. // Note also that after a DLL is loaded with LoadLibrary,
  82. // only threads created after the DLL is loaded will
  83. // post this notification.
  84. //
  85. break;
  86. case DLL_THREAD_DETACH:
  87. //
  88. // This notification indicates that a thread is exiting
  89. // cleanly. The DLL should use this opportunity to
  90. // free any data stored in TLS indices.
  91. //
  92. break;
  93. default:
  94. //
  95. // Who knows? Just ignore it.
  96. //
  97. break;
  98. }
  99. return fResult;
  100. } // W3DbgDllInitialize
  101. /*******************************************************************
  102. NAME: GrabDebugApis
  103. SYNOPSIS: Initializes the global variables that hold pointers
  104. to the debugger API functions.
  105. ENTRY: lpExtensionApis - Points to a structure that
  106. contains pointers to the
  107. various debugger APIs.
  108. HISTORY:
  109. KeithMo 18-May-1993 Created.
  110. ********************************************************************/
  111. VOID GrabDebugApis( LPVOID lpExtensionApis )
  112. {
  113. PNTSD_EXTENSION_APIS lpNtsdApis = (PNTSD_EXTENSION_APIS)lpExtensionApis;
  114. DebugPrint = lpNtsdApis->lpOutputRoutine;
  115. DebugEval = lpNtsdApis->lpGetExpressionRoutine;
  116. DebugGetSymbol = lpNtsdApis->lpGetSymbolRoutine;
  117. DebugDisassem = lpNtsdApis->lpDisasmRoutine;
  118. DebugCheckCtrlC = lpNtsdApis->lpCheckControlCRoutine;
  119. } // GrabDebugApis