dbghelp: Fix StackWalk when dwarf or pdb unwinders are called on first frame (CPU...
[wine/multimedia.git] / dlls / dbghelp / cpu_i386.c
blob817033b40fe8cff1791811bafccdb055bd4e143d
1 /*
2 * File cpu_i386.c
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
21 #include <assert.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "dbghelp_private.h"
26 #include "wine/winbase16.h"
27 #include "winternl.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)
37 #ifdef __i386__
38 static ADDRESS_MODE get_selector_type(HANDLE hThread, const CONTEXT* ctx, WORD sel)
40 LDT_ENTRY le;
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 */
48 return -1;
51 static unsigned i386_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr,
52 unsigned seg, unsigned long offset)
54 addr->Mode = AddrModeFlat;
55 addr->Segment = seg;
56 addr->Offset = offset;
57 if (seg)
59 switch (addr->Mode = get_selector_type(hThread, ctx, seg))
61 case AddrModeReal:
62 case AddrMode1616:
63 addr->Offset &= 0xffff;
64 break;
65 case AddrModeFlat:
66 case AddrMode1632:
67 break;
68 default:
69 return FALSE;
72 return TRUE;
74 #endif
76 static unsigned i386_get_addr(HANDLE hThread, const CONTEXT* ctx,
77 enum cpu_addr ca, ADDRESS64* addr)
79 #ifdef __i386__
80 switch (ca)
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);
86 #endif
87 return FALSE;
90 enum st_mode {stm_start, stm_32bit, stm_16bit, stm_done};
92 /* indexes in Reserved array */
93 #define __CurrentMode 0
94 #define __CurrentSwitch 1
95 #define __NextSwitch 2
97 #define curr_mode (frame->Reserved[__CurrentMode])
98 #define curr_switch (frame->Reserved[__CurrentSwitch])
99 #define next_switch (frame->Reserved[__NextSwitch])
101 static BOOL i386_stack_walk(struct cpu_stack_walk* csw, LPSTACKFRAME64 frame, CONTEXT* context)
103 STACK32FRAME frame32;
104 STACK16FRAME frame16;
105 char ch;
106 ADDRESS64 tmp;
107 DWORD p;
108 WORD val16;
109 DWORD val32;
110 BOOL do_switch;
111 unsigned deltapc = 1;
112 #ifdef __i386__
113 CONTEXT _context;
114 #endif
116 /* sanity check */
117 if (curr_mode >= stm_done) return FALSE;
119 TRACE("Enter: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%p nSwitch=%p\n",
120 wine_dbgstr_addr(&frame->AddrPC),
121 wine_dbgstr_addr(&frame->AddrFrame),
122 wine_dbgstr_addr(&frame->AddrReturn),
123 wine_dbgstr_addr(&frame->AddrStack),
124 curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
125 (void*)(DWORD_PTR)curr_switch, (void*)(DWORD_PTR)next_switch);
127 #ifdef __i386__
128 if (!context)
130 /* setup a pseudo context for the rest of the code (esp. unwinding) */
131 context = &_context;
132 memset(context, 0, sizeof(*context));
133 context->ContextFlags = CONTEXT_CONTROL | CONTEXT_SEGMENTS;
134 if (frame->AddrPC.Mode != AddrModeFlat) context->SegCs = frame->AddrPC.Segment;
135 context->Eip = frame->AddrPC.Offset;
136 if (frame->AddrFrame.Mode != AddrModeFlat) context->SegSs = frame->AddrFrame.Segment;
137 context->Ebp = frame->AddrFrame.Offset;
138 if (frame->AddrStack.Mode != AddrModeFlat) context->SegSs = frame->AddrStack.Segment;
139 context->Esp = frame->AddrStack.Offset;
141 #endif
142 if (curr_mode == stm_start)
144 THREAD_BASIC_INFORMATION info;
146 if ((frame->AddrPC.Mode == AddrModeFlat) &&
147 (frame->AddrFrame.Mode != AddrModeFlat))
149 WARN("Bad AddrPC.Mode / AddrFrame.Mode combination\n");
150 goto done_err;
153 /* Init done */
154 curr_mode = (frame->AddrPC.Mode == AddrModeFlat) ? stm_32bit : stm_16bit;
155 deltapc = 0;
157 /* cur_switch holds address of WOW32Reserved field in TEB in debuggee
158 * address space
160 if (NtQueryInformationThread(csw->hThread, ThreadBasicInformation, &info,
161 sizeof(info), NULL) == STATUS_SUCCESS)
163 curr_switch = (unsigned long)info.TebBaseAddress + FIELD_OFFSET(TEB, WOW32Reserved);
164 if (!sw_read_mem(csw, curr_switch, &p, sizeof(p)))
166 WARN("Can't read TEB:WOW32Reserved\n");
167 goto done_err;
169 next_switch = p;
170 if (!next_switch) /* no 16-bit stack */
172 curr_switch = 0;
174 else if (curr_mode == stm_16bit)
176 if (!sw_read_mem(csw, next_switch, &frame32, sizeof(frame32)))
178 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
179 goto done_err;
181 curr_switch = (DWORD)frame32.frame16;
182 tmp.Mode = AddrMode1616;
183 tmp.Segment = SELECTOROF(curr_switch);
184 tmp.Offset = OFFSETOF(curr_switch);
185 if (!sw_read_mem(csw, sw_xlat_addr(csw, &tmp), &ch, sizeof(ch)))
186 curr_switch = 0xFFFFFFFF;
188 else
190 tmp.Mode = AddrMode1616;
191 tmp.Segment = SELECTOROF(next_switch);
192 tmp.Offset = OFFSETOF(next_switch);
193 p = sw_xlat_addr(csw, &tmp);
194 if (!sw_read_mem(csw, p, &frame16, sizeof(frame16)))
196 WARN("Bad stack frame 0x%08x\n", p);
197 goto done_err;
199 curr_switch = (DWORD_PTR)frame16.frame32;
201 if (!sw_read_mem(csw, curr_switch, &ch, sizeof(ch)))
202 curr_switch = 0xFFFFFFFF;
205 else
206 /* FIXME: this will allow to work when we're not attached to a live target,
207 * but the 16 <=> 32 switch facility won't be available.
209 curr_switch = 0;
210 frame->AddrReturn.Mode = frame->AddrStack.Mode = (curr_mode == stm_16bit) ? AddrMode1616 : AddrModeFlat;
211 /* don't set up AddrStack on first call. Either the caller has set it up, or
212 * we will get it in the next frame
214 memset(&frame->AddrBStore, 0, sizeof(frame->AddrBStore));
215 #ifdef __i386__
216 if (curr_mode == stm_32bit)
218 DWORD_PTR xframe;
219 struct pdb_cmd_pair cpair[4];
220 CONTEXT newctx = *context;
222 if (dwarf2_virtual_unwind(csw, frame->AddrPC.Offset - deltapc, &newctx, &xframe))
224 frame->AddrReturn.Mode = AddrModeFlat;
225 frame->AddrReturn.Offset = newctx.Eip;
226 goto done_pep;
228 cpair[0].name = "$ebp"; cpair[0].pvalue = &newctx.Ebp;
229 cpair[1].name = "$esp"; cpair[1].pvalue = &newctx.Esp;
230 cpair[2].name = "$eip"; cpair[2].pvalue = &newctx.Eip;
231 cpair[3].name = NULL; cpair[3].pvalue = NULL;
233 if (pdb_virtual_unwind(csw, frame->AddrPC.Offset - deltapc, &newctx, cpair))
235 frame->AddrReturn.Mode = AddrModeFlat;
236 frame->AddrReturn.Offset = newctx.Eip;
237 goto done_pep;
240 #endif
242 else
244 if (frame->AddrFrame.Offset == 0) goto done_err;
245 if (frame->AddrFrame.Mode == AddrModeFlat)
247 assert(curr_mode == stm_32bit);
248 do_switch = curr_switch && frame->AddrFrame.Offset >= curr_switch;
250 else
252 assert(curr_mode == stm_16bit);
253 do_switch = curr_switch &&
254 frame->AddrFrame.Segment == SELECTOROF(curr_switch) &&
255 frame->AddrFrame.Offset >= OFFSETOF(curr_switch);
258 if (do_switch)
260 if (curr_mode == stm_16bit)
262 if (!sw_read_mem(csw, next_switch, &frame32, sizeof(frame32)))
264 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
265 goto done_err;
268 frame->AddrPC.Mode = AddrModeFlat;
269 frame->AddrPC.Segment = 0;
270 frame->AddrPC.Offset = frame32.retaddr;
271 frame->AddrFrame.Mode = AddrModeFlat;
272 frame->AddrFrame.Segment = 0;
273 frame->AddrFrame.Offset = frame32.ebp;
275 frame->AddrStack.Mode = AddrModeFlat;
276 frame->AddrStack.Segment = 0;
277 frame->AddrReturn.Mode = AddrModeFlat;
278 frame->AddrReturn.Segment = 0;
280 next_switch = curr_switch;
281 tmp.Mode = AddrMode1616;
282 tmp.Segment = SELECTOROF(next_switch);
283 tmp.Offset = OFFSETOF(next_switch);
284 p = sw_xlat_addr(csw, &tmp);
286 if (!sw_read_mem(csw, p, &frame16, sizeof(frame16)))
288 WARN("Bad stack frame 0x%08x\n", p);
289 goto done_err;
291 curr_switch = (DWORD_PTR)frame16.frame32;
292 curr_mode = stm_32bit;
293 if (!sw_read_mem(csw, curr_switch, &ch, sizeof(ch)))
294 curr_switch = 0;
296 else
298 tmp.Mode = AddrMode1616;
299 tmp.Segment = SELECTOROF(next_switch);
300 tmp.Offset = OFFSETOF(next_switch);
301 p = sw_xlat_addr(csw, &tmp);
303 if (!sw_read_mem(csw, p, &frame16, sizeof(frame16)))
305 WARN("Bad stack frame 0x%08x\n", p);
306 goto done_err;
309 TRACE("Got a 16 bit stack switch:"
310 "\n\tframe32: %08lx"
311 "\n\tedx:%08x ecx:%08x ebp:%08x"
312 "\n\tds:%04x es:%04x fs:%04x gs:%04x"
313 "\n\tcall_from_ip:%08x module_cs:%04x relay=%08x"
314 "\n\tentry_ip:%04x entry_point:%08x"
315 "\n\tbp:%04x ip:%04x cs:%04x\n",
316 (unsigned long)frame16.frame32,
317 frame16.edx, frame16.ecx, frame16.ebp,
318 frame16.ds, frame16.es, frame16.fs, frame16.gs,
319 frame16.callfrom_ip, frame16.module_cs, frame16.relay,
320 frame16.entry_ip, frame16.entry_point,
321 frame16.bp, frame16.ip, frame16.cs);
323 frame->AddrPC.Mode = AddrMode1616;
324 frame->AddrPC.Segment = frame16.cs;
325 frame->AddrPC.Offset = frame16.ip;
327 frame->AddrFrame.Mode = AddrMode1616;
328 frame->AddrFrame.Segment = SELECTOROF(next_switch);
329 frame->AddrFrame.Offset = frame16.bp;
331 frame->AddrStack.Mode = AddrMode1616;
332 frame->AddrStack.Segment = SELECTOROF(next_switch);
334 frame->AddrReturn.Mode = AddrMode1616;
335 frame->AddrReturn.Segment = frame16.cs;
337 next_switch = curr_switch;
338 if (!sw_read_mem(csw, next_switch, &frame32, sizeof(frame32)))
340 WARN("Bad stack frame %p\n", (void*)(DWORD_PTR)next_switch);
341 goto done_err;
343 curr_switch = (DWORD)frame32.frame16;
344 tmp.Mode = AddrMode1616;
345 tmp.Segment = SELECTOROF(curr_switch);
346 tmp.Offset = OFFSETOF(curr_switch);
348 if (!sw_read_mem(csw, sw_xlat_addr(csw, &tmp), &ch, sizeof(ch)))
349 curr_switch = 0;
350 curr_mode = stm_16bit;
353 else
355 frame->AddrPC = frame->AddrReturn;
356 if (curr_mode == stm_16bit)
358 frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(WORD);
359 /* "pop up" previous BP value */
360 if (!sw_read_mem(csw, sw_xlat_addr(csw, &frame->AddrFrame),
361 &val16, sizeof(WORD)))
362 goto done_err;
363 frame->AddrFrame.Offset = val16;
365 else
367 #ifdef __i386__
368 DWORD_PTR xframe;
369 struct pdb_cmd_pair cpair[4];
371 if (dwarf2_virtual_unwind(csw, frame->AddrPC.Offset - deltapc, context, &xframe))
373 frame->AddrStack.Mode = frame->AddrFrame.Mode = frame->AddrReturn.Mode = AddrModeFlat;
374 frame->AddrStack.Offset = context->Esp = xframe;
375 frame->AddrFrame.Offset = context->Ebp;
376 frame->AddrReturn.Offset = context->Eip;
377 goto done_pep;
379 cpair[0].name = "$ebp"; cpair[0].pvalue = &context->Ebp;
380 cpair[1].name = "$esp"; cpair[1].pvalue = &context->Esp;
381 cpair[2].name = "$eip"; cpair[2].pvalue = &context->Eip;
382 cpair[3].name = NULL; cpair[3].pvalue = NULL;
384 if (pdb_virtual_unwind(csw, frame->AddrPC.Offset - deltapc, context, cpair))
386 frame->AddrStack.Mode = frame->AddrFrame.Mode = frame->AddrReturn.Mode = AddrModeFlat;
387 frame->AddrStack.Offset = context->Esp;
388 frame->AddrFrame.Offset = context->Ebp;
389 frame->AddrReturn.Offset = context->Eip;
390 goto done_pep;
392 #endif
393 frame->AddrStack.Offset = frame->AddrFrame.Offset + 2 * sizeof(DWORD);
394 /* "pop up" previous EBP value */
395 if (!sw_read_mem(csw, frame->AddrFrame.Offset, &val32, sizeof(DWORD)))
396 goto done_err;
397 frame->AddrFrame.Offset = val32;
402 if (curr_mode == stm_16bit)
404 unsigned int i;
406 p = sw_xlat_addr(csw, &frame->AddrFrame);
407 if (!sw_read_mem(csw, p + sizeof(WORD), &val16, sizeof(WORD)))
408 goto done_err;
409 frame->AddrReturn.Offset = val16;
410 /* get potential cs if a far call was used */
411 if (!sw_read_mem(csw, p + 2 * sizeof(WORD), &val16, sizeof(WORD)))
412 goto done_err;
413 if (frame->AddrFrame.Offset & 1)
414 frame->AddrReturn.Segment = val16; /* far call assumed */
415 else
417 /* not explicitly marked as far call,
418 * but check whether it could be anyway
420 if ((val16 & 7) == 7 && val16 != frame->AddrReturn.Segment)
422 LDT_ENTRY le;
424 if (GetThreadSelectorEntry(csw->hThread, val16, &le) &&
425 (le.HighWord.Bits.Type & 0x08)) /* code segment */
427 /* it is very uncommon to push a code segment cs as
428 * a parameter, so this should work in most cases
430 frame->AddrReturn.Segment = val16;
434 frame->AddrFrame.Offset &= ~1;
435 /* we "pop" parameters as 16 bit entities... of course, this won't
436 * work if the parameter is in fact bigger than 16bit, but
437 * there's no way to know that here
439 for (i = 0; i < sizeof(frame->Params) / sizeof(frame->Params[0]); i++)
441 sw_read_mem(csw, p + (2 + i) * sizeof(WORD), &val16, sizeof(val16));
442 frame->Params[i] = val16;
445 else
447 unsigned int i;
448 if (!sw_read_mem(csw, frame->AddrFrame.Offset + sizeof(DWORD), &val32, sizeof(DWORD)))
450 WARN("Cannot read new frame offset %p\n",
451 (void*)(DWORD_PTR)(frame->AddrFrame.Offset + (int)sizeof(DWORD)));
452 goto done_err;
454 frame->AddrReturn.Offset = val32;
455 for (i = 0; i < sizeof(frame->Params) / sizeof(frame->Params[0]); i++)
457 sw_read_mem(csw, frame->AddrFrame.Offset + (2 + i) * sizeof(DWORD), &val32, sizeof(val32));
458 frame->Params[i] = val32;
461 #ifdef __i386__
462 if (context)
464 #define SET(field, seg, reg) \
465 switch (frame->field.Mode) \
467 case AddrModeFlat: context->reg = frame->field.Offset; break; \
468 case AddrMode1616: context->seg = frame->field.Segment; context->reg = frame->field.Offset; break; \
469 default: assert(0); \
471 SET(AddrStack, SegSs, Esp);
472 SET(AddrFrame, SegSs, Ebp);
473 SET(AddrReturn, SegCs, Eip);
474 #undef SET
476 done_pep:
477 #endif
479 frame->Far = TRUE;
480 frame->Virtual = TRUE;
481 p = sw_xlat_addr(csw, &frame->AddrPC);
482 if (p && sw_module_base(csw, p))
483 frame->FuncTableEntry = sw_table_access(csw, p);
484 else
485 frame->FuncTableEntry = NULL;
487 TRACE("Leave: PC=%s Frame=%s Return=%s Stack=%s Mode=%s cSwitch=%p nSwitch=%p FuncTable=%p\n",
488 wine_dbgstr_addr(&frame->AddrPC),
489 wine_dbgstr_addr(&frame->AddrFrame),
490 wine_dbgstr_addr(&frame->AddrReturn),
491 wine_dbgstr_addr(&frame->AddrStack),
492 curr_mode == stm_start ? "start" : (curr_mode == stm_16bit ? "16bit" : "32bit"),
493 (void*)(DWORD_PTR)curr_switch, (void*)(DWORD_PTR)next_switch, frame->FuncTableEntry);
495 return TRUE;
496 done_err:
497 curr_mode = stm_done;
498 return FALSE;
501 static unsigned i386_map_dwarf_register(unsigned regno)
503 unsigned reg;
505 switch (regno)
507 case 0: reg = CV_REG_EAX; break;
508 case 1: reg = CV_REG_ECX; break;
509 case 2: reg = CV_REG_EDX; break;
510 case 3: reg = CV_REG_EBX; break;
511 case 4: reg = CV_REG_ESP; break;
512 case 5: reg = CV_REG_EBP; break;
513 case 6: reg = CV_REG_ESI; break;
514 case 7: reg = CV_REG_EDI; break;
515 case 8: reg = CV_REG_EIP; break;
516 case 9: reg = CV_REG_EFLAGS; break;
517 case 10: reg = CV_REG_CS; break;
518 case 11: reg = CV_REG_SS; break;
519 case 12: reg = CV_REG_DS; break;
520 case 13: reg = CV_REG_ES; break;
521 case 14: reg = CV_REG_FS; break;
522 case 15: reg = CV_REG_GS; break;
523 case 16: case 17: case 18: case 19:
524 case 20: case 21: case 22: case 23:
525 reg = CV_REG_ST0 + regno - 16; break;
526 case 24: reg = CV_REG_CTRL; break;
527 case 25: reg = CV_REG_STAT; break;
528 case 26: reg = CV_REG_TAG; break;
530 reg: fiseg 27
531 reg: fioff 28
532 reg: foseg 29
533 reg: fooff 30
534 reg: fop 31
536 case 32: case 33: case 34: case 35:
537 case 36: case 37: case 38: case 39:
538 reg = CV_REG_XMM0 + regno - 32; break;
539 case 40: reg = CV_REG_MXCSR; break;
540 default:
541 FIXME("Don't know how to map register %d\n", regno);
542 return 0;
544 return reg;
547 static void* i386_fetch_context_reg(CONTEXT* ctx, unsigned regno, unsigned* size)
549 #ifdef __i386__
550 switch (regno)
552 case CV_REG_EAX: *size = sizeof(ctx->Eax); return &ctx->Eax;
553 case CV_REG_EDX: *size = sizeof(ctx->Edx); return &ctx->Edx;
554 case CV_REG_ECX: *size = sizeof(ctx->Ecx); return &ctx->Ecx;
555 case CV_REG_EBX: *size = sizeof(ctx->Ebx); return &ctx->Ebx;
556 case CV_REG_ESI: *size = sizeof(ctx->Esi); return &ctx->Esi;
557 case CV_REG_EDI: *size = sizeof(ctx->Edi); return &ctx->Edi;
558 case CV_REG_EBP: *size = sizeof(ctx->Ebp); return &ctx->Ebp;
559 case CV_REG_ESP: *size = sizeof(ctx->Esp); return &ctx->Esp;
560 case CV_REG_EIP: *size = sizeof(ctx->Eip); return &ctx->Eip;
562 case CV_REG_ST0 + 0: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[0*sizeof(long double)];
563 case CV_REG_ST0 + 1: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[1*sizeof(long double)];
564 case CV_REG_ST0 + 2: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[2*sizeof(long double)];
565 case CV_REG_ST0 + 3: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[3*sizeof(long double)];
566 case CV_REG_ST0 + 4: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[4*sizeof(long double)];
567 case CV_REG_ST0 + 5: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[5*sizeof(long double)];
568 case CV_REG_ST0 + 6: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[6*sizeof(long double)];
569 case CV_REG_ST0 + 7: *size = sizeof(long double); return &ctx->FloatSave.RegisterArea[7*sizeof(long double)];
571 case CV_REG_EFLAGS: *size = sizeof(ctx->EFlags); return &ctx->EFlags;
572 case CV_REG_ES: *size = sizeof(ctx->SegEs); return &ctx->SegEs;
573 case CV_REG_CS: *size = sizeof(ctx->SegCs); return &ctx->SegCs;
574 case CV_REG_SS: *size = sizeof(ctx->SegSs); return &ctx->SegSs;
575 case CV_REG_DS: *size = sizeof(ctx->SegDs); return &ctx->SegDs;
576 case CV_REG_FS: *size = sizeof(ctx->SegFs); return &ctx->SegFs;
577 case CV_REG_GS: *size = sizeof(ctx->SegGs); return &ctx->SegGs;
580 #endif
581 FIXME("Unknown register %x\n", regno);
582 return NULL;
585 static const char* i386_fetch_regname(unsigned regno)
587 switch (regno)
589 case CV_REG_EAX: return "eax";
590 case CV_REG_EDX: return "edx";
591 case CV_REG_ECX: return "ecx";
592 case CV_REG_EBX: return "ebx";
593 case CV_REG_ESI: return "esi";
594 case CV_REG_EDI: return "edi";
595 case CV_REG_EBP: return "ebp";
596 case CV_REG_ESP: return "esp";
597 case CV_REG_EIP: return "eip";
599 case CV_REG_ST0 + 0: return "st0";
600 case CV_REG_ST0 + 1: return "st1";
601 case CV_REG_ST0 + 2: return "st2";
602 case CV_REG_ST0 + 3: return "st3";
603 case CV_REG_ST0 + 4: return "st4";
604 case CV_REG_ST0 + 5: return "st5";
605 case CV_REG_ST0 + 6: return "st6";
606 case CV_REG_ST0 + 7: return "st7";
608 case CV_REG_EFLAGS: return "eflags";
609 case CV_REG_ES: return "es";
610 case CV_REG_CS: return "cs";
611 case CV_REG_SS: return "ss";
612 case CV_REG_DS: return "ds";
613 case CV_REG_FS: return "fs";
614 case CV_REG_GS: return "gs";
616 FIXME("Unknown register %x\n", regno);
617 return NULL;
620 struct cpu cpu_i386 = {
621 IMAGE_FILE_MACHINE_I386,
623 i386_get_addr,
624 i386_stack_walk,
625 NULL,
626 i386_map_dwarf_register,
627 i386_fetch_context_reg,
628 i386_fetch_regname,