2 * Wine debugger utility routines
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
20 /***********************************************************************
23 * Implementation of the 'print' command.
25 void DEBUG_PrintBasic( const DBG_VALUE
* value
, int count
, char format
)
27 char * default_format
;
30 assert(value
->cookie
== DV_TARGET
|| value
->cookie
== DV_HOST
);
31 if( value
->type
== NULL
)
33 DEBUG_Printf(DBG_CHN_MESG
, "Unable to evaluate expression\n");
37 default_format
= NULL
;
38 res
= DEBUG_GetExprValue(value
, &default_format
);
45 DEBUG_nchar
+= DEBUG_Printf( DBG_CHN_MESG
, "0x%04lx", (long unsigned int) res
);
49 DEBUG_nchar
+= DEBUG_Printf( DBG_CHN_MESG
, "0x%08lx", (long unsigned int) res
);
54 DEBUG_nchar
+= DEBUG_Printf( DBG_CHN_MESG
, "%ld\n", (long int) res
);
58 DEBUG_nchar
+= DEBUG_Printf( DBG_CHN_MESG
, "%d = '%c'",
59 (char)(res
& 0xff), (char)(res
& 0xff) );
66 DEBUG_Printf( DBG_CHN_MESG
, "Format specifier '%c' is meaningless in 'print' command\n", format
);
68 if( default_format
!= NULL
)
70 if (strstr(default_format
, "%S") == NULL
)
72 DEBUG_nchar
+= DEBUG_Printf( DBG_CHN_MESG
, default_format
, res
);
79 /* FIXME: simplistic implementation for default_format being
80 * foo%Sbar => will print foo, then string then bar
82 for (ptr
= default_format
; *ptr
; ptr
++)
84 DEBUG_Printf(DBG_CHN_MESG
, "[%c]", *ptr
);
86 if (*ptr
== '%') state
++;
92 char* str
= (char*)(long)res
;
94 for (; DEBUG_READ_MEM(str
, &ch
, 1) && ch
; str
++) {
101 /* shouldn't happen */
121 /***********************************************************************
124 * Print an 16- or 32-bit address, with the nearest symbol if any.
127 DEBUG_PrintAddress( const DBG_ADDR
*addr
, int addrlen
, int flag
)
129 struct symbol_info rtn
;
131 const char *name
= DEBUG_FindNearestSymbol( addr
, flag
, &rtn
.sym
, 0,
134 if (addr
->seg
) DEBUG_Printf( DBG_CHN_MESG
, "0x%04lx:", addr
->seg
&0xFFFF );
135 if (addrlen
== 16) DEBUG_Printf( DBG_CHN_MESG
, "0x%04lx", addr
->off
);
136 else DEBUG_Printf( DBG_CHN_MESG
, "0x%08lx", addr
->off
);
137 if (name
) DEBUG_Printf( DBG_CHN_MESG
, " (%s)", name
);
140 /***********************************************************************
141 * DEBUG_PrintAddressAndArgs
143 * Print an 16- or 32-bit address, with the nearest symbol if any.
144 * Similar to DEBUG_PrintAddress, but we print the arguments to
145 * each function (if known). This is useful in a backtrace.
148 DEBUG_PrintAddressAndArgs( const DBG_ADDR
*addr
, int addrlen
,
149 unsigned int ebp
, int flag
)
151 struct symbol_info rtn
;
153 const char *name
= DEBUG_FindNearestSymbol( addr
, flag
, &rtn
.sym
, ebp
,
156 if (addr
->seg
) DEBUG_Printf( DBG_CHN_MESG
, "0x%04lx:", addr
->seg
);
157 if (addrlen
== 16) DEBUG_Printf( DBG_CHN_MESG
, "0x%04lx", addr
->off
);
158 else DEBUG_Printf( DBG_CHN_MESG
, "0x%08lx", addr
->off
);
159 if (name
) DEBUG_Printf( DBG_CHN_MESG
, " (%s)", name
);
165 /***********************************************************************
168 * Implementation of the 'help' command.
170 void DEBUG_Help(void)
173 static const char * const helptext
[] =
175 "The commands accepted by the Wine debugger are a reasonable",
176 "subset of the commands that gdb accepts.",
177 "The commands currently are:",
179 " break [*<addr>] delete break bpnum",
180 " disable bpnum enable bpnum",
181 " condition <bpnum> [<expr>] pass",
183 " step [N] next [N]",
184 " stepi [N] nexti [N]",
185 " x <addr> print <expr>",
186 " set <reg> = <expr> set *<addr> = <expr>",
188 " list <lines> disassemble [<addr>][,<addr>]",
190 " show dir dir <path>",
191 " display <expr> undisplay <disnum>",
192 " delete display <disnum> debugmsg <class>[-+]<type>\n",
193 " mode [16,32] walk [wnd,class,queue,module,",
194 " whatis process,modref <pid>]",
195 " info (see 'help info' for options)\n",
197 "The 'x' command accepts repeat counts and formats (including 'i') in the",
198 "same way that gdb does.\n",
200 " The following are examples of legal expressions:",
201 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
202 " Also, a nm format symbol table can be read from a file using the",
203 " symbolfile command. Symbols can also be defined individually with",
204 " the define command.",
209 while(helptext
[i
]) DEBUG_Printf(DBG_CHN_MESG
,"%s\n", helptext
[i
++]);
213 /***********************************************************************
216 * Implementation of the 'help info' command.
218 void DEBUG_HelpInfo(void)
221 static const char * const infotext
[] =
223 "The info commands allow you to get assorted bits of interesting stuff",
224 "to be displayed. The options are:",
225 " info break Dumps information about breakpoints",
226 " info display Shows auto-display expressions in use",
227 " info locals Displays values of all local vars for current frame",
228 " info maps Dumps all virtual memory mappings",
229 " info module <handle> Displays internal module state",
230 " info queue <handle> Displays internal queue state",
231 " info reg Displays values in all registers at top of stack",
232 " info segments Dumps information about all known segments",
233 " info share Dumps information about shared libraries",
234 " info stack Dumps information about top of stack",
235 " info wnd <handle> Displays internal window state",
240 while(infotext
[i
]) DEBUG_Printf(DBG_CHN_MESG
,"%s\n", infotext
[i
++]);
243 /* FIXME: merge InfoClass and InfoClass2 */
244 void DEBUG_InfoClass(const char* name
)
248 if (!GetClassInfoEx(0, name
, &wca
)) {
249 DEBUG_Printf(DBG_CHN_MESG
, "Cannot find class '%s'\n", name
);
253 DEBUG_Printf(DBG_CHN_MESG
, "Class '%s':\n", name
);
254 DEBUG_Printf(DBG_CHN_MESG
,
255 "style=%08x wndProc=%08lx\n"
256 "inst=%04x icon=%04x cursor=%04x bkgnd=%04x\n"
257 "clsExtra=%d winExtra=%d\n",
258 wca
.style
, (DWORD
)wca
.lpfnWndProc
, wca
.hInstance
,
259 wca
.hIcon
, wca
.hCursor
, wca
.hbrBackground
,
260 wca
.cbClsExtra
, wca
.cbWndExtra
);
263 * + print #windows (or even list of windows...)
264 * + print extra bytes => this requires a window handle on this very class...
268 static void DEBUG_InfoClass2(HWND hWnd
, const char* name
)
272 if (!GetClassInfoEx(GetWindowLong(hWnd
, GWL_HINSTANCE
), name
, &wca
)) {
273 DEBUG_Printf(DBG_CHN_MESG
, "Cannot find class '%s'\n", name
);
277 DEBUG_Printf(DBG_CHN_MESG
, "Class '%s':\n", name
);
278 DEBUG_Printf(DBG_CHN_MESG
,
279 "style=%08x wndProc=%08lx\n"
280 "inst=%04x icon=%04x cursor=%04x bkgnd=%04x\n"
281 "clsExtra=%d winExtra=%d\n",
282 wca
.style
, (DWORD
)wca
.lpfnWndProc
, wca
.hInstance
,
283 wca
.hIcon
, wca
.hCursor
, wca
.hbrBackground
,
284 wca
.cbClsExtra
, wca
.cbWndExtra
);
286 if (wca
.cbClsExtra
) {
290 DEBUG_Printf(DBG_CHN_MESG
, "Extra bytes:" );
291 for (i
= 0; i
< wca
.cbClsExtra
/ 2; i
++) {
292 w
= GetClassWord(hWnd
, i
* 2);
293 /* FIXME: depends on i386 endian-ity */
294 DEBUG_Printf(DBG_CHN_MESG
, " %02x", HIBYTE(w
));
295 DEBUG_Printf(DBG_CHN_MESG
, " %02x", LOBYTE(w
));
297 DEBUG_Printf(DBG_CHN_MESG
, "\n" );
299 DEBUG_Printf(DBG_CHN_MESG
, "\n" );
302 struct class_walker
{
308 static void DEBUG_WalkClassesHelper(HWND hWnd
, struct class_walker
* cw
)
315 if (!GetClassName(hWnd
, clsName
, sizeof(clsName
)))
317 if ((atom
= FindAtom(clsName
)) == 0)
320 for (i
= 0; i
< cw
->used
; i
++) {
321 if (cw
->table
[i
] == atom
)
325 if (cw
->used
>= cw
->alloc
) {
327 cw
->table
= DBG_realloc(cw
->table
, cw
->alloc
* sizeof(ATOM
));
329 cw
->table
[cw
->used
++] = atom
;
330 DEBUG_InfoClass2(hWnd
, clsName
);
333 if ((child
= GetWindow(hWnd
, GW_CHILD
)) != 0)
334 DEBUG_WalkClassesHelper(child
, cw
);
335 } while ((hWnd
= GetWindow(hWnd
, GW_HWNDNEXT
)) != 0);
338 void DEBUG_WalkClasses(void)
340 struct class_walker cw
;
343 cw
.used
= cw
.alloc
= 0;
344 DEBUG_WalkClassesHelper(GetDesktopWindow(), &cw
);
348 void DEBUG_DumpQueue(DWORD q
)
350 DEBUG_Printf(DBG_CHN_MESG
, "No longer doing info queue '0x%08lx'\n", q
);
353 void DEBUG_WalkQueues(void)
355 DEBUG_Printf(DBG_CHN_MESG
, "No longer walking queues list\n");
358 void DEBUG_InfoWindow(HWND hWnd
)
367 if (!GetClassName(hWnd
, clsName
, sizeof(clsName
)))
368 strcpy(clsName
, "-- Unknown --");
369 if (!GetWindowText(hWnd
, wndName
, sizeof(wndName
)))
370 strcpy(wndName
, "-- Empty --");
371 if (!GetClientRect(hWnd
, &clientRect
))
372 SetRectEmpty(&clientRect
);
373 if (!GetWindowRect(hWnd
, &windowRect
))
374 SetRectEmpty(&windowRect
);
376 /* FIXME missing fields: hmemTaskQ, hrgnUpdate, dce, flags, pProp, scroll */
377 DEBUG_Printf(DBG_CHN_MESG
,
378 "next=0x%04x child=0x%04x parent=0x%04x owner=0x%04x class='%s'\n"
379 "inst=%08lx active=%04x idmenu=%08lx\n"
380 "style=%08lx exstyle=%08lx wndproc=%08lx text='%s'\n"
381 "client=%d,%d-%d,%d window=%d,%d-%d,%d sysmenu=%04x\n",
382 GetWindow(hWnd
, GW_HWNDNEXT
),
383 GetWindow(hWnd
, GW_CHILD
),
385 GetWindow(hWnd
, GW_OWNER
),
387 GetWindowLong(hWnd
, GWL_HINSTANCE
),
388 GetLastActivePopup(hWnd
),
389 GetWindowLong(hWnd
, GWL_ID
),
390 GetWindowLong(hWnd
, GWL_STYLE
),
391 GetWindowLong(hWnd
, GWL_EXSTYLE
),
392 GetWindowLong(hWnd
, GWL_WNDPROC
),
394 clientRect
.left
, clientRect
.top
, clientRect
.right
, clientRect
.bottom
,
395 windowRect
.left
, windowRect
.top
, windowRect
.right
, windowRect
.bottom
,
396 GetSystemMenu(hWnd
, FALSE
));
398 if (GetClassLong(hWnd
, GCL_CBWNDEXTRA
)) {
399 DEBUG_Printf(DBG_CHN_MESG
, "Extra bytes:" );
400 for (i
= 0; i
< GetClassLong(hWnd
, GCL_CBWNDEXTRA
) / 2; i
++) {
401 w
= GetWindowWord(hWnd
, i
* 2);
402 /* FIXME: depends on i386 endian-ity */
403 DEBUG_Printf(DBG_CHN_MESG
, " %02x", HIBYTE(w
));
404 DEBUG_Printf(DBG_CHN_MESG
, " %02x", LOBYTE(w
));
406 DEBUG_Printf(DBG_CHN_MESG
, "\n");
408 DEBUG_Printf(DBG_CHN_MESG
, "\n");
411 void DEBUG_WalkWindows(HWND hWnd
, int indent
)
418 hWnd
= GetDesktopWindow();
420 if (!indent
) /* first time around */
421 DEBUG_Printf(DBG_CHN_MESG
,
422 "%-16.16s %-17.17s %-8.8s %s\n",
423 "hwnd", "Class Name", " Style", " WndProc Text");
426 if (!GetClassName(hWnd
, clsName
, sizeof(clsName
)))
427 strcpy(clsName
, "-- Unknown --");
428 if (!GetWindowText(hWnd
, wndName
, sizeof(wndName
)))
429 strcpy(wndName
, "-- Empty --");
431 /* FIXME: missing hmemTaskQ */
432 DEBUG_Printf(DBG_CHN_MESG
, "%*s%04x%*s", indent
, "", hWnd
, 13-indent
,"");
433 DEBUG_Printf(DBG_CHN_MESG
, "%-17.17s %08lx %08lx %.14s\n",
434 clsName
, GetWindowLong(hWnd
, GWL_STYLE
),
435 GetWindowLong(hWnd
, GWL_WNDPROC
), wndName
);
437 if ((child
= GetWindow(hWnd
, GW_CHILD
)) != 0)
438 DEBUG_WalkWindows(child
, indent
+ 1 );
439 } while ((hWnd
= GetWindow(hWnd
, GW_HWNDNEXT
)) != 0);
442 void DEBUG_WalkProcess(void)
444 HANDLE snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
445 if (snap
!= INVALID_HANDLE_VALUE
)
447 PROCESSENTRY32 entry
;
448 DWORD current
= DEBUG_CurrProcess
? DEBUG_CurrProcess
->pid
: 0;
449 BOOL ok
= Process32First( snap
, &entry
);
451 DEBUG_Printf(DBG_CHN_MESG
, "%-8.8s %-8.8s %-8.8s %s\n",
452 "pid", "threads", "parent", "exe" );
455 if (entry
.th32ProcessID
!= GetCurrentProcessId())
456 DEBUG_Printf(DBG_CHN_MESG
, "%08lx %8d %08lx '%s'%s\n",
457 entry
.th32ProcessID
, entry
.cntThreads
,
458 entry
.th32ParentProcessID
, entry
.szExeFile
,
459 (entry
.th32ProcessID
== current
) ? " <==" : "" );
460 ok
= Process32Next( snap
, &entry
);
466 void DEBUG_WalkThreads(void)
468 HANDLE snap
= CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD
, 0 );
469 if (snap
!= INVALID_HANDLE_VALUE
)
472 DWORD current
= DEBUG_CurrThread
? DEBUG_CurrThread
->tid
: 0;
473 BOOL ok
= Thread32First( snap
, &entry
);
475 DEBUG_Printf(DBG_CHN_MESG
, "%-8.8s %-8.8s %s\n",
476 "tid", "process", "prio" );
479 if (entry
.th32OwnerProcessID
!= GetCurrentProcessId())
480 DEBUG_Printf(DBG_CHN_MESG
, "%08lx %08lx %4ld%s\n",
481 entry
.th32ThreadID
, entry
.th32OwnerProcessID
,
482 entry
.tbBasePri
, (entry
.th32ThreadID
== current
) ? " <==" : "" );
483 ok
= Thread32Next( snap
, &entry
);
489 void DEBUG_WalkModref(DWORD p
)
491 DEBUG_Printf(DBG_CHN_MESG
, "No longer walking module references list\n");
494 void DEBUG_InfoSegments(DWORD start
, int length
)
500 if (length
== -1) length
= (8192 - start
);
502 for (i
= start
; i
< start
+ length
; i
++)
504 if (!GetThreadSelectorEntry(DEBUG_CurrThread
->handle
, (i
<< 3)|7, &le
))
507 if (le
.HighWord
.Bits
.Type
& 0x08)
509 flags
[0] = (le
.HighWord
.Bits
.Type
& 0x2) ? 'r' : '-';
516 flags
[1] = (le
.HighWord
.Bits
.Type
& 0x2) ? 'w' : '-';
519 DEBUG_Printf(DBG_CHN_MESG
,
520 "%04lx: sel=%04lx base=%08x limit=%08x %d-bit %c%c%c\n",
522 (le
.HighWord
.Bits
.BaseHi
<< 24) +
523 (le
.HighWord
.Bits
.BaseMid
<< 16) + le
.BaseLow
,
524 ((le
.HighWord
.Bits
.LimitHi
<< 8) + le
.LimitLow
) <<
525 (le
.HighWord
.Bits
.Granularity
? 12 : 0),
526 le
.HighWord
.Bits
.Default_Big
? 32 : 16,
527 flags
[0], flags
[1], flags
[2] );
531 void DEBUG_InfoVirtual(void)
533 DEBUG_Printf(DBG_CHN_MESG
, "No longer providing virtual mapping information\n");