- Removed no longer used queue & modref related commands.
[wine/multimedia.git] / programs / winedbg / info.c
blob3290d4ef3e331bc2b9a3c30d87a3ce6c334bbcef
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include <stdlib.h>
24 #include <string.h>
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "tlhelp32.h"
29 #include "debugger.h"
30 #include "expr.h"
32 /***********************************************************************
33 * DEBUG_PrintBasic
35 * Implementation of the 'print' command.
37 void DEBUG_PrintBasic( const DBG_VALUE* value, int count, char format )
39 char * default_format;
40 long long int res;
42 assert(value->cookie == DV_TARGET || value->cookie == DV_HOST);
43 if (value->type == NULL)
45 DEBUG_Printf(DBG_CHN_MESG, "Unable to evaluate expression\n");
46 return;
49 default_format = NULL;
50 res = DEBUG_GetExprValue(value, &default_format);
52 switch (format)
54 case 'x':
55 if (value->addr.seg)
57 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "0x%04lx", (long unsigned int)res);
59 else
61 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "0x%08lx", (long unsigned int)res);
63 break;
65 case 'd':
66 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%ld\n", (long int)res);
67 break;
69 case 'c':
70 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%d = '%c'",
71 (char)(res & 0xff), (char)(res & 0xff));
72 break;
74 case 'u':
76 WCHAR wch = (WCHAR)(res & 0xFFFF);
77 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%d = '", (unsigned)(res & 0xffff));
78 DEBUG_OutputW(DBG_CHN_MESG, &wch, 1);
79 DEBUG_Printf(DBG_CHN_MESG, "'");
81 break;
83 case 'i':
84 case 's':
85 case 'w':
86 case 'b':
87 DEBUG_Printf(DBG_CHN_MESG, "Format specifier '%c' is meaningless in 'print' command\n", format);
88 case 0:
89 if (default_format == NULL) break;
91 if (strstr(default_format, "%S") != NULL)
93 char* ptr;
94 int state = 0;
96 /* FIXME: simplistic implementation for default_format being
97 * foo%Sbar => will print foo, then string then bar
99 for (ptr = default_format; *ptr; ptr++)
101 if (*ptr == '%')
103 state++;
105 else if (state == 1)
107 if (*ptr == 'S')
109 DBG_ADDR addr;
111 addr.seg = 0;
112 addr.off = (long)res;
113 DEBUG_nchar += DEBUG_PrintStringA(DBG_CHN_MESG, &addr, -1);
115 else
117 /* shouldn't happen */
118 DEBUG_Printf(DBG_CHN_MESG, "%%%c", *ptr);
119 DEBUG_nchar += 2;
121 state = 0;
123 else
125 DEBUG_OutputA(DBG_CHN_MESG, ptr, 1);
126 DEBUG_nchar++;
130 else if (strcmp(default_format, "%B") == 0)
132 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, "%s", res ? "true" : "false");
134 else if (strcmp(default_format, "%R") == 0)
136 if (value->cookie == DV_HOST)
137 DEBUG_InfoRegisters((CONTEXT*)value->addr.off);
138 else
139 DEBUG_Printf(DBG_CHN_MESG, "NIY: info on register struct in debuggee address space\n");
140 DEBUG_nchar = 0;
142 else
144 DEBUG_nchar += DEBUG_Printf(DBG_CHN_MESG, default_format, res);
146 break;
151 /***********************************************************************
152 * DEBUG_PrintAddress
154 * Print an 16- or 32-bit address, with the nearest symbol if any.
156 struct symbol_info
157 DEBUG_PrintAddress( const DBG_ADDR *addr, enum dbg_mode mode, int flag )
159 struct symbol_info rtn;
161 const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, 0,
162 &rtn.list );
164 if (addr->seg) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx:", addr->seg&0xFFFF );
165 if (mode != MODE_32) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx", addr->off );
166 else DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", addr->off );
167 if (name) DEBUG_Printf( DBG_CHN_MESG, " (%s)", name );
168 return rtn;
170 /***********************************************************************
171 * DEBUG_PrintAddressAndArgs
173 * Print an 16- or 32-bit address, with the nearest symbol if any.
174 * Similar to DEBUG_PrintAddress, but we print the arguments to
175 * each function (if known). This is useful in a backtrace.
177 struct symbol_info
178 DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, enum dbg_mode mode,
179 unsigned int ebp, int flag )
181 struct symbol_info rtn;
183 const char *name = DEBUG_FindNearestSymbol( addr, flag, &rtn.sym, ebp,
184 &rtn.list );
186 if (addr->seg) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx:", addr->seg );
187 if (mode != MODE_32) DEBUG_Printf( DBG_CHN_MESG, "0x%04lx", addr->off );
188 else DEBUG_Printf( DBG_CHN_MESG, "0x%08lx", addr->off );
189 if (name) DEBUG_Printf( DBG_CHN_MESG, " (%s)", name );
191 return rtn;
195 /***********************************************************************
196 * DEBUG_Help
198 * Implementation of the 'help' command.
200 void DEBUG_Help(void)
202 int i = 0;
203 static const char * const helptext[] =
205 "The commands accepted by the Wine debugger are a reasonable",
206 "subset of the commands that gdb accepts.",
207 "The commands currently are:",
208 " help quit",
209 " break [*<addr>] watch *<addr>",
210 " delete break bpnum disable bpnum",
211 " enable bpnum condition <bpnum> [<expr>]",
212 " finish cont [N]",
213 " step [N] next [N]",
214 " stepi [N] nexti [N]",
215 " x <addr> print <expr>",
216 " display <expr> undisplay <disnum>",
217 " delete display <disnum> pass",
218 " bt frame <n>",
219 " up down",
220 " list <lines> disassemble [<addr>][,<addr>]",
221 " show dir dir <path>",
222 " set <reg> = <expr> set *<addr> = <expr>",
223 " mode [16,32,vm86] walk [wnd,class,module,maps,",
224 " whatis process,thread,exception]",
225 " info (see 'help info' for options) debugmsg <class>[-+]<type>\n",
227 "The 'x' command accepts repeat counts and formats (including 'i') in the",
228 "same way that gdb does.\n",
230 " The following are examples of legal expressions:",
231 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
232 " Also, a nm format symbol table can be read from a file using the",
233 " symbolfile command. Symbols can also be defined individually with",
234 " the define command.",
236 NULL
239 while(helptext[i]) DEBUG_Printf(DBG_CHN_MESG,"%s\n", helptext[i++]);
243 /***********************************************************************
244 * DEBUG_HelpInfo
246 * Implementation of the 'help info' command.
248 void DEBUG_HelpInfo(void)
250 int i = 0;
251 static const char * const infotext[] =
253 "The info commands allow you to get assorted bits of interesting stuff",
254 "to be displayed. The options are:",
255 " info break Dumps information about breakpoints",
256 " info display Shows auto-display expressions in use",
257 " info locals Displays values of all local vars for current frame",
258 " info module <handle> Displays internal module state",
259 " info reg Displays values in all registers at top of stack",
260 " info segments Dumps information about all known segments",
261 " info share Dumps information about shared libraries",
262 " info stack Dumps information about top of stack",
263 " info wnd <handle> Displays internal window state",
265 NULL
268 while(infotext[i]) DEBUG_Printf(DBG_CHN_MESG,"%s\n", infotext[i++]);
271 /* FIXME: merge InfoClass and InfoClass2 */
272 void DEBUG_InfoClass(const char* name)
274 WNDCLASSEXA wca;
276 if (!GetClassInfoEx(0, name, &wca)) {
277 DEBUG_Printf(DBG_CHN_MESG, "Cannot find class '%s'\n", name);
278 return;
281 DEBUG_Printf(DBG_CHN_MESG, "Class '%s':\n", name);
282 DEBUG_Printf(DBG_CHN_MESG,
283 "style=%08x wndProc=%08lx\n"
284 "inst=%p icon=%p cursor=%p bkgnd=%p\n"
285 "clsExtra=%d winExtra=%d\n",
286 wca.style, (DWORD)wca.lpfnWndProc, wca.hInstance,
287 wca.hIcon, wca.hCursor, wca.hbrBackground,
288 wca.cbClsExtra, wca.cbWndExtra);
290 /* FIXME:
291 * + print #windows (or even list of windows...)
292 * + print extra bytes => this requires a window handle on this very class...
296 static void DEBUG_InfoClass2(HWND hWnd, const char* name)
298 WNDCLASSEXA wca;
300 if (!GetClassInfoEx((HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE), name, &wca)) {
301 DEBUG_Printf(DBG_CHN_MESG, "Cannot find class '%s'\n", name);
302 return;
305 DEBUG_Printf(DBG_CHN_MESG, "Class '%s':\n", name);
306 DEBUG_Printf(DBG_CHN_MESG,
307 "style=%08x wndProc=%08lx\n"
308 "inst=%p icon=%p cursor=%p bkgnd=%p\n"
309 "clsExtra=%d winExtra=%d\n",
310 wca.style, (DWORD)wca.lpfnWndProc, wca.hInstance,
311 wca.hIcon, wca.hCursor, wca.hbrBackground,
312 wca.cbClsExtra, wca.cbWndExtra);
314 if (wca.cbClsExtra) {
315 int i;
316 WORD w;
318 DEBUG_Printf(DBG_CHN_MESG, "Extra bytes:" );
319 for (i = 0; i < wca.cbClsExtra / 2; i++) {
320 w = GetClassWord(hWnd, i * 2);
321 /* FIXME: depends on i386 endian-ity */
322 DEBUG_Printf(DBG_CHN_MESG, " %02x", HIBYTE(w));
323 DEBUG_Printf(DBG_CHN_MESG, " %02x", LOBYTE(w));
325 DEBUG_Printf(DBG_CHN_MESG, "\n" );
327 DEBUG_Printf(DBG_CHN_MESG, "\n" );
330 struct class_walker {
331 ATOM* table;
332 int used;
333 int alloc;
336 static void DEBUG_WalkClassesHelper(HWND hWnd, struct class_walker* cw)
338 char clsName[128];
339 int i;
340 ATOM atom;
341 HWND child;
343 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
344 return;
345 if ((atom = FindAtom(clsName)) == 0)
346 return;
348 for (i = 0; i < cw->used; i++) {
349 if (cw->table[i] == atom)
350 break;
352 if (i == cw->used) {
353 if (cw->used >= cw->alloc) {
354 cw->alloc += 16;
355 cw->table = DBG_realloc(cw->table, cw->alloc * sizeof(ATOM));
357 cw->table[cw->used++] = atom;
358 DEBUG_InfoClass2(hWnd, clsName);
360 do {
361 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
362 DEBUG_WalkClassesHelper(child, cw);
363 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
366 void DEBUG_WalkClasses(void)
368 struct class_walker cw;
370 cw.table = NULL;
371 cw.used = cw.alloc = 0;
372 DEBUG_WalkClassesHelper(GetDesktopWindow(), &cw);
373 DBG_free(cw.table);
376 void DEBUG_InfoWindow(HWND hWnd)
378 char clsName[128];
379 char wndName[128];
380 RECT clientRect;
381 RECT windowRect;
382 int i;
383 WORD w;
385 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
386 strcpy(clsName, "-- Unknown --");
387 if (!GetWindowText(hWnd, wndName, sizeof(wndName)))
388 strcpy(wndName, "-- Empty --");
389 if (!GetClientRect(hWnd, &clientRect))
390 SetRectEmpty(&clientRect);
391 if (!GetWindowRect(hWnd, &windowRect))
392 SetRectEmpty(&windowRect);
394 /* FIXME missing fields: hmemTaskQ, hrgnUpdate, dce, flags, pProp, scroll */
395 DEBUG_Printf(DBG_CHN_MESG,
396 "next=%p child=%p parent=%p owner=%p class='%s'\n"
397 "inst=%p active=%p idmenu=%08lx\n"
398 "style=%08lx exstyle=%08lx wndproc=%08lx text='%s'\n"
399 "client=%ld,%ld-%ld,%ld window=%ld,%ld-%ld,%ld sysmenu=%p\n",
400 GetWindow(hWnd, GW_HWNDNEXT),
401 GetWindow(hWnd, GW_CHILD),
402 GetParent(hWnd),
403 GetWindow(hWnd, GW_OWNER),
404 clsName,
405 (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE),
406 GetLastActivePopup(hWnd),
407 GetWindowLong(hWnd, GWL_ID),
408 GetWindowLong(hWnd, GWL_STYLE),
409 GetWindowLong(hWnd, GWL_EXSTYLE),
410 GetWindowLong(hWnd, GWL_WNDPROC),
411 wndName,
412 clientRect.left, clientRect.top, clientRect.right, clientRect.bottom,
413 windowRect.left, windowRect.top, windowRect.right, windowRect.bottom,
414 GetSystemMenu(hWnd, FALSE));
416 if (GetClassLong(hWnd, GCL_CBWNDEXTRA)) {
417 DEBUG_Printf(DBG_CHN_MESG, "Extra bytes:" );
418 for (i = 0; i < GetClassLong(hWnd, GCL_CBWNDEXTRA) / 2; i++) {
419 w = GetWindowWord(hWnd, i * 2);
420 /* FIXME: depends on i386 endian-ity */
421 DEBUG_Printf(DBG_CHN_MESG, " %02x", HIBYTE(w));
422 DEBUG_Printf(DBG_CHN_MESG, " %02x", LOBYTE(w));
424 DEBUG_Printf(DBG_CHN_MESG, "\n");
426 DEBUG_Printf(DBG_CHN_MESG, "\n");
429 void DEBUG_WalkWindows(HWND hWnd, int indent)
431 char clsName[128];
432 char wndName[128];
433 HWND child;
435 if (!IsWindow(hWnd))
436 hWnd = GetDesktopWindow();
438 if (!indent) /* first time around */
439 DEBUG_Printf(DBG_CHN_MESG,
440 "%-16.16s %-17.17s %-8.8s %s\n",
441 "hwnd", "Class Name", " Style", " WndProc Text");
443 do {
444 if (!GetClassName(hWnd, clsName, sizeof(clsName)))
445 strcpy(clsName, "-- Unknown --");
446 if (!GetWindowText(hWnd, wndName, sizeof(wndName)))
447 strcpy(wndName, "-- Empty --");
449 /* FIXME: missing hmemTaskQ */
450 DEBUG_Printf(DBG_CHN_MESG, "%*s%04x%*s", indent, "", (UINT)hWnd, 13-indent,"");
451 DEBUG_Printf(DBG_CHN_MESG, "%-17.17s %08lx %08lx %.14s\n",
452 clsName, GetWindowLong(hWnd, GWL_STYLE),
453 GetWindowLong(hWnd, GWL_WNDPROC), wndName);
455 if ((child = GetWindow(hWnd, GW_CHILD)) != 0)
456 DEBUG_WalkWindows(child, indent + 1 );
457 } while ((hWnd = GetWindow(hWnd, GW_HWNDNEXT)) != 0);
460 void DEBUG_WalkProcess(void)
462 HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
463 if (snap != INVALID_HANDLE_VALUE)
465 PROCESSENTRY32 entry;
466 DWORD current = DEBUG_CurrProcess ? DEBUG_CurrProcess->pid : 0;
467 BOOL ok;
469 entry.dwSize = sizeof(entry);
470 ok = Process32First( snap, &entry );
472 DEBUG_Printf(DBG_CHN_MESG, " %-8.8s %-8.8s %-8.8s %s\n",
473 "pid", "threads", "parent", "executable" );
474 while (ok)
476 if (entry.th32ProcessID != GetCurrentProcessId())
477 DEBUG_Printf(DBG_CHN_MESG, "%c%08lx %-8ld %08lx '%s'\n",
478 (entry.th32ProcessID == current) ? '>' : ' ',
479 entry.th32ProcessID, entry.cntThreads,
480 entry.th32ParentProcessID, entry.szExeFile);
481 ok = Process32Next( snap, &entry );
483 CloseHandle( snap );
487 void DEBUG_WalkThreads(void)
489 HANDLE snap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
490 if (snap != INVALID_HANDLE_VALUE)
492 THREADENTRY32 entry;
493 DWORD current = DEBUG_CurrThread ? DEBUG_CurrThread->tid : 0;
494 BOOL ok;
495 DWORD lastProcessId = 0;
497 entry.dwSize = sizeof(entry);
498 ok = Thread32First( snap, &entry );
500 DEBUG_Printf(DBG_CHN_MESG, "%-8.8s %-8.8s %s\n", "process", "tid", "prio" );
501 while (ok)
503 if (entry.th32OwnerProcessID != GetCurrentProcessId())
505 /* FIXME: this assumes that, in the snapshot, all threads of a same process are
506 * listed sequentially, which is not specified in the doc (Wine's implementation
507 * does it)
509 if (entry.th32OwnerProcessID != lastProcessId)
511 DBG_PROCESS* p = DEBUG_GetProcess(entry.th32OwnerProcessID);
513 DEBUG_Printf(DBG_CHN_MESG, "%08lx%s %s\n",
514 entry.th32OwnerProcessID, p ? " (D)" : "", p ? p->imageName : "");
515 lastProcessId = entry.th32OwnerProcessID;
517 DEBUG_Printf(DBG_CHN_MESG, "\t%08lx %4ld%s\n",
518 entry.th32ThreadID, entry.tpBasePri,
519 (entry.th32ThreadID == current) ? " <==" : "");
522 ok = Thread32Next( snap, &entry );
525 CloseHandle( snap );
529 /***********************************************************************
530 * DEBUG_WalkExceptions
532 * Walk the exception frames of a given thread.
534 void DEBUG_WalkExceptions(DWORD tid)
536 DBG_THREAD * thread;
537 void *next_frame;
539 if (!DEBUG_CurrProcess || !DEBUG_CurrThread)
541 DEBUG_Printf(DBG_CHN_MESG,
542 "Cannot walk exceptions while no process is loaded\n");
543 return;
546 DEBUG_Printf( DBG_CHN_MESG, "Exception frames:\n" );
548 if (tid == DEBUG_CurrTid) thread = DEBUG_CurrThread;
549 else
551 thread = DEBUG_GetThread(DEBUG_CurrProcess, tid);
553 if (!thread)
555 DEBUG_Printf( DBG_CHN_MESG, "Unknown thread id (0x%08lx) in current process\n", tid);
556 return;
558 if (SuspendThread( thread->handle ) == -1)
560 DEBUG_Printf( DBG_CHN_MESG, "Can't suspend thread id (0x%08lx)\n", tid);
561 return;
565 if (!DEBUG_READ_MEM(thread->teb, &next_frame, sizeof(next_frame)))
567 DEBUG_Printf( DBG_CHN_MESG, "Can't read TEB:except_frame\n");
568 return;
571 while (next_frame != (void *)-1)
573 EXCEPTION_FRAME frame;
575 DEBUG_Printf( DBG_CHN_MESG, "%p: ", next_frame );
576 if (!DEBUG_READ_MEM(next_frame, &frame, sizeof(frame)))
578 DEBUG_Printf( DBG_CHN_MESG, "Invalid frame address\n" );
579 break;
581 DEBUG_Printf( DBG_CHN_MESG, "prev=%p handler=%p\n", frame.Prev, frame.Handler );
582 next_frame = frame.Prev;
585 if (tid != DEBUG_CurrTid) ResumeThread( thread->handle );
589 void DEBUG_InfoSegments(DWORD start, int length)
591 char flags[3];
592 DWORD i;
593 LDT_ENTRY le;
595 if (length == -1) length = (8192 - start);
597 for (i = start; i < start + length; i++)
599 if (!GetThreadSelectorEntry(DEBUG_CurrThread->handle, (i << 3) | 7, &le))
600 continue;
602 if (le.HighWord.Bits.Type & 0x08)
604 flags[0] = (le.HighWord.Bits.Type & 0x2) ? 'r' : '-';
605 flags[1] = '-';
606 flags[2] = 'x';
608 else
610 flags[0] = 'r';
611 flags[1] = (le.HighWord.Bits.Type & 0x2) ? 'w' : '-';
612 flags[2] = '-';
614 DEBUG_Printf(DBG_CHN_MESG,
615 "%04lx: sel=%04lx base=%08x limit=%08x %d-bit %c%c%c\n",
616 i, (i<<3)|7,
617 (le.HighWord.Bits.BaseHi << 24) +
618 (le.HighWord.Bits.BaseMid << 16) + le.BaseLow,
619 ((le.HighWord.Bits.LimitHi << 8) + le.LimitLow) <<
620 (le.HighWord.Bits.Granularity ? 12 : 0),
621 le.HighWord.Bits.Default_Big ? 32 : 16,
622 flags[0], flags[1], flags[2] );
626 void DEBUG_InfoVirtual(DWORD pid)
628 MEMORY_BASIC_INFORMATION mbi;
629 char* addr = 0;
630 char* state;
631 char* type;
632 char prot[3+1];
633 HANDLE hProc;
635 if (pid == 0)
637 if (DEBUG_CurrProcess == NULL)
639 DEBUG_Printf(DBG_CHN_MESG,
640 "Cannot look at mapping of current process, while no process is loaded\n");
641 return;
643 hProc = DEBUG_CurrProcess->handle;
645 else
647 hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
648 if (hProc == NULL)
650 DEBUG_Printf(DBG_CHN_MESG, "Cannot open process <%lu>\n", pid);
651 return;
655 DEBUG_Printf(DBG_CHN_MESG, "Address Size State Type RWX\n");
657 while (VirtualQueryEx(hProc, addr, &mbi, sizeof(mbi)) >= sizeof(mbi))
659 switch (mbi.State)
661 case MEM_COMMIT: state = "commit "; break;
662 case MEM_FREE: state = "free "; break;
663 case MEM_RESERVE: state = "reserve"; break;
664 default: state = "??? "; break;
666 if (mbi.State != MEM_FREE)
668 switch (mbi.Type)
670 case MEM_IMAGE: type = "image "; break;
671 case MEM_MAPPED: type = "mapped "; break;
672 case MEM_PRIVATE: type = "private"; break;
673 case 0: type = " "; break;
674 default: type = "??? "; break;
676 memset(prot, ' ' , sizeof(prot)-1);
677 prot[sizeof(prot)-1] = '\0';
678 if (mbi.AllocationProtect & (PAGE_READONLY|PAGE_READWRITE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE))
679 prot[0] = 'R';
680 if (mbi.AllocationProtect & (PAGE_READWRITE|PAGE_EXECUTE_READWRITE))
681 prot[1] = 'W';
682 if (mbi.AllocationProtect & (PAGE_WRITECOPY|PAGE_EXECUTE_WRITECOPY))
683 prot[1] = 'C';
684 if (mbi.AllocationProtect & (PAGE_EXECUTE|PAGE_EXECUTE_READ|PAGE_EXECUTE_READWRITE))
685 prot[2] = 'X';
687 else
689 type = "";
690 prot[0] = '\0';
692 DEBUG_Printf(DBG_CHN_MESG, "%08lx %08lx %s %s %s\n",
693 (DWORD)addr, mbi.RegionSize, state, type, prot);
694 if (addr + mbi.RegionSize < addr) /* wrap around ? */
695 break;
696 addr += mbi.RegionSize;
698 if (hProc != DEBUG_CurrProcess->handle) CloseHandle(hProc);
701 struct dll_option_layout
703 void* next;
704 void* prev;
705 char* const* channels;
706 int nb_channels;
709 void DEBUG_DbgChannel(BOOL turn_on, const char* chnl, const char* name)
711 DBG_VALUE val;
712 struct dll_option_layout dol;
713 int i;
714 char* str;
715 unsigned char buffer[32];
716 unsigned char mask;
717 int done = 0;
718 BOOL bAll;
719 void* addr;
721 if (DEBUG_GetSymbolValue("first_dll", -1, &val, FALSE) != gsv_found)
723 DEBUG_Printf(DBG_CHN_MESG, "Can't get first_option symbol");
724 return;
726 addr = (void*)DEBUG_ToLinear(&val.addr);
727 if (!chnl) mask = 15;
728 else if (!strcmp(chnl, "fixme")) mask = 1;
729 else if (!strcmp(chnl, "err")) mask = 2;
730 else if (!strcmp(chnl, "warn")) mask = 4;
731 else if (!strcmp(chnl, "trace")) mask = 8;
732 else { DEBUG_Printf(DBG_CHN_MESG, "Unknown channel %s\n", chnl); return; }
734 bAll = !strcmp("all", name);
735 while (addr && DEBUG_READ_MEM(addr, &dol, sizeof(dol)))
737 for (i = 0; i < dol.nb_channels; i++)
739 if (DEBUG_READ_MEM((void*)(dol.channels + i), &str, sizeof(str)) &&
740 DEBUG_READ_MEM(str, buffer, sizeof(buffer)) &&
741 (!strcmp(buffer + 1, name) || bAll))
743 if (turn_on) buffer[0] |= mask; else buffer[0] &= ~mask;
744 if (DEBUG_WRITE_MEM(str, buffer, 1)) done++;
747 addr = dol.next;
749 if (!done) DEBUG_Printf(DBG_CHN_MESG, "Unable to find debug channel %s\n", name);
750 else DEBUG_Printf(DBG_CHN_TRACE, "Changed %d channel instances\n", done);