Release 961222
[wine/multimedia.git] / debugger / info.c
blob2abc9813ad4a979f48a89a0e54d765715a04b9d3
1 /*
2 * Wine debugger utility routines
4 * Copyright 1993 Eric Youngdale
5 * Copyright 1995 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include "debugger.h"
12 /***********************************************************************
13 * DEBUG_Print
15 * Implementation of the 'print' command.
17 void DEBUG_Print( const DBG_ADDR *addr, int count, char format )
19 if (count != 1)
21 fprintf( stderr, "Count other than 1 is meaningless in 'print' command\n" );
22 return;
25 if (addr->seg && (addr->seg != 0xffffffff))
27 switch(format)
29 case 'x':
30 fprintf( stderr, "0x%04lx:", addr->seg );
31 break;
33 case 'd':
34 fprintf( stderr, "%ld:", addr->seg );
35 break;
37 case 'c':
38 break; /* No segment to print */
40 case 'i':
41 case 's':
42 case 'w':
43 case 'b':
44 break; /* Meaningless format */
48 switch(format)
50 case 'x':
51 if (addr->seg) fprintf( stderr, "0x%04lx\n", addr->off );
52 else fprintf( stderr, "0x%08lx\n", addr->off );
53 break;
55 case 'd':
56 fprintf( stderr, "%ld\n", addr->off );
57 break;
59 case 'c':
60 fprintf( stderr, "%d = '%c'\n",
61 (char)(addr->off & 0xff), (char)(addr->off & 0xff) );
62 break;
64 case 'i':
65 case 's':
66 case 'w':
67 case 'b':
68 fprintf( stderr, "Format specifier '%c' is meaningless in 'print' command\n", format );
69 break;
74 /***********************************************************************
75 * DEBUG_PrintAddress
77 * Print an 16- or 32-bit address, with the nearest symbol if any.
79 struct name_hash *
80 DEBUG_PrintAddress( const DBG_ADDR *addr, int addrlen, int flag )
82 struct name_hash * nh;
83 const char *name = DEBUG_FindNearestSymbol( addr, flag, &nh, 0 );
85 if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg );
86 if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
87 else fprintf( stderr, "0x%08lx", addr->off );
88 if (name) fprintf( stderr, " (%s)", name );
89 return nh;
91 /***********************************************************************
92 * DEBUG_PrintAddressAndArgs
94 * Print an 16- or 32-bit address, with the nearest symbol if any.
95 * Similar to DEBUG_PrintAddress, but we print the arguments to
96 * each function (if known). This is useful in a backtrace.
98 struct name_hash *
99 DEBUG_PrintAddressAndArgs( const DBG_ADDR *addr, int addrlen,
100 unsigned int ebp, int flag )
102 struct name_hash * nh;
103 const char *name = DEBUG_FindNearestSymbol( addr, flag, &nh, ebp );
105 if (addr->seg) fprintf( stderr, "0x%04lx:", addr->seg );
106 if (addrlen == 16) fprintf( stderr, "0x%04lx", addr->off );
107 else fprintf( stderr, "0x%08lx", addr->off );
108 if (name) fprintf( stderr, " (%s)", name );
110 return nh;
114 /***********************************************************************
115 * DEBUG_Help
117 * Implementation of the 'help' command.
119 void DEBUG_Help(void)
121 int i = 0;
122 static const char * const helptext[] =
124 "The commands accepted by the Wine debugger are a small subset",
125 "of the commands that gdb would accept.",
126 "The commands currently are:",
127 " break [*<addr>] delete break bpnum",
128 " disable bpnum enable bpnum",
129 " help quit",
130 " bt cont",
131 " step next",
132 " x <addr> print <expr>",
133 " set <reg> = <expr> set *<addr> = <expr>",
134 " symbolfile <filename> define <identifier> <addr>",
135 " up down\n",
136 " list <addr> frame <n>\n",
138 "Wine-specific commands:",
139 " mode [16,32] walk [wnd,class,queue] <handle>",
140 " info [reg,stack,break,segments,locals] info [wnd, queue] <handle>\n",
142 "The 'x' command accepts repeat counts and formats (including 'i') in the",
143 "same way that gdb does.\n",
145 " The following are examples of legal expressions:",
146 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
147 " Also, a nm format symbol table can be read from a file using the",
148 " symbolfile command. Symbols can also be defined individually with",
149 " the define command.",
151 NULL
154 while(helptext[i]) fprintf(stderr,"%s\n", helptext[i++]);
159 /***********************************************************************
160 * DEBUG_List
162 * Implementation of the 'list' command.
164 void DEBUG_List( DBG_ADDR *addr, int count )
166 static DBG_ADDR lasttime = { 0xffffffff, 0 };
168 if (addr == NULL) addr = &lasttime;
169 DBG_FIX_ADDR_SEG( addr, CS_reg(DEBUG_context) );
170 while (count-- > 0)
172 DEBUG_PrintAddress( addr, dbg_mode, FALSE );
173 fprintf( stderr, ": " );
174 if (!DBG_CHECK_READ_PTR( addr, 1 )) return;
175 DEBUG_Disasm( addr );
176 fprintf (stderr, "\n");
178 lasttime = *addr;