4 * Copyright (C) 2009-2009, Eric Pouech.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
25 #include "dbghelp_private.h"
26 #include "wine/winbase16.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp
);
32 #define V86_FLAG 0x00020000
34 #define IS_VM86_MODE(ctx) (ctx->EFlags & V86_FLAG)
37 static ADDRESS_MODE
get_selector_type(HANDLE hThread
, const CONTEXT
* ctx
, WORD sel
)
41 if (IS_VM86_MODE(ctx
)) return AddrModeReal
;
42 /* null or system selector */
43 if (!(sel
& 4) || ((sel
>> 3) < 17)) return AddrModeFlat
;
44 if (hThread
&& GetThreadSelectorEntry(hThread
, sel
, &le
))
45 return le
.HighWord
.Bits
.Default_Big
? AddrMode1632
: AddrMode1616
;
46 /* selector doesn't exist */
50 static BOOL
i386_build_addr(HANDLE hThread
, const CONTEXT
* ctx
, ADDRESS64
* addr
,
51 unsigned seg
, ULONG_PTR offset
)
53 addr
->Mode
= AddrModeFlat
;
55 addr
->Offset
= offset
;
58 switch (addr
->Mode
= get_selector_type(hThread
, ctx
, seg
))
62 addr
->Offset
&= 0xffff;
75 static BOOL
i386_get_addr(HANDLE hThread
, const CONTEXT
* ctx
,
76 enum cpu_addr ca
, ADDRESS64
* addr
)
81 case cpu_addr_pc
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegCs
, ctx
->Eip
);
82 case cpu_addr_stack
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegSs
, ctx
->Esp
);
83 case cpu_addr_frame
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegSs
, ctx
->Ebp
);
89 /* fetch_next_frame32()
91 * modify (at least) context.{eip, esp, ebp} using unwind information
92 * either out of debug info (dwarf, pdb), or simple stack unwind
94 static BOOL
fetch_next_frame32(struct cpu_stack_walk
* csw
,
95 union ctx
*pcontext
, DWORD_PTR curr_pc
)
98 struct pdb_cmd_pair cpair
[4];
100 WOW64_CONTEXT
*context
= &pcontext
->x86
;
102 if (dwarf2_virtual_unwind(csw
, curr_pc
, pcontext
, &xframe
))
104 context
->Esp
= xframe
;
107 cpair
[0].name
= "$ebp"; cpair
[0].pvalue
= &context
->Ebp
;
108 cpair
[1].name
= "$esp"; cpair
[1].pvalue
= &context
->Esp
;
109 cpair
[2].name
= "$eip"; cpair
[2].pvalue
= &context
->Eip
;
110 cpair
[3].name
= NULL
; cpair
[3].pvalue
= NULL
;
112 if (!pdb_virtual_unwind(csw
, curr_pc
, pcontext
, cpair
))
114 /* do a simple unwind using ebp
115 * we assume a "regular" prologue in the function has been used
117 if (!context
->Ebp
) return FALSE
;
118 context
->Esp
= context
->Ebp
+ 2 * sizeof(DWORD
);
119 if (!sw_read_mem(csw
, context
->Ebp
+ sizeof(DWORD
), &val32
, sizeof(DWORD
)))
121 WARN("Cannot read new frame offset %p\n",
122 (void*)(DWORD_PTR
)(context
->Ebp
+ (int)sizeof(DWORD
)));
125 context
->Eip
= val32
;
126 /* "pop up" previous EBP value */
127 if (!sw_read_mem(csw
, context
->Ebp
, &val32
, sizeof(DWORD
)))
129 context
->Ebp
= val32
;
134 enum st_mode
{stm_start
, stm_32bit
, stm_16bit
, stm_done
};
136 /* indexes in Reserved array */
137 #define __CurrentModeCount 0
138 #define __CurrentSwitch 1
139 #define __NextSwitch 2
141 #define curr_mode (frame->Reserved[__CurrentModeCount] & 0x0F)
142 #define curr_count (frame->Reserved[__CurrentModeCount] >> 4)
143 #define curr_switch (frame->Reserved[__CurrentSwitch])
144 #define next_switch (frame->Reserved[__NextSwitch])
146 #define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);}
147 #define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10)
149 static BOOL
i386_stack_walk(struct cpu_stack_walk
*csw
, STACKFRAME64
*frame
,
152 STACK32FRAME frame32
;
153 STACK16FRAME frame16
;
164 if (curr_mode
>= stm_done
) return FALSE
;
166 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s cSwitch=%p nSwitch=%p\n",
167 wine_dbgstr_addr(&frame
->AddrPC
),
168 wine_dbgstr_addr(&frame
->AddrFrame
),
169 wine_dbgstr_addr(&frame
->AddrReturn
),
170 wine_dbgstr_addr(&frame
->AddrStack
),
171 curr_mode
== stm_start
? "start" : (curr_mode
== stm_16bit
? "16bit" : "32bit"),
172 wine_dbgstr_longlong(curr_count
),
173 (void*)(DWORD_PTR
)curr_switch
, (void*)(DWORD_PTR
)next_switch
);
175 /* if we're at first call (which doesn't actually unwind, it just computes ReturnPC,
176 * or if we're doing the first real unwind (count == 1), then we can directly use
177 * eip. otherwise, eip is *after* the insn that actually made the call to
178 * previous frame, so decrease eip by delta pc (1!) so that we're inside previous
180 * Doing so, we ensure that the pc used for unwinding is always inside the function
181 * we want to use for next frame
183 deltapc
= curr_count
<= 1 ? 0 : 1;
187 /* setup a pseudo context for the rest of the code (esp. unwinding) */
189 memset(context
, 0, sizeof(*context
));
190 context
->x86
.ContextFlags
= WOW64_CONTEXT_CONTROL
| WOW64_CONTEXT_SEGMENTS
;
191 if (frame
->AddrPC
.Mode
!= AddrModeFlat
)
192 context
->x86
.SegCs
= frame
->AddrPC
.Segment
;
193 context
->x86
.Eip
= frame
->AddrPC
.Offset
;
194 if (frame
->AddrFrame
.Mode
!= AddrModeFlat
)
195 context
->x86
.SegSs
= frame
->AddrFrame
.Segment
;
196 context
->x86
.Ebp
= frame
->AddrFrame
.Offset
;
197 if (frame
->AddrStack
.Mode
!= AddrModeFlat
)
198 context
->x86
.SegSs
= frame
->AddrStack
.Segment
;
199 context
->x86
.Esp
= frame
->AddrStack
.Offset
;
202 if (curr_mode
== stm_start
)
204 THREAD_BASIC_INFORMATION info
;
206 if ((frame
->AddrPC
.Mode
== AddrModeFlat
) &&
207 (frame
->AddrFrame
.Mode
!= AddrModeFlat
))
209 WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
214 set_curr_mode((frame
->AddrPC
.Mode
== AddrModeFlat
) ? stm_32bit
: stm_16bit
);
216 /* cur_switch holds address of WOW32Reserved field in TEB in debuggee
219 if (NtQueryInformationThread(csw
->hThread
, ThreadBasicInformation
, &info
,
220 sizeof(info
), NULL
) == STATUS_SUCCESS
)
222 curr_switch
= (DWORD_PTR
)info
.TebBaseAddress
+ FIELD_OFFSET(TEB
, WOW32Reserved
);
223 if (!sw_read_mem(csw
, curr_switch
, &p
, sizeof(p
)))
225 WARN("Can't read TEB:WOW32Reserved\n");
229 if (!next_switch
) /* no 16-bit stack */
233 else if (curr_mode
== stm_16bit
)
235 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
237 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
240 curr_switch
= (DWORD
)frame32
.frame16
;
241 tmp
.Mode
= AddrMode1616
;
242 tmp
.Segment
= SELECTOROF(curr_switch
);
243 tmp
.Offset
= OFFSETOF(curr_switch
);
244 if (!sw_read_mem(csw
, sw_xlat_addr(csw
, &tmp
), &ch
, sizeof(ch
)))
245 curr_switch
= 0xFFFFFFFF;
249 tmp
.Mode
= AddrMode1616
;
250 tmp
.Segment
= SELECTOROF(next_switch
);
251 tmp
.Offset
= OFFSETOF(next_switch
);
252 p
= sw_xlat_addr(csw
, &tmp
);
253 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
255 WARN("Bad stack frame 0x%08x\n", p
);
258 curr_switch
= (DWORD_PTR
)frame16
.frame32
;
259 if (!sw_read_mem(csw
, curr_switch
, &ch
, sizeof(ch
)))
260 curr_switch
= 0xFFFFFFFF;
264 /* FIXME: this will allow it to work when we're not attached to a live target,
265 * but the 16 <=> 32 switch facility won't be available.
268 frame
->AddrReturn
.Mode
= frame
->AddrStack
.Mode
= (curr_mode
== stm_16bit
) ? AddrMode1616
: AddrModeFlat
;
269 /* don't set up AddrStack on first call. Either the caller has set it up, or
270 * we will get it in the next frame
272 memset(&frame
->AddrBStore
, 0, sizeof(frame
->AddrBStore
));
276 if (frame
->AddrFrame
.Mode
== AddrModeFlat
)
278 assert(curr_mode
== stm_32bit
);
279 do_switch
= curr_switch
&& frame
->AddrFrame
.Offset
>= curr_switch
;
283 assert(curr_mode
== stm_16bit
);
284 do_switch
= curr_switch
&&
285 frame
->AddrFrame
.Segment
== SELECTOROF(curr_switch
) &&
286 frame
->AddrFrame
.Offset
>= OFFSETOF(curr_switch
);
291 if (curr_mode
== stm_16bit
)
293 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
295 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
299 frame
->AddrPC
.Mode
= AddrModeFlat
;
300 frame
->AddrPC
.Segment
= 0;
301 frame
->AddrPC
.Offset
= frame32
.retaddr
;
302 frame
->AddrFrame
.Mode
= AddrModeFlat
;
303 frame
->AddrFrame
.Segment
= 0;
304 frame
->AddrFrame
.Offset
= frame32
.ebp
;
306 frame
->AddrStack
.Mode
= AddrModeFlat
;
307 frame
->AddrStack
.Segment
= 0;
308 frame
->AddrReturn
.Mode
= AddrModeFlat
;
309 frame
->AddrReturn
.Segment
= 0;
311 next_switch
= curr_switch
;
312 tmp
.Mode
= AddrMode1616
;
313 tmp
.Segment
= SELECTOROF(next_switch
);
314 tmp
.Offset
= OFFSETOF(next_switch
);
315 p
= sw_xlat_addr(csw
, &tmp
);
317 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
319 WARN("Bad stack frame 0x%08x\n", p
);
322 curr_switch
= (DWORD_PTR
)frame16
.frame32
;
323 set_curr_mode(stm_32bit
);
324 if (!sw_read_mem(csw
, curr_switch
, &ch
, sizeof(ch
)))
329 tmp
.Mode
= AddrMode1616
;
330 tmp
.Segment
= SELECTOROF(next_switch
);
331 tmp
.Offset
= OFFSETOF(next_switch
);
332 p
= sw_xlat_addr(csw
, &tmp
);
334 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
336 WARN("Bad stack frame 0x%08x\n", p
);
340 TRACE("Got a 16 bit stack switch:"
342 "\n\tedx:%08x ecx:%08x ebp:%08x"
343 "\n\tds:%04x es:%04x fs:%04x gs:%04x"
344 "\n\tcall_from_ip:%08x module_cs:%04x relay=%08x"
345 "\n\tentry_ip:%04x entry_point:%08x"
346 "\n\tbp:%04x ip:%04x cs:%04x\n",
348 frame16
.edx
, frame16
.ecx
, frame16
.ebp
,
349 frame16
.ds
, frame16
.es
, frame16
.fs
, frame16
.gs
,
350 frame16
.callfrom_ip
, frame16
.module_cs
, frame16
.relay
,
351 frame16
.entry_ip
, frame16
.entry_point
,
352 frame16
.bp
, frame16
.ip
, frame16
.cs
);
354 frame
->AddrPC
.Mode
= AddrMode1616
;
355 frame
->AddrPC
.Segment
= frame16
.cs
;
356 frame
->AddrPC
.Offset
= frame16
.ip
;
358 frame
->AddrFrame
.Mode
= AddrMode1616
;
359 frame
->AddrFrame
.Segment
= SELECTOROF(next_switch
);
360 frame
->AddrFrame
.Offset
= frame16
.bp
;
362 frame
->AddrStack
.Mode
= AddrMode1616
;
363 frame
->AddrStack
.Segment
= SELECTOROF(next_switch
);
365 frame
->AddrReturn
.Mode
= AddrMode1616
;
366 frame
->AddrReturn
.Segment
= frame16
.cs
;
368 next_switch
= curr_switch
;
369 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
371 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
374 curr_switch
= (DWORD
)frame32
.frame16
;
375 tmp
.Mode
= AddrMode1616
;
376 tmp
.Segment
= SELECTOROF(curr_switch
);
377 tmp
.Offset
= OFFSETOF(curr_switch
);
379 if (!sw_read_mem(csw
, sw_xlat_addr(csw
, &tmp
), &ch
, sizeof(ch
)))
381 set_curr_mode(stm_16bit
);
386 if (curr_mode
== stm_16bit
)
388 frame
->AddrPC
= frame
->AddrReturn
;
389 frame
->AddrStack
.Offset
= frame
->AddrFrame
.Offset
+ 2 * sizeof(WORD
);
390 /* "pop up" previous BP value */
391 if (!frame
->AddrFrame
.Offset
||
392 !sw_read_mem(csw
, sw_xlat_addr(csw
, &frame
->AddrFrame
),
393 &val16
, sizeof(WORD
)))
395 frame
->AddrFrame
.Offset
= val16
;
399 if (!fetch_next_frame32(csw
, context
, sw_xlat_addr(csw
, &frame
->AddrPC
) - deltapc
))
402 frame
->AddrStack
.Mode
= frame
->AddrFrame
.Mode
= frame
->AddrPC
.Mode
= AddrModeFlat
;
403 frame
->AddrStack
.Offset
= context
->x86
.Esp
;
404 frame
->AddrFrame
.Offset
= context
->x86
.Ebp
;
405 if (frame
->AddrReturn
.Offset
!= context
->x86
.Eip
)
406 FIXME("new PC=%s different from Eip=%x\n",
407 wine_dbgstr_longlong(frame
->AddrReturn
.Offset
), context
->x86
.Eip
);
408 frame
->AddrPC
.Offset
= context
->x86
.Eip
;
413 if (curr_mode
== stm_16bit
)
417 p
= sw_xlat_addr(csw
, &frame
->AddrFrame
);
418 if (!sw_read_mem(csw
, p
+ sizeof(WORD
), &val16
, sizeof(WORD
)))
420 frame
->AddrReturn
.Offset
= val16
;
421 /* get potential cs if a far call was used */
422 if (!sw_read_mem(csw
, p
+ 2 * sizeof(WORD
), &val16
, sizeof(WORD
)))
424 if (frame
->AddrFrame
.Offset
& 1)
425 frame
->AddrReturn
.Segment
= val16
; /* far call assumed */
428 /* not explicitly marked as far call,
429 * but check whether it could be anyway
431 if ((val16
& 7) == 7 && val16
!= frame
->AddrReturn
.Segment
)
435 if (GetThreadSelectorEntry(csw
->hThread
, val16
, &le
) &&
436 (le
.HighWord
.Bits
.Type
& 0x08)) /* code segment */
438 /* it is very uncommon to push a code segment cs as
439 * a parameter, so this should work in most cases
441 frame
->AddrReturn
.Segment
= val16
;
445 frame
->AddrFrame
.Offset
&= ~1;
446 /* we "pop" parameters as 16 bit entities... of course, this won't
447 * work if the parameter is in fact bigger than 16bit, but
448 * there's no way to know that here
450 for (i
= 0; i
< ARRAY_SIZE(frame
->Params
); i
++)
452 sw_read_mem(csw
, p
+ (2 + i
) * sizeof(WORD
), &val16
, sizeof(val16
));
453 frame
->Params
[i
] = val16
;
457 #define SET(field, seg, reg) \
458 switch (frame->field.Mode) \
460 case AddrModeFlat: context->x86.reg = frame->field.Offset; break; \
461 case AddrMode1616: context->x86.seg = frame->field.Segment; context->x86.reg = frame->field.Offset; break; \
462 default: assert(0); \
464 SET(AddrStack
, SegSs
, Esp
);
465 SET(AddrFrame
, SegSs
, Ebp
);
466 SET(AddrReturn
, SegCs
, Eip
);
473 union ctx newctx
= *context
;
475 if (!fetch_next_frame32(csw
, &newctx
, frame
->AddrPC
.Offset
- deltapc
))
477 frame
->AddrReturn
.Mode
= AddrModeFlat
;
478 frame
->AddrReturn
.Offset
= newctx
.x86
.Eip
;
480 for (i
= 0; i
< ARRAY_SIZE(frame
->Params
); i
++)
482 sw_read_mem(csw
, frame
->AddrFrame
.Offset
+ (2 + i
) * sizeof(DWORD
), &val32
, sizeof(val32
));
483 frame
->Params
[i
] = val32
;
488 frame
->Virtual
= TRUE
;
489 p
= sw_xlat_addr(csw
, &frame
->AddrPC
);
490 if (p
&& sw_module_base(csw
, p
))
491 frame
->FuncTableEntry
= sw_table_access(csw
, p
);
493 frame
->FuncTableEntry
= NULL
;
496 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s cSwitch=%p nSwitch=%p FuncTable=%p\n",
497 wine_dbgstr_addr(&frame
->AddrPC
),
498 wine_dbgstr_addr(&frame
->AddrFrame
),
499 wine_dbgstr_addr(&frame
->AddrReturn
),
500 wine_dbgstr_addr(&frame
->AddrStack
),
501 curr_mode
== stm_start
? "start" : (curr_mode
== stm_16bit
? "16bit" : "32bit"),
502 wine_dbgstr_longlong(curr_count
),
503 (void*)(DWORD_PTR
)curr_switch
, (void*)(DWORD_PTR
)next_switch
, frame
->FuncTableEntry
);
507 set_curr_mode(stm_done
);
511 static unsigned i386_map_dwarf_register(unsigned regno
, const struct module
* module
, BOOL eh_frame
)
517 case 0: reg
= CV_REG_EAX
; break;
518 case 1: reg
= CV_REG_ECX
; break;
519 case 2: reg
= CV_REG_EDX
; break;
520 case 3: reg
= CV_REG_EBX
; break;
523 /* On OS X, DWARF eh_frame uses a different mapping for the registers. It's
524 apparently the mapping as emitted by GCC, at least at some point in its history. */
525 if (eh_frame
&& module
->type
== DMT_MACHO
)
526 reg
= (regno
== 4) ? CV_REG_EBP
: CV_REG_ESP
;
528 reg
= (regno
== 4) ? CV_REG_ESP
: CV_REG_EBP
;
530 case 6: reg
= CV_REG_ESI
; break;
531 case 7: reg
= CV_REG_EDI
; break;
532 case 8: reg
= CV_REG_EIP
; break;
533 case 9: reg
= CV_REG_EFLAGS
; break;
534 case 10: reg
= CV_REG_CS
; break;
535 case 11: reg
= CV_REG_SS
; break;
536 case 12: reg
= CV_REG_DS
; break;
537 case 13: reg
= CV_REG_ES
; break;
538 case 14: reg
= CV_REG_FS
; break;
539 case 15: reg
= CV_REG_GS
; break;
540 case 16: case 17: case 18: case 19:
541 case 20: case 21: case 22: case 23:
542 reg
= CV_REG_ST0
+ regno
- 16; break;
543 case 24: reg
= CV_REG_CTRL
; break;
544 case 25: reg
= CV_REG_STAT
; break;
545 case 26: reg
= CV_REG_TAG
; break;
546 case 27: reg
= CV_REG_FPCS
; break;
547 case 28: reg
= CV_REG_FPIP
; break;
548 case 29: reg
= CV_REG_FPDS
; break;
549 case 30: reg
= CV_REG_FPDO
; break;
553 case 32: case 33: case 34: case 35:
554 case 36: case 37: case 38: case 39:
555 reg
= CV_REG_XMM0
+ regno
- 32; break;
556 case 40: reg
= CV_REG_MXCSR
; break;
558 FIXME("Don't know how to map register %d\n", regno
);
564 static void *i386_fetch_context_reg(union ctx
*pctx
, unsigned regno
, unsigned *size
)
566 WOW64_CONTEXT
*ctx
= &pctx
->x86
;
570 case CV_REG_EAX
: *size
= sizeof(ctx
->Eax
); return &ctx
->Eax
;
571 case CV_REG_EDX
: *size
= sizeof(ctx
->Edx
); return &ctx
->Edx
;
572 case CV_REG_ECX
: *size
= sizeof(ctx
->Ecx
); return &ctx
->Ecx
;
573 case CV_REG_EBX
: *size
= sizeof(ctx
->Ebx
); return &ctx
->Ebx
;
574 case CV_REG_ESI
: *size
= sizeof(ctx
->Esi
); return &ctx
->Esi
;
575 case CV_REG_EDI
: *size
= sizeof(ctx
->Edi
); return &ctx
->Edi
;
576 case CV_REG_EBP
: *size
= sizeof(ctx
->Ebp
); return &ctx
->Ebp
;
577 case CV_REG_ESP
: *size
= sizeof(ctx
->Esp
); return &ctx
->Esp
;
578 case CV_REG_EIP
: *size
= sizeof(ctx
->Eip
); return &ctx
->Eip
;
580 /* These are x87 floating point registers... They do not match a C type in
581 * the Linux ABI, so hardcode their 80-bitness. */
582 case CV_REG_ST0
+ 0: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[0*10];
583 case CV_REG_ST0
+ 1: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[1*10];
584 case CV_REG_ST0
+ 2: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[2*10];
585 case CV_REG_ST0
+ 3: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[3*10];
586 case CV_REG_ST0
+ 4: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[4*10];
587 case CV_REG_ST0
+ 5: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[5*10];
588 case CV_REG_ST0
+ 6: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[6*10];
589 case CV_REG_ST0
+ 7: *size
= 10; return &ctx
->FloatSave
.RegisterArea
[7*10];
591 case CV_REG_CTRL
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ControlWord
;
592 case CV_REG_STAT
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.StatusWord
;
593 case CV_REG_TAG
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.TagWord
;
594 case CV_REG_FPCS
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ErrorSelector
;
595 case CV_REG_FPIP
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ErrorOffset
;
596 case CV_REG_FPDS
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.DataSelector
;
597 case CV_REG_FPDO
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.DataOffset
;
599 case CV_REG_EFLAGS
: *size
= sizeof(ctx
->EFlags
); return &ctx
->EFlags
;
600 case CV_REG_ES
: *size
= sizeof(ctx
->SegEs
); return &ctx
->SegEs
;
601 case CV_REG_CS
: *size
= sizeof(ctx
->SegCs
); return &ctx
->SegCs
;
602 case CV_REG_SS
: *size
= sizeof(ctx
->SegSs
); return &ctx
->SegSs
;
603 case CV_REG_DS
: *size
= sizeof(ctx
->SegDs
); return &ctx
->SegDs
;
604 case CV_REG_FS
: *size
= sizeof(ctx
->SegFs
); return &ctx
->SegFs
;
605 case CV_REG_GS
: *size
= sizeof(ctx
->SegGs
); return &ctx
->SegGs
;
607 case CV_REG_XMM0
+ 0: *size
= 16; return &ctx
->ExtendedRegisters
[10*16];
608 case CV_REG_XMM0
+ 1: *size
= 16; return &ctx
->ExtendedRegisters
[11*16];
609 case CV_REG_XMM0
+ 2: *size
= 16; return &ctx
->ExtendedRegisters
[12*16];
610 case CV_REG_XMM0
+ 3: *size
= 16; return &ctx
->ExtendedRegisters
[13*16];
611 case CV_REG_XMM0
+ 4: *size
= 16; return &ctx
->ExtendedRegisters
[14*16];
612 case CV_REG_XMM0
+ 5: *size
= 16; return &ctx
->ExtendedRegisters
[15*16];
613 case CV_REG_XMM0
+ 6: *size
= 16; return &ctx
->ExtendedRegisters
[16*16];
614 case CV_REG_XMM0
+ 7: *size
= 16; return &ctx
->ExtendedRegisters
[17*16];
616 case CV_REG_MXCSR
: *size
= sizeof(DWORD
); return &ctx
->ExtendedRegisters
[24];
618 FIXME("Unknown register %x\n", regno
);
622 static const char* i386_fetch_regname(unsigned regno
)
626 case CV_REG_EAX
: return "eax";
627 case CV_REG_EDX
: return "edx";
628 case CV_REG_ECX
: return "ecx";
629 case CV_REG_EBX
: return "ebx";
630 case CV_REG_ESI
: return "esi";
631 case CV_REG_EDI
: return "edi";
632 case CV_REG_EBP
: return "ebp";
633 case CV_REG_ESP
: return "esp";
634 case CV_REG_EIP
: return "eip";
636 case CV_REG_ST0
+ 0: return "st0";
637 case CV_REG_ST0
+ 1: return "st1";
638 case CV_REG_ST0
+ 2: return "st2";
639 case CV_REG_ST0
+ 3: return "st3";
640 case CV_REG_ST0
+ 4: return "st4";
641 case CV_REG_ST0
+ 5: return "st5";
642 case CV_REG_ST0
+ 6: return "st6";
643 case CV_REG_ST0
+ 7: return "st7";
645 case CV_REG_EFLAGS
: return "eflags";
646 case CV_REG_ES
: return "es";
647 case CV_REG_CS
: return "cs";
648 case CV_REG_SS
: return "ss";
649 case CV_REG_DS
: return "ds";
650 case CV_REG_FS
: return "fs";
651 case CV_REG_GS
: return "gs";
653 case CV_REG_CTRL
: return "fpControl";
654 case CV_REG_STAT
: return "fpStatus";
655 case CV_REG_TAG
: return "fpTag";
656 case CV_REG_FPCS
: return "fpCS";
657 case CV_REG_FPIP
: return "fpIP";
658 case CV_REG_FPDS
: return "fpDS";
659 case CV_REG_FPDO
: return "fpData";
661 case CV_REG_XMM0
+ 0: return "xmm0";
662 case CV_REG_XMM0
+ 1: return "xmm1";
663 case CV_REG_XMM0
+ 2: return "xmm2";
664 case CV_REG_XMM0
+ 3: return "xmm3";
665 case CV_REG_XMM0
+ 4: return "xmm4";
666 case CV_REG_XMM0
+ 5: return "xmm5";
667 case CV_REG_XMM0
+ 6: return "xmm6";
668 case CV_REG_XMM0
+ 7: return "xmm7";
670 case CV_REG_MXCSR
: return "MxCSR";
672 FIXME("Unknown register %x\n", regno
);
676 static BOOL
i386_fetch_minidump_thread(struct dump_context
* dc
, unsigned index
, unsigned flags
, const CONTEXT
* ctx
)
678 if (ctx
->ContextFlags
&& (flags
& ThreadWriteInstructionWindow
))
680 /* FIXME: crop values across module boundaries, */
682 ULONG base
= ctx
->Eip
<= 0x80 ? 0 : ctx
->Eip
- 0x80;
683 minidump_add_memory_block(dc
, base
, ctx
->Eip
+ 0x80 - base
, 0);
690 static BOOL
i386_fetch_minidump_module(struct dump_context
* dc
, unsigned index
, unsigned flags
)
692 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
693 * function table minidump stream
698 DECLSPEC_HIDDEN
struct cpu cpu_i386
= {
699 IMAGE_FILE_MACHINE_I386
,
705 i386_map_dwarf_register
,
706 i386_fetch_context_reg
,
708 i386_fetch_minidump_thread
,
709 i386_fetch_minidump_module
,