2004-03-23 02:19:54 +01:00
|
|
|
/*
|
|
|
|
* ReactOS Task Manager
|
|
|
|
*
|
|
|
|
* dbgchnl.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 - 2004 Eric Pouech
|
2008-08-20 10:34:48 +02:00
|
|
|
* Copyright (C) 2008 Vladimir Pankratov
|
2004-03-23 02:19:54 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-03-23 02:19:54 +01:00
|
|
|
*/
|
2012-01-23 12:04:05 +01:00
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
#include <ctype.h>
|
2004-03-23 02:19:54 +01:00
|
|
|
#include <stdio.h>
|
2012-01-23 12:04:05 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
2004-03-23 02:19:54 +01:00
|
|
|
#include <winnt.h>
|
2012-01-23 12:04:05 +01:00
|
|
|
|
2004-03-23 02:19:54 +01:00
|
|
|
#include "taskmgr.h"
|
|
|
|
#include "perfdata.h"
|
|
|
|
#include "column.h"
|
2005-09-28 17:21:48 +02:00
|
|
|
#include "wine/debug.h"
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
* - the dialog box could be non modal
|
|
|
|
* - in that case,
|
|
|
|
* + could refresh channels from time to time
|
|
|
|
* + set the name of exec (and perhaps its pid) in dialog title
|
|
|
|
* - get a better UI (replace the 'x' by real tick boxes in list view)
|
|
|
|
* - enhance visual feedback: the list is large, and it's hard to get the
|
|
|
|
* right line when clicking on rightmost column (trace for example)
|
|
|
|
* - get rid of printfs (error reporting) and use real message boxes
|
|
|
|
* - include the column width settings in the full column management scheme
|
|
|
|
* - use more global settings (like having a temporary on/off
|
|
|
|
* setting for a fixme:s or err:s
|
|
|
|
*/
|
|
|
|
|
|
|
|
static DWORD get_selected_pid(void)
|
|
|
|
{
|
2011-05-18 14:06:29 +02:00
|
|
|
LVITEMW lvitem;
|
|
|
|
ULONG Index, Count;
|
2004-03-23 02:19:54 +01:00
|
|
|
DWORD dwProcessId;
|
|
|
|
|
2011-05-18 14:06:29 +02:00
|
|
|
Count = SendMessageW(hProcessPageListCtrl, LVM_GETITEMCOUNT, 0, 0);
|
|
|
|
for (Index = 0; Index < Count; Index++)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
|
|
|
lvitem.mask = LVIF_STATE;
|
|
|
|
lvitem.stateMask = LVIS_SELECTED;
|
|
|
|
lvitem.iItem = Index;
|
2006-10-05 11:02:27 +02:00
|
|
|
lvitem.iSubItem = 0;
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2011-05-18 14:06:29 +02:00
|
|
|
SendMessageW(hProcessPageListCtrl, LVM_GETITEMW, 0, (LPARAM) &lvitem);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
if (lvitem.state & LVIS_SELECTED)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-18 14:06:29 +02:00
|
|
|
Count = SendMessageW(hProcessPageListCtrl, LVM_GETSELECTEDCOUNT, 0, 0);
|
2004-03-23 02:19:54 +01:00
|
|
|
dwProcessId = PerfDataGetProcessId(Index);
|
2011-05-18 14:06:29 +02:00
|
|
|
if ((Count != 1) || (dwProcessId == 0))
|
2004-03-23 02:19:54 +01:00
|
|
|
return 0;
|
|
|
|
return dwProcessId;
|
|
|
|
}
|
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
static int list_channel_CB(HANDLE hProcess, void* addr, struct __wine_debug_channel* channel, void* user)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
|
|
|
int j;
|
2011-05-18 14:06:29 +02:00
|
|
|
WCHAR nameW[sizeof(channel->name)], val[2];
|
|
|
|
LVITEMW lvitem;
|
2004-03-23 02:19:54 +01:00
|
|
|
int index;
|
2008-12-08 04:07:58 +01:00
|
|
|
HWND hChannelLV = user;
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2018-07-24 00:01:16 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, channel->name, sizeof(channel->name), nameW, ARRAY_SIZE(nameW));
|
2011-05-18 14:06:29 +02:00
|
|
|
|
2006-10-05 11:02:27 +02:00
|
|
|
lvitem.mask = LVIF_TEXT;
|
2011-05-18 14:06:29 +02:00
|
|
|
lvitem.pszText = nameW;
|
2006-10-05 11:02:27 +02:00
|
|
|
lvitem.iItem = 0;
|
|
|
|
lvitem.iSubItem = 0;
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2011-05-18 14:06:29 +02:00
|
|
|
index = ListView_InsertItemW(hChannelLV, &lvitem);
|
2004-03-23 02:19:54 +01:00
|
|
|
if (index == -1) return 0;
|
|
|
|
|
|
|
|
val[1] = '\0';
|
|
|
|
for (j = 0; j < 4; j++)
|
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
val[0] = (channel->flags & (1 << j)) ? 'x' : ' ';
|
2009-08-24 06:55:22 +02:00
|
|
|
ListView_SetItemTextW(hChannelLV, index, j + 1, val);
|
2004-03-23 02:19:54 +01:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cce_user
|
|
|
|
{
|
|
|
|
const char* name; /* channel to look for */
|
|
|
|
unsigned value, mask; /* how to change channel */
|
|
|
|
unsigned done; /* number of successful changes */
|
|
|
|
unsigned notdone; /* number of unsuccessful changes */
|
|
|
|
};
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* change_channel_CB
|
|
|
|
*
|
|
|
|
* Callback used for changing a given channel attributes
|
|
|
|
*/
|
2005-09-28 17:21:48 +02:00
|
|
|
static int change_channel_CB(HANDLE hProcess, void* addr, struct __wine_debug_channel *channel, void* pmt)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
|
|
|
struct cce_user* user = (struct cce_user*)pmt;
|
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
if (!user->name || !strcmp(channel->name, user->name))
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
channel->flags = (channel->flags & ~user->mask) | (user->value & user->mask);
|
|
|
|
if (WriteProcessMemory(hProcess, addr, channel, sizeof(*channel), NULL))
|
2004-03-23 02:19:54 +01:00
|
|
|
user->done++;
|
|
|
|
else
|
|
|
|
user->notdone++;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-28 17:21:48 +02:00
|
|
|
typedef int (*EnumChannelCB)(HANDLE, void*, struct __wine_debug_channel*, void*);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* enum_channel
|
|
|
|
*
|
|
|
|
* Enumerates all known channels on process hProcess through callback
|
|
|
|
* ce.
|
|
|
|
*/
|
2005-12-19 18:16:57 +01:00
|
|
|
static int enum_channel(HANDLE hProcess, EnumChannelCB ce, void* user)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
struct __wine_debug_channel channel;
|
2021-05-24 21:32:11 +02:00
|
|
|
PROCESS_BASIC_INFORMATION info;
|
2005-09-28 17:21:48 +02:00
|
|
|
int ret = 1;
|
2004-03-23 02:19:54 +01:00
|
|
|
void* addr;
|
|
|
|
|
2021-05-24 21:32:11 +02:00
|
|
|
NtQueryInformationProcess( hProcess, ProcessBasicInformation, &info, sizeof(info), NULL );
|
|
|
|
#ifdef _WIN64
|
|
|
|
addr = (char *)info.PebBaseAddress + 0x2000;
|
|
|
|
#else
|
|
|
|
addr = (char *)info.PebBaseAddress + 0x1000;
|
|
|
|
#endif
|
2005-09-28 17:21:48 +02:00
|
|
|
while (ret && addr && ReadProcessMemory(hProcess, addr, &channel, sizeof(channel), NULL))
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
2005-09-28 17:21:48 +02:00
|
|
|
if (!channel.name[0]) break;
|
|
|
|
ret = ce(hProcess, addr, &channel, user);
|
|
|
|
addr = (struct __wine_debug_channel *)addr + 1;
|
2004-03-23 02:19:54 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DebugChannels_FillList(HWND hChannelLV)
|
|
|
|
{
|
|
|
|
HANDLE hProcess;
|
|
|
|
|
2011-05-18 14:06:29 +02:00
|
|
|
SendMessageW(hChannelLV, LVM_DELETEALLITEMS, 0, 0);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
2005-12-19 18:16:57 +01:00
|
|
|
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ, FALSE, get_selected_pid());
|
2004-03-23 02:19:54 +01:00
|
|
|
if (!hProcess) return; /* FIXME messagebox */
|
2011-05-18 14:06:29 +02:00
|
|
|
SendMessageW(hChannelLV, WM_SETREDRAW, FALSE, 0);
|
2005-12-19 18:16:57 +01:00
|
|
|
enum_channel(hProcess, list_channel_CB, (void*)hChannelLV);
|
2011-05-18 14:06:29 +02:00
|
|
|
SendMessageW(hChannelLV, WM_SETREDRAW, TRUE, 0);
|
2004-03-23 02:19:54 +01:00
|
|
|
CloseHandle(hProcess);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DebugChannels_OnCreate(HWND hwndDlg)
|
|
|
|
{
|
2012-02-08 19:34:29 +01:00
|
|
|
static WCHAR fixmeW[] = {'F','i','x','m','e','\0'};
|
|
|
|
static WCHAR errW[] = {'E','r','r','\0'};
|
|
|
|
static WCHAR warnW[] = {'W','a','r','n','\0'};
|
|
|
|
static WCHAR traceW[] = {'T','r','a','c','e','\0'};
|
2004-03-23 02:19:54 +01:00
|
|
|
HWND hLV = GetDlgItem(hwndDlg, IDC_DEBUG_CHANNELS_LIST);
|
2008-08-20 10:34:48 +02:00
|
|
|
LVCOLUMNW lvc;
|
2009-06-25 21:43:11 +02:00
|
|
|
WCHAR debug_channelW[255];
|
|
|
|
|
2018-07-24 00:01:16 +02:00
|
|
|
LoadStringW(hInst, IDS_DEBUG_CHANNEL, debug_channelW, ARRAY_SIZE(debug_channelW));
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
lvc.fmt = LVCFMT_LEFT;
|
2008-08-20 10:34:48 +02:00
|
|
|
lvc.pszText = debug_channelW;
|
2004-03-23 02:19:54 +01:00
|
|
|
lvc.cx = 100;
|
2008-08-20 10:34:48 +02:00
|
|
|
SendMessageW(hLV, LVM_INSERTCOLUMNW, 0, (LPARAM) &lvc);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
lvc.fmt = LVCFMT_CENTER;
|
2008-08-20 10:34:48 +02:00
|
|
|
lvc.pszText = fixmeW;
|
2004-03-23 02:19:54 +01:00
|
|
|
lvc.cx = 55;
|
2008-08-20 10:34:48 +02:00
|
|
|
SendMessageW(hLV, LVM_INSERTCOLUMNW, 1, (LPARAM) &lvc);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
lvc.fmt = LVCFMT_CENTER;
|
2008-08-20 10:34:48 +02:00
|
|
|
lvc.pszText = errW;
|
2004-03-23 02:19:54 +01:00
|
|
|
lvc.cx = 55;
|
2008-08-20 10:34:48 +02:00
|
|
|
SendMessageW(hLV, LVM_INSERTCOLUMNW, 2, (LPARAM) &lvc);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
lvc.fmt = LVCFMT_CENTER;
|
2008-08-20 10:34:48 +02:00
|
|
|
lvc.pszText = warnW;
|
2004-03-23 02:19:54 +01:00
|
|
|
lvc.cx = 55;
|
2008-08-20 10:34:48 +02:00
|
|
|
SendMessageW(hLV, LVM_INSERTCOLUMNW, 3, (LPARAM) &lvc);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
|
|
|
|
lvc.fmt = LVCFMT_CENTER;
|
2008-08-20 10:34:48 +02:00
|
|
|
lvc.pszText = traceW;
|
2004-03-23 02:19:54 +01:00
|
|
|
lvc.cx = 55;
|
2008-08-20 10:34:48 +02:00
|
|
|
SendMessageW(hLV, LVM_INSERTCOLUMNW, 4, (LPARAM) &lvc);
|
2004-03-23 02:19:54 +01:00
|
|
|
|
|
|
|
DebugChannels_FillList(hLV);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DebugChannels_OnNotify(HWND hDlg, LPARAM lParam)
|
|
|
|
{
|
|
|
|
NMHDR* nmh = (NMHDR*)lParam;
|
|
|
|
|
|
|
|
switch (nmh->code)
|
|
|
|
{
|
|
|
|
case NM_CLICK:
|
|
|
|
if (nmh->idFrom == IDC_DEBUG_CHANNELS_LIST)
|
|
|
|
{
|
|
|
|
LVHITTESTINFO lhti;
|
|
|
|
HWND hChannelLV;
|
|
|
|
HANDLE hProcess;
|
|
|
|
NMITEMACTIVATE* nmia = (NMITEMACTIVATE*)lParam;
|
|
|
|
|
2015-10-14 19:27:10 +02:00
|
|
|
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE,
|
|
|
|
FALSE, get_selected_pid());
|
2004-03-23 02:19:54 +01:00
|
|
|
if (!hProcess) return; /* FIXME message box */
|
|
|
|
lhti.pt = nmia->ptAction;
|
|
|
|
hChannelLV = GetDlgItem(hDlg, IDC_DEBUG_CHANNELS_LIST);
|
2011-05-18 14:06:29 +02:00
|
|
|
SendMessageW(hChannelLV, LVM_SUBITEMHITTEST, 0, (LPARAM)&lhti);
|
2004-03-23 02:19:54 +01:00
|
|
|
if (nmia->iSubItem >= 1 && nmia->iSubItem <= 4)
|
|
|
|
{
|
2009-08-24 06:55:22 +02:00
|
|
|
WCHAR val[2];
|
|
|
|
char name[32];
|
2004-03-23 02:19:54 +01:00
|
|
|
unsigned bitmask = 1 << (lhti.iSubItem - 1);
|
|
|
|
struct cce_user user;
|
|
|
|
|
2018-07-24 00:01:16 +02:00
|
|
|
ListView_GetItemTextA(hChannelLV, lhti.iItem, 0, name, ARRAY_SIZE(name));
|
|
|
|
ListView_GetItemTextW(hChannelLV, lhti.iItem, lhti.iSubItem, val, ARRAY_SIZE(val));
|
2004-03-23 02:19:54 +01:00
|
|
|
user.name = name;
|
|
|
|
user.value = (val[0] == 'x') ? 0 : bitmask;
|
|
|
|
user.mask = bitmask;
|
|
|
|
user.done = user.notdone = 0;
|
2005-12-19 18:16:57 +01:00
|
|
|
enum_channel(hProcess, change_channel_CB, &user);
|
2004-03-23 02:19:54 +01:00
|
|
|
if (user.done)
|
|
|
|
{
|
|
|
|
val[0] ^= ('x' ^ ' ');
|
2009-08-24 06:55:22 +02:00
|
|
|
ListView_SetItemTextW(hChannelLV, lhti.iItem, lhti.iSubItem, val);
|
2004-03-23 02:19:54 +01:00
|
|
|
}
|
|
|
|
if (user.notdone)
|
2005-12-19 18:16:57 +01:00
|
|
|
printf("Some channel instances weren't correctly set\n");
|
2004-03-23 02:19:54 +01:00
|
|
|
}
|
|
|
|
CloseHandle(hProcess);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-14 12:06:09 +02:00
|
|
|
static INT_PTR CALLBACK DebugChannelsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
2004-03-23 02:19:54 +01:00
|
|
|
{
|
|
|
|
switch (message)
|
|
|
|
{
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
DebugChannels_OnCreate(hDlg);
|
|
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
|
|
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
|
|
|
{
|
|
|
|
EndDialog(hDlg, LOWORD(wParam));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NOTIFY:
|
|
|
|
DebugChannels_OnNotify(hDlg, lParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessPage_OnDebugChannels(void)
|
|
|
|
{
|
2008-08-20 10:34:48 +02:00
|
|
|
DialogBoxW(hInst, (LPCWSTR)IDD_DEBUG_CHANNELS_DIALOG, hMainWnd, DebugChannelsDlgProc);
|
2004-03-23 02:19:54 +01:00
|
|
|
}
|