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.

122 lines
3.7 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: debug.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * This module contains random debugging related functions.
  7. *
  8. * History:
  9. * 17-May-1991 DarrinM Created.
  10. * 22-Jan-1992 IanJa ANSI/Unicode neutral (all debug output is ANSI)
  11. \***************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /*
  15. * Include stuff necessary to send a datagram to winsrv.
  16. */
  17. #include "ntcsrmsg.h"
  18. #include "csrmsg.h"
  19. /**************************************************************************\
  20. * ActivateDebugger
  21. *
  22. * Force an exception on the active application's context so it will break
  23. * into the debugger.
  24. *
  25. * History:
  26. * 05-10-91 DarrinM Created.
  27. \***************************************************************************/
  28. BOOL xxxActivateDebugger(
  29. UINT fsModifiers)
  30. {
  31. USER_API_MSG m;
  32. PACTIVATEDEBUGGERMSG a = &m.u.ActivateDebugger;
  33. PEPROCESS Process;
  34. HANDLE hDebugPort;
  35. NTSTATUS Status;
  36. if (fsModifiers & MOD_CONTROL) {
  37. #if DBG
  38. if (RipOutput(0, RIP_WARNING, "User debugger", 0, "", "Debug prompt", NULL)) {
  39. DbgBreakPoint();
  40. }
  41. #endif
  42. return FALSE;
  43. } else if (fsModifiers & MOD_SHIFT) {
  44. /*
  45. * Bail out if the process is not being debugged.
  46. */
  47. if (PsGetProcessDebugPort(gpepCSRSS) == NULL) {
  48. return FALSE;
  49. }
  50. a->ClientId.UniqueProcess = PsGetProcessId(gpepCSRSS);
  51. } else {
  52. if (gpqForeground == NULL || gpqForeground->ptiKeyboard == NULL) {
  53. return FALSE;
  54. }
  55. a->ClientId.UniqueProcess = PsGetThreadProcessId(gpqForeground->ptiKeyboard->pEThread);
  56. a->ClientId.UniqueThread = PsGetThreadId(gpqForeground->ptiKeyboard->pEThread);
  57. Status = LockProcessByClientId(a->ClientId.UniqueProcess, &Process);
  58. /*
  59. * Bail out if the process is not being debugged or the process id
  60. * is invalid.
  61. */
  62. if (!NT_SUCCESS(Status)) {
  63. return FALSE;
  64. }
  65. hDebugPort = PsGetProcessDebugPort(Process);
  66. UnlockProcess(Process);
  67. if (hDebugPort == NULL) {
  68. return FALSE;
  69. }
  70. }
  71. /*
  72. * Send the datagram to CSR.
  73. */
  74. if (CsrApiPort != NULL) {
  75. ULONG ArgLength = sizeof(*a);
  76. ArgLength |= (ArgLength << 16);
  77. ArgLength += ((sizeof( CSR_API_MSG ) - sizeof( m.u )) << 16) |
  78. (FIELD_OFFSET( CSR_API_MSG, u ) - sizeof( m.h ));
  79. m.h.u1.Length = ArgLength;
  80. m.h.u2.ZeroInit = 0;
  81. m.CaptureBuffer = NULL;
  82. m.ApiNumber = CSR_MAKE_API_NUMBER(USERSRV_SERVERDLL_INDEX,
  83. UserpActivateDebugger);
  84. LeaveCrit();
  85. Status = LpcRequestPort(CsrApiPort, (PPORT_MESSAGE)&m);
  86. EnterCrit();
  87. UserAssert(NT_SUCCESS(Status));
  88. }
  89. /*
  90. * Don't eat this event unless we are breaking into CSR! Since we have
  91. * choosen an arbitrary hot key like F12 for the debug key, we need to
  92. * pass on the key to the application, or apps that want this key would
  93. * never see it. If we had an api for installing a debug hot key
  94. * (export or MOD_DEBUG flag to RegisterHotKey()), then it would be ok
  95. * to eat because the user selected the hot key. But it is not ok to
  96. * eat it as long as we've picked an arbitrary hot key.
  97. */
  98. if (fsModifiers & MOD_SHIFT) {
  99. return TRUE;
  100. } else {
  101. return FALSE;
  102. }
  103. }
  104. DWORD GetRipComponent(
  105. VOID)
  106. {
  107. return RIP_USERKRNL;
  108. }