debug.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * ReactOS Task Manager
  3. *
  4. * debug.c
  5. *
  6. * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
  7. * Copyright (C) 2008 Vladimir Pankratov
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include <winnt.h>
  28. #include "taskmgr.h"
  29. #include "perfdata.h"
  30. void ProcessPage_OnDebug(void)
  31. {
  32. LVITEMW lvitem;
  33. ULONG Index, Count;
  34. DWORD dwProcessId;
  35. WCHAR wstrErrorText[256];
  36. HKEY hKey;
  37. WCHAR wstrDebugPath[256];
  38. WCHAR wstrDebugger[256];
  39. DWORD dwDebuggerSize;
  40. PROCESS_INFORMATION pi;
  41. STARTUPINFOW si;
  42. HANDLE hDebugEvent;
  43. WCHAR wszWarnTitle[255];
  44. WCHAR wszUnable2Debug[255];
  45. WCHAR wszWarnMsg[255];
  46. static const WCHAR wszSubKey[] = {'S','o','f','t','w','a','r','e','\\',
  47. 'M','i','c','r','o','s','o','f','t','\\',
  48. 'W','i','n','d','o','w','s',' ','N','T','\\',
  49. 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
  50. 'A','e','D','e','b','u','g',0};
  51. static const WCHAR wszDebugger[] = {'D','e','b','u','g','g','e','r',0};
  52. LoadStringW(hInst, IDS_WARNING_TITLE, wszWarnTitle, ARRAY_SIZE(wszWarnTitle));
  53. LoadStringW(hInst, IDS_DEBUG_UNABLE2DEBUG, wszUnable2Debug, ARRAY_SIZE(wszUnable2Debug));
  54. LoadStringW(hInst, IDS_DEBUG_MESSAGE, wszWarnMsg, ARRAY_SIZE(wszWarnMsg));
  55. Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
  56. for (Index=0; Index<Count; Index++)
  57. {
  58. lvitem.mask = LVIF_STATE;
  59. lvitem.stateMask = LVIS_SELECTED;
  60. lvitem.iItem = Index;
  61. lvitem.iSubItem = 0;
  62. SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
  63. if (lvitem.state & LVIS_SELECTED)
  64. break;
  65. }
  66. Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
  67. dwProcessId = PerfDataGetProcessId(Index);
  68. if ((Count != 1) || (dwProcessId == 0))
  69. return;
  70. if (MessageBoxW(hMainWnd, wszWarnMsg, wszWarnTitle, MB_YESNO|MB_ICONWARNING) != IDYES)
  71. {
  72. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  73. MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Debug, MB_OK|MB_ICONSTOP);
  74. return;
  75. }
  76. if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, wszSubKey, 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  77. {
  78. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  79. MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Debug, MB_OK|MB_ICONSTOP);
  80. return;
  81. }
  82. dwDebuggerSize = 260;
  83. if (RegQueryValueExW(hKey, wszDebugger, NULL, NULL, (LPBYTE)wstrDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
  84. {
  85. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  86. MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Debug, MB_OK|MB_ICONSTOP);
  87. RegCloseKey(hKey);
  88. return;
  89. }
  90. RegCloseKey(hKey);
  91. hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
  92. if (!hDebugEvent)
  93. {
  94. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  95. MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Debug, MB_OK|MB_ICONSTOP);
  96. return;
  97. }
  98. wsprintfW(wstrDebugPath, wstrDebugger, dwProcessId, hDebugEvent);
  99. memset(&pi, 0, sizeof(PROCESS_INFORMATION));
  100. memset(&si, 0, sizeof(STARTUPINFOW));
  101. si.cb = sizeof(STARTUPINFOW);
  102. if (!CreateProcessW(NULL, wstrDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
  103. {
  104. GetLastErrorText(wstrErrorText, ARRAY_SIZE(wstrErrorText));
  105. MessageBoxW(hMainWnd, wstrErrorText, wszUnable2Debug, MB_OK|MB_ICONSTOP);
  106. }
  107. CloseHandle(hDebugEvent);
  108. }