d3dx10/tests: Fix texture leak in check_resource_data.
[wine.git] / programs / winedbg / info.c
blobae0fd90e9384059ed9f8ecca65191ca9e6a50ec0
1 /*
2 * Wine debugger utility routines
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdarg.h>
27 #include "debugger.h"
28 #include "wingdi.h"
29 #include "winuser.h"
30 #include "tlhelp32.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
35 /***********************************************************************
36 * print_help
38 * Implementation of the 'help' command.
40 void print_help(void)
42 int i = 0;
43 static const char * const helptext[] =
45 "The commands accepted by the Wine debugger are a reasonable",
46 "subset of the commands that gdb accepts.",
47 "The commands currently are:",
48 " help quit",
49 " attach <wpid> detach",
50 " break [*<addr>] watch | rwatch *<addr>",
51 " delete break bpnum disable bpnum",
52 " enable bpnum condition <bpnum> [<expr>]",
53 " finish cont [N]",
54 " step [N] next [N]",
55 " stepi [N] nexti [N]",
56 " x <addr> print <expr>",
57 " display <expr> undisplay <disnum>",
58 " local display <expr> delete display <disnum>",
59 " enable display <disnum> disable display <disnum>",
60 " bt [<tid>|all] frame <n>",
61 " up down",
62 " list <lines> disassemble [<addr>][,<addr>]",
63 " show dir dir <path>",
64 " set <reg> = <expr> set *<addr> = <expr>",
65 " pass whatis",
66 " info (see 'help info' for options) thread <tid>",
68 "The 'x' command accepts repeat counts and formats (including 'i') in the",
69 "same way that gdb does.\n",
71 "The following are examples of legal expressions:",
72 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
73 " Also, a nm format symbol table can be read from a file using the",
74 " symbolfile command.", /* Symbols can also be defined individually with",
75 " the define command.", */
76 "",
77 NULL
80 while (helptext[i]) dbg_printf("%s\n", helptext[i++]);
84 /***********************************************************************
85 * info_help
87 * Implementation of the 'help info' command.
89 void info_help(void)
91 int i = 0;
92 static const char * const infotext[] =
94 "The info commands allow you to get assorted bits of interesting stuff",
95 "to be displayed. The options are:",
96 " info break Displays information about breakpoints",
97 " info class <name> Displays information about window class <name>",
98 " info display Shows auto-display expressions in use",
99 " info except <pid> Shows exception handler chain (in a given process)",
100 " info locals Displays values of all local vars for current frame",
101 " info maps <pid> Shows virtual mappings (in a given process)",
102 " info process Shows all running processes",
103 " info reg Displays values of the general registers at top of stack",
104 " info all-reg Displays the general and floating point registers",
105 " info segments <pid> Displays information about all known segments",
106 " info share Displays all loaded modules",
107 " info share <addr> Displays internal module state",
108 " info stack [<len>] Dumps information about top of stack, up to len words",
109 " info symbol <sym> Displays information about a given symbol",
110 " info thread Shows all running threads",
111 " info wnd <handle> Displays internal window state",
113 NULL
116 while (infotext[i]) dbg_printf("%s\n", infotext[i++]);
119 static const char* get_symtype_str(const IMAGEHLP_MODULE64* mi)
121 switch (mi->SymType)
123 default:
124 case SymNone: return "--none--";
125 case SymCoff: return "COFF";
126 case SymCv: return "CodeView";
127 case SymPdb: return "PDB";
128 case SymExport: return "Export";
129 case SymDeferred: return "Deferred";
130 case SymSym: return "Sym";
131 case SymDia:
132 switch (mi->CVSig)
134 case 'S' | ('T' << 8) | ('A' << 16) | ('B' << 24):
135 return "Stabs";
136 case 'D' | ('W' << 8) | ('A' << 16) | ('R' << 24):
137 /* previous versions of dbghelp used to report this... */
138 return "Dwarf";
139 default:
140 if ((mi->CVSig & 0x00FFFFFF) == ('D' | ('W' << 8) | ('F' << 16)))
142 static char tmp[64];
143 DWORD versbit = mi->CVSig >> 24;
144 strcpy(tmp, "Dwarf");
145 if (versbit & 1) strcat(tmp, "-2");
146 if (versbit & 2) strcat(tmp, "-3");
147 if (versbit & 4) strcat(tmp, "-4");
148 if (versbit & 8) strcat(tmp, "-5");
149 return tmp;
151 return "DIA";
156 struct info_module
158 IMAGEHLP_MODULE64 mi;
159 char name[64];
162 struct info_modules
164 struct info_module *modules;
165 unsigned num_alloc;
166 unsigned num_used;
169 static void module_print_info(const struct info_module *module, BOOL is_embedded)
171 dbg_printf("%*.*I64x-%*.*I64x\t%-16s%s\n",
172 ADDRWIDTH, ADDRWIDTH, module->mi.BaseOfImage,
173 ADDRWIDTH, ADDRWIDTH, module->mi.BaseOfImage + module->mi.ImageSize,
174 is_embedded ? "\\" : get_symtype_str(&module->mi), module->name);
177 static int __cdecl module_compare(const void* p1, const void* p2)
179 struct info_module *left = (struct info_module *)p1;
180 struct info_module *right = (struct info_module *)p2;
181 LONGLONG val = left->mi.BaseOfImage - right->mi.BaseOfImage;
183 if (val < 0) return -1;
184 else if (val > 0) return 1;
185 else return 0;
188 static inline BOOL module_is_container(const struct info_module *wmod_cntnr,
189 const struct info_module *wmod_child)
191 return wmod_cntnr->mi.BaseOfImage <= wmod_child->mi.BaseOfImage &&
192 wmod_cntnr->mi.BaseOfImage + wmod_cntnr->mi.ImageSize >=
193 wmod_child->mi.BaseOfImage + wmod_child->mi.ImageSize;
196 static BOOL CALLBACK info_mod_cb(PCSTR mod_name, DWORD64 base, PVOID ctx)
198 struct info_modules *im = ctx;
200 if (im->num_used + 1 > im->num_alloc)
202 im->num_alloc += 16;
203 im->modules = dbg_heap_realloc(im->modules, im->num_alloc * sizeof(*im->modules));
205 im->modules[im->num_used].mi.SizeOfStruct = sizeof(im->modules[im->num_used].mi);
206 if (SymGetModuleInfo64(dbg_curr_process->handle, base, &im->modules[im->num_used].mi))
208 const int dst_len = sizeof(im->modules[im->num_used].name);
209 lstrcpynA(im->modules[im->num_used].name, mod_name, dst_len - 1);
210 im->modules[im->num_used].name[dst_len - 1] = 0;
211 im->num_used++;
213 return TRUE;
216 /***********************************************************************
217 * info_win32_module
219 * Display information about a given module (DLL or EXE), or about all modules
221 void info_win32_module(DWORD64 base)
223 struct info_modules im;
224 UINT i, j, num_printed = 0;
225 BOOL opt;
227 if (!dbg_curr_process)
229 dbg_printf("Cannot get info on module while no process is loaded\n");
230 return;
233 im.modules = NULL;
234 im.num_alloc = im.num_used = 0;
236 /* this is a wine specific options to return also ELF modules in the
237 * enumeration
239 opt = SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, TRUE);
240 SymEnumerateModules64(dbg_curr_process->handle, info_mod_cb, &im);
241 SymSetExtendedOption(SYMOPT_EX_WINE_NATIVE_MODULES, opt);
243 qsort(im.modules, im.num_used, sizeof(im.modules[0]), module_compare);
245 dbg_printf("Module\tAddress\t\t\t%sDebug info\tName (%d modules)\n",
246 ADDRWIDTH == 16 ? "\t\t" : "", im.num_used);
248 for (i = 0; i < im.num_used; i++)
250 if (base &&
251 (base < im.modules[i].mi.BaseOfImage || base >= im.modules[i].mi.BaseOfImage + im.modules[i].mi.ImageSize))
252 continue;
253 if (strstr(im.modules[i].name, "<elf>"))
255 dbg_printf("ELF\t");
256 module_print_info(&im.modules[i], FALSE);
257 /* print all modules embedded in this one */
258 for (j = 0; j < im.num_used; j++)
260 if (!strstr(im.modules[j].name, "<elf>") && module_is_container(&im.modules[i], &im.modules[j]))
262 dbg_printf(" \\-PE\t");
263 module_print_info(&im.modules[j], TRUE);
267 else
269 /* check module is not embedded in another module */
270 for (j = 0; j < im.num_used; j++)
272 if (strstr(im.modules[j].name, "<elf>") && module_is_container(&im.modules[j], &im.modules[i]))
273 break;
275 if (j < im.num_used) continue;
276 if (strstr(im.modules[i].name, ".so") || strchr(im.modules[i].name, '<'))
277 dbg_printf("ELF\t");
278 else
279 dbg_printf("PE\t");
280 module_print_info(&im.modules[i], FALSE);
282 num_printed++;
284 HeapFree(GetProcessHeap(), 0, im.modules);
286 if (base && !num_printed)
287 dbg_printf("'0x%0*I64x' is not a valid module address\n", ADDRWIDTH, base);
290 struct class_walker
292 ATOM* table;
293 int used;
294 int alloc;
297 static void class_walker(HWND hWnd, struct class_walker* cw)
299 char clsName[128];
300 int i;
301 ATOM atom;
302 HWND child;
304 if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
305 return;
306 if ((atom = FindAtomA(clsName)) == 0)
307 return;
309 for (i = 0; i < cw->used; i++)
311 if (cw->table[i] == atom)
312 break;
314 if (i == cw->used)
316 if (cw->used >= cw->alloc)
318 cw->alloc += 16;
319 cw->table = dbg_heap_realloc(cw->table, cw->alloc * sizeof(ATOM));
321 cw->table[cw->used++] = atom;
322 info_win32_class(hWnd, clsName);
326 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
327 class_walker(child, cw);
328 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
331 void info_win32_class(HWND hWnd, const char* name)
333 WNDCLASSEXA wca;
334 HINSTANCE hInst = hWnd ? (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE) : 0;
336 if (!name)
338 struct class_walker cw;
340 cw.table = NULL;
341 cw.used = cw.alloc = 0;
342 class_walker(GetDesktopWindow(), &cw);
343 HeapFree(GetProcessHeap(), 0, cw.table);
344 return;
347 if (!GetClassInfoExA(hInst, name, &wca))
349 dbg_printf("Cannot find class '%s'\n", name);
350 return;
353 dbg_printf("Class '%s':\n", name);
354 dbg_printf("style=0x%08x wndProc=%p\n"
355 "inst=%p icon=%p cursor=%p bkgnd=%p\n"
356 "clsExtra=%d winExtra=%d\n",
357 wca.style, wca.lpfnWndProc, wca.hInstance,
358 wca.hIcon, wca.hCursor, wca.hbrBackground,
359 wca.cbClsExtra, wca.cbWndExtra);
361 if (hWnd && wca.cbClsExtra)
363 int i;
364 WORD w;
366 dbg_printf("Extra bytes:");
367 for (i = 0; i < wca.cbClsExtra / 2; i++)
369 w = GetClassWord(hWnd, i * 2);
370 /* FIXME: depends on i386 endian-ity */
371 dbg_printf(" %02x %02x", HIBYTE(w), LOBYTE(w));
373 dbg_printf("\n");
375 dbg_printf("\n");
376 /* FIXME:
377 * + print #windows (or even list of windows...)
378 * + print extra bytes => this requires a window handle on this very class...
382 static void info_window(HWND hWnd, int indent)
384 char clsName[128];
385 char wndName[128];
386 HWND child;
390 if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
391 strcpy(clsName, "-- Unknown --");
392 if (!GetWindowTextA(hWnd, wndName, sizeof(wndName)))
393 strcpy(wndName, "-- Empty --");
395 dbg_printf("%*s%08Ix%*s %-17.17s %08lx %0*Ix %08lx %.14s\n",
396 indent, "", (DWORD_PTR)hWnd, 12 - indent, "",
397 clsName, GetWindowLongW(hWnd, GWL_STYLE),
398 ADDRWIDTH, (ULONG_PTR)GetWindowLongPtrW(hWnd, GWLP_WNDPROC),
399 GetWindowThreadProcessId(hWnd, NULL), wndName);
401 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
402 info_window(child, indent + 1);
403 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
406 void info_win32_window(HWND hWnd, BOOL detailed)
408 char clsName[128];
409 char wndName[128];
410 RECT clientRect;
411 RECT windowRect;
412 WORD w;
414 if (!IsWindow(hWnd)) hWnd = GetDesktopWindow();
416 if (!detailed)
418 dbg_printf("%-20.20s %-17.17s %-8.8s %-*.*s %-8.8s %s\n",
419 "Window handle", "Class Name", "Style",
420 ADDRWIDTH, ADDRWIDTH, "WndProc", "Thread", "Text");
421 info_window(hWnd, 0);
422 return;
425 if (!GetClassNameA(hWnd, clsName, sizeof(clsName)))
426 strcpy(clsName, "-- Unknown --");
427 if (!GetWindowTextA(hWnd, wndName, sizeof(wndName)))
428 strcpy(wndName, "-- Empty --");
429 if (!GetClientRect(hWnd, &clientRect) ||
430 !MapWindowPoints(hWnd, 0, (LPPOINT) &clientRect, 2))
431 SetRectEmpty(&clientRect);
432 if (!GetWindowRect(hWnd, &windowRect))
433 SetRectEmpty(&windowRect);
435 /* FIXME missing fields: hmemTaskQ, hrgnUpdate, dce, flags, pProp, scroll */
436 dbg_printf("next=%p child=%p parent=%p owner=%p class='%s'\n"
437 "inst=%p active=%p idmenu=%08Ix\n"
438 "style=0x%08lx exstyle=0x%08lx wndproc=%p text='%s'\n"
439 "client=%ld,%ld-%ld,%ld window=%ld,%ld-%ld,%ld sysmenu=%p\n",
440 GetWindow(hWnd, GW_HWNDNEXT),
441 GetWindow(hWnd, GW_CHILD),
442 GetParent(hWnd),
443 GetWindow(hWnd, GW_OWNER),
444 clsName,
445 (HINSTANCE)GetWindowLongPtrW(hWnd, GWLP_HINSTANCE),
446 GetLastActivePopup(hWnd),
447 (ULONG_PTR)GetWindowLongPtrW(hWnd, GWLP_ID),
448 GetWindowLongW(hWnd, GWL_STYLE),
449 GetWindowLongW(hWnd, GWL_EXSTYLE),
450 (void*)GetWindowLongPtrW(hWnd, GWLP_WNDPROC),
451 wndName,
452 clientRect.left, clientRect.top, clientRect.right, clientRect.bottom,
453 windowRect.left, windowRect.top, windowRect.right, windowRect.bottom,
454 GetSystemMenu(hWnd, FALSE));
456 if (GetClassLongW(hWnd, GCL_CBWNDEXTRA))
458 UINT i;
460 dbg_printf("Extra bytes:");
461 for (i = 0; i < GetClassLongW(hWnd, GCL_CBWNDEXTRA) / 2; i++)
463 w = GetWindowWord(hWnd, i * 2);
464 /* FIXME: depends on i386 endian-ity */
465 dbg_printf(" %02x %02x", HIBYTE(w), LOBYTE(w));
467 dbg_printf("\n");
469 dbg_printf("\n");
472 struct dump_proc_entry
474 PROCESSENTRY32 proc;
475 unsigned children; /* index in dump_proc.entries of first child */
476 unsigned sibling; /* index in dump_proc.entries of next sibling */
479 struct dump_proc
481 struct dump_proc_entry*entries;
482 unsigned count;
483 unsigned alloc;
486 static unsigned get_parent(const struct dump_proc* dp, unsigned idx)
488 unsigned i;
490 for (i = 0; i < dp->count; i++)
492 if (i != idx && dp->entries[i].proc.th32ProcessID == dp->entries[idx].proc.th32ParentProcessID)
493 return i;
495 return -1;
498 static void dump_proc_info(const struct dump_proc* dp, unsigned idx, unsigned depth)
500 struct dump_proc_entry* dpe;
501 char info;
502 for ( ; idx != -1; idx = dp->entries[idx].sibling)
504 assert(idx < dp->count);
505 dpe = &dp->entries[idx];
506 if (dbg_curr_process && dpe->proc.th32ProcessID == dbg_curr_process->pid)
507 info = '>';
508 else if (dpe->proc.th32ProcessID == GetCurrentProcessId())
509 info = '=';
510 else
511 info = ' ';
512 dbg_printf("%c%08lx %-8ld ", info, dpe->proc.th32ProcessID, dpe->proc.cntThreads);
513 if (depth)
515 unsigned i;
516 for (i = 3 * (depth - 1); i > 0; i--) dbg_printf(" ");
517 dbg_printf("\\_ ");
519 dbg_printf("'%s'\n", dpe->proc.szExeFile);
520 dump_proc_info(dp, dpe->children, depth + 1);
524 void info_win32_processes(void)
526 HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
527 if (snap != INVALID_HANDLE_VALUE)
529 struct dump_proc dp;
530 unsigned i, first = -1;
531 BOOL ok;
533 dp.count = 0;
534 dp.alloc = 16;
535 dp.entries = HeapAlloc(GetProcessHeap(), 0, sizeof(*dp.entries) * dp.alloc);
536 if (!dp.entries)
538 CloseHandle(snap);
539 return;
541 dp.entries[dp.count].proc.dwSize = sizeof(dp.entries[dp.count].proc);
542 ok = Process32First(snap, &dp.entries[dp.count].proc);
544 /* fetch all process information into dp */
545 while (ok)
547 dp.entries[dp.count++].children = -1;
548 if (dp.count >= dp.alloc)
550 dp.entries = HeapReAlloc(GetProcessHeap(), 0, dp.entries, sizeof(*dp.entries) * (dp.alloc *= 2));
551 if (!dp.entries) return;
553 dp.entries[dp.count].proc.dwSize = sizeof(dp.entries[dp.count].proc);
554 ok = Process32Next(snap, &dp.entries[dp.count].proc);
556 CloseHandle(snap);
557 /* chain the siblings wrt. their parent */
558 for (i = 0; i < dp.count; i++)
560 unsigned parent = get_parent(&dp, i);
561 unsigned *chain = parent == -1 ? &first : &dp.entries[parent].children;
562 dp.entries[i].sibling = *chain;
563 *chain = i;
565 dbg_printf(" %-8.8s %-8.8s %s (all id:s are in hex)\n", "pid", "threads", "executable");
566 dump_proc_info(&dp, first, 0);
567 HeapFree(GetProcessHeap(), 0, dp.entries);
571 static BOOL get_process_name(DWORD pid, PROCESSENTRY32W* entry)
573 BOOL ret = FALSE;
574 HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
576 if (snap != INVALID_HANDLE_VALUE)
578 entry->dwSize = sizeof(*entry);
579 if (Process32FirstW(snap, entry))
580 while (!(ret = (entry->th32ProcessID == pid)) &&
581 Process32NextW(snap, entry));
582 CloseHandle(snap);
584 return ret;
587 void info_win32_threads(void)
589 HANDLE snap = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
590 if (snap != INVALID_HANDLE_VALUE)
592 THREADENTRY32 entry;
593 BOOL ok;
594 DWORD lastProcessId = 0;
595 struct dbg_process* p = NULL;
596 struct dbg_thread* t = NULL;
598 entry.dwSize = sizeof(entry);
599 ok = Thread32First(snap, &entry);
601 dbg_printf("%-8.8s %-8.8s %s %s (all IDs are in hex)\n",
602 "process", "tid", "prio", "name");
603 while (ok)
605 if (entry.th32OwnerProcessID != GetCurrentProcessId())
607 /* FIXME: this assumes that, in the snapshot, all threads of a same process are
608 * listed sequentially, which is not specified in the doc (Wine's implementation
609 * does it)
611 if (entry.th32OwnerProcessID != lastProcessId)
613 PROCESSENTRY32W pcs_entry;
614 const WCHAR* exename;
616 p = dbg_get_process(entry.th32OwnerProcessID);
617 if (p)
618 exename = p->imageName;
619 else if (get_process_name(entry.th32OwnerProcessID, &pcs_entry))
620 exename = pcs_entry.szExeFile;
621 else
622 exename = L"";
624 dbg_printf("%08lx%s %ls\n",
625 entry.th32OwnerProcessID, p ? " (D)" : "", exename);
626 lastProcessId = entry.th32OwnerProcessID;
628 t = dbg_get_thread(p, entry.th32ThreadID);
629 dbg_printf("\t%08lx %4ld%s %s\n",
630 entry.th32ThreadID, entry.tpBasePri,
631 (entry.th32ThreadID == dbg_curr_tid) ? " <==" : " ",
632 t ? t->name : "");
635 ok = Thread32Next(snap, &entry);
638 CloseHandle(snap);
642 /***********************************************************************
643 * info_win32_frame_exceptions
645 * Get info on the exception frames of a given thread.
647 void info_win32_frame_exceptions(DWORD tid)
649 struct dbg_thread* thread;
650 void* next_frame;
652 if (!dbg_curr_process || !dbg_curr_thread)
654 dbg_printf("Cannot get info on exceptions while no process is loaded\n");
655 return;
658 dbg_printf("Exception frames:\n");
660 if (tid == dbg_curr_tid) thread = dbg_curr_thread;
661 else
663 thread = dbg_get_thread(dbg_curr_process, tid);
665 if (!thread)
667 dbg_printf("Unknown thread id (%04lx) in current process\n", tid);
668 return;
670 if (SuspendThread(thread->handle) == -1)
672 dbg_printf("Can't suspend thread id (%04lx)\n", tid);
673 return;
677 if (!dbg_read_memory(thread->teb, &next_frame, sizeof(next_frame)))
679 dbg_printf("Can't read TEB:except_frame\n");
680 return;
683 while (next_frame != (void*)-1)
685 EXCEPTION_REGISTRATION_RECORD frame;
687 dbg_printf("%p: ", next_frame);
688 if (!dbg_read_memory(next_frame, &frame, sizeof(frame)))
690 dbg_printf("Invalid frame address\n");
691 break;
693 dbg_printf("prev=%p handler=%p\n", frame.Prev, frame.Handler);
694 next_frame = frame.Prev;
697 if (tid != dbg_curr_tid) ResumeThread(thread->handle);
700 void info_win32_segments(DWORD start, int length)
702 char flags[3];
703 DWORD i;
704 LDT_ENTRY le;
706 if (length == -1) length = (8192 - start);
708 for (i = start; i < start + length; i++)
710 if (!dbg_curr_process->process_io->get_selector(dbg_curr_thread->handle, (i << 3) | 7, &le))
711 continue;
713 if (le.HighWord.Bits.Type & 0x08)
715 flags[0] = (le.HighWord.Bits.Type & 0x2) ? 'r' : '-';
716 flags[1] = '-';
717 flags[2] = 'x';
719 else
721 flags[0] = 'r';
722 flags[1] = (le.HighWord.Bits.Type & 0x2) ? 'w' : '-';
723 flags[2] = '-';
725 dbg_printf("%04lx: sel=%04lx base=%08x limit=%08x %d-bit %c%c%c\n",
726 i, (i << 3) | 7,
727 (le.HighWord.Bits.BaseHi << 24) +
728 (le.HighWord.Bits.BaseMid << 16) + le.BaseLow,
729 ((le.HighWord.Bits.LimitHi << 8) + le.LimitLow) <<
730 (le.HighWord.Bits.Granularity ? 12 : 0),
731 le.HighWord.Bits.Default_Big ? 32 : 16,
732 flags[0], flags[1], flags[2]);
736 void info_win32_virtual(DWORD pid)
738 MEMORY_BASIC_INFORMATION mbi;
739 char* addr = 0;
740 const char* state;
741 const char* type;
742 char prot[3+1];
743 HANDLE hProc;
745 if (pid == dbg_curr_pid)
747 if (dbg_curr_process == NULL)
749 dbg_printf("Cannot look at mapping of current process, while no process is loaded\n");
750 return;
752 hProc = dbg_curr_process->handle;
754 else
756 hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
757 if (hProc == NULL)
759 dbg_printf("Cannot open process <%04lx>\n", pid);
760 return;
764 dbg_printf("Address End State Type RWX\n");
766 while (VirtualQueryEx(hProc, addr, &mbi, sizeof(mbi)) >= sizeof(mbi))
768 switch (mbi.State)
770 case MEM_COMMIT: state = "commit "; break;
771 case MEM_FREE: state = "free "; break;
772 case MEM_RESERVE: state = "reserve"; break;
773 default: state = "??? "; break;
775 if (mbi.State != MEM_FREE)
777 switch (mbi.Type)
779 case MEM_IMAGE: type = "image "; break;
780 case MEM_MAPPED: type = "mapped "; break;
781 case MEM_PRIVATE: type = "private"; break;
782 case 0: type = " "; break;
783 default: type = "??? "; break;
785 memset(prot, ' ' , sizeof(prot) - 1);
786 prot[sizeof(prot) - 1] = '\0';
787 if (mbi.AllocationProtect & (PAGE_READONLY|PAGE_READWRITE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_WRITECOPY|PAGE_EXECUTE_WRITECOPY))
788 prot[0] = 'R';
789 if (mbi.AllocationProtect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE))
790 prot[1] = 'W';
791 if (mbi.AllocationProtect & (PAGE_WRITECOPY|PAGE_EXECUTE_WRITECOPY))
792 prot[1] = 'C';
793 if (mbi.AllocationProtect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE|PAGE_EXECUTE_WRITECOPY))
794 prot[2] = 'X';
796 else
798 type = "";
799 prot[0] = '\0';
801 dbg_printf("%0*Ix %0*Ix %s %s %s\n",
802 ADDRWIDTH, (DWORD_PTR)addr, ADDRWIDTH, (DWORD_PTR)addr + mbi.RegionSize - 1, state, type, prot);
803 if (addr + mbi.RegionSize < addr) /* wrap around ? */
804 break;
805 addr += mbi.RegionSize;
807 if (pid != dbg_curr_pid) CloseHandle(hProc);
810 void info_wine_dbg_channel(BOOL turn_on, const char* cls, const char* name)
812 struct dbg_lvalue lvalue;
813 struct __wine_debug_channel channel;
814 unsigned char mask;
815 int done = 0;
816 BOOL bAll;
817 void* addr;
819 if (!dbg_curr_process || !dbg_curr_thread)
821 dbg_printf("Cannot set/get debug channels while no process is loaded\n");
822 return;
825 if (symbol_get_lvalue("debug_options", -1, &lvalue, FALSE) != sglv_found)
827 return;
829 addr = memory_to_linear_addr(&lvalue.addr);
831 if (!cls) mask = ~0;
832 else if (!strcmp(cls, "fixme")) mask = (1 << __WINE_DBCL_FIXME);
833 else if (!strcmp(cls, "err")) mask = (1 << __WINE_DBCL_ERR);
834 else if (!strcmp(cls, "warn")) mask = (1 << __WINE_DBCL_WARN);
835 else if (!strcmp(cls, "trace")) mask = (1 << __WINE_DBCL_TRACE);
836 else
838 dbg_printf("Unknown debug class %s\n", cls);
839 return;
842 bAll = !strcmp("all", name);
843 while (addr && dbg_read_memory(addr, &channel, sizeof(channel)))
845 if (!channel.name[0]) break;
846 if (bAll || !strcmp( channel.name, name ))
848 if (turn_on) channel.flags |= mask;
849 else channel.flags &= ~mask;
850 if (dbg_write_memory(addr, &channel, sizeof(channel))) done++;
852 addr = (struct __wine_debug_channel *)addr + 1;
854 if (!done) dbg_printf("Unable to find debug channel %s\n", name);
855 else WINE_TRACE("Changed %d channel instances\n", done);
858 void info_win32_exception(void)
860 const EXCEPTION_RECORD* rec;
861 ADDRESS64 addr;
862 char hexbuf[MAX_OFFSET_TO_STR_LEN];
864 if (!dbg_curr_thread->in_exception)
866 dbg_printf("Thread isn't in an exception\n");
867 return;
869 rec = &dbg_curr_thread->excpt_record;
870 memory_get_current_pc(&addr);
872 /* print some infos */
873 dbg_printf("%s: ",
874 dbg_curr_thread->first_chance ? "First chance exception" : "Unhandled exception");
875 switch (rec->ExceptionCode)
877 case EXCEPTION_BREAKPOINT:
878 dbg_printf("breakpoint");
879 break;
880 case EXCEPTION_SINGLE_STEP:
881 dbg_printf("single step");
882 break;
883 case EXCEPTION_INT_DIVIDE_BY_ZERO:
884 dbg_printf("divide by zero");
885 break;
886 case EXCEPTION_INT_OVERFLOW:
887 dbg_printf("overflow");
888 break;
889 case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
890 dbg_printf("array bounds");
891 break;
892 case EXCEPTION_ILLEGAL_INSTRUCTION:
893 dbg_printf("illegal instruction");
894 break;
895 case EXCEPTION_STACK_OVERFLOW:
896 dbg_printf("stack overflow");
897 break;
898 case EXCEPTION_PRIV_INSTRUCTION:
899 dbg_printf("privileged instruction");
900 break;
901 case EXCEPTION_ACCESS_VIOLATION:
902 if (rec->NumberParameters == 2)
903 dbg_printf("page fault on %s access to 0x%0*Ix",
904 rec->ExceptionInformation[0] == EXCEPTION_WRITE_FAULT ? "write" :
905 rec->ExceptionInformation[0] == EXCEPTION_EXECUTE_FAULT ? "execute" : "read",
906 ADDRWIDTH, rec->ExceptionInformation[1]);
907 else
908 dbg_printf("page fault");
909 break;
910 case EXCEPTION_DATATYPE_MISALIGNMENT:
911 dbg_printf("Alignment");
912 break;
913 case DBG_CONTROL_C:
914 dbg_printf("^C");
915 break;
916 case CONTROL_C_EXIT:
917 dbg_printf("^C");
918 break;
919 case STATUS_POSSIBLE_DEADLOCK:
921 ADDRESS64 recaddr;
923 recaddr.Mode = AddrModeFlat;
924 recaddr.Offset = rec->ExceptionInformation[0];
926 dbg_printf("wait failed on critical section ");
927 print_address(&recaddr, FALSE);
929 break;
930 case EXCEPTION_WINE_STUB:
932 char dll[64], name[256];
933 memory_get_string(dbg_curr_process,
934 (void*)rec->ExceptionInformation[0], TRUE, FALSE,
935 dll, sizeof(dll));
936 if (HIWORD(rec->ExceptionInformation[1]))
937 memory_get_string(dbg_curr_process,
938 (void*)rec->ExceptionInformation[1], TRUE, FALSE,
939 name, sizeof(name));
940 else
941 sprintf( name, "%Id", rec->ExceptionInformation[1] );
942 dbg_printf("unimplemented function %s.%s called", dll, name);
944 break;
945 case EXCEPTION_WINE_ASSERTION:
946 dbg_printf("assertion failed");
947 break;
948 case EXCEPTION_FLT_DENORMAL_OPERAND:
949 dbg_printf("denormal float operand");
950 break;
951 case EXCEPTION_FLT_DIVIDE_BY_ZERO:
952 dbg_printf("divide by zero");
953 break;
954 case EXCEPTION_FLT_INEXACT_RESULT:
955 dbg_printf("inexact float result");
956 break;
957 case EXCEPTION_FLT_INVALID_OPERATION:
958 dbg_printf("invalid float operation");
959 break;
960 case EXCEPTION_FLT_OVERFLOW:
961 dbg_printf("floating point overflow");
962 break;
963 case EXCEPTION_FLT_UNDERFLOW:
964 dbg_printf("floating point underflow");
965 break;
966 case EXCEPTION_FLT_STACK_CHECK:
967 dbg_printf("floating point stack check");
968 break;
969 case EXCEPTION_WINE_CXX_EXCEPTION:
970 if(rec->NumberParameters == 3 && rec->ExceptionInformation[0] == EXCEPTION_WINE_CXX_FRAME_MAGIC)
971 dbg_printf("C++ exception(object = 0x%0*Ix, type = 0x%0*Ix)",
972 ADDRWIDTH, rec->ExceptionInformation[1], ADDRWIDTH, rec->ExceptionInformation[2]);
973 else if(rec->NumberParameters == 4 && rec->ExceptionInformation[0] == EXCEPTION_WINE_CXX_FRAME_MAGIC)
974 dbg_printf("C++ exception(object = %p, type = %p, base = %p)",
975 (void*)rec->ExceptionInformation[1], (void*)rec->ExceptionInformation[2],
976 (void*)rec->ExceptionInformation[3]);
977 else
978 dbg_printf("C++ exception with strange parameter count %ld or magic 0x%0*Ix",
979 rec->NumberParameters, ADDRWIDTH, rec->ExceptionInformation[0]);
980 break;
981 default:
982 dbg_printf("0x%08lx", rec->ExceptionCode);
983 break;
985 if (rec->ExceptionFlags & EH_STACK_INVALID)
986 dbg_printf(", invalid program stack");
988 switch (addr.Mode)
990 case AddrModeFlat:
991 dbg_printf(" in %ld-bit code (%s)",
992 dbg_curr_process->be_cpu->pointer_size * 8,
993 memory_offset_to_string(hexbuf, addr.Offset, 0));
994 break;
995 case AddrModeReal:
996 dbg_printf(" in vm86 code (%04x:%04x)", addr.Segment, (unsigned) addr.Offset);
997 break;
998 case AddrMode1616:
999 dbg_printf(" in 16-bit code (%04x:%04x)", addr.Segment, (unsigned) addr.Offset);
1000 break;
1001 case AddrMode1632:
1002 dbg_printf(" in segmented 32-bit code (%04x:%08x)", addr.Segment, (unsigned) addr.Offset);
1003 break;
1004 default: dbg_printf(" bad address");
1006 dbg_printf(".\n");