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 STEP_FLAG 0x00000100 /* single step flag */
33 #define V86_FLAG 0x00020000
35 #define IS_VM86_MODE(ctx) (ctx->EFlags & V86_FLAG)
38 static ADDRESS_MODE
get_selector_type(HANDLE hThread
, const CONTEXT
* ctx
, WORD sel
)
42 if (IS_VM86_MODE(ctx
)) return AddrModeReal
;
43 /* null or system selector */
44 if (!(sel
& 4) || ((sel
>> 3) < 17)) return AddrModeFlat
;
45 if (hThread
&& GetThreadSelectorEntry(hThread
, sel
, &le
))
46 return le
.HighWord
.Bits
.Default_Big
? AddrMode1632
: AddrMode1616
;
47 /* selector doesn't exist */
51 static unsigned i386_build_addr(HANDLE hThread
, const CONTEXT
* ctx
, ADDRESS64
* addr
,
52 unsigned seg
, unsigned long offset
)
54 addr
->Mode
= AddrModeFlat
;
56 addr
->Offset
= offset
;
59 switch (addr
->Mode
= get_selector_type(hThread
, ctx
, seg
))
63 addr
->Offset
&= 0xffff;
76 static unsigned i386_get_addr(HANDLE hThread
, const CONTEXT
* ctx
,
77 enum cpu_addr ca
, ADDRESS64
* addr
)
82 case cpu_addr_pc
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegCs
, ctx
->Eip
);
83 case cpu_addr_stack
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegSs
, ctx
->Esp
);
84 case cpu_addr_frame
: return i386_build_addr(hThread
, ctx
, addr
, ctx
->SegSs
, ctx
->Ebp
);
91 /* fetch_next_frame32()
93 * modify (at least) context.{eip, esp, ebp} using unwind information
94 * either out of debug info (dwarf, pdb), or simple stack unwind
96 static BOOL
fetch_next_frame32(struct cpu_stack_walk
* csw
,
97 CONTEXT
* context
, DWORD_PTR curr_pc
)
100 struct pdb_cmd_pair cpair
[4];
103 if (dwarf2_virtual_unwind(csw
, curr_pc
, context
, &xframe
))
105 context
->Esp
= xframe
;
108 cpair
[0].name
= "$ebp"; cpair
[0].pvalue
= &context
->Ebp
;
109 cpair
[1].name
= "$esp"; cpair
[1].pvalue
= &context
->Esp
;
110 cpair
[2].name
= "$eip"; cpair
[2].pvalue
= &context
->Eip
;
111 cpair
[3].name
= NULL
; cpair
[3].pvalue
= NULL
;
113 if (!pdb_virtual_unwind(csw
, curr_pc
, context
, cpair
))
115 /* do a simple unwind using ebp
116 * we assume a "regular" prologue in the function has been used
118 if (!context
->Ebp
) return FALSE
;
119 context
->Esp
= context
->Ebp
+ 2 * sizeof(DWORD
);
120 if (!sw_read_mem(csw
, context
->Ebp
+ sizeof(DWORD
), &val32
, sizeof(DWORD
)))
122 WARN("Cannot read new frame offset %p\n",
123 (void*)(DWORD_PTR
)(context
->Ebp
+ (int)sizeof(DWORD
)));
126 context
->Eip
= val32
;
127 /* "pop up" previous EBP value */
128 if (!sw_read_mem(csw
, context
->Ebp
, &val32
, sizeof(DWORD
)))
130 context
->Ebp
= val32
;
136 enum st_mode
{stm_start
, stm_32bit
, stm_16bit
, stm_done
};
138 /* indexes in Reserved array */
139 #define __CurrentModeCount 0
140 #define __CurrentSwitch 1
141 #define __NextSwitch 2
143 #define curr_mode (frame->Reserved[__CurrentModeCount] & 0x0F)
144 #define curr_count (frame->Reserved[__CurrentModeCount] >> 4)
145 #define curr_switch (frame->Reserved[__CurrentSwitch])
146 #define next_switch (frame->Reserved[__NextSwitch])
148 #define set_curr_mode(m) {frame->Reserved[__CurrentModeCount] &= ~0x0F; frame->Reserved[__CurrentModeCount] |= (m & 0x0F);}
149 #define inc_curr_count() (frame->Reserved[__CurrentModeCount] += 0x10)
151 static BOOL
i386_stack_walk(struct cpu_stack_walk
* csw
, LPSTACKFRAME64 frame
, CONTEXT
* context
)
153 STACK32FRAME frame32
;
154 STACK16FRAME frame16
;
167 if (curr_mode
>= stm_done
) return FALSE
;
169 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s cSwitch=%p nSwitch=%p\n",
170 wine_dbgstr_addr(&frame
->AddrPC
),
171 wine_dbgstr_addr(&frame
->AddrFrame
),
172 wine_dbgstr_addr(&frame
->AddrReturn
),
173 wine_dbgstr_addr(&frame
->AddrStack
),
174 curr_mode
== stm_start
? "start" : (curr_mode
== stm_16bit
? "16bit" : "32bit"),
175 wine_dbgstr_longlong(curr_count
),
176 (void*)(DWORD_PTR
)curr_switch
, (void*)(DWORD_PTR
)next_switch
);
179 /* if we're at first call (which doesn't actually unwind, it just computes ReturnPC,
180 * or if we're doing the first real unwind (count == 1), then we can directly use
181 * eip. otherwise, eip is *after* the insn that actually made the call to
182 * previous frame, so decrease eip by delta pc (1!) so that we're inside previous
184 * Doing so, we ensure that the pc used for unwinding is always inside the function
185 * we want to use for next frame
187 deltapc
= curr_count
<= 1 ? 0 : 1;
191 /* setup a pseudo context for the rest of the code (esp. unwinding) */
193 memset(context
, 0, sizeof(*context
));
194 context
->ContextFlags
= CONTEXT_CONTROL
| CONTEXT_SEGMENTS
;
195 if (frame
->AddrPC
.Mode
!= AddrModeFlat
) context
->SegCs
= frame
->AddrPC
.Segment
;
196 context
->Eip
= frame
->AddrPC
.Offset
;
197 if (frame
->AddrFrame
.Mode
!= AddrModeFlat
) context
->SegSs
= frame
->AddrFrame
.Segment
;
198 context
->Ebp
= frame
->AddrFrame
.Offset
;
199 if (frame
->AddrStack
.Mode
!= AddrModeFlat
) context
->SegSs
= frame
->AddrStack
.Segment
;
200 context
->Esp
= frame
->AddrStack
.Offset
;
203 if (curr_mode
== stm_start
)
205 THREAD_BASIC_INFORMATION info
;
207 if ((frame
->AddrPC
.Mode
== AddrModeFlat
) &&
208 (frame
->AddrFrame
.Mode
!= AddrModeFlat
))
210 WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
215 set_curr_mode((frame
->AddrPC
.Mode
== AddrModeFlat
) ? stm_32bit
: stm_16bit
);
217 /* cur_switch holds address of WOW32Reserved field in TEB in debuggee
220 if (NtQueryInformationThread(csw
->hThread
, ThreadBasicInformation
, &info
,
221 sizeof(info
), NULL
) == STATUS_SUCCESS
)
223 curr_switch
= (DWORD_PTR
)info
.TebBaseAddress
+ FIELD_OFFSET(TEB
, WOW32Reserved
);
224 if (!sw_read_mem(csw
, curr_switch
, &p
, sizeof(p
)))
226 WARN("Can't read TEB:WOW32Reserved\n");
230 if (!next_switch
) /* no 16-bit stack */
234 else if (curr_mode
== stm_16bit
)
236 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
238 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
241 curr_switch
= (DWORD
)frame32
.frame16
;
242 tmp
.Mode
= AddrMode1616
;
243 tmp
.Segment
= SELECTOROF(curr_switch
);
244 tmp
.Offset
= OFFSETOF(curr_switch
);
245 if (!sw_read_mem(csw
, sw_xlat_addr(csw
, &tmp
), &ch
, sizeof(ch
)))
246 curr_switch
= 0xFFFFFFFF;
250 tmp
.Mode
= AddrMode1616
;
251 tmp
.Segment
= SELECTOROF(next_switch
);
252 tmp
.Offset
= OFFSETOF(next_switch
);
253 p
= sw_xlat_addr(csw
, &tmp
);
254 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
256 WARN("Bad stack frame 0x%08x\n", p
);
259 curr_switch
= (DWORD_PTR
)frame16
.frame32
;
260 if (!sw_read_mem(csw
, curr_switch
, &ch
, sizeof(ch
)))
261 curr_switch
= 0xFFFFFFFF;
265 /* FIXME: this will allow to work when we're not attached to a live target,
266 * but the 16 <=> 32 switch facility won't be available.
269 frame
->AddrReturn
.Mode
= frame
->AddrStack
.Mode
= (curr_mode
== stm_16bit
) ? AddrMode1616
: AddrModeFlat
;
270 /* don't set up AddrStack on first call. Either the caller has set it up, or
271 * we will get it in the next frame
273 memset(&frame
->AddrBStore
, 0, sizeof(frame
->AddrBStore
));
277 if (frame
->AddrFrame
.Mode
== AddrModeFlat
)
279 assert(curr_mode
== stm_32bit
);
280 do_switch
= curr_switch
&& frame
->AddrFrame
.Offset
>= curr_switch
;
284 assert(curr_mode
== stm_16bit
);
285 do_switch
= curr_switch
&&
286 frame
->AddrFrame
.Segment
== SELECTOROF(curr_switch
) &&
287 frame
->AddrFrame
.Offset
>= OFFSETOF(curr_switch
);
292 if (curr_mode
== stm_16bit
)
294 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
296 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
300 frame
->AddrPC
.Mode
= AddrModeFlat
;
301 frame
->AddrPC
.Segment
= 0;
302 frame
->AddrPC
.Offset
= frame32
.retaddr
;
303 frame
->AddrFrame
.Mode
= AddrModeFlat
;
304 frame
->AddrFrame
.Segment
= 0;
305 frame
->AddrFrame
.Offset
= frame32
.ebp
;
307 frame
->AddrStack
.Mode
= AddrModeFlat
;
308 frame
->AddrStack
.Segment
= 0;
309 frame
->AddrReturn
.Mode
= AddrModeFlat
;
310 frame
->AddrReturn
.Segment
= 0;
312 next_switch
= curr_switch
;
313 tmp
.Mode
= AddrMode1616
;
314 tmp
.Segment
= SELECTOROF(next_switch
);
315 tmp
.Offset
= OFFSETOF(next_switch
);
316 p
= sw_xlat_addr(csw
, &tmp
);
318 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
320 WARN("Bad stack frame 0x%08x\n", p
);
323 curr_switch
= (DWORD_PTR
)frame16
.frame32
;
324 set_curr_mode(stm_32bit
);
325 if (!sw_read_mem(csw
, curr_switch
, &ch
, sizeof(ch
)))
330 tmp
.Mode
= AddrMode1616
;
331 tmp
.Segment
= SELECTOROF(next_switch
);
332 tmp
.Offset
= OFFSETOF(next_switch
);
333 p
= sw_xlat_addr(csw
, &tmp
);
335 if (!sw_read_mem(csw
, p
, &frame16
, sizeof(frame16
)))
337 WARN("Bad stack frame 0x%08x\n", p
);
341 TRACE("Got a 16 bit stack switch:"
343 "\n\tedx:%08x ecx:%08x ebp:%08x"
344 "\n\tds:%04x es:%04x fs:%04x gs:%04x"
345 "\n\tcall_from_ip:%08x module_cs:%04x relay=%08x"
346 "\n\tentry_ip:%04x entry_point:%08x"
347 "\n\tbp:%04x ip:%04x cs:%04x\n",
349 frame16
.edx
, frame16
.ecx
, frame16
.ebp
,
350 frame16
.ds
, frame16
.es
, frame16
.fs
, frame16
.gs
,
351 frame16
.callfrom_ip
, frame16
.module_cs
, frame16
.relay
,
352 frame16
.entry_ip
, frame16
.entry_point
,
353 frame16
.bp
, frame16
.ip
, frame16
.cs
);
355 frame
->AddrPC
.Mode
= AddrMode1616
;
356 frame
->AddrPC
.Segment
= frame16
.cs
;
357 frame
->AddrPC
.Offset
= frame16
.ip
;
359 frame
->AddrFrame
.Mode
= AddrMode1616
;
360 frame
->AddrFrame
.Segment
= SELECTOROF(next_switch
);
361 frame
->AddrFrame
.Offset
= frame16
.bp
;
363 frame
->AddrStack
.Mode
= AddrMode1616
;
364 frame
->AddrStack
.Segment
= SELECTOROF(next_switch
);
366 frame
->AddrReturn
.Mode
= AddrMode1616
;
367 frame
->AddrReturn
.Segment
= frame16
.cs
;
369 next_switch
= curr_switch
;
370 if (!sw_read_mem(csw
, next_switch
, &frame32
, sizeof(frame32
)))
372 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR
)next_switch
);
375 curr_switch
= (DWORD
)frame32
.frame16
;
376 tmp
.Mode
= AddrMode1616
;
377 tmp
.Segment
= SELECTOROF(curr_switch
);
378 tmp
.Offset
= OFFSETOF(curr_switch
);
380 if (!sw_read_mem(csw
, sw_xlat_addr(csw
, &tmp
), &ch
, sizeof(ch
)))
382 set_curr_mode(stm_16bit
);
387 if (curr_mode
== stm_16bit
)
389 frame
->AddrPC
= frame
->AddrReturn
;
390 frame
->AddrStack
.Offset
= frame
->AddrFrame
.Offset
+ 2 * sizeof(WORD
);
391 /* "pop up" previous BP value */
392 if (!frame
->AddrFrame
.Offset
||
393 !sw_read_mem(csw
, sw_xlat_addr(csw
, &frame
->AddrFrame
),
394 &val16
, sizeof(WORD
)))
396 frame
->AddrFrame
.Offset
= val16
;
401 if (!fetch_next_frame32(csw
, context
, sw_xlat_addr(csw
, &frame
->AddrPC
) - deltapc
))
404 frame
->AddrStack
.Mode
= frame
->AddrFrame
.Mode
= frame
->AddrPC
.Mode
= AddrModeFlat
;
405 frame
->AddrStack
.Offset
= context
->Esp
;
406 frame
->AddrFrame
.Offset
= context
->Ebp
;
407 if (frame
->AddrReturn
.Offset
!= context
->Eip
)
408 FIXME("new PC=%s different from Eip=%x\n",
409 wine_dbgstr_longlong(frame
->AddrReturn
.Offset
), context
->Eip
);
410 frame
->AddrPC
.Offset
= context
->Eip
;
416 if (curr_mode
== stm_16bit
)
420 p
= sw_xlat_addr(csw
, &frame
->AddrFrame
);
421 if (!sw_read_mem(csw
, p
+ sizeof(WORD
), &val16
, sizeof(WORD
)))
423 frame
->AddrReturn
.Offset
= val16
;
424 /* get potential cs if a far call was used */
425 if (!sw_read_mem(csw
, p
+ 2 * sizeof(WORD
), &val16
, sizeof(WORD
)))
427 if (frame
->AddrFrame
.Offset
& 1)
428 frame
->AddrReturn
.Segment
= val16
; /* far call assumed */
431 /* not explicitly marked as far call,
432 * but check whether it could be anyway
434 if ((val16
& 7) == 7 && val16
!= frame
->AddrReturn
.Segment
)
438 if (GetThreadSelectorEntry(csw
->hThread
, val16
, &le
) &&
439 (le
.HighWord
.Bits
.Type
& 0x08)) /* code segment */
441 /* it is very uncommon to push a code segment cs as
442 * a parameter, so this should work in most cases
444 frame
->AddrReturn
.Segment
= val16
;
448 frame
->AddrFrame
.Offset
&= ~1;
449 /* we "pop" parameters as 16 bit entities... of course, this won't
450 * work if the parameter is in fact bigger than 16bit, but
451 * there's no way to know that here
453 for (i
= 0; i
< sizeof(frame
->Params
) / sizeof(frame
->Params
[0]); i
++)
455 sw_read_mem(csw
, p
+ (2 + i
) * sizeof(WORD
), &val16
, sizeof(val16
));
456 frame
->Params
[i
] = val16
;
461 #define SET(field, seg, reg) \
462 switch (frame->field.Mode) \
464 case AddrModeFlat: context->reg = frame->field.Offset; break; \
465 case AddrMode1616: context->seg = frame->field.Segment; context->reg = frame->field.Offset; break; \
466 default: assert(0); \
468 SET(AddrStack
, SegSs
, Esp
);
469 SET(AddrFrame
, SegSs
, Ebp
);
470 SET(AddrReturn
, SegCs
, Eip
);
479 CONTEXT newctx
= *context
;
481 if (!fetch_next_frame32(csw
, &newctx
, frame
->AddrPC
.Offset
- deltapc
))
483 frame
->AddrReturn
.Mode
= AddrModeFlat
;
484 frame
->AddrReturn
.Offset
= newctx
.Eip
;
486 for (i
= 0; i
< sizeof(frame
->Params
) / sizeof(frame
->Params
[0]); i
++)
488 sw_read_mem(csw
, frame
->AddrFrame
.Offset
+ (2 + i
) * sizeof(DWORD
), &val32
, sizeof(val32
));
489 frame
->Params
[i
] = val32
;
494 frame
->Virtual
= TRUE
;
495 p
= sw_xlat_addr(csw
, &frame
->AddrPC
);
496 if (p
&& sw_module_base(csw
, p
))
497 frame
->FuncTableEntry
= sw_table_access(csw
, p
);
499 frame
->FuncTableEntry
= NULL
;
502 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s Count=%s cSwitch=%p nSwitch=%p FuncTable=%p\n",
503 wine_dbgstr_addr(&frame
->AddrPC
),
504 wine_dbgstr_addr(&frame
->AddrFrame
),
505 wine_dbgstr_addr(&frame
->AddrReturn
),
506 wine_dbgstr_addr(&frame
->AddrStack
),
507 curr_mode
== stm_start
? "start" : (curr_mode
== stm_16bit
? "16bit" : "32bit"),
508 wine_dbgstr_longlong(curr_count
),
509 (void*)(DWORD_PTR
)curr_switch
, (void*)(DWORD_PTR
)next_switch
, frame
->FuncTableEntry
);
513 set_curr_mode(stm_done
);
517 static unsigned i386_map_dwarf_register(unsigned regno
)
523 case 0: reg
= CV_REG_EAX
; break;
524 case 1: reg
= CV_REG_ECX
; break;
525 case 2: reg
= CV_REG_EDX
; break;
526 case 3: reg
= CV_REG_EBX
; break;
527 case 4: reg
= CV_REG_ESP
; break;
528 case 5: reg
= CV_REG_EBP
; break;
529 case 6: reg
= CV_REG_ESI
; break;
530 case 7: reg
= CV_REG_EDI
; break;
531 case 8: reg
= CV_REG_EIP
; break;
532 case 9: reg
= CV_REG_EFLAGS
; break;
533 case 10: reg
= CV_REG_CS
; break;
534 case 11: reg
= CV_REG_SS
; break;
535 case 12: reg
= CV_REG_DS
; break;
536 case 13: reg
= CV_REG_ES
; break;
537 case 14: reg
= CV_REG_FS
; break;
538 case 15: reg
= CV_REG_GS
; break;
539 case 16: case 17: case 18: case 19:
540 case 20: case 21: case 22: case 23:
541 reg
= CV_REG_ST0
+ regno
- 16; break;
542 case 24: reg
= CV_REG_CTRL
; break;
543 case 25: reg
= CV_REG_STAT
; break;
544 case 26: reg
= CV_REG_TAG
; break;
545 case 27: reg
= CV_REG_FPCS
; break;
546 case 28: reg
= CV_REG_FPIP
; break;
547 case 29: reg
= CV_REG_FPDS
; break;
548 case 30: reg
= CV_REG_FPDO
; break;
552 case 32: case 33: case 34: case 35:
553 case 36: case 37: case 38: case 39:
554 reg
= CV_REG_XMM0
+ regno
- 32; break;
555 case 40: reg
= CV_REG_MXCSR
; break;
557 FIXME("Don't know how to map register %d\n", regno
);
563 static void* i386_fetch_context_reg(CONTEXT
* ctx
, unsigned regno
, unsigned* size
)
568 case CV_REG_EAX
: *size
= sizeof(ctx
->Eax
); return &ctx
->Eax
;
569 case CV_REG_EDX
: *size
= sizeof(ctx
->Edx
); return &ctx
->Edx
;
570 case CV_REG_ECX
: *size
= sizeof(ctx
->Ecx
); return &ctx
->Ecx
;
571 case CV_REG_EBX
: *size
= sizeof(ctx
->Ebx
); return &ctx
->Ebx
;
572 case CV_REG_ESI
: *size
= sizeof(ctx
->Esi
); return &ctx
->Esi
;
573 case CV_REG_EDI
: *size
= sizeof(ctx
->Edi
); return &ctx
->Edi
;
574 case CV_REG_EBP
: *size
= sizeof(ctx
->Ebp
); return &ctx
->Ebp
;
575 case CV_REG_ESP
: *size
= sizeof(ctx
->Esp
); return &ctx
->Esp
;
576 case CV_REG_EIP
: *size
= sizeof(ctx
->Eip
); return &ctx
->Eip
;
578 case CV_REG_ST0
+ 0: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[0*sizeof(long double)];
579 case CV_REG_ST0
+ 1: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[1*sizeof(long double)];
580 case CV_REG_ST0
+ 2: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[2*sizeof(long double)];
581 case CV_REG_ST0
+ 3: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[3*sizeof(long double)];
582 case CV_REG_ST0
+ 4: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[4*sizeof(long double)];
583 case CV_REG_ST0
+ 5: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[5*sizeof(long double)];
584 case CV_REG_ST0
+ 6: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[6*sizeof(long double)];
585 case CV_REG_ST0
+ 7: *size
= sizeof(long double); return &ctx
->FloatSave
.RegisterArea
[7*sizeof(long double)];
587 case CV_REG_CTRL
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ControlWord
;
588 case CV_REG_STAT
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.StatusWord
;
589 case CV_REG_TAG
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.TagWord
;
590 case CV_REG_FPCS
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ErrorSelector
;
591 case CV_REG_FPIP
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.ErrorOffset
;
592 case CV_REG_FPDS
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.DataSelector
;
593 case CV_REG_FPDO
: *size
= sizeof(DWORD
); return &ctx
->FloatSave
.DataOffset
;
595 case CV_REG_EFLAGS
: *size
= sizeof(ctx
->EFlags
); return &ctx
->EFlags
;
596 case CV_REG_ES
: *size
= sizeof(ctx
->SegEs
); return &ctx
->SegEs
;
597 case CV_REG_CS
: *size
= sizeof(ctx
->SegCs
); return &ctx
->SegCs
;
598 case CV_REG_SS
: *size
= sizeof(ctx
->SegSs
); return &ctx
->SegSs
;
599 case CV_REG_DS
: *size
= sizeof(ctx
->SegDs
); return &ctx
->SegDs
;
600 case CV_REG_FS
: *size
= sizeof(ctx
->SegFs
); return &ctx
->SegFs
;
601 case CV_REG_GS
: *size
= sizeof(ctx
->SegGs
); return &ctx
->SegGs
;
605 FIXME("Unknown register %x\n", regno
);
609 static const char* i386_fetch_regname(unsigned regno
)
613 case CV_REG_EAX
: return "eax";
614 case CV_REG_EDX
: return "edx";
615 case CV_REG_ECX
: return "ecx";
616 case CV_REG_EBX
: return "ebx";
617 case CV_REG_ESI
: return "esi";
618 case CV_REG_EDI
: return "edi";
619 case CV_REG_EBP
: return "ebp";
620 case CV_REG_ESP
: return "esp";
621 case CV_REG_EIP
: return "eip";
623 case CV_REG_ST0
+ 0: return "st0";
624 case CV_REG_ST0
+ 1: return "st1";
625 case CV_REG_ST0
+ 2: return "st2";
626 case CV_REG_ST0
+ 3: return "st3";
627 case CV_REG_ST0
+ 4: return "st4";
628 case CV_REG_ST0
+ 5: return "st5";
629 case CV_REG_ST0
+ 6: return "st6";
630 case CV_REG_ST0
+ 7: return "st7";
632 case CV_REG_EFLAGS
: return "eflags";
633 case CV_REG_ES
: return "es";
634 case CV_REG_CS
: return "cs";
635 case CV_REG_SS
: return "ss";
636 case CV_REG_DS
: return "ds";
637 case CV_REG_FS
: return "fs";
638 case CV_REG_GS
: return "gs";
640 case CV_REG_CTRL
: return "fpControl";
641 case CV_REG_STAT
: return "fpStatus";
642 case CV_REG_TAG
: return "fpTag";
643 case CV_REG_FPCS
: return "fpCS";
644 case CV_REG_FPIP
: return "fpIP";
645 case CV_REG_FPDS
: return "fpDS";
646 case CV_REG_FPDO
: return "fpData";
648 case CV_REG_XMM0
+ 0: return "xmm0";
649 case CV_REG_XMM0
+ 1: return "xmm1";
650 case CV_REG_XMM0
+ 2: return "xmm2";
651 case CV_REG_XMM0
+ 3: return "xmm3";
652 case CV_REG_XMM0
+ 4: return "xmm4";
653 case CV_REG_XMM0
+ 5: return "xmm5";
654 case CV_REG_XMM0
+ 6: return "xmm6";
655 case CV_REG_XMM0
+ 7: return "xmm7";
657 case CV_REG_MXCSR
: return "MxCSR";
659 FIXME("Unknown register %x\n", regno
);
663 static BOOL
i386_fetch_minidump_thread(struct dump_context
* dc
, unsigned index
, unsigned flags
, const CONTEXT
* ctx
)
665 if (ctx
->ContextFlags
&& (flags
& ThreadWriteInstructionWindow
))
667 /* FIXME: crop values across module boundaries, */
669 ULONG base
= ctx
->Eip
<= 0x80 ? 0 : ctx
->Eip
- 0x80;
670 minidump_add_memory_block(dc
, base
, ctx
->Eip
+ 0x80 - base
, 0);
677 static BOOL
i386_fetch_minidump_module(struct dump_context
* dc
, unsigned index
, unsigned flags
)
679 /* FIXME: actually, we should probably take care of FPO data, unless it's stored in
680 * function table minidump stream
685 DECLSPEC_HIDDEN
struct cpu cpu_i386
= {
686 IMAGE_FILE_MACHINE_I386
,
692 i386_map_dwarf_register
,
693 i386_fetch_context_reg
,
695 i386_fetch_minidump_thread
,
696 i386_fetch_minidump_module
,