Fixed WM_GETTEXTLENGTH handling.
[wine/multimedia.git] / debugger / info.c
blob677c60182a0b7e69970f0b10e68db27787507b60
1 /*
2 * Wine debugger utility routines
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
6 */
8 #include "config.h"
9 #include <stdlib.h>
10 #include <string.h>
11 #include "winbase.h"
12 #include "wingdi.h"
13 #include "winuser.h"
14 #include "toolhelp.h"
15 #include "tlhelp32.h"
16 #include "debugger.h"
17 #include "expr.h"
19 /***********************************************************************
20 * DEBUG_PrintBasic
22 * Implementation of the 'print' command.
24 void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format )
26 char * default_format;
27 long long int res;
29 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
30 if( value->type == NULL )
32 DEBUG_Printf(DBG_CHN_MESG, "Unable to evaluate expression\n");
33 return;
36 default_format = NULL;
37 res = DEBUG_GetExprValue(value, &default_format);
39 switch(format)
41 case 'x':
42 if (value->addr.seg)
44 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%04lx", (long unsigned int) res );
46 else
48 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", (long unsigned int) res );
50 break;
52 case 'd':
53 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "%ld\n", (long int) res );
54 break;
56 case 'c':
57 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, "%d = '%c'",
58 (char)(res & 0xff), (char)(res & 0xff) );
59 break;
61 case 'i':
62 case 's':
63 case 'w':
64 case 'b':
65 DEBUG_Printf( DBG_CHN_MESG, "Format specifier '%c' is meaningless in 'print' command\n", format );
66 case 0:
67 if( default_format != NULL )
69 if (strstr(default_format, "%S") == NULL)
71 DEBUG_nchar += DEBUG_Printf( DBG_CHN_MESG, default_format, res );
73 else
75 char* ptr;
76 int state = 0;
78 /* FIXME: simplistic implementation for default_format being
79 * foo%Sbar => will print foo, then string then bar
81 for (ptr = default_format; *ptr; ptr++)
83 if (*ptr == '%') state++;
84 else if (state == 1)
86 if (*ptr == 'S')
88 char ch;
89 char* str = (char*)(long)res;
91 for (; DEBUG_READ_MEM(str, &ch, 1) && ch; str++) {
92 DEBUG_Output(DBG_CHN_MESG, &ch, 1);
93 DEBUG_nchar++;
96 else
98 /* shouldn't happen */
99 DEBUG_Printf(DBG_CHN_MESG, "%%%c", *ptr);
100 DEBUG_nchar += 2;
102 state = 0;
104 else
106 DEBUG_Output(DBG_CHN_MESG, ptr, 1);
107 DEBUG_nchar++;
112 break;
117 /***********************************************************************
118 * DEBUG_PrintAddress
120 * Print an 16- or 32-bit address, with the nearest symbol if any.
122 struct symbol_info
123 DEBUG_PrintAddress( const DBG_ADDR *addr, enum dbg_mode mode, int flag )
125 struct symbol_info rtn;
127 const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, 0,
128 &rtn.list );
130 if (addr->seg) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx:", addr->seg&0xFFFF );
131 if (mode != MODE_32) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx", addr->off );
132 else DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", addr->off );
133 if (name) DEBUG_Printf( DBG_CHN_MESG, " (%s)", name );
134 return rtn;
136 /***********************************************************************
137 * DEBUG_PrintAddressAndArgs
139 * Print an 16- or 32-bit address, with the nearest symbol if any.
140 * Similar to DEBUG_PrintAddress, but we print the arguments to
141 * each function (if known). This is useful in a backtrace.
143 struct symbol_info
144 DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, enum dbg_mode mode,
145 unsigned int ebp, int flag )
147 struct symbol_info rtn;
149 const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, ebp,
150 &rtn.list );
152 if (addr->seg) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx:", addr->seg );
153 if (mode != MODE_32) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx", addr->off );
154 else DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", addr->off );
155 if (name) DEBUG_Printf( DBG_CHN_MESG, " (%s)", name );
157 return rtn;
161 /***********************************************************************
162 * DEBUG_Help
164 * Implementation of the 'help' command.
166 void DEBUG_Help(void)
168 int i = 0;
169 static const char * const helptext[] =
171 "The commands accepted by the Wine debugger are a reasonable",
172 "subset of the commands that gdb accepts.",
173 "The commands currently are:",
174 " help quit",
175 " break [*<addr>] delete break bpnum",
176 " disable bpnum enable bpnum",
177 " condition <bpnum> [<expr>] pass",
178 " bt cont [N]",
179 " step [N] next [N]",
180 " stepi [N] nexti [N]",
181 " x <addr> print <expr>",
182 " set <reg> = <expr> set *<addr> = <expr>",
183 " up down",
184 " list <lines> disassemble [<addr>][,<addr>]",
185 " frame <n> finish",
186 " show dir dir <path>",
187 " display <expr> undisplay <disnum>",
188 " delete display <disnum> debugmsg <class>[-+]<type>\n",
189 " mode [16,32,vm86] walk [wnd,class,queue,module,",
190 " whatis process,modref <pid>]",
191 " info (see 'help info' for options)\n",
193 "The 'x' command accepts repeat counts and formats (including 'i') in the",
194 "same way that gdb does.\n",
196 " The following are examples of legal expressions:",
197 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
198 " Also, a nm format symbol table can be read from a file using the",
199 " symbolfile command. Symbols can also be defined individually with",
200 " the define command.",
202 NULL
205 while(helptext[i]) DEBUG_Printf(DBG_CHN_MESG,"%s\n", helptext[i++]);
209 /***********************************************************************
210 * DEBUG_HelpInfo
212 * Implementation of the 'help info' command.
214 void DEBUG_HelpInfo(void)
216 int i = 0;
217 static const char * const infotext[] =
219 "The info commands allow you to get assorted bits of interesting stuff",
220 "to be displayed. The options are:",
221 " info break Dumps information about breakpoints",
222 " info display Shows auto-display expressions in use",
223 " info locals Displays values of all local vars for current frame",
224 " info maps Dumps all virtual memory mappings",
225 " info module <handle> Displays internal module state",
226 " info queue <handle> Displays internal queue state",
227 " info reg Displays values in all registers at top of stack",
228 " info segments Dumps information about all known segments",
229 " info share Dumps information about shared libraries",
230 " info stack Dumps information about top of stack",
231 " info wnd <handle> Displays internal window state",
233 NULL
236 while(infotext[i]) DEBUG_Printf(DBG_CHN_MESG,"%s\n", infotext[i++]);
239 /* FIXME: merge InfoClass and InfoClass2 */
240 void DEBUG_InfoClass(const char* name)
242 WNDCLASSEXA wca;
244 if (!GetClassInfoEx(0, name, &wca)) {
245 DEBUG_Printf(DBG_CHN_MESG, "Cannot find class '%s'\n", name);
246 return;
249 DEBUG_Printf(DBG_CHN_MESG, "Class '%s':\n", name);
250 DEBUG_Printf(DBG_CHN_MESG,
251 "style=%08x wndProc=%08lx\n"
252 "inst=%p icon=%p cursor=%p bkgnd=%p\n"
253 "clsExtra=%d winExtra=%d\n",
254 wca.style, (DWORD)wca.lpfnWndProc, wca.hInstance,
255 wca.hIcon, wca.hCursor, wca.hbrBackground,
256 wca.cbClsExtra, wca.cbWndExtra);
258 /* FIXME:
259 * + print #windows (or even list of windows...)
260 * + print extra bytes => this requires a window handle on this very class...
264 static void DEBUG_InfoClass2(HWND hWnd, const char* name)
266 WNDCLASSEXA wca;
268 if (!GetClassInfoEx((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), name, &wca)) {
269 DEBUG_Printf(DBG_CHN_MESG, "Cannot find class '%s'\n", name);
270 return;
273 DEBUG_Printf(DBG_CHN_MESG, "Class '%s':\n", name);
274 DEBUG_Printf(DBG_CHN_MESG,
275 "style=%08x wndProc=%08lx\n"
276 "inst=%p icon=%p cursor=%p bkgnd=%p\n"
277 "clsExtra=%d winExtra=%d\n",
278 wca.style, (DWORD)wca.lpfnWndProc, wca.hInstance,
279 wca.hIcon, wca.hCursor, wca.hbrBackground,
280 wca.cbClsExtra, wca.cbWndExtra);
282 if (wca.cbClsExtra) {
283 int i;
284 WORD w;
286 DEBUG_Printf(DBG_CHN_MESG, "Extra bytes:" );
287 for (i = 0; i < wca.cbClsExtra / 2; i++) {
288 w = GetClassWord(hWnd, i * 2);
289 /* FIXME: depends on i386 endian-ity */
290 DEBUG_Printf(DBG_CHN_MESG, " %02x", HIBYTE(w));
291 DEBUG_Printf(DBG_CHN_MESG, " %02x", LOBYTE(w));
293 DEBUG_Printf(DBG_CHN_MESG, "\n" );
295 DEBUG_Printf(DBG_CHN_MESG, "\n" );
298 struct class_walker {
299 ATOM* table;
300 int used;
301 int alloc;
304 static void DEBUG_WalkClassesHelper(HWND hWnd, struct class_walker* cw)
306 char clsName[128];
307 int i;
308 ATOM atom;
309 HWND child;
311 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
312 return;
313 if ((atom = FindAtom(clsName)) == 0)
314 return;
316 for (i = 0; i < cw->used; i++) {
317 if (cw->table[i] == atom)
318 break;
320 if (i == cw->used) {
321 if (cw->used >= cw->alloc) {
322 cw->alloc += 16;
323 cw->table = DBG_realloc(cw->table, cw->alloc * sizeof(ATOM));
325 cw->table[cw->used++] = atom;
326 DEBUG_InfoClass2(hWnd, clsName);
328 do {
329 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
330 DEBUG_WalkClassesHelper(child, cw);
331 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
334 void DEBUG_WalkClasses(void)
336 struct class_walker cw;
338 cw.table = NULL;
339 cw.used = cw.alloc = 0;
340 DEBUG_WalkClassesHelper(GetDesktopWindow(), &cw);
341 DBG_free(cw.table);
344 void DEBUG_DumpQueue(DWORD q)
346 DEBUG_Printf(DBG_CHN_MESG, "No longer doing info queue '0x%08lx'\n", q);
349 void DEBUG_WalkQueues(void)
351 DEBUG_Printf(DBG_CHN_MESG, "No longer walking queues list\n");
354 void DEBUG_InfoWindow(HWND hWnd)
356 char clsName[128];
357 char wndName[128];
358 RECT clientRect;
359 RECT windowRect;
360 int i;
361 WORD w;
363 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
364 strcpy(clsName, "-- Unknown --");
365 if (!GetWindowText(hWnd, wndName, sizeof(wndName)))
366 strcpy(wndName, "-- Empty --");
367 if (!GetClientRect(hWnd, &clientRect))
368 SetRectEmpty(&clientRect);
369 if (!GetWindowRect(hWnd, &windowRect))
370 SetRectEmpty(&windowRect);
372 /* FIXME missing fields: hmemTaskQ, hrgnUpdate, dce, flags, pProp, scroll */
373 DEBUG_Printf(DBG_CHN_MESG,
374 "next=%p child=%p parent=%p owner=%p class='%s'\n"
375 "inst=%p active=%p idmenu=%08lx\n"
376 "style=%08lx exstyle=%08lx wndproc=%08lx text='%s'\n"
377 "client=%d,%d-%d,%d window=%d,%d-%d,%d sysmenu=%p\n",
378 GetWindow(hWnd, GW_HWNDNEXT),
379 GetWindow(hWnd, GW_CHILD),
380 GetParent(hWnd),
381 GetWindow(hWnd, GW_OWNER),
382 clsName,
383 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
384 GetLastActivePopup(hWnd),
385 GetWindowLong(hWnd, GWL_ID),
386 GetWindowLong(hWnd, GWL_STYLE),
387 GetWindowLong(hWnd, GWL_EXSTYLE),
388 GetWindowLong(hWnd, GWL_WNDPROC),
389 wndName,
390 clientRect.left, clientRect.top, clientRect.right, clientRect.bottom,
391 windowRect.left, windowRect.top, windowRect.right, windowRect.bottom,
392 GetSystemMenu(hWnd, FALSE));
394 if (GetClassLong(hWnd, GCL_CBWNDEXTRA)) {
395 DEBUG_Printf(DBG_CHN_MESG, "Extra bytes:" );
396 for (i = 0; i < GetClassLong(hWnd, GCL_CBWNDEXTRA) / 2; i++) {
397 w = GetWindowWord(hWnd, i * 2);
398 /* FIXME: depends on i386 endian-ity */
399 DEBUG_Printf(DBG_CHN_MESG, " %02x", HIBYTE(w));
400 DEBUG_Printf(DBG_CHN_MESG, " %02x", LOBYTE(w));
402 DEBUG_Printf(DBG_CHN_MESG, "\n");
404 DEBUG_Printf(DBG_CHN_MESG, "\n");
407 void DEBUG_WalkWindows(HWND hWnd, int indent)
409 char clsName[128];
410 char wndName[128];
411 HWND child;
413 if (!IsWindow(hWnd))
414 hWnd = GetDesktopWindow();
416 if (!indent) /* first time around */
417 DEBUG_Printf(DBG_CHN_MESG,
418 "%-16.16s %-17.17s %-8.8s %s\n",
419 "hwnd", "Class Name", " Style", " WndProc Text");
421 do {
422 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
423 strcpy(clsName, "-- Unknown --");
424 if (!GetWindowText(hWnd, wndName, sizeof(wndName)))
425 strcpy(wndName, "-- Empty --");
427 /* FIXME: missing hmemTaskQ */
428 DEBUG_Printf(DBG_CHN_MESG, "%*s%04x%*s", indent, "", (UINT)hWnd, 13-indent,"");
429 DEBUG_Printf(DBG_CHN_MESG, "%-17.17s %08lx %08lx %.14s\n",
430 clsName, GetWindowLong(hWnd, GWL_STYLE),
431 GetWindowLong(hWnd, GWL_WNDPROC), wndName);
433 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
434 DEBUG_WalkWindows(child, indent + 1 );
435 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
438 void DEBUG_WalkProcess(void)
440 HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
441 if (snap != INVALID_HANDLE_VALUE)
443 PROCESSENTRY32 entry;
444 DWORD current = DEBUG_CurrProcess ? DEBUG_CurrProcess->pid : 0;
445 BOOL ok;
447 entry.dwSize = sizeof(entry);
448 ok = Process32First( snap, &entry );
450 DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %-8.8s %s\n",
451 "pid", "threads", "parent", "exe" );
452 while (ok)
454 if (entry.th32ProcessID != GetCurrentProcessId())
455 DEBUG_Printf(DBG_CHN_MESG, "%08lx %8ld %08lx '%s'%s\n",
456 entry.th32ProcessID, entry.cntThreads,
457 entry.th32ParentProcessID, entry.szExeFile,
458 (entry.th32ProcessID == current) ? " <==" : "" );
459 ok = Process32Next( snap, &entry );
461 CloseHandle( snap );
465 void DEBUG_WalkThreads(void)
467 HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
468 if (snap != INVALID_HANDLE_VALUE)
470 THREADENTRY32 entry;
471 DWORD current = DEBUG_CurrThread ? DEBUG_CurrThread->tid : 0;
472 BOOL ok;
474 entry.dwSize = sizeof(entry);
475 ok = Thread32First( snap, &entry );
477 DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %s\n",
478 "tid", "process", "prio" );
479 while (ok)
481 if (entry.th32OwnerProcessID != GetCurrentProcessId())
482 DEBUG_Printf(DBG_CHN_MESG, "%08lx %08lx %4ld%s\n",
483 entry.th32ThreadID, entry.th32OwnerProcessID,
484 entry.tpBasePri, (entry.th32ThreadID == current) ? " <==" : "" );
485 ok = Thread32Next( snap, &entry );
487 CloseHandle( snap );
491 void DEBUG_WalkModref(DWORD p)
493 DEBUG_Printf(DBG_CHN_MESG, "No longer walking module references list\n");
496 void DEBUG_InfoSegments(DWORD start, int length)
498 char flags[3];
499 DWORD i;
500 LDT_ENTRY le;
502 if (length == -1) length = (8192 - start);
504 for (i = start; i < start + length; i++)
506 if (!GetThreadSelectorEntry(DEBUG_CurrThread->handle, (i << 3)|7, &le))
507 continue;
509 if (le.HighWord.Bits.Type & 0x08)
511 flags[0] = (le.HighWord.Bits.Type & 0x2) ? 'r' : '-';
512 flags[1] = '-';
513 flags[2] = 'x';
515 else
517 flags[0] = 'r';
518 flags[1] = (le.HighWord.Bits.Type & 0x2) ? 'w' : '-';
519 flags[2] = '-';
521 DEBUG_Printf(DBG_CHN_MESG,
522 "%04lx: sel=%04lx base=%08x limit=%08x %d-bit %c%c%c\n",
523 i, (i<<3)|7,
524 (le.HighWord.Bits.BaseHi << 24) +
525 (le.HighWord.Bits.BaseMid << 16) + le.BaseLow,
526 ((le.HighWord.Bits.LimitHi << 8) + le.LimitLow) <<
527 (le.HighWord.Bits.Granularity ? 12 : 0),
528 le.HighWord.Bits.Default_Big ? 32 : 16,
529 flags[0], flags[1], flags[2] );
533 void DEBUG_InfoVirtual(void)
535 DEBUG_Printf(DBG_CHN_MESG, "No longer providing virtual mapping information\n");