2 * Wine debugger utility routines
11 extern unsigned int dbg_mask
;
12 extern unsigned int dbg_mode
;
14 extern int print_insn(char * memaddr
, char * realaddr
, FILE * stream
, int addrlen
);
16 /* THese three helper functions eliminate the need for patching the
17 module from gdb for disassembly of code */
19 void application_not_running()
21 fprintf(stderr
,"Application not running\n");
24 void read_memory(char * memaddr
, char * buffer
, int len
){
25 memcpy(buffer
, memaddr
, len
);
28 void fputs_filtered(char * buffer
, FILE * outfile
){
29 fputs(buffer
, outfile
);
32 void print_address(unsigned int addr
, FILE * outfile
){
34 name
= find_nearest_symbol(addr
);
36 fprintf(outfile
,"0x%8.8x(%s)", addr
, name
);
38 fprintf(outfile
,"0x%8.8x", addr
);
46 application_not_running();
50 fprintf(stderr
,"Register dump:\n");
51 /* First get the segment registers out of the way */
52 fprintf(stderr
," CS:%4.4x SS:%4.4x DS:%4.4x ES:%4.4x GS:%4.4x FS:%4.4x\n",
53 SC_CS
, SC_SS
, SC_DS
, SC_ES
, SC_GS
, SC_FS
);
55 /* Now dump the main registers */
56 fprintf(stderr
," EIP:%8.8x ESP:%8.8x EBP:%8.8x EFLAGS:%8.8x\n",
57 SC_EIP(dbg_mask
), SC_ESP(dbg_mask
), SC_EBP(dbg_mask
), SC_EFLAGS
);
59 /* And dump the regular registers */
61 fprintf(stderr
," EAX:%8.8x EBX:%8.8x ECX:%8.8x EDX:%8.8x\n",
62 SC_EAX(dbg_mask
), SC_EBX(dbg_mask
), SC_ECX(dbg_mask
), SC_EDX(dbg_mask
));
64 /* Finally dump these main registers */
65 fprintf(stderr
," EDI:%8.8x ESI:%8.8x\n",
66 SC_EDI(dbg_mask
), SC_ESI(dbg_mask
));
75 application_not_running();
79 fprintf(stderr
,"Stack dump:\n");
80 dump
= (int*) SC_EIP(dbg_mask
);
83 fprintf(stderr
," %8.8x", *dump
++);
91 void examine_memory(int addr
, int count
, char format
){
94 unsigned short int * wdump
;
97 if((addr
& 0xffff0000) == 0 && dbg_mode
== 16)
98 addr
|= (format
== 'i' ? SC_CS
: SC_DS
) << 16;
101 if(format
!= 'i' && count
> 1) {
102 print_address(addr
, stderr
);
103 fprintf(stderr
,": ");
110 if (count
== 1) count
= 256;
111 while(*pnt
&& count
) {
112 fputc( *pnt
++, stderr
);
115 fprintf(stderr
,"\n");
119 for(i
=0; i
<count
; i
++) {
120 print_address(addr
, stderr
);
121 fprintf(stderr
,": ");
122 addr
+= print_insn((char *) addr
, (char *) addr
, stderr
, dbg_mode
);
123 fprintf(stderr
,"\n");
127 dump
= (unsigned int *) addr
;
128 for(i
=0; i
<count
; i
++)
130 fprintf(stderr
," %8.8x", *dump
++);
132 fprintf(stderr
,"\n");
133 print_address((unsigned int) dump
, stderr
);
134 fprintf(stderr
,": ");
137 fprintf(stderr
,"\n");
141 dump
= (unsigned int *) addr
;
142 for(i
=0; i
<count
; i
++)
144 fprintf(stderr
," %d", *dump
++);
146 fprintf(stderr
,"\n");
147 print_address((unsigned int) dump
, stderr
);
148 fprintf(stderr
,": ");
151 fprintf(stderr
,"\n");
155 wdump
= (unsigned short int *) addr
;
156 for(i
=0; i
<count
; i
++)
158 fprintf(stderr
," %x", *wdump
++);
160 fprintf(stderr
,"\n");
161 print_address((unsigned int) wdump
, stderr
);
162 fprintf(stderr
,": ");
165 fprintf(stderr
,"\n");
170 for(i
=0; i
<count
; i
++)
176 fprintf(stderr
," %c", *pnt
++);
178 fprintf(stderr
,"\n");
179 print_address((unsigned int) dump
, stderr
);
180 fprintf(stderr
,": ");
183 fprintf(stderr
,"\n");
188 for(i
=0; i
<count
; i
++)
190 fprintf(stderr
," %02.2x", (*pnt
++) & 0xff);
192 fprintf(stderr
,"\n");
193 print_address((unsigned int) pnt
, stderr
);
194 fprintf(stderr
,": ");
197 fprintf(stderr
,"\n");
201 /* The rest are fairly straightforward */
203 fprintf(stderr
,"examine mem: %x %d %c\n", addr
, count
, format
);
206 char * helptext
[] = {
207 "The commands accepted by the Wine debugger are a small subset",
208 "of the commands that gdb would accept. The commands currently",
210 " info [reg,stack,break]",
219 " symbolfile <filename>",
220 " define <identifier> <expr>",
223 " set <reg> = <expr>",
224 " set *<expr> = <expr>",
226 "The 'x' command accepts repeat counts and formats (including 'i') in the",
227 "same way that gdb does.",
229 " The following are examples of legal expressions:",
230 " $eax $eax+0x3 0x1000 ($eip + 256) *$eax *($esp + 3)",
231 " Also, a nm format symbol table can be read from a file using the",
232 " symbolfile command. Symbols can also be defined individually with",
233 " the define command.",
235 "The disassembly code seems to work most of the time, but it does get",
236 "a little confused at times. The 16 bit mode probably has not been used",
237 "much so there are probably bugs. I snagged the file from the gdb-4.7",
238 "source tree, which is what was on my latest cdrom. I should check to see",
239 "if newer versions of gdb have anything substanitally different for the",
247 while(helptext
[i
]) fprintf(stderr
,"%s\n", helptext
[i
++]);
254 unsigned short saved_bp
;
255 unsigned short saved_ip
;
256 unsigned short saved_cs
;
259 unsigned long saved_bp
;
260 unsigned long saved_ip
;
261 unsigned short saved_cs
;
268 struct frame
* frame
;
273 application_not_running();
277 fprintf(stderr
,"Backtrace:\n");
278 fprintf(stderr
,"%d: %4.4x:%4.4x\n", frameno
++, SC_CS
, SC_EIP(dbg_mask
));
281 frame
= (struct frame
*) ((SC_EBP(dbg_mask
) & ~1) | (SC_SS
<< 16));
282 while((cs
& 3) == 3) {
283 /* See if in 32 bit mode or not. Assume GDT means 32 bit. */
285 cs
= frame
->u
.win32
.saved_cs
;
286 fprintf(stderr
,"%d %4.4x:%4.4x\n", frameno
++, cs
,
287 frame
->u
.win32
.saved_ip
);
288 frame
= (struct frame
*) frame
->u
.win32
.saved_bp
;
290 cs
= frame
->u
.win16
.saved_cs
;
291 fprintf(stderr
,"%d %4.4x:%4.4x\n", frameno
++, cs
,
292 frame
->u
.win16
.saved_ip
);
293 frame
= (struct frame
*) ((frame
->u
.win16
.saved_bp
& ~1) |