9c1f8708a487d686dccc9ef0f9f468760d086833
[reactos.git] / reactos / base / applications / taskmgr / debug.c
1 /*
2 * ReactOS Task Manager
3 *
4 * debug.cpp
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 * 2005 Klemens Friedl <frik85@reactos.at>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <precomp.h>
25
26 void ProcessPage_OnDebug(void)
27 {
28 LVITEM lvitem;
29 ULONG Index;
30 DWORD dwProcessId;
31 WCHAR strErrorText[260];
32 HKEY hKey;
33 WCHAR strDebugPath[260];
34 WCHAR strDebugger[260];
35 DWORD dwDebuggerSize;
36 PROCESS_INFORMATION pi;
37 STARTUPINFOW si;
38 HANDLE hDebugEvent;
39 WCHAR szTemp[256];
40 WCHAR szTempA[256];
41
42
43 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
44 {
45 memset(&lvitem, 0, sizeof(LVITEM));
46
47 lvitem.mask = LVIF_STATE;
48 lvitem.stateMask = LVIS_SELECTED;
49 lvitem.iItem = Index;
50
51 (void)ListView_GetItem(hProcessPageListCtrl, &lvitem);
52
53 if (lvitem.state & LVIS_SELECTED)
54 break;
55 }
56
57 dwProcessId = PerfDataGetProcessId(Index);
58
59 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
60 return;
61
62 LoadStringW(hInst, IDS_MSG_WARNINGDEBUG, szTemp, 256);
63 LoadStringW(hInst, IDS_MSG_TASKMGRWARNING, szTempA, 256);
64
65 if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO|MB_ICONWARNING) != IDYES)
66 {
67 GetLastErrorText(strErrorText, 260);
68 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
69 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
70 return;
71 }
72
73 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
74 {
75 GetLastErrorText(strErrorText, 260);
76 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
77 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
78 return;
79 }
80
81 dwDebuggerSize = 260;
82 if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
83 {
84 GetLastErrorText(strErrorText, 260);
85 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
86 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
87 RegCloseKey(hKey);
88 return;
89 }
90
91 RegCloseKey(hKey);
92
93 hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
94 if (!hDebugEvent)
95 {
96 GetLastErrorText(strErrorText, 260);
97 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
98 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
99 return;
100 }
101
102 wsprintfW(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
103
104 memset(&pi, 0, sizeof(PROCESS_INFORMATION));
105 memset(&si, 0, sizeof(STARTUPINFOW));
106 si.cb = sizeof(STARTUPINFOW);
107 if (!CreateProcessW(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
108 {
109 GetLastErrorText(strErrorText, 260);
110 LoadStringW(hInst, IDS_MSG_UNABLEDEBUGPROCESS, szTemp, 256);
111 MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK|MB_ICONSTOP);
112 }
113
114 CloseHandle(hDebugEvent);
115 }