6 * Copyright (C) 2003 - 2004 Eric Pouech
7 * Copyright (C) 2008 Vladimir Pankratov
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.
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.
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
35 #include "wine/debug.h"
38 * - the dialog box could be non modal
40 * + could refresh channels from time to time
41 * + set the name of exec (and perhaps its pid) in dialog title
42 * - get a better UI (replace the 'x' by real tick boxes in list view)
43 * - enhance visual feedback: the list is large, and it's hard to get the
44 * right line when clicking on rightmost column (trace for example)
45 * - get rid of printfs (error reporting) and use real message boxes
46 * - include the column width settings in the full column management scheme
47 * - use more global settings (like having a temporary on/off
48 * setting for a fixme:s or err:s
51 static DWORD
get_selected_pid(void)
57 Count
= SendMessageW(hProcessPageListCtrl
, LVM_GETITEMCOUNT
, 0, 0);
58 for (Index
= 0; Index
< Count
; Index
++)
60 lvitem
.mask
= LVIF_STATE
;
61 lvitem
.stateMask
= LVIS_SELECTED
;
65 SendMessageW(hProcessPageListCtrl
, LVM_GETITEMW
, 0, (LPARAM
) &lvitem
);
67 if (lvitem
.state
& LVIS_SELECTED
)
71 Count
= SendMessageW(hProcessPageListCtrl
, LVM_GETSELECTEDCOUNT
, 0, 0);
72 dwProcessId
= PerfDataGetProcessId(Index
);
73 if ((Count
!= 1) || (dwProcessId
== 0))
78 static int list_channel_CB(HANDLE hProcess
, void* addr
, struct __wine_debug_channel
* channel
, void* user
)
81 WCHAR nameW
[sizeof(channel
->name
)], val
[2];
84 HWND hChannelLV
= user
;
86 MultiByteToWideChar(CP_ACP
, 0, channel
->name
, sizeof(channel
->name
), nameW
, ARRAY_SIZE(nameW
));
88 lvitem
.mask
= LVIF_TEXT
;
89 lvitem
.pszText
= nameW
;
93 index
= ListView_InsertItemW(hChannelLV
, &lvitem
);
94 if (index
== -1) return 0;
97 for (j
= 0; j
< 4; j
++)
99 val
[0] = (channel
->flags
& (1 << j
)) ? 'x' : ' ';
100 ListView_SetItemTextW(hChannelLV
, index
, j
+ 1, val
);
107 const char* name
; /* channel to look for */
108 unsigned value
, mask
; /* how to change channel */
109 unsigned done
; /* number of successful changes */
110 unsigned notdone
; /* number of unsuccessful changes */
113 /******************************************************************
116 * Callback used for changing a given channel attributes
118 static int change_channel_CB(HANDLE hProcess
, void* addr
, struct __wine_debug_channel
*channel
, void* pmt
)
120 struct cce_user
* user
= (struct cce_user
*)pmt
;
122 if (!user
->name
|| !strcmp(channel
->name
, user
->name
))
124 channel
->flags
= (channel
->flags
& ~user
->mask
) | (user
->value
& user
->mask
);
125 if (WriteProcessMemory(hProcess
, addr
, channel
, sizeof(*channel
), NULL
))
134 typedef int (*EnumChannelCB
)(HANDLE
, void*, struct __wine_debug_channel
*, void*);
136 /******************************************************************
139 * Enumerates all known channels on process hProcess through callback
142 static int enum_channel(HANDLE hProcess
, EnumChannelCB ce
, void* user
)
144 struct __wine_debug_channel channel
;
145 PROCESS_BASIC_INFORMATION info
;
149 NtQueryInformationProcess( hProcess
, ProcessBasicInformation
, &info
, sizeof(info
), NULL
);
151 addr
= (char *)info
.PebBaseAddress
+ 0x2000;
153 addr
= (char *)info
.PebBaseAddress
+ 0x1000;
155 while (ret
&& addr
&& ReadProcessMemory(hProcess
, addr
, &channel
, sizeof(channel
), NULL
))
157 if (!channel
.name
[0]) break;
158 ret
= ce(hProcess
, addr
, &channel
, user
);
159 addr
= (struct __wine_debug_channel
*)addr
+ 1;
164 static void DebugChannels_FillList(HWND hChannelLV
)
168 SendMessageW(hChannelLV
, LVM_DELETEALLITEMS
, 0, 0);
170 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_OPERATION
| PROCESS_VM_READ
, FALSE
, get_selected_pid());
171 if (!hProcess
) return; /* FIXME messagebox */
172 SendMessageW(hChannelLV
, WM_SETREDRAW
, FALSE
, 0);
173 enum_channel(hProcess
, list_channel_CB
, (void*)hChannelLV
);
174 SendMessageW(hChannelLV
, WM_SETREDRAW
, TRUE
, 0);
175 CloseHandle(hProcess
);
178 static void DebugChannels_OnCreate(HWND hwndDlg
)
180 static WCHAR fixmeW
[] = {'F','i','x','m','e','\0'};
181 static WCHAR errW
[] = {'E','r','r','\0'};
182 static WCHAR warnW
[] = {'W','a','r','n','\0'};
183 static WCHAR traceW
[] = {'T','r','a','c','e','\0'};
184 HWND hLV
= GetDlgItem(hwndDlg
, IDC_DEBUG_CHANNELS_LIST
);
186 WCHAR debug_channelW
[255];
188 LoadStringW(hInst
, IDS_DEBUG_CHANNEL
, debug_channelW
, ARRAY_SIZE(debug_channelW
));
190 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
191 lvc
.fmt
= LVCFMT_LEFT
;
192 lvc
.pszText
= debug_channelW
;
194 SendMessageW(hLV
, LVM_INSERTCOLUMNW
, 0, (LPARAM
) &lvc
);
196 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
197 lvc
.fmt
= LVCFMT_CENTER
;
198 lvc
.pszText
= fixmeW
;
200 SendMessageW(hLV
, LVM_INSERTCOLUMNW
, 1, (LPARAM
) &lvc
);
202 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
203 lvc
.fmt
= LVCFMT_CENTER
;
206 SendMessageW(hLV
, LVM_INSERTCOLUMNW
, 2, (LPARAM
) &lvc
);
208 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
209 lvc
.fmt
= LVCFMT_CENTER
;
212 SendMessageW(hLV
, LVM_INSERTCOLUMNW
, 3, (LPARAM
) &lvc
);
214 lvc
.mask
= LVCF_FMT
| LVCF_TEXT
| LVCF_WIDTH
;
215 lvc
.fmt
= LVCFMT_CENTER
;
216 lvc
.pszText
= traceW
;
218 SendMessageW(hLV
, LVM_INSERTCOLUMNW
, 4, (LPARAM
) &lvc
);
220 DebugChannels_FillList(hLV
);
223 static void DebugChannels_OnNotify(HWND hDlg
, LPARAM lParam
)
225 NMHDR
* nmh
= (NMHDR
*)lParam
;
230 if (nmh
->idFrom
== IDC_DEBUG_CHANNELS_LIST
)
235 NMITEMACTIVATE
* nmia
= (NMITEMACTIVATE
*)lParam
;
237 hProcess
= OpenProcess(PROCESS_QUERY_INFORMATION
| PROCESS_VM_OPERATION
| PROCESS_VM_READ
| PROCESS_VM_WRITE
,
238 FALSE
, get_selected_pid());
239 if (!hProcess
) return; /* FIXME message box */
240 lhti
.pt
= nmia
->ptAction
;
241 hChannelLV
= GetDlgItem(hDlg
, IDC_DEBUG_CHANNELS_LIST
);
242 SendMessageW(hChannelLV
, LVM_SUBITEMHITTEST
, 0, (LPARAM
)&lhti
);
243 if (nmia
->iSubItem
>= 1 && nmia
->iSubItem
<= 4)
247 unsigned bitmask
= 1 << (lhti
.iSubItem
- 1);
248 struct cce_user user
;
250 ListView_GetItemTextA(hChannelLV
, lhti
.iItem
, 0, name
, ARRAY_SIZE(name
));
251 ListView_GetItemTextW(hChannelLV
, lhti
.iItem
, lhti
.iSubItem
, val
, ARRAY_SIZE(val
));
253 user
.value
= (val
[0] == 'x') ? 0 : bitmask
;
255 user
.done
= user
.notdone
= 0;
256 enum_channel(hProcess
, change_channel_CB
, &user
);
259 val
[0] ^= ('x' ^ ' ');
260 ListView_SetItemTextW(hChannelLV
, lhti
.iItem
, lhti
.iSubItem
, val
);
263 printf("Some channel instances weren't correctly set\n");
265 CloseHandle(hProcess
);
271 static INT_PTR CALLBACK
DebugChannelsDlgProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
276 DebugChannels_OnCreate(hDlg
);
279 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
281 EndDialog(hDlg
, LOWORD(wParam
));
286 DebugChannels_OnNotify(hDlg
, lParam
);
292 void ProcessPage_OnDebugChannels(void)
294 DialogBoxW(hInst
, (LPCWSTR
)IDD_DEBUG_CHANNELS_DIALOG
, hMainWnd
, DebugChannelsDlgProc
);