8 german language files (update)
[reactos.git] / reactos / subsys / system / taskmgr / debug.c
1 /*
2 * ReactOS Task Manager
3 *
4 * debug.cpp
5 *
6 * Copyright (C) 1999 - 2001 Brian Palmer <brianp@reactos.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include "precomp.h"
24 #include <commctrl.h>
25 #include <stdlib.h>
26 #include <malloc.h>
27 #include <memory.h>
28 #include <tchar.h>
29 #include <stdio.h>
30 #include <winnt.h>
31
32 #include "debug.h"
33 #include "procpage.h"
34 #include "perfdata.h"
35
36 void ProcessPage_OnDebug(void)
37 {
38 LVITEM lvitem;
39 ULONG Index;
40 DWORD dwProcessId;
41 TCHAR strErrorText[260];
42 HKEY hKey;
43 TCHAR strDebugPath[260];
44 TCHAR strDebugger[260];
45 DWORD dwDebuggerSize;
46 PROCESS_INFORMATION pi;
47 STARTUPINFO si;
48 HANDLE hDebugEvent;
49
50 for (Index=0; Index<(ULONG)ListView_GetItemCount(hProcessPageListCtrl); Index++)
51 {
52 memset(&lvitem, 0, sizeof(LVITEM));
53
54 lvitem.mask = LVIF_STATE;
55 lvitem.stateMask = LVIS_SELECTED;
56 lvitem.iItem = Index;
57
58 ListView_GetItem(hProcessPageListCtrl, &lvitem);
59
60 if (lvitem.state & LVIS_SELECTED)
61 break;
62 }
63
64 dwProcessId = PerfDataGetProcessId(Index);
65
66 if ((ListView_GetSelectedCount(hProcessPageListCtrl) != 1) || (dwProcessId == 0))
67 return;
68
69 if (MessageBox(hMainWnd, _T("WARNING: Debugging this process may result in loss of data.\nAre you sure you wish to attach the debugger?"), _T("Task Manager Warning"), MB_YESNO|MB_ICONWARNING) != IDYES)
70 {
71 GetLastErrorText(strErrorText, 260);
72 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
73 return;
74 }
75
76 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug"), 0, KEY_READ, &hKey) != ERROR_SUCCESS)
77 {
78 GetLastErrorText(strErrorText, 260);
79 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
80 return;
81 }
82
83 dwDebuggerSize = 260;
84 if (RegQueryValueEx(hKey, _T("Debugger"), NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
85 {
86 GetLastErrorText(strErrorText, 260);
87 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
88 RegCloseKey(hKey);
89 return;
90 }
91
92 RegCloseKey(hKey);
93
94 hDebugEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
95 if (!hDebugEvent)
96 {
97 GetLastErrorText(strErrorText, 260);
98 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
99 return;
100 }
101
102 wsprintf(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
103
104 memset(&pi, 0, sizeof(PROCESS_INFORMATION));
105 memset(&si, 0, sizeof(STARTUPINFO));
106 si.cb = sizeof(STARTUPINFO);
107 if (!CreateProcess(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
108 {
109 GetLastErrorText(strErrorText, 260);
110 MessageBox(hMainWnd, strErrorText, _T("Unable to Debug Process"), MB_OK|MB_ICONSTOP);
111 }
112
113 CloseHandle(hDebugEvent);
114 }