ReactOS  0.4.12-dev-43-g63b00d8
debug.c
Go to the documentation of this file.
1 /*
2  * ReactOS Task Manager
3  *
4  * debug.c
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "precomp.h"
25 
27 {
28  DWORD dwProcessId;
29  WCHAR strErrorText[260];
30  HKEY hKey;
31  WCHAR strDebugPath[260];
32  WCHAR strDebugger[260];
33  DWORD dwDebuggerSize;
35  STARTUPINFOW si;
36  HANDLE hDebugEvent;
37  WCHAR szTemp[256];
38  WCHAR szTempA[256];
39 
40  dwProcessId = GetSelectedProcessId();
41 
42  if (dwProcessId == 0)
43  return;
44 
47 
48  if (MessageBoxW(hMainWnd, szTemp, szTempA, MB_YESNO | MB_ICONWARNING) != IDYES)
49  {
50  GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText));
52  MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP);
53  return;
54  }
55 
56  if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
57  {
58  GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText));
60  MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP);
61  return;
62  }
63 
64  dwDebuggerSize = sizeof(strDebugger);
65  if (RegQueryValueExW(hKey, L"Debugger", NULL, NULL, (LPBYTE)strDebugger, &dwDebuggerSize) != ERROR_SUCCESS)
66  {
67  GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText));
69  MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP);
70  RegCloseKey(hKey);
71  return;
72  }
73 
74  RegCloseKey(hKey);
75 
76  hDebugEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
77  if (!hDebugEvent)
78  {
79  GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText));
81  MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP);
82  return;
83  }
84 
85  wsprintfW(strDebugPath, strDebugger, dwProcessId, hDebugEvent);
86 
87  ZeroMemory(&pi, sizeof(pi));
88  ZeroMemory(&si, sizeof(si));
89  si.cb = sizeof(si);
90  if (!CreateProcessW(NULL, strDebugPath, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
91  {
92  GetLastErrorText(strErrorText, ARRAYSIZE(strErrorText));
94  MessageBoxW(hMainWnd, strErrorText, szTemp, MB_OK | MB_ICONSTOP);
95  }
96  else
97  {
98  CloseHandle(pi.hThread);
100  }
101 
102  CloseHandle(hDebugEvent);
103 }
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
DWORD GetSelectedProcessId(void)
Definition: procpage.c:99
#define CloseHandle
Definition: compat.h:398
#define ERROR_SUCCESS
Definition: deptool.c:10
#define IDYES
Definition: winuser.h:829
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define ZeroMemory
Definition: winbase.h:1635
#define MB_ICONSTOP
Definition: winuser.h:797
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
#define MB_ICONWARNING
Definition: winuser.h:780
void ProcessPage_OnDebug(void)
Definition: debug.c:26
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
#define MB_YESNO
Definition: winuser.h:811
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4623
DWORD cb
Definition: winbase.h:817
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
unsigned long DWORD
Definition: ntddk_ex.h:95
static DWORD pi
Definition: protocol.c:150
#define IDS_MSG_UNABLEDEBUGPROCESS
Definition: resource.h:244
HWND hMainWnd
Definition: magnifier.c:33
static const WCHAR L[]
Definition: oid.c:1087
#define IDS_MSG_TASKMGRWARNING
Definition: resource.h:246
HINSTANCE hInst
Definition: dxdiag.c:13
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
LPWSTR GetLastErrorText(LPWSTR lpszBuf, DWORD dwSize)
Definition: taskmgr.c:1152
#define MB_OK
Definition: winuser.h:784
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
#define IDS_MSG_WARNINGDEBUG
Definition: resource.h:245
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12