Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/winedbg/be_cpu.h | 2 -- programs/winedbg/break.c | 40 ++++++++++++++-------------- programs/winedbg/db_disasm.c | 4 +-- programs/winedbg/dbg.y | 4 +-- programs/winedbg/debugger.h | 3 ++- programs/winedbg/expr.c | 4 +-- programs/winedbg/gdbproxy.c | 17 ++++++------ programs/winedbg/info.c | 2 +- programs/winedbg/memory.c | 26 +++++++++--------- programs/winedbg/stack.c | 10 +++---- programs/winedbg/symbol.c | 2 +- programs/winedbg/tgt_active.c | 9 ++++--- programs/winedbg/tgt_minidump.c | 4 +-- programs/winedbg/types.c | 17 ++++++------ programs/winedbg/winedbg.c | 58 ++++++++++++++++++++--------------------- 15 files changed, 101 insertions(+), 101 deletions(-)
diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h index d62b517..751ac9d 100644 --- a/programs/winedbg/be_cpu.h +++ b/programs/winedbg/be_cpu.h @@ -116,8 +116,6 @@ struct backend_cpu BOOL (*store_integer)(const struct dbg_lvalue* lvalue, unsigned size, BOOL is_signed, LONGLONG); };
-extern struct backend_cpu* be_cpu; - /* some handy functions for non segmented CPUs */ void* be_cpu_linearize(HANDLE hThread, const ADDRESS64*); BOOL be_cpu_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr, diff --git a/programs/winedbg/break.c b/programs/winedbg/break.c index cedeed7..2896c17 100644 --- a/programs/winedbg/break.c +++ b/programs/winedbg/break.c @@ -63,15 +63,13 @@ void break_set_xpoints(BOOL set) addr = memory_to_linear_addr(&bp[i].addr);
if (set) - ret = be_cpu->insert_Xpoint(dbg_curr_process->handle, - dbg_curr_process->process_io, - &dbg_context, bp[i].xpoint_type, addr, - &bp[i].info, size); + ret = dbg_curr_process->be_cpu->insert_Xpoint(dbg_curr_process->handle, + dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type, + addr, &bp[i].info, size); else - ret = be_cpu->remove_Xpoint(dbg_curr_process->handle, - dbg_curr_process->process_io, - &dbg_context, bp[i].xpoint_type, addr, - bp[i].info, size); + ret = dbg_curr_process->be_cpu->remove_Xpoint(dbg_curr_process->handle, + dbg_curr_process->process_io, &dbg_context, bp[i].xpoint_type, + addr, bp[i].info, size); if (!ret) { dbg_printf("Invalid address ("); @@ -572,9 +570,9 @@ static int find_triggered_watch(void) DWORD64 val = 0;
if (bp[i].refcount && bp[i].enabled && !is_xpoint_break(i) && - (be_cpu->is_watchpoint_set(&dbg_context, bp[i].info))) + (dbg_curr_process->be_cpu->is_watchpoint_set(&dbg_context, bp[i].info))) { - be_cpu->clear_watchpoint(&dbg_context, bp[i].info); + dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info);
if (get_watched_value(i, &val)) { @@ -599,7 +597,7 @@ static int find_triggered_watch(void) { if (val != bp[i].w.oldval) { - be_cpu->clear_watchpoint(&dbg_context, bp[i].info); + dbg_curr_process->be_cpu->clear_watchpoint(&dbg_context, bp[i].info); bp[i].w.oldval = val; found = i; /* cannot break, because two watch points may have been triggered on @@ -805,7 +803,7 @@ void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_br
/* If not single-stepping, back up to the break instruction */ if (code == EXCEPTION_BREAKPOINT) - addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, TRUE); + addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, TRUE);
dbg_curr_thread->stopped_xpoint = find_xpoint(addr, be_xpoint_break); dbg_curr_process->bp[0].enabled = FALSE; /* disable the step-over breakpoint */ @@ -821,7 +819,7 @@ void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_br { /* If not single-stepping, do not back up over the break instruction */ if (code == EXCEPTION_BREAKPOINT) - addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE); + addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE); return; } } @@ -833,7 +831,7 @@ void break_adjust_pc(ADDRESS64* addr, DWORD code, BOOL first_chance, BOOL* is_br if (dbg_curr_thread->stopped_xpoint == -1 && code == EXCEPTION_BREAKPOINT) { *is_break = TRUE; - addr->Offset += be_cpu->adjust_pc_for_break(&dbg_context, FALSE); + addr->Offset += dbg_curr_process->be_cpu->adjust_pc_for_break(&dbg_context, FALSE); } }
@@ -890,7 +888,7 @@ void break_restart_execution(int count) dbg_printf("Not stopped at any breakpoint; argument ignored.\n"); }
- if (mode == dbg_exec_finish && be_cpu->is_function_return(linear)) + if (mode == dbg_exec_finish && dbg_curr_process->be_cpu->is_function_return(linear)) { mode = ret_mode = dbg_exec_step_into_insn; } @@ -901,7 +899,7 @@ void break_restart_execution(int count) * FIXME - we need to check for things like thunks or trampolines, * as the actual function may in fact have debug info. */ - if (be_cpu->is_function_call(linear, &callee)) + if (dbg_curr_process->be_cpu->is_function_call(linear, &callee)) { status = symbol_get_function_line_status(&callee); #if 0 @@ -936,7 +934,7 @@ void break_restart_execution(int count) switch (mode) { case dbg_exec_cont: /* Continuous execution */ - be_cpu->single_step(&dbg_context, FALSE); + dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE); break_set_xpoints(TRUE); break;
@@ -968,16 +966,16 @@ void break_restart_execution(int count) case dbg_exec_finish: case dbg_exec_step_over_insn: /* Stepping over a call */ case dbg_exec_step_over_line: /* Stepping over a call */ - if (be_cpu->is_step_over_insn(linear)) + if (dbg_curr_process->be_cpu->is_step_over_insn(linear)) { - be_cpu->disasm_one_insn(&addr, FALSE); + dbg_curr_process->be_cpu->disasm_one_insn(&addr, FALSE); dbg_curr_process->bp[0].addr = addr; dbg_curr_process->bp[0].enabled = TRUE; dbg_curr_process->bp[0].refcount = 1; dbg_curr_process->bp[0].skipcount = 0; dbg_curr_process->bp[0].xpoint_type = be_xpoint_break; dbg_curr_process->bp[0].condition = NULL; - be_cpu->single_step(&dbg_context, FALSE); + dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE); break_set_xpoints(TRUE); break; } @@ -985,7 +983,7 @@ void break_restart_execution(int count)
case dbg_exec_step_into_line: /* Single-stepping a line */ case dbg_exec_step_into_insn: /* Single-stepping an instruction */ - be_cpu->single_step(&dbg_context, TRUE); + dbg_curr_process->be_cpu->single_step(&dbg_context, TRUE); break; default: RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); } diff --git a/programs/winedbg/db_disasm.c b/programs/winedbg/db_disasm.c index fc25e1c..9bdfb90 100644 --- a/programs/winedbg/db_disasm.c +++ b/programs/winedbg/db_disasm.c @@ -1800,8 +1800,8 @@ void be_i386_disasm_one_insn(ADDRESS64 *addr, int display) short_addr ? 2 : 4, FALSE ); get_value_inc( address.Segment, addr, /* segment */ 2, FALSE ); - be_cpu->build_addr(dbg_curr_thread->handle, &dbg_context, - &address, address.Segment, address.Offset); + dbg_curr_process->be_cpu->build_addr(dbg_curr_thread->handle, + &dbg_context, &address, address.Segment, address.Offset); if( db_display ) { print_address( &address, TRUE ); diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y index 61acb90..6b080a5 100644 --- a/programs/winedbg/dbg.y +++ b/programs/winedbg/dbg.y @@ -270,8 +270,8 @@ info_command: tINFO tBREAK { break_info(); } | tINFO tSHARE { info_win32_module(0); } | tINFO tSHARE expr_rvalue { info_win32_module($3); } - | tINFO tREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); } - | tINFO tALLREGS { be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); } + | tINFO tREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); } + | tINFO tALLREGS { dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 1); } | tINFO tSEGMENTS expr_rvalue { info_win32_segments($3 >> 3, 1); } | tINFO tSEGMENTS { info_win32_segments(0, -1); } | tINFO tSTACK tNUM { stack_info($3); } diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index a1aac82..0ceb150 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -39,7 +39,7 @@ #include "oaidl.h" #include <wine/list.h>
-#define ADDRSIZE (be_cpu->pointer_size) +#define ADDRSIZE (dbg_curr_process->be_cpu->pointer_size) #define ADDRWIDTH (ADDRSIZE * 2)
/* the debugger uses these exceptions for its internal use */ @@ -228,6 +228,7 @@ struct dbg_process void* pio_data; const WCHAR* imageName; struct list threads; + struct backend_cpu* be_cpu; BOOL continue_on_first_exception : 1, active_debuggee : 1; struct dbg_breakpoint bp[MAX_BREAKPOINTS]; diff --git a/programs/winedbg/expr.c b/programs/winedbg/expr.c index 96a617c..d18ff8d 100644 --- a/programs/winedbg/expr.c +++ b/programs/winedbg/expr.c @@ -546,8 +546,8 @@ struct dbg_lvalue expr_eval(struct expr* exp) case EXP_OP_SEG: rtn.type.id = dbg_itype_segptr; rtn.type.module = 0; - be_cpu->build_addr(dbg_curr_thread->handle, &dbg_context, &rtn.addr, - types_extract_as_integer(&exp1), types_extract_as_integer(&exp2)); + dbg_curr_process->be_cpu->build_addr(dbg_curr_thread->handle, &dbg_context, &rtn.addr, + types_extract_as_integer(&exp1), types_extract_as_integer(&exp2)); break; case EXP_OP_LOR: exp->un.binop.result = (types_extract_as_integer(&exp1) || types_extract_as_integer(&exp2)); diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index 3ecf629..a9a65c2 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -886,7 +886,8 @@ static void wait_for_debuggee(struct gdb_context* gdbctx)
static void detach_debuggee(struct gdb_context* gdbctx, BOOL kill) { - be_cpu->single_step(&gdbctx->context, FALSE); + assert(gdbctx->process->be_cpu); + gdbctx->process->be_cpu->single_step(&gdbctx->context, FALSE); resume_debuggee(gdbctx, DBG_CONTINUE); if (!kill) DebugActiveProcessStop(gdbctx->process->pid); @@ -1309,13 +1310,13 @@ static enum packet_return packet_verbose_cont(struct gdb_context* gdbctx) switch (gdbctx->in_packet[actionIndex[i] + 1]) { case 's': /* step */ - be_cpu->single_step(&gdbctx->context, TRUE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, TRUE); /* fall through*/ case 'c': /* continue */ resume_debuggee_thread(gdbctx, DBG_CONTINUE, threadID); break; case 'S': /* step Sig, */ - be_cpu->single_step(&gdbctx->context, TRUE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, TRUE); /* fall through */ case 'C': /* continue sig */ hex_from(&sig, gdbctx->in_packet + actionIndex[i] + 2, 1); @@ -1352,13 +1353,13 @@ static enum packet_return packet_verbose_cont(struct gdb_context* gdbctx) switch (gdbctx->in_packet[actionIndex[defaultAction] + 1]) { case 's': /* step */ - be_cpu->single_step(&gdbctx->context, TRUE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, TRUE); /* fall through */ case 'c': /* continue */ resume_debuggee_thread(gdbctx, DBG_CONTINUE, threadID); break; case 'S': - be_cpu->single_step(&gdbctx->context, TRUE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, TRUE); /* fall through */ case 'C': /* continue sig */ hex_from(&sig, gdbctx->in_packet + actionIndex[defaultAction] + 2, 1); @@ -1375,7 +1376,7 @@ static enum packet_return packet_verbose_cont(struct gdb_context* gdbctx) } /* if(defaultAction >=0) */
wait_for_debuggee(gdbctx); - be_cpu->single_step(&gdbctx->context, FALSE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, FALSE); return packet_reply_status(gdbctx); }
@@ -2090,10 +2091,10 @@ static enum packet_return packet_step(struct gdb_context* gdbctx) if (gdbctx->trace & GDBPXY_TRC_COMMAND_FIXME) fprintf(stderr, "NIY: step on %04x, while last thread is %04x\n", gdbctx->exec_thread->tid, dbg_curr_thread->tid); - be_cpu->single_step(&gdbctx->context, TRUE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, TRUE); resume_debuggee(gdbctx, DBG_CONTINUE); wait_for_debuggee(gdbctx); - be_cpu->single_step(&gdbctx->context, FALSE); + gdbctx->process->be_cpu->single_step(&gdbctx->context, FALSE); return packet_reply_status(gdbctx); }
diff --git a/programs/winedbg/info.c b/programs/winedbg/info.c index 83341c0..c965759 100644 --- a/programs/winedbg/info.c +++ b/programs/winedbg/info.c @@ -974,7 +974,7 @@ void info_win32_exception(void) { case AddrModeFlat: dbg_printf(" in %d-bit code (%s)", - be_cpu->pointer_size * 8, + dbg_curr_process->be_cpu->pointer_size * 8, memory_offset_to_string(hexbuf, addr.Offset, 0)); break; case AddrModeReal: diff --git a/programs/winedbg/memory.c b/programs/winedbg/memory.c index 970e81a..6e65fa6 100644 --- a/programs/winedbg/memory.c +++ b/programs/winedbg/memory.c @@ -50,20 +50,20 @@ BOOL be_cpu_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr,
void* memory_to_linear_addr(const ADDRESS64* addr) { - return be_cpu->linearize(dbg_curr_thread->handle, addr); + return dbg_curr_process->be_cpu->linearize(dbg_curr_thread->handle, addr); }
BOOL memory_get_current_pc(ADDRESS64* addr) { - assert(be_cpu->get_addr); - return be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, + assert(dbg_curr_process->be_cpu->get_addr); + return dbg_curr_process->be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, be_cpu_addr_pc, addr); }
BOOL memory_get_current_stack(ADDRESS64* addr) { - assert(be_cpu->get_addr); - return be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, + assert(dbg_curr_process->be_cpu->get_addr); + return dbg_curr_process->be_cpu->get_addr(dbg_curr_thread->handle, &dbg_context, be_cpu_addr_stack, addr); }
@@ -374,17 +374,17 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue) { case btInt: case btLong: - if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; if (size == 1) goto print_char; dbg_print_hex(size, val_int); break; case btUInt: case btULong: - if (!be_cpu->fetch_integer(lvalue, size, FALSE, &val_int)) return; + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, FALSE, &val_int)) return; dbg_print_hex(size, val_int); break; case btFloat: - if (!be_cpu->fetch_float(lvalue, size, &val_real)) return; + if (!dbg_curr_process->be_cpu->fetch_float(lvalue, size, &val_real)) return; dbg_printf("%Lf", val_real); break; case btChar: @@ -392,7 +392,7 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue) /* sometimes WCHAR is defined as btChar with size = 2, so discrimate * Ansi/Unicode based on size, not on basetype */ - if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; print_char: if (size == 1 && isprint((char)val_int)) dbg_printf("'%c'", (char)val_int); @@ -407,7 +407,7 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue) dbg_printf("%d", (int)val_int); break; case btBool: - if (!be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return; dbg_printf("%s", val_int ? "true" : "false"); break; default: @@ -455,7 +455,7 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue) * (not supported yet in dbghelp) * Assuming 4 as for an int */ - if (!be_cpu->fetch_integer(lvalue, 4, TRUE, &val_int)) return; + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, 4, TRUE, &val_int)) return;
if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count)) { @@ -631,7 +631,7 @@ BOOL memory_disasm_one_insn(ADDRESS64* addr) dbg_printf("-- no code accessible --\n"); return FALSE; } - be_cpu->disasm_one_insn(addr, TRUE); + dbg_curr_process->be_cpu->disasm_one_insn(addr, TRUE); dbg_printf("\n"); return TRUE; } @@ -685,7 +685,7 @@ BOOL memory_get_register(DWORD regno, DWORD_PTR** value, char* buffer, int len) return FALSE; }
- for (div = be_cpu->context_vars; div->name; div++) + for (div = dbg_curr_process->be_cpu->context_vars; div->name; div++) { if (div->val == regno) { diff --git a/programs/winedbg/stack.c b/programs/winedbg/stack.c index f49480a..2ab4e60 100644 --- a/programs/winedbg/stack.c +++ b/programs/winedbg/stack.c @@ -121,7 +121,7 @@ BOOL stack_get_register_frame(const struct dbg_internal_var* div, DWORD_PTR** pv { enum be_cpu_addr kind;
- if (!be_cpu->get_register_info(div->val, &kind)) return FALSE; + if (!dbg_curr_process->be_cpu->get_register_info(div->val, &kind)) return FALSE;
/* reuse some known registers directly out of stackwalk details */ switch (kind) @@ -198,9 +198,9 @@ unsigned stack_fetch_frames(const CONTEXT* _ctx) dbg_curr_thread->frames = NULL;
memset(&sf, 0, sizeof(sf)); - be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_frame, &sf.AddrFrame); - be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_pc, &sf.AddrPC); - be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_stack, &sf.AddrStack); + dbg_curr_process->be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_frame, &sf.AddrFrame); + dbg_curr_process->be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_pc, &sf.AddrPC); + dbg_curr_process->be_cpu->get_addr(dbg_curr_thread->handle, &ctx, be_cpu_addr_stack, &sf.AddrStack);
/* don't confuse StackWalk by passing in inconsistent addresses */ if ((sf.AddrPC.Mode == AddrModeFlat) && (sf.AddrFrame.Mode != AddrModeFlat)) @@ -209,7 +209,7 @@ unsigned stack_fetch_frames(const CONTEXT* _ctx) sf.AddrFrame.Mode = AddrModeFlat; }
- while ((ret = StackWalk64(be_cpu->machine, dbg_curr_process->handle, + while ((ret = StackWalk64(dbg_curr_process->be_cpu->machine, dbg_curr_process->handle, dbg_curr_thread->handle, &sf, &ctx, stack_read_mem, SymFunctionTableAccess64, SymGetModuleBase64, NULL)) || nf == 0) /* we always register first frame information */ diff --git a/programs/winedbg/symbol.c b/programs/winedbg/symbol.c index 1040187..aa88ffc 100644 --- a/programs/winedbg/symbol.c +++ b/programs/winedbg/symbol.c @@ -590,7 +590,7 @@ enum dbg_line_status symbol_get_function_line_status(const ADDRESS64* addr) /* some compilers insert thunks in their code without debug info associated * take care of this situation */ - if (be_cpu->is_jump((void*)lin, &jumpee)) + if (dbg_curr_process->be_cpu->is_jump((void*)lin, &jumpee)) return symbol_get_function_line_status(&jumpee); return dbg_no_line_info; } diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index 07edccc..d891cfe 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -148,7 +148,8 @@ static BOOL dbg_exception_prolog(BOOL is_debug, const EXCEPTION_RECORD* rec) case AddrMode1616: name = "16 bit"; break; case AddrMode1632: name = "segmented 32 bit"; break; case AddrModeReal: name = "vm86"; break; - case AddrModeFlat: name = be_cpu->pointer_size == 4 ? "32 bit" : "64 bit"; break; + case AddrModeFlat: name = dbg_curr_process->be_cpu->pointer_size == 4 + ? "32 bit" : "64 bit"; break; } dbg_printf("In %s mode.\n", name); dbg_curr_thread->addr_mode = addr.Mode; @@ -158,9 +159,9 @@ static BOOL dbg_exception_prolog(BOOL is_debug, const EXCEPTION_RECORD* rec) if (!is_debug) { /* This is a real crash, dump some info */ - be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); + dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); stack_info(-1); - be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context); + dbg_curr_process->be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context); stack_backtrace(dbg_curr_tid); } else @@ -997,7 +998,7 @@ static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill) /* needed for single stepping (ugly). * should this be handled inside the server ??? */ - be_cpu->single_step(&dbg_context, FALSE); + dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE); if (dbg_curr_thread->in_exception) { SetThreadContext(dbg_curr_thread->handle, &dbg_context); diff --git a/programs/winedbg/tgt_minidump.c b/programs/winedbg/tgt_minidump.c index 5bf5a60..a17f32b 100644 --- a/programs/winedbg/tgt_minidump.c +++ b/programs/winedbg/tgt_minidump.c @@ -477,9 +477,9 @@ static enum dbg_start minidump_do_reload(struct tgt_process_minidump_data* data) min(sizeof(dbg_context), mes->ThreadContext.DataSize)); memory_get_current_pc(&addr); stack_fetch_frames(&dbg_context); - be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); + dbg_curr_process->be_cpu->print_context(dbg_curr_thread->handle, &dbg_context, 0); stack_info(-1); - be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context); + dbg_curr_process->be_cpu->print_segment_info(dbg_curr_thread->handle, &dbg_context); stack_backtrace(mes->ThreadId); source_list_from_addr(&addr, 0); } diff --git a/programs/winedbg/types.c b/programs/winedbg/types.c index 3268d7e..696a9fd 100644 --- a/programs/winedbg/types.c +++ b/programs/winedbg/types.c @@ -92,11 +92,11 @@ LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue, { case btChar: case btInt: - if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn)) + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn)) RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); break; case btUInt: - if (!be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn)) + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn)) RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); break; case btFloat: @@ -106,17 +106,17 @@ LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue, if (issigned) *issigned = s; break; case SymTagPointerType: - if (!be_cpu->fetch_integer(lvalue, sizeof(void*), s = FALSE, &rtn)) + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(void*), s = FALSE, &rtn)) RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); break; case SymTagArrayType: case SymTagUDT: - if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn)) + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn)) RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); break; case SymTagEnum: /* FIXME: we don't handle enum size */ - if (!be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn)) + if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn)) RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL); break; case SymTagFunctionType: @@ -173,7 +173,7 @@ BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lv } /* FIXME: should support floats as well */ val = types_extract_as_longlong(lvalue_from, NULL, &is_signed); - return be_cpu->store_integer(lvalue_to, size, is_signed, val); + return dbg_curr_process->be_cpu->store_integer(lvalue_to, size, is_signed, val); }
/****************************************************************** @@ -302,9 +302,10 @@ BOOL types_array_index(const struct dbg_lvalue* lvalue, int index, struct dbg_lv result->addr = lvalue->addr; break; case SymTagPointerType: - if (!memory_read_value(lvalue, be_cpu->pointer_size, &result->addr.Offset)) return FALSE; + if (!memory_read_value(lvalue, dbg_curr_process->be_cpu->pointer_size, &result->addr.Offset)) + return FALSE; result->addr.Mode = AddrModeFlat; - switch (be_cpu->pointer_size) + switch (dbg_curr_process->be_cpu->pointer_size) { case 4: result->addr.Offset = (DWORD)result->addr.Offset; break; case 8: break; diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index e0ad4d8..b32b24c 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -241,7 +241,7 @@ const struct dbg_internal_var* dbg_get_internal_var(const char* name) { if (!strcmp(div->name, name)) return div; } - for (div = be_cpu->context_vars; div->name; div++) + for (div = dbg_curr_process->be_cpu->context_vars; div->name; div++) { if (!strcasecmp(div->name, name)) { @@ -279,6 +279,20 @@ struct dbg_process* dbg_get_process_h(HANDLE h) return NULL; }
+#ifdef __i386__ +extern struct backend_cpu be_i386; +#elif defined(__powerpc__) +extern struct backend_cpu be_ppc; +#elif defined(__x86_64__) +extern struct backend_cpu be_x86_64; +#elif defined(__arm__) && !defined(__ARMEB__) +extern struct backend_cpu be_arm; +#elif defined(__aarch64__) && !defined(__AARCH64EB__) +extern struct backend_cpu be_arm64; +#else +# error CPU unknown +#endif + struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid, HANDLE h) { struct dbg_process* p; @@ -318,6 +332,20 @@ struct dbg_process* dbg_add_process(const struct be_process_io* pio, DWORD pid, p->source_end_line = -1;
list_add_head(&dbg_process_list, &p->entry); + +#ifdef __i386__ + p->be_cpu = &be_i386; +#elif defined(__powerpc__) + p->be_cpu = &be_ppc; +#elif defined(__x86_64__) + p->be_cpu = &be_x86_64; +#elif defined(__arm__) && !defined(__ARMEB__) + p->be_cpu = &be_arm; +#elif defined(__aarch64__) && !defined(__AARCH64EB__) + p->be_cpu = &be_arm64; +#else +# error CPU unknown +#endif return p; }
@@ -609,40 +637,12 @@ static LONG CALLBACK top_filter( EXCEPTION_POINTERS *ptr ) return EXCEPTION_EXECUTE_HANDLER; }
-struct backend_cpu* be_cpu; -#ifdef __i386__ -extern struct backend_cpu be_i386; -#elif defined(__powerpc__) -extern struct backend_cpu be_ppc; -#elif defined(__x86_64__) -extern struct backend_cpu be_x86_64; -#elif defined(__arm__) && !defined(__ARMEB__) -extern struct backend_cpu be_arm; -#elif defined(__aarch64__) && !defined(__AARCH64EB__) -extern struct backend_cpu be_arm64; -#else -# error CPU unknown -#endif - int main(int argc, char** argv) { int retv = 0; HANDLE hFile = INVALID_HANDLE_VALUE; enum dbg_start ds;
-#ifdef __i386__ - be_cpu = &be_i386; -#elif defined(__powerpc__) - be_cpu = &be_ppc; -#elif defined(__x86_64__) - be_cpu = &be_x86_64; -#elif defined(__arm__) && !defined(__ARMEB__) - be_cpu = &be_arm; -#elif defined(__aarch64__) && !defined(__AARCH64EB__) - be_cpu = &be_arm64; -#else -# error CPU unknown -#endif /* Initialize the output */ dbg_houtput = GetStdHandle(STD_OUTPUT_HANDLE);
And simplify the assignment to use CONTEXT_ALL instead. If we don't support reading from a register then we just ignore its value.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/winedbg/gdbproxy.c | 478 ++++++++++++++++++++------------------------ 1 file changed, 222 insertions(+), 256 deletions(-)
diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index a9a65c2..8742135 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -199,10 +199,9 @@ struct cpu_register size_t ctx_offset; size_t ctx_length; size_t gdb_length; - ULONG ctx_flags; };
-#define REG(r,gs,m) {FIELD_OFFSET(CONTEXT, r), sizeof(((CONTEXT*)NULL)->r), gs, m} +#define REG(r,gs) {FIELD_OFFSET(CONTEXT, r), sizeof(((CONTEXT*)NULL)->r), gs}
#ifdef __i386__ typedef struct DECLSPEC_ALIGN(16) _M128A { @@ -231,185 +230,185 @@ typedef struct _XMM_SAVE_AREA32 {
static const char target_xml[] = ""; static struct cpu_register cpu_register_map[] = { - REG(Eax, 4, CONTEXT_INTEGER), - REG(Ecx, 4, CONTEXT_INTEGER), - REG(Edx, 4, CONTEXT_INTEGER), - REG(Ebx, 4, CONTEXT_INTEGER), - REG(Esp, 4, CONTEXT_CONTROL), - REG(Ebp, 4, CONTEXT_CONTROL), - REG(Esi, 4, CONTEXT_INTEGER), - REG(Edi, 4, CONTEXT_INTEGER), - REG(Eip, 4, CONTEXT_CONTROL), - REG(EFlags, 4, CONTEXT_CONTROL), - REG(SegCs, 4, CONTEXT_CONTROL), - REG(SegSs, 4, CONTEXT_SEGMENTS), - REG(SegDs, 4, CONTEXT_SEGMENTS), - REG(SegEs, 4, CONTEXT_SEGMENTS), - REG(SegFs, 4, CONTEXT_SEGMENTS), - REG(SegGs, 4, CONTEXT_SEGMENTS), - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[ 0]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[10]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[20]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[30]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[40]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[50]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[60]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[70]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.ControlWord), 2, 4, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.StatusWord), 2, 4, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.TagWord), 2, 4, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, FloatSave.ErrorSelector), 2, 4, CONTEXT_FLOATING_POINT }, - REG(FloatSave.ErrorOffset, 4, CONTEXT_FLOATING_POINT ), - { FIELD_OFFSET(CONTEXT, FloatSave.DataSelector), 2, 4, CONTEXT_FLOATING_POINT }, - REG(FloatSave.DataOffset, 4, CONTEXT_FLOATING_POINT ), - { FIELD_OFFSET(CONTEXT, FloatSave.ErrorSelector)+2, 2, 4, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[0]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[1]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[2]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[3]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[4]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[5]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[6]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[7]), 16, 16, CONTEXT_EXTENDED_REGISTERS }, - { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, MxCsr), 4, 4, CONTEXT_EXTENDED_REGISTERS }, + REG(Eax, 4), + REG(Ecx, 4), + REG(Edx, 4), + REG(Ebx, 4), + REG(Esp, 4), + REG(Ebp, 4), + REG(Esi, 4), + REG(Edi, 4), + REG(Eip, 4), + REG(EFlags, 4), + REG(SegCs, 4), + REG(SegSs, 4), + REG(SegDs, 4), + REG(SegEs, 4), + REG(SegFs, 4), + REG(SegGs, 4), + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[ 0]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[10]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[20]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[30]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[40]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[50]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[60]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[70]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, FloatSave.ControlWord), 2, 4 }, + { FIELD_OFFSET(CONTEXT, FloatSave.StatusWord), 2, 4 }, + { FIELD_OFFSET(CONTEXT, FloatSave.TagWord), 2, 4 }, + { FIELD_OFFSET(CONTEXT, FloatSave.ErrorSelector), 2, 4 }, + REG(FloatSave.ErrorOffset, 4 ), + { FIELD_OFFSET(CONTEXT, FloatSave.DataSelector), 2, 4 }, + REG(FloatSave.DataOffset, 4 ), + { FIELD_OFFSET(CONTEXT, FloatSave.ErrorSelector)+2, 2, 4 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[0]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[1]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[2]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[3]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[4]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[5]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[6]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[7]), 16, 16 }, + { FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, MxCsr), 4, 4 }, }; #elif defined(__powerpc__) static const char target_xml[] = ""; static struct cpu_register cpu_register_map[] = { - REG(Gpr0, 4, CONTEXT_INTEGER), - REG(Gpr1, 4, CONTEXT_INTEGER), - REG(Gpr2, 4, CONTEXT_INTEGER), - REG(Gpr3, 4, CONTEXT_INTEGER), - REG(Gpr4, 4, CONTEXT_INTEGER), - REG(Gpr5, 4, CONTEXT_INTEGER), - REG(Gpr6, 4, CONTEXT_INTEGER), - REG(Gpr7, 4, CONTEXT_INTEGER), - REG(Gpr8, 4, CONTEXT_INTEGER), - REG(Gpr9, 4, CONTEXT_INTEGER), - REG(Gpr10, 4, CONTEXT_INTEGER), - REG(Gpr11, 4, CONTEXT_INTEGER), - REG(Gpr12, 4, CONTEXT_INTEGER), - REG(Gpr13, 4, CONTEXT_INTEGER), - REG(Gpr14, 4, CONTEXT_INTEGER), - REG(Gpr15, 4, CONTEXT_INTEGER), - REG(Gpr16, 4, CONTEXT_INTEGER), - REG(Gpr17, 4, CONTEXT_INTEGER), - REG(Gpr18, 4, CONTEXT_INTEGER), - REG(Gpr19, 4, CONTEXT_INTEGER), - REG(Gpr20, 4, CONTEXT_INTEGER), - REG(Gpr21, 4, CONTEXT_INTEGER), - REG(Gpr22, 4, CONTEXT_INTEGER), - REG(Gpr23, 4, CONTEXT_INTEGER), - REG(Gpr24, 4, CONTEXT_INTEGER), - REG(Gpr25, 4, CONTEXT_INTEGER), - REG(Gpr26, 4, CONTEXT_INTEGER), - REG(Gpr27, 4, CONTEXT_INTEGER), - REG(Gpr28, 4, CONTEXT_INTEGER), - REG(Gpr29, 4, CONTEXT_INTEGER), - REG(Gpr30, 4, CONTEXT_INTEGER), - REG(Gpr31, 4, CONTEXT_INTEGER), - REG(Fpr0, 4, CONTEXT_FLOATING_POINT), - REG(Fpr1, 4, CONTEXT_FLOATING_POINT), - REG(Fpr2, 4, CONTEXT_FLOATING_POINT), - REG(Fpr3, 4, CONTEXT_FLOATING_POINT), - REG(Fpr4, 4, CONTEXT_FLOATING_POINT), - REG(Fpr5, 4, CONTEXT_FLOATING_POINT), - REG(Fpr6, 4, CONTEXT_FLOATING_POINT), - REG(Fpr7, 4, CONTEXT_FLOATING_POINT), - REG(Fpr8, 4, CONTEXT_FLOATING_POINT), - REG(Fpr9, 4, CONTEXT_FLOATING_POINT), - REG(Fpr10, 4, CONTEXT_FLOATING_POINT), - REG(Fpr11, 4, CONTEXT_FLOATING_POINT), - REG(Fpr12, 4, CONTEXT_FLOATING_POINT), - REG(Fpr13, 4, CONTEXT_FLOATING_POINT), - REG(Fpr14, 4, CONTEXT_FLOATING_POINT), - REG(Fpr15, 4, CONTEXT_FLOATING_POINT), - REG(Fpr16, 4, CONTEXT_FLOATING_POINT), - REG(Fpr17, 4, CONTEXT_FLOATING_POINT), - REG(Fpr18, 4, CONTEXT_FLOATING_POINT), - REG(Fpr19, 4, CONTEXT_FLOATING_POINT), - REG(Fpr20, 4, CONTEXT_FLOATING_POINT), - REG(Fpr21, 4, CONTEXT_FLOATING_POINT), - REG(Fpr22, 4, CONTEXT_FLOATING_POINT), - REG(Fpr23, 4, CONTEXT_FLOATING_POINT), - REG(Fpr24, 4, CONTEXT_FLOATING_POINT), - REG(Fpr25, 4, CONTEXT_FLOATING_POINT), - REG(Fpr26, 4, CONTEXT_FLOATING_POINT), - REG(Fpr27, 4, CONTEXT_FLOATING_POINT), - REG(Fpr28, 4, CONTEXT_FLOATING_POINT), - REG(Fpr29, 4, CONTEXT_FLOATING_POINT), - REG(Fpr30, 4, CONTEXT_FLOATING_POINT), - REG(Fpr31, 4, CONTEXT_FLOATING_POINT), + REG(Gpr0, 4), + REG(Gpr1, 4), + REG(Gpr2, 4), + REG(Gpr3, 4), + REG(Gpr4, 4), + REG(Gpr5, 4), + REG(Gpr6, 4), + REG(Gpr7, 4), + REG(Gpr8, 4), + REG(Gpr9, 4), + REG(Gpr10, 4), + REG(Gpr11, 4), + REG(Gpr12, 4), + REG(Gpr13, 4), + REG(Gpr14, 4), + REG(Gpr15, 4), + REG(Gpr16, 4), + REG(Gpr17, 4), + REG(Gpr18, 4), + REG(Gpr19, 4), + REG(Gpr20, 4), + REG(Gpr21, 4), + REG(Gpr22, 4), + REG(Gpr23, 4), + REG(Gpr24, 4), + REG(Gpr25, 4), + REG(Gpr26, 4), + REG(Gpr27, 4), + REG(Gpr28, 4), + REG(Gpr29, 4), + REG(Gpr30, 4), + REG(Gpr31, 4), + REG(Fpr0, 4), + REG(Fpr1, 4), + REG(Fpr2, 4), + REG(Fpr3, 4), + REG(Fpr4, 4), + REG(Fpr5, 4), + REG(Fpr6, 4), + REG(Fpr7, 4), + REG(Fpr8, 4), + REG(Fpr9, 4), + REG(Fpr10, 4), + REG(Fpr11, 4), + REG(Fpr12, 4), + REG(Fpr13, 4), + REG(Fpr14, 4), + REG(Fpr15, 4), + REG(Fpr16, 4), + REG(Fpr17, 4), + REG(Fpr18, 4), + REG(Fpr19, 4), + REG(Fpr20, 4), + REG(Fpr21, 4), + REG(Fpr22, 4), + REG(Fpr23, 4), + REG(Fpr24, 4), + REG(Fpr25, 4), + REG(Fpr26, 4), + REG(Fpr27, 4), + REG(Fpr28, 4), + REG(Fpr29, 4), + REG(Fpr30, 4), + REG(Fpr31, 4),
- REG(Iar, 4, CONTEXT_CONTROL), - REG(Msr, 4, CONTEXT_CONTROL), - REG(Cr, 4, CONTEXT_INTEGER), - REG(Lr, 4, CONTEXT_CONTROL), - REG(Ctr, 4, CONTEXT_CONTROL), - REG(Xer, 4, CONTEXT_INTEGER), + REG(Iar, 4), + REG(Msr, 4), + REG(Cr, 4), + REG(Lr, 4), + REG(Ctr, 4), + REG(Xer, 4), /* FIXME: MQ is missing? FIELD_OFFSET(CONTEXT, Mq), */ /* see gdb/nlm/ppc.c */ }; #elif defined(__x86_64__) static const char target_xml[] = ""; static struct cpu_register cpu_register_map[] = { - REG(Rax, 8, CONTEXT_INTEGER), - REG(Rbx, 8, CONTEXT_INTEGER), - REG(Rcx, 8, CONTEXT_INTEGER), - REG(Rdx, 8, CONTEXT_INTEGER), - REG(Rsi, 8, CONTEXT_INTEGER), - REG(Rdi, 8, CONTEXT_INTEGER), - REG(Rbp, 8, CONTEXT_INTEGER), - REG(Rsp, 8, CONTEXT_INTEGER), - REG(R8, 8, CONTEXT_INTEGER), - REG(R9, 8, CONTEXT_INTEGER), - REG(R10, 8, CONTEXT_INTEGER), - REG(R11, 8, CONTEXT_INTEGER), - REG(R12, 8, CONTEXT_INTEGER), - REG(R13, 8, CONTEXT_INTEGER), - REG(R14, 8, CONTEXT_INTEGER), - REG(R15, 8, CONTEXT_INTEGER), - REG(Rip, 8, CONTEXT_CONTROL), - REG(EFlags, 4, CONTEXT_CONTROL), - REG(SegCs, 4, CONTEXT_CONTROL), - REG(SegSs, 4, CONTEXT_CONTROL), - REG(SegDs, 4, CONTEXT_SEGMENTS), - REG(SegEs, 4, CONTEXT_SEGMENTS), - REG(SegFs, 4, CONTEXT_SEGMENTS), - REG(SegGs, 4, CONTEXT_SEGMENTS), - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 0]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 1]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 2]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 3]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 4]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 5]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 6]), 10, 10, CONTEXT_FLOATING_POINT }, - { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 7]), 10, 10, CONTEXT_FLOATING_POINT }, - REG(u.FltSave.ControlWord, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.StatusWord, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.TagWord, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.ErrorSelector, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.ErrorOffset, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.DataSelector, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.DataOffset, 4, CONTEXT_FLOATING_POINT), - REG(u.FltSave.ErrorOpcode, 4, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm0, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm1, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm2, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm3, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm4, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm5, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm6, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm7, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm8, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm9, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm10, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm11, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm12, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm13, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm14, 16, CONTEXT_FLOATING_POINT), - REG(u.s.Xmm15, 16, CONTEXT_FLOATING_POINT), - REG(u.FltSave.MxCsr, 4, CONTEXT_FLOATING_POINT), + REG(Rax, 8), + REG(Rbx, 8), + REG(Rcx, 8), + REG(Rdx, 8), + REG(Rsi, 8), + REG(Rdi, 8), + REG(Rbp, 8), + REG(Rsp, 8), + REG(R8, 8), + REG(R9, 8), + REG(R10, 8), + REG(R11, 8), + REG(R12, 8), + REG(R13, 8), + REG(R14, 8), + REG(R15, 8), + REG(Rip, 8), + REG(EFlags, 4), + REG(SegCs, 4), + REG(SegSs, 4), + REG(SegDs, 4), + REG(SegEs, 4), + REG(SegFs, 4), + REG(SegGs, 4), + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 0]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 1]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 2]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 3]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 4]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 5]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 6]), 10, 10 }, + { FIELD_OFFSET(CONTEXT, u.FltSave.FloatRegisters[ 7]), 10, 10 }, + REG(u.FltSave.ControlWord, 4), + REG(u.FltSave.StatusWord, 4), + REG(u.FltSave.TagWord, 4), + REG(u.FltSave.ErrorSelector, 4), + REG(u.FltSave.ErrorOffset, 4), + REG(u.FltSave.DataSelector, 4), + REG(u.FltSave.DataOffset, 4), + REG(u.FltSave.ErrorOpcode, 4), + REG(u.s.Xmm0, 16), + REG(u.s.Xmm1, 16), + REG(u.s.Xmm2, 16), + REG(u.s.Xmm3, 16), + REG(u.s.Xmm4, 16), + REG(u.s.Xmm5, 16), + REG(u.s.Xmm6, 16), + REG(u.s.Xmm7, 16), + REG(u.s.Xmm8, 16), + REG(u.s.Xmm9, 16), + REG(u.s.Xmm10, 16), + REG(u.s.Xmm11, 16), + REG(u.s.Xmm12, 16), + REG(u.s.Xmm13, 16), + REG(u.s.Xmm14, 16), + REG(u.s.Xmm15, 16), + REG(u.FltSave.MxCsr, 4), }; #elif defined(__arm__) static const char target_xml[] = @@ -435,61 +434,61 @@ static const char target_xml[] = "</feature></target>\n";
static struct cpu_register cpu_register_map[] = { - REG(R0, 4, CONTEXT_INTEGER), - REG(R1, 4, CONTEXT_INTEGER), - REG(R2, 4, CONTEXT_INTEGER), - REG(R3, 4, CONTEXT_INTEGER), - REG(R4, 4, CONTEXT_INTEGER), - REG(R5, 4, CONTEXT_INTEGER), - REG(R6, 4, CONTEXT_INTEGER), - REG(R7, 4, CONTEXT_INTEGER), - REG(R8, 4, CONTEXT_INTEGER), - REG(R9, 4, CONTEXT_INTEGER), - REG(R10, 4, CONTEXT_INTEGER), - REG(R11, 4, CONTEXT_INTEGER), - REG(R12, 4, CONTEXT_INTEGER), - REG(Sp, 4, CONTEXT_CONTROL), - REG(Lr, 4, CONTEXT_CONTROL), - REG(Pc, 4, CONTEXT_CONTROL), - REG(Cpsr, 4, CONTEXT_CONTROL), + REG(R0, 4), + REG(R1, 4), + REG(R2, 4), + REG(R3, 4), + REG(R4, 4), + REG(R5, 4), + REG(R6, 4), + REG(R7, 4), + REG(R8, 4), + REG(R9, 4), + REG(R10, 4), + REG(R11, 4), + REG(R12, 4), + REG(Sp, 4), + REG(Lr, 4), + REG(Pc, 4), + REG(Cpsr, 4), }; #elif defined(__aarch64__) static const char target_xml[] = ""; static struct cpu_register cpu_register_map[] = { - REG(Cpsr, 4, CONTEXT_CONTROL), - REG(u.s.X0, 8, CONTEXT_INTEGER), - REG(u.s.X1, 8, CONTEXT_INTEGER), - REG(u.s.X2, 8, CONTEXT_INTEGER), - REG(u.s.X3, 8, CONTEXT_INTEGER), - REG(u.s.X4, 8, CONTEXT_INTEGER), - REG(u.s.X5, 8, CONTEXT_INTEGER), - REG(u.s.X6, 8, CONTEXT_INTEGER), - REG(u.s.X7, 8, CONTEXT_INTEGER), - REG(u.s.X8, 8, CONTEXT_INTEGER), - REG(u.s.X9, 8, CONTEXT_INTEGER), - REG(u.s.X10, 8, CONTEXT_INTEGER), - REG(u.s.X11, 8, CONTEXT_INTEGER), - REG(u.s.X12, 8, CONTEXT_INTEGER), - REG(u.s.X13, 8, CONTEXT_INTEGER), - REG(u.s.X14, 8, CONTEXT_INTEGER), - REG(u.s.X15, 8, CONTEXT_INTEGER), - REG(u.s.X16, 8, CONTEXT_INTEGER), - REG(u.s.X17, 8, CONTEXT_INTEGER), - REG(u.s.X18, 8, CONTEXT_INTEGER), - REG(u.s.X19, 8, CONTEXT_INTEGER), - REG(u.s.X20, 8, CONTEXT_INTEGER), - REG(u.s.X21, 8, CONTEXT_INTEGER), - REG(u.s.X22, 8, CONTEXT_INTEGER), - REG(u.s.X23, 8, CONTEXT_INTEGER), - REG(u.s.X24, 8, CONTEXT_INTEGER), - REG(u.s.X25, 8, CONTEXT_INTEGER), - REG(u.s.X26, 8, CONTEXT_INTEGER), - REG(u.s.X27, 8, CONTEXT_INTEGER), - REG(u.s.X28, 8, CONTEXT_INTEGER), - REG(u.s.Fp, 8, CONTEXT_INTEGER), - REG(u.s.Lr, 8, CONTEXT_INTEGER), - REG(Sp, 8, CONTEXT_CONTROL), - REG(Pc, 8, CONTEXT_CONTROL), + REG(Cpsr, 4), + REG(u.s.X0, 8), + REG(u.s.X1, 8), + REG(u.s.X2, 8), + REG(u.s.X3, 8), + REG(u.s.X4, 8), + REG(u.s.X5, 8), + REG(u.s.X6, 8), + REG(u.s.X7, 8), + REG(u.s.X8, 8), + REG(u.s.X9, 8), + REG(u.s.X10, 8), + REG(u.s.X11, 8), + REG(u.s.X12, 8), + REG(u.s.X13, 8), + REG(u.s.X14, 8), + REG(u.s.X15, 8), + REG(u.s.X16, 8), + REG(u.s.X17, 8), + REG(u.s.X18, 8), + REG(u.s.X19, 8), + REG(u.s.X20, 8), + REG(u.s.X21, 8), + REG(u.s.X22, 8), + REG(u.s.X23, 8), + REG(u.s.X24, 8), + REG(u.s.X25, 8), + REG(u.s.X26, 8), + REG(u.s.X27, 8), + REG(u.s.X28, 8), + REG(u.s.Fp, 8), + REG(u.s.Lr, 8), + REG(Sp, 8), + REG(Pc, 8), }; #else # error Define the registers map for your CPU @@ -553,21 +552,7 @@ static inline void cpu_register_hex_from(CONTEXT* ctx, unsigned idx, const
static BOOL fetch_context(struct gdb_context* gdbctx, HANDLE h, CONTEXT* ctx) { - ctx->ContextFlags = CONTEXT_CONTROL - | CONTEXT_INTEGER -#if defined(__powerpc__) || defined(__i386__) || defined(__x86_64__) - | CONTEXT_FLOATING_POINT -#endif -#ifdef CONTEXT_SEGMENTS - | CONTEXT_SEGMENTS -#endif -#ifdef CONTEXT_DEBUG_REGISTERS - | CONTEXT_DEBUG_REGISTERS -#endif -#ifdef CONTEXT_EXTENDED_REGISTERS - | CONTEXT_EXTENDED_REGISTERS -#endif - ; + ctx->ContextFlags = CONTEXT_ALL; if (!GetThreadContext(h, ctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) @@ -1135,10 +1120,6 @@ static enum packet_return packet_reply_status(struct gdb_context* gdbctx)
for (i = 0; i < cpu_num_regs; i++) { - ULONG flags = cpu_register_map[i].ctx_flags; - if ((gdbctx->context.ContextFlags & flags) != flags) - break; - /* FIXME: this call will also grow the buffer... * unneeded, but not harmful */ @@ -1474,12 +1455,7 @@ static enum packet_return packet_read_registers(struct gdb_context* gdbctx)
packet_reply_open(gdbctx); for (i = 0; i < cpu_num_regs; i++) - { - ULONG flags = cpu_register_map[i].ctx_flags; - if ((gdbctx->context.ContextFlags & flags) != flags) - break; packet_reply_register_hex_to(gdbctx, i); - } packet_reply_close(gdbctx); return packet_done; } @@ -1501,12 +1477,8 @@ static enum packet_return packet_write_registers(struct gdb_context* gdbctx)
ptr = gdbctx->in_packet; for (i = 0; i < cpu_num_regs; i++) - { - ULONG flags = cpu_register_map[i].ctx_flags; - if ((pctx->ContextFlags & flags) != flags) - break; cpu_register_hex_from(pctx, i, &ptr); - } + if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, pctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) @@ -1704,12 +1676,6 @@ static enum packet_return packet_write_register(struct gdb_context* gdbctx) if (!fetch_context(gdbctx, gdbctx->other_thread->handle, pctx = &ctx)) return packet_error; } - if ((pctx->ContextFlags & cpu_register_map[reg].ctx_flags) != cpu_register_map[reg].ctx_flags) - { - if (gdbctx->trace & GDBPXY_TRC_COMMAND_ERROR) - fprintf(stderr, "Writing reg %u is not supported on this host\n", reg); - return packet_error; - }
cpu_register_hex_from(pctx, reg, (const char**)&ptr); if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, pctx))
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/winedbg/be_cpu.h | 22 ++--- programs/winedbg/be_i386.c | 211 ++++++++++++++++++++-------------------- programs/winedbg/be_x86_64.c | 73 +++++++------- programs/winedbg/debugger.h | 12 ++- programs/winedbg/gdbproxy.c | 35 ++++--- programs/winedbg/memory.c | 2 +- programs/winedbg/stack.c | 16 +-- programs/winedbg/tgt_active.c | 10 +- programs/winedbg/tgt_minidump.c | 2 +- programs/winedbg/winedbg.c | 2 +- 10 files changed, 199 insertions(+), 186 deletions(-)
diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h index 751ac9d..03776d0 100644 --- a/programs/winedbg/be_cpu.h +++ b/programs/winedbg/be_cpu.h @@ -37,13 +37,13 @@ struct backend_cpu * in an ADDRESS64 (except an linear one). * Non segmented CPU shall use be_cpu_build_addr */ - BOOL (*build_addr)(HANDLE hThread, const CONTEXT* ctx, + BOOL (*build_addr)(HANDLE hThread, const dbg_ctx_t *ctx, ADDRESS64* addr, unsigned seg, unsigned long offset); /* Retrieves in addr an address related to the context (program counter, stack * pointer, frame pointer) */ - BOOL (*get_addr)(HANDLE hThread, const CONTEXT* ctx, + BOOL (*get_addr)(HANDLE hThread, const dbg_ctx_t *ctx, enum be_cpu_addr, ADDRESS64* addr);
/* returns which kind of information a given register number refers to */ @@ -53,13 +53,13 @@ struct backend_cpu * context manipulation * ------------------------------------------------------------------------------- */ /* Enables/disables CPU single step mode (depending on enable) */ - void (*single_step)(CONTEXT* ctx, BOOL enable); + void (*single_step)(dbg_ctx_t *ctx, BOOL enable); /* Dumps out the content of the context */ - void (*print_context)(HANDLE hThread, const CONTEXT* ctx, int all_regs); + void (*print_context)(HANDLE hThread, const dbg_ctx_t *ctx, int all_regs); /* Prints information about segments. Non segmented CPU should leave this * function empty */ - void (*print_segment_info)(HANDLE hThread, const CONTEXT* ctx); + void (*print_segment_info)(HANDLE hThread, const dbg_ctx_t *ctx); /* all the CONTEXT's relative variables, bound to this CPU */ const struct dbg_internal_var* context_vars;
@@ -89,22 +89,22 @@ struct backend_cpu * -------------------------------------------------------------------------------*/ /* Inserts an Xpoint in the CPU context and/or debuggee address space */ BOOL (*insert_Xpoint)(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long* val, unsigned size); /* Removes an Xpoint in the CPU context and/or debuggee address space */ BOOL (*remove_Xpoint)(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long val, unsigned size); /* Checks whether a given watchpoint has been triggered */ - BOOL (*is_watchpoint_set)(const CONTEXT* ctx, unsigned idx); + BOOL (*is_watchpoint_set)(const dbg_ctx_t *ctx, unsigned idx); /* Clears the watchpoint indicator */ - void (*clear_watchpoint)(CONTEXT* ctx, unsigned idx); + void (*clear_watchpoint)(dbg_ctx_t *ctx, unsigned idx); /* After a break instruction is executed, in the corresponding exception handler, * some CPUs report the address of the insn after the break insn, some others * report the address of the break insn itself. * This function lets adjust the context PC to reflect this behavior. */ - int (*adjust_pc_for_break)(CONTEXT* ctx, BOOL way); + int (*adjust_pc_for_break)(dbg_ctx_t *ctx, BOOL way); /* ------------------------------------------------------------------------------- * basic type read/write * -------------------------------------------------------------------------------*/ @@ -118,5 +118,5 @@ struct backend_cpu
/* some handy functions for non segmented CPUs */ void* be_cpu_linearize(HANDLE hThread, const ADDRESS64*); -BOOL be_cpu_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr, +BOOL be_cpu_build_addr(HANDLE hThread, const dbg_ctx_t *ctx, ADDRESS64* addr, unsigned seg, unsigned long offset); diff --git a/programs/winedbg/be_i386.c b/programs/winedbg/be_i386.c index 4d22708..bdc2ece 100644 --- a/programs/winedbg/be_i386.c +++ b/programs/winedbg/be_i386.c @@ -57,7 +57,7 @@ typedef struct _XMM_SAVE_AREA32 { BYTE Reserved4[96]; /* 1a0 */ } XMM_SAVE_AREA32, *PXMM_SAVE_AREA32;
-static ADDRESS_MODE get_selector_type(HANDLE hThread, const CONTEXT* ctx, WORD sel) +static ADDRESS_MODE get_selector_type(HANDLE hThread, const WOW64_CONTEXT *ctx, WORD sel) { LDT_ENTRY le;
@@ -93,7 +93,7 @@ static void* be_i386_linearize(HANDLE hThread, const ADDRESS64* addr) return NULL; }
-static BOOL be_i386_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr, +static BOOL be_i386_build_addr(HANDLE hThread, const dbg_ctx_t *ctx, ADDRESS64* addr, unsigned seg, unsigned long offset) { addr->Mode = AddrModeFlat; @@ -101,7 +101,7 @@ static BOOL be_i386_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* ad addr->Offset = offset; if (seg) { - addr->Mode = get_selector_type(hThread, ctx, seg); + addr->Mode = get_selector_type(hThread, &ctx->x86, seg); switch (addr->Mode) { case AddrModeReal: @@ -119,17 +119,17 @@ static BOOL be_i386_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* ad return TRUE; }
-static BOOL be_i386_get_addr(HANDLE hThread, const CONTEXT* ctx, +static BOOL be_i386_get_addr(HANDLE hThread, const dbg_ctx_t *ctx, enum be_cpu_addr bca, ADDRESS64* addr) { switch (bca) { case be_cpu_addr_pc: - return be_i386_build_addr(hThread, ctx, addr, ctx->SegCs, ctx->Eip); + return be_i386_build_addr(hThread, ctx, addr, ctx->x86.SegCs, ctx->x86.Eip); case be_cpu_addr_stack: - return be_i386_build_addr(hThread, ctx, addr, ctx->SegSs, ctx->Esp); + return be_i386_build_addr(hThread, ctx, addr, ctx->x86.SegSs, ctx->x86.Esp); case be_cpu_addr_frame: - return be_i386_build_addr(hThread, ctx, addr, ctx->SegSs, ctx->Ebp); + return be_i386_build_addr(hThread, ctx, addr, ctx->x86.SegSs, ctx->x86.Ebp); } return FALSE; } @@ -145,16 +145,17 @@ static BOOL be_i386_get_register_info(int regno, enum be_cpu_addr* kind) return FALSE; }
-static void be_i386_single_step(CONTEXT* ctx, BOOL enable) +static void be_i386_single_step(dbg_ctx_t *ctx, BOOL enable) { - if (enable) ctx->EFlags |= STEP_FLAG; - else ctx->EFlags &= ~STEP_FLAG; + if (enable) ctx->x86.EFlags |= STEP_FLAG; + else ctx->x86.EFlags &= ~STEP_FLAG; }
-static void be_i386_all_print_context(HANDLE hThread, const CONTEXT* ctx) +static void be_i386_all_print_context(HANDLE hThread, const dbg_ctx_t *pctx) { static const char mxcsr_flags[16][4] = { "IE", "DE", "ZE", "OE", "UE", "PE", "DAZ", "IM", "DM", "ZM", "OM", "UM", "PM", "R-", "R+", "FZ" }; + const WOW64_CONTEXT *ctx = &pctx->x86; XMM_SAVE_AREA32 *xmm_area; long double ST[8]; /* These are for floating regs */ int cnt; @@ -245,9 +246,10 @@ static void be_i386_all_print_context(HANDLE hThread, const CONTEXT* ctx) dbg_printf("\n"); }
-static void be_i386_print_context(HANDLE hThread, const CONTEXT* ctx, int all_regs) +static void be_i386_print_context(HANDLE hThread, const dbg_ctx_t *pctx, int all_regs) { static const char flags[] = "aVR-N--ODITSZ-A-P-C"; + const WOW64_CONTEXT *ctx = &pctx->x86; int i; char buf[33];
@@ -287,72 +289,73 @@ static void be_i386_print_context(HANDLE hThread, const CONTEXT* ctx, int all_re break; }
- if (all_regs) be_i386_all_print_context(hThread, ctx); /* print floating regs */ + if (all_regs) be_i386_all_print_context(hThread, pctx);
}
-static void be_i386_print_segment_info(HANDLE hThread, const CONTEXT* ctx) +static void be_i386_print_segment_info(HANDLE hThread, const dbg_ctx_t *ctx) { - if (get_selector_type(hThread, ctx, ctx->SegCs) == AddrMode1616) + if (get_selector_type(hThread, &ctx->x86, ctx->x86.SegCs) == AddrMode1616) { - info_win32_segments(ctx->SegDs >> 3, 1); - if (ctx->SegEs != ctx->SegDs) info_win32_segments(ctx->SegEs >> 3, 1); + info_win32_segments(ctx->x86.SegDs >> 3, 1); + if (ctx->x86.SegEs != ctx->x86.SegDs) + info_win32_segments(ctx->x86.SegEs >> 3, 1); } - info_win32_segments(ctx->SegFs >> 3, 1); + info_win32_segments(ctx->x86.SegFs >> 3, 1); }
static struct dbg_internal_var be_i386_ctx[] = { - {CV_REG_AL, "AL", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Eax), dbg_itype_unsigned_char_int}, - {CV_REG_CL, "CL", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ecx), dbg_itype_unsigned_char_int}, - {CV_REG_DL, "DL", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Edx), dbg_itype_unsigned_char_int}, - {CV_REG_BL, "BL", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ebx), dbg_itype_unsigned_char_int}, - {CV_REG_AH, "AH", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, Eax)+1), dbg_itype_unsigned_char_int}, - {CV_REG_CH, "CH", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, Ecx)+1), dbg_itype_unsigned_char_int}, - {CV_REG_DH, "DH", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, Edx)+1), dbg_itype_unsigned_char_int}, - {CV_REG_BH, "BH", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, Ebx)+1), dbg_itype_unsigned_char_int}, - {CV_REG_AX, "AX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Eax), dbg_itype_unsigned_short_int}, - {CV_REG_CX, "CX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ecx), dbg_itype_unsigned_short_int}, - {CV_REG_DX, "DX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Edx), dbg_itype_unsigned_short_int}, - {CV_REG_BX, "BX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ebx), dbg_itype_unsigned_short_int}, - {CV_REG_SP, "SP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Esp), dbg_itype_unsigned_short_int}, - {CV_REG_BP, "BP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ebp), dbg_itype_unsigned_short_int}, - {CV_REG_SI, "SI", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Esi), dbg_itype_unsigned_short_int}, - {CV_REG_DI, "DI", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Edi), dbg_itype_unsigned_short_int}, - {CV_REG_EAX, "EAX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Eax), dbg_itype_unsigned_int}, - {CV_REG_ECX, "ECX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ecx), dbg_itype_unsigned_int}, - {CV_REG_EDX, "EDX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Edx), dbg_itype_unsigned_int}, - {CV_REG_EBX, "EBX", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ebx), dbg_itype_unsigned_int}, - {CV_REG_ESP, "ESP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Esp), dbg_itype_unsigned_int}, - {CV_REG_EBP, "EBP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Ebp), dbg_itype_unsigned_int}, - {CV_REG_ESI, "ESI", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Esi), dbg_itype_unsigned_int}, - {CV_REG_EDI, "EDI", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Edi), dbg_itype_unsigned_int}, - {CV_REG_ES, "ES", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegEs), dbg_itype_unsigned_short_int}, - {CV_REG_CS, "CS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegCs), dbg_itype_unsigned_short_int}, - {CV_REG_SS, "SS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegSs), dbg_itype_unsigned_short_int}, - {CV_REG_DS, "DS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegDs), dbg_itype_unsigned_short_int}, - {CV_REG_FS, "FS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegFs), dbg_itype_unsigned_short_int}, - {CV_REG_GS, "GS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, SegGs), dbg_itype_unsigned_short_int}, - {CV_REG_IP, "IP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Eip), dbg_itype_unsigned_short_int}, - {CV_REG_FLAGS, "FLAGS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_short_int}, - {CV_REG_EIP, "EIP", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, Eip), dbg_itype_unsigned_int}, - {CV_REG_EFLAGS, "EFLAGS", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, EFlags), dbg_itype_unsigned_int}, - {CV_REG_ST0, "ST0", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[ 0]), dbg_itype_long_real}, - {CV_REG_ST0+1, "ST1", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[10]), dbg_itype_long_real}, - {CV_REG_ST0+2, "ST2", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[20]), dbg_itype_long_real}, - {CV_REG_ST0+3, "ST3", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[30]), dbg_itype_long_real}, - {CV_REG_ST0+4, "ST4", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[40]), dbg_itype_long_real}, - {CV_REG_ST0+5, "ST5", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[50]), dbg_itype_long_real}, - {CV_REG_ST0+6, "ST6", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[60]), dbg_itype_long_real}, - {CV_REG_ST0+7, "ST7", (DWORD_PTR*)FIELD_OFFSET(CONTEXT, FloatSave.RegisterArea[70]), dbg_itype_long_real}, - {CV_AMD64_XMM0, "XMM0", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[0])), dbg_itype_m128a}, - {CV_AMD64_XMM0+1, "XMM1", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[1])), dbg_itype_m128a}, - {CV_AMD64_XMM0+2, "XMM2", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[2])), dbg_itype_m128a}, - {CV_AMD64_XMM0+3, "XMM3", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[3])), dbg_itype_m128a}, - {CV_AMD64_XMM0+4, "XMM4", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[4])), dbg_itype_m128a}, - {CV_AMD64_XMM0+5, "XMM5", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[5])), dbg_itype_m128a}, - {CV_AMD64_XMM0+6, "XMM6", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[6])), dbg_itype_m128a}, - {CV_AMD64_XMM0+7, "XMM7", (DWORD_PTR*)(FIELD_OFFSET(CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[7])), dbg_itype_m128a}, + {CV_REG_AL, "AL", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Eax), dbg_itype_unsigned_char_int}, + {CV_REG_CL, "CL", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ecx), dbg_itype_unsigned_char_int}, + {CV_REG_DL, "DL", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Edx), dbg_itype_unsigned_char_int}, + {CV_REG_BL, "BL", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ebx), dbg_itype_unsigned_char_int}, + {CV_REG_AH, "AH", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, Eax)+1), dbg_itype_unsigned_char_int}, + {CV_REG_CH, "CH", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, Ecx)+1), dbg_itype_unsigned_char_int}, + {CV_REG_DH, "DH", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, Edx)+1), dbg_itype_unsigned_char_int}, + {CV_REG_BH, "BH", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, Ebx)+1), dbg_itype_unsigned_char_int}, + {CV_REG_AX, "AX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Eax), dbg_itype_unsigned_short_int}, + {CV_REG_CX, "CX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ecx), dbg_itype_unsigned_short_int}, + {CV_REG_DX, "DX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Edx), dbg_itype_unsigned_short_int}, + {CV_REG_BX, "BX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ebx), dbg_itype_unsigned_short_int}, + {CV_REG_SP, "SP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Esp), dbg_itype_unsigned_short_int}, + {CV_REG_BP, "BP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ebp), dbg_itype_unsigned_short_int}, + {CV_REG_SI, "SI", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Esi), dbg_itype_unsigned_short_int}, + {CV_REG_DI, "DI", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Edi), dbg_itype_unsigned_short_int}, + {CV_REG_EAX, "EAX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Eax), dbg_itype_unsigned_int}, + {CV_REG_ECX, "ECX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ecx), dbg_itype_unsigned_int}, + {CV_REG_EDX, "EDX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Edx), dbg_itype_unsigned_int}, + {CV_REG_EBX, "EBX", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ebx), dbg_itype_unsigned_int}, + {CV_REG_ESP, "ESP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Esp), dbg_itype_unsigned_int}, + {CV_REG_EBP, "EBP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Ebp), dbg_itype_unsigned_int}, + {CV_REG_ESI, "ESI", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Esi), dbg_itype_unsigned_int}, + {CV_REG_EDI, "EDI", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Edi), dbg_itype_unsigned_int}, + {CV_REG_ES, "ES", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegEs), dbg_itype_unsigned_short_int}, + {CV_REG_CS, "CS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegCs), dbg_itype_unsigned_short_int}, + {CV_REG_SS, "SS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegSs), dbg_itype_unsigned_short_int}, + {CV_REG_DS, "DS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegDs), dbg_itype_unsigned_short_int}, + {CV_REG_FS, "FS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegFs), dbg_itype_unsigned_short_int}, + {CV_REG_GS, "GS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, SegGs), dbg_itype_unsigned_short_int}, + {CV_REG_IP, "IP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Eip), dbg_itype_unsigned_short_int}, + {CV_REG_FLAGS, "FLAGS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, EFlags), dbg_itype_unsigned_short_int}, + {CV_REG_EIP, "EIP", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, Eip), dbg_itype_unsigned_int}, + {CV_REG_EFLAGS, "EFLAGS", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, EFlags), dbg_itype_unsigned_int}, + {CV_REG_ST0, "ST0", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[ 0]), dbg_itype_long_real}, + {CV_REG_ST0+1, "ST1", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[10]), dbg_itype_long_real}, + {CV_REG_ST0+2, "ST2", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[20]), dbg_itype_long_real}, + {CV_REG_ST0+3, "ST3", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[30]), dbg_itype_long_real}, + {CV_REG_ST0+4, "ST4", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[40]), dbg_itype_long_real}, + {CV_REG_ST0+5, "ST5", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[50]), dbg_itype_long_real}, + {CV_REG_ST0+6, "ST6", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[60]), dbg_itype_long_real}, + {CV_REG_ST0+7, "ST7", (DWORD_PTR*)FIELD_OFFSET(WOW64_CONTEXT, FloatSave.RegisterArea[70]), dbg_itype_long_real}, + {CV_AMD64_XMM0, "XMM0", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[0])), dbg_itype_m128a}, + {CV_AMD64_XMM0+1, "XMM1", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[1])), dbg_itype_m128a}, + {CV_AMD64_XMM0+2, "XMM2", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[2])), dbg_itype_m128a}, + {CV_AMD64_XMM0+3, "XMM3", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[3])), dbg_itype_m128a}, + {CV_AMD64_XMM0+4, "XMM4", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[4])), dbg_itype_m128a}, + {CV_AMD64_XMM0+5, "XMM5", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[5])), dbg_itype_m128a}, + {CV_AMD64_XMM0+6, "XMM6", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[6])), dbg_itype_m128a}, + {CV_AMD64_XMM0+7, "XMM7", (DWORD_PTR*)(FIELD_OFFSET(WOW64_CONTEXT, ExtendedRegisters) + FIELD_OFFSET(XMM_SAVE_AREA32, XmmRegisters[7])), dbg_itype_m128a}, {0, NULL, 0, dbg_itype_none} };
@@ -477,8 +480,8 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) unsigned operand_size; ADDRESS_MODE cs_addr_mode;
- cs_addr_mode = get_selector_type(dbg_curr_thread->handle, &dbg_context, - dbg_context.SegCs); + cs_addr_mode = get_selector_type(dbg_curr_thread->handle, &dbg_context.x86, + dbg_context.x86.SegCs); operand_size = get_size(cs_addr_mode);
/* get operand_size (also getting rid of the various prefixes */ @@ -498,7 +501,7 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) callee->Mode = cs_addr_mode; if (!fetch_value((const char*)insn + 1, operand_size, &delta)) return FALSE; - callee->Segment = dbg_context.SegCs; + callee->Segment = dbg_context.x86.SegCs; callee->Offset = (DWORD)insn + 1 + (operand_size / 8) + delta; return TRUE;
@@ -506,7 +509,7 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) if (!dbg_read_memory((const char*)insn + 1 + operand_size / 8, &segment, sizeof(segment))) return FALSE; - callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context, + callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context.x86, segment); if (!fetch_value((const char*)insn + 1, operand_size, &delta)) return FALSE; @@ -521,7 +524,7 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) switch ((ch >> 3) & 0x07) { case 0x02: - segment = dbg_context.SegCs; + segment = dbg_context.x86.SegCs; break; case 0x03: if (!dbg_read_memory((const char*)insn + 1 + operand_size / 8, @@ -555,10 +558,10 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) if (!dbg_read_memory((const char*)addr + operand_size, &segment, sizeof(segment))) return FALSE; } - else segment = dbg_context.SegCs; + else segment = dbg_context.x86.SegCs; if (!dbg_read_memory((const char*)addr, &dst, sizeof(dst))) return FALSE; - callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context, segment); + callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context.x86, segment); callee->Segment = segment; callee->Offset = dst; return TRUE; @@ -567,14 +570,14 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) default: switch (ch & 0x07) { - case 0x00: dst = dbg_context.Eax; break; - case 0x01: dst = dbg_context.Ecx; break; - case 0x02: dst = dbg_context.Edx; break; - case 0x03: dst = dbg_context.Ebx; break; - case 0x04: dst = dbg_context.Esp; break; - case 0x05: dst = dbg_context.Ebp; break; - case 0x06: dst = dbg_context.Esi; break; - case 0x07: dst = dbg_context.Edi; break; + case 0x00: dst = dbg_context.x86.Eax; break; + case 0x01: dst = dbg_context.x86.Ecx; break; + case 0x02: dst = dbg_context.x86.Edx; break; + case 0x03: dst = dbg_context.x86.Ebx; break; + case 0x04: dst = dbg_context.x86.Esp; break; + case 0x05: dst = dbg_context.x86.Ebp; break; + case 0x06: dst = dbg_context.x86.Esi; break; + case 0x07: dst = dbg_context.x86.Edi; break; } if ((ch >> 6) != 0x03) /* indirect address */ { @@ -589,10 +592,10 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) if (!dbg_read_memory((const char*)dst + operand_size, &segment, sizeof(segment))) return FALSE; } - else segment = dbg_context.SegCs; + else segment = dbg_context.x86.SegCs; if (!dbg_read_memory((const char*)dst, &delta, sizeof(delta))) return FALSE; - callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context, + callee->Mode = get_selector_type(dbg_curr_thread->handle, &dbg_context.x86, segment); callee->Segment = segment; callee->Offset = delta; @@ -600,7 +603,7 @@ static BOOL be_i386_is_func_call(const void* insn, ADDRESS64* callee) else { callee->Mode = cs_addr_mode; - callee->Segment = dbg_context.SegCs; + callee->Segment = dbg_context.x86.SegCs; callee->Offset = dst; } } @@ -618,8 +621,8 @@ static BOOL be_i386_is_jump(const void* insn, ADDRESS64* jumpee) unsigned operand_size; ADDRESS_MODE cs_addr_mode;
- cs_addr_mode = get_selector_type(dbg_curr_thread->handle, &dbg_context, - dbg_context.SegCs); + cs_addr_mode = get_selector_type(dbg_curr_thread->handle, &dbg_context.x86, + dbg_context.x86.SegCs); operand_size = get_size(cs_addr_mode);
/* get operand_size (also getting rid of the various prefixes */ @@ -639,7 +642,7 @@ static BOOL be_i386_is_jump(const void* insn, ADDRESS64* jumpee) jumpee->Mode = cs_addr_mode; if (!fetch_value((const char*)insn + 1, operand_size, &delta)) return FALSE; - jumpee->Segment = dbg_context.SegCs; + jumpee->Segment = dbg_context.x86.SegCs; jumpee->Offset = (DWORD)insn + 1 + (operand_size / 8) + delta; return TRUE; default: WINE_FIXME("unknown %x\n", ch); return FALSE; @@ -672,8 +675,10 @@ static BOOL be_i386_is_jump(const void* insn, ADDRESS64* jumpee) #define DR7_ENABLE_MASK(dr) (1<<(DR7_LOCAL_ENABLE_SHIFT+DR7_ENABLE_SIZE*(dr))) #define IS_DR7_SET(ctrl,dr) ((ctrl)&DR7_ENABLE_MASK(dr))
-static inline int be_i386_get_unused_DR(CONTEXT* ctx, DWORD** r) +static inline int be_i386_get_unused_DR(dbg_ctx_t *pctx, DWORD** r) { + WOW64_CONTEXT *ctx = &pctx->x86; + if (!IS_DR7_SET(ctx->Dr7, 0)) { *r = &ctx->Dr0; @@ -700,7 +705,7 @@ static inline int be_i386_get_unused_DR(CONTEXT* ctx, DWORD** r) }
static BOOL be_i386_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long* val, unsigned size) { unsigned char ch; @@ -738,10 +743,10 @@ static BOOL be_i386_insert_Xpoint(HANDLE hProcess, const struct be_process_io* p } *val = reg; /* clear old values */ - ctx->Dr7 &= ~(0x0F << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg)); + ctx->x86.Dr7 &= ~(0x0F << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg)); /* set the correct ones */ - ctx->Dr7 |= bits << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg); - ctx->Dr7 |= DR7_ENABLE_MASK(reg) | DR7_LOCAL_SLOWDOWN; + ctx->x86.Dr7 |= bits << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg); + ctx->x86.Dr7 |= DR7_ENABLE_MASK(reg) | DR7_LOCAL_SLOWDOWN; break; default: dbg_printf("Unknown bp type %c\n", type); @@ -751,7 +756,7 @@ static BOOL be_i386_insert_Xpoint(HANDLE hProcess, const struct be_process_io* p }
static BOOL be_i386_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long val, unsigned size) { SIZE_T sz; @@ -772,7 +777,7 @@ static BOOL be_i386_remove_Xpoint(HANDLE hProcess, const struct be_process_io* p case be_xpoint_watch_read: case be_xpoint_watch_write: /* simply disable the entry */ - ctx->Dr7 &= ~DR7_ENABLE_MASK(val); + ctx->x86.Dr7 &= ~DR7_ENABLE_MASK(val); break; default: dbg_printf("Unknown bp type %c\n", type); @@ -781,24 +786,24 @@ static BOOL be_i386_remove_Xpoint(HANDLE hProcess, const struct be_process_io* p return TRUE; }
-static BOOL be_i386_is_watchpoint_set(const CONTEXT* ctx, unsigned idx) +static BOOL be_i386_is_watchpoint_set(const dbg_ctx_t *ctx, unsigned idx) { - return ctx->Dr6 & (1 << idx); + return ctx->x86.Dr6 & (1 << idx); }
-static void be_i386_clear_watchpoint(CONTEXT* ctx, unsigned idx) +static void be_i386_clear_watchpoint(dbg_ctx_t *ctx, unsigned idx) { - ctx->Dr6 &= ~(1 << idx); + ctx->x86.Dr6 &= ~(1 << idx); }
-static int be_i386_adjust_pc_for_break(CONTEXT* ctx, BOOL way) +static int be_i386_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way) { if (way) { - ctx->Eip--; + ctx->x86.Eip--; return -1; } - ctx->Eip++; + ctx->x86.Eip++; return 1; }
diff --git a/programs/winedbg/be_x86_64.c b/programs/winedbg/be_x86_64.c index 280cdec..450cc87 100644 --- a/programs/winedbg/be_x86_64.c +++ b/programs/winedbg/be_x86_64.c @@ -31,23 +31,23 @@ WINE_DEFAULT_DEBUG_CHANNEL(winedbg);
#define STEP_FLAG 0x00000100 /* single step flag */
-static BOOL be_x86_64_get_addr(HANDLE hThread, const CONTEXT* ctx, +static BOOL be_x86_64_get_addr(HANDLE hThread, const dbg_ctx_t *ctx, enum be_cpu_addr bca, ADDRESS64* addr) { addr->Mode = AddrModeFlat; switch (bca) { case be_cpu_addr_pc: - addr->Segment = ctx->SegCs; - addr->Offset = ctx->Rip; + addr->Segment = ctx->ctx.SegCs; + addr->Offset = ctx->ctx.Rip; return TRUE; case be_cpu_addr_stack: - addr->Segment = ctx->SegSs; - addr->Offset = ctx->Rsp; + addr->Segment = ctx->ctx.SegSs; + addr->Offset = ctx->ctx.Rsp; return TRUE; case be_cpu_addr_frame: - addr->Segment = ctx->SegSs; - addr->Offset = ctx->Rbp; + addr->Segment = ctx->ctx.SegSs; + addr->Offset = ctx->ctx.Rbp; return TRUE; default: addr->Mode = -1; @@ -67,10 +67,10 @@ static BOOL be_x86_64_get_register_info(int regno, enum be_cpu_addr* kind) return FALSE; }
-static void be_x86_64_single_step(CONTEXT* ctx, BOOL enable) +static void be_x86_64_single_step(dbg_ctx_t *ctx, BOOL enable) { - if (enable) ctx->EFlags |= STEP_FLAG; - else ctx->EFlags &= ~STEP_FLAG; + if (enable) ctx->ctx.EFlags |= STEP_FLAG; + else ctx->ctx.EFlags &= ~STEP_FLAG; }
static inline long double m128a_to_longdouble(const M128A m) @@ -81,12 +81,13 @@ static inline long double m128a_to_longdouble(const M128A m) return *(long double*)&m; }
-static void be_x86_64_print_context(HANDLE hThread, const CONTEXT* ctx, +static void be_x86_64_print_context(HANDLE hThread, const dbg_ctx_t *pctx, int all_regs) { static const char mxcsr_flags[16][4] = { "IE", "DE", "ZE", "OE", "UE", "PE", "DAZ", "IM", "DM", "ZM", "OM", "UM", "PM", "R-", "R+", "FZ" }; static const char flags[] = "aVR-N--ODITSZ-A-P-C"; + const CONTEXT *ctx = &pctx->ctx; char buf[33]; int i;
@@ -183,7 +184,7 @@ static void be_x86_64_print_context(HANDLE hThread, const CONTEXT* ctx, } }
-static void be_x86_64_print_segment_info(HANDLE hThread, const CONTEXT* ctx) +static void be_x86_64_print_segment_info(HANDLE hThread, const dbg_ctx_t *ctx) { }
@@ -390,7 +391,7 @@ static BOOL be_x86_64_is_func_call(const void* insn, ADDRESS64* callee)
/* that's the only mode we support anyway */ callee->Mode = AddrModeFlat; - callee->Segment = dbg_context.SegCs; + callee->Segment = dbg_context.ctx.SegCs;
switch (ch) { @@ -435,14 +436,14 @@ static BOOL be_x86_64_is_func_call(const void* insn, ADDRESS64* callee) default: switch (f_rm(ch)) { - case 0x00: dst = dbg_context.Rax; break; - case 0x01: dst = dbg_context.Rcx; break; - case 0x02: dst = dbg_context.Rdx; break; - case 0x03: dst = dbg_context.Rbx; break; - case 0x04: dst = dbg_context.Rsp; break; - case 0x05: dst = dbg_context.Rbp; break; - case 0x06: dst = dbg_context.Rsi; break; - case 0x07: dst = dbg_context.Rdi; break; + case 0x00: dst = dbg_context.ctx.Rax; break; + case 0x01: dst = dbg_context.ctx.Rcx; break; + case 0x02: dst = dbg_context.ctx.Rdx; break; + case 0x03: dst = dbg_context.ctx.Rbx; break; + case 0x04: dst = dbg_context.ctx.Rsp; break; + case 0x05: dst = dbg_context.ctx.Rbp; break; + case 0x06: dst = dbg_context.ctx.Rsi; break; + case 0x07: dst = dbg_context.ctx.Rdi; break; } if (f_mod(ch) != 0x03) WINE_FIXME("Unsupported yet call insn (0xFF 0x%02x) at %p\n", ch, insn); @@ -494,8 +495,10 @@ extern void be_x86_64_disasm_one_insn(ADDRESS64* addr, int display); #define DR7_ENABLE_MASK(dr) (1<<(DR7_LOCAL_ENABLE_SHIFT+DR7_ENABLE_SIZE*(dr))) #define IS_DR7_SET(ctrl,dr) ((ctrl)&DR7_ENABLE_MASK(dr))
-static inline int be_x86_64_get_unused_DR(CONTEXT* ctx, DWORD64** r) +static inline int be_x86_64_get_unused_DR(dbg_ctx_t *pctx, DWORD64** r) { + CONTEXT *ctx = &pctx->ctx; + if (!IS_DR7_SET(ctx->Dr7, 0)) { *r = &ctx->Dr0; @@ -522,7 +525,7 @@ static inline int be_x86_64_get_unused_DR(CONTEXT* ctx, DWORD64** r) }
static BOOL be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long* val, unsigned size) { unsigned char ch; @@ -561,10 +564,10 @@ static BOOL be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* } *val = reg; /* clear old values */ - ctx->Dr7 &= ~(0x0F << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg)); + ctx->ctx.Dr7 &= ~(0x0F << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg)); /* set the correct ones */ - ctx->Dr7 |= bits << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg); - ctx->Dr7 |= DR7_ENABLE_MASK(reg) | DR7_LOCAL_SLOWDOWN; + ctx->ctx.Dr7 |= bits << (DR7_CONTROL_SHIFT + DR7_CONTROL_SIZE * reg); + ctx->ctx.Dr7 |= DR7_ENABLE_MASK(reg) | DR7_LOCAL_SLOWDOWN; break; default: dbg_printf("Unknown bp type %c\n", type); @@ -574,7 +577,7 @@ static BOOL be_x86_64_insert_Xpoint(HANDLE hProcess, const struct be_process_io* }
static BOOL be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* pio, - CONTEXT* ctx, enum be_xpoint_type type, + dbg_ctx_t *ctx, enum be_xpoint_type type, void* addr, unsigned long val, unsigned size) { SIZE_T sz; @@ -594,7 +597,7 @@ static BOOL be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* case be_xpoint_watch_read: case be_xpoint_watch_write: /* simply disable the entry */ - ctx->Dr7 &= ~DR7_ENABLE_MASK(val); + ctx->ctx.Dr7 &= ~DR7_ENABLE_MASK(val); break; default: dbg_printf("Unknown bp type %c\n", type); @@ -603,24 +606,24 @@ static BOOL be_x86_64_remove_Xpoint(HANDLE hProcess, const struct be_process_io* return TRUE; }
-static BOOL be_x86_64_is_watchpoint_set(const CONTEXT* ctx, unsigned idx) +static BOOL be_x86_64_is_watchpoint_set(const dbg_ctx_t *ctx, unsigned idx) { - return ctx->Dr6 & (1 << idx); + return ctx->ctx.Dr6 & (1 << idx); }
-static void be_x86_64_clear_watchpoint(CONTEXT* ctx, unsigned idx) +static void be_x86_64_clear_watchpoint(dbg_ctx_t *ctx, unsigned idx) { - ctx->Dr6 &= ~(1 << idx); + ctx->ctx.Dr6 &= ~(1 << idx); }
-static int be_x86_64_adjust_pc_for_break(CONTEXT* ctx, BOOL way) +static int be_x86_64_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way) { if (way) { - ctx->Rip--; + ctx->ctx.Rip--; return -1; } - ctx->Rip++; + ctx->ctx.Rip++; return 1; }
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h index 0ceb150..490bd06 100644 --- a/programs/winedbg/debugger.h +++ b/programs/winedbg/debugger.h @@ -170,6 +170,12 @@ typedef struct tagTHREADNAME_INFO DWORD dwFlags; /* Reserved for future use. Must be zero. */ } THREADNAME_INFO;
+typedef union dbg_ctx +{ + CONTEXT ctx; + WOW64_CONTEXT x86; +} dbg_ctx_t; + struct dbg_thread { struct list entry; @@ -196,7 +202,7 @@ struct dbg_thread DWORD_PTR linear_pc; DWORD_PTR linear_frame; DWORD_PTR linear_stack; - CONTEXT context; /* context we got out of stackwalk for this frame */ + dbg_ctx_t context; /* context we got out of stackwalk for this frame */ BOOL is_ctx_valid; /* is the context above valid */ }* frames; int num_frames; @@ -255,7 +261,7 @@ extern struct dbg_process* dbg_curr_process; extern DWORD_PTR dbg_curr_pid; extern struct dbg_thread* dbg_curr_thread; extern DWORD_PTR dbg_curr_tid; -extern CONTEXT dbg_context; +extern dbg_ctx_t dbg_context; extern BOOL dbg_interactiveP; extern HANDLE dbg_houtput;
@@ -396,7 +402,7 @@ extern void stack_backtrace(DWORD threadID); extern BOOL stack_set_frame(int newframe); extern BOOL stack_get_current_frame(IMAGEHLP_STACK_FRAME* ihsf); extern BOOL stack_get_register_frame(const struct dbg_internal_var* div, DWORD_PTR** pval); -extern unsigned stack_fetch_frames(const CONTEXT* ctx); +extern unsigned stack_fetch_frames(const dbg_ctx_t *ctx); extern BOOL stack_get_current_symbol(SYMBOL_INFO* sym);
/* symbol.c */ diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index 8742135..d5786b2 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -95,7 +95,7 @@ struct gdb_context /* current Win32 trap env */ unsigned last_sig; BOOL in_trap; - CONTEXT context; + dbg_ctx_t context; /* Win32 information */ struct dbg_process* process; /* Unix environment */ @@ -497,13 +497,13 @@ static struct cpu_register cpu_register_map[] = {
static const size_t cpu_num_regs = (sizeof(cpu_register_map) / sizeof(cpu_register_map[0]));
-static inline void* cpu_register_ptr(CONTEXT* ctx, unsigned idx) +static inline void* cpu_register_ptr(dbg_ctx_t *ctx, unsigned idx) { assert(idx < cpu_num_regs); return (char*)ctx + cpu_register_map[idx].ctx_offset; }
-static inline DWORD64 cpu_register(CONTEXT* ctx, unsigned idx) +static inline DWORD64 cpu_register(dbg_ctx_t *ctx, unsigned idx) { switch (cpu_register_map[idx].ctx_length) { @@ -518,7 +518,7 @@ static inline DWORD64 cpu_register(CONTEXT* ctx, unsigned idx) } }
-static inline void cpu_register_hex_from(CONTEXT* ctx, unsigned idx, const char** phex) +static inline void cpu_register_hex_from(dbg_ctx_t* ctx, unsigned idx, const char **phex) { if (cpu_register_map[idx].gdb_length == cpu_register_map[idx].ctx_length) hex_from(cpu_register_ptr(ctx, idx), *phex, cpu_register_map[idx].gdb_length); @@ -550,10 +550,9 @@ static inline void cpu_register_hex_from(CONTEXT* ctx, unsigned idx, const * =============================================== * */
-static BOOL fetch_context(struct gdb_context* gdbctx, HANDLE h, CONTEXT* ctx) +static BOOL fetch_context(struct gdb_context *gdbctx, HANDLE h, dbg_ctx_t *ctx) { - ctx->ContextFlags = CONTEXT_ALL; - if (!GetThreadContext(h, ctx)) + if (!GetThreadContext(h, &ctx->ctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Can't get thread's context\n"); @@ -769,7 +768,7 @@ static void resume_debuggee(struct gdb_context* gdbctx, DWORD cont) { if (dbg_curr_thread) { - if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context)) + if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context.ctx)) if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", dbg_curr_thread->tid); if (!ContinueDebugEvent(gdbctx->process->pid, dbg_curr_thread->tid, cont)) @@ -789,7 +788,7 @@ static void resume_debuggee_thread(struct gdb_context* gdbctx, DWORD cont, unsig { if(dbg_curr_thread->tid == threadid){ /* Windows debug and GDB don't seem to work well here, windows only likes ContinueDebugEvent being used on the reporter of the event */ - if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context)) + if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context.ctx)) if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", dbg_curr_thread->tid); if (!ContinueDebugEvent(gdbctx->process->pid, dbg_curr_thread->tid, cont)) @@ -1443,7 +1442,7 @@ static enum packet_return packet_detach(struct gdb_context* gdbctx) static enum packet_return packet_read_registers(struct gdb_context* gdbctx) { int i; - CONTEXT ctx; + dbg_ctx_t ctx;
assert(gdbctx->in_trap);
@@ -1463,8 +1462,8 @@ static enum packet_return packet_read_registers(struct gdb_context* gdbctx) static enum packet_return packet_write_registers(struct gdb_context* gdbctx) { unsigned i; - CONTEXT ctx; - CONTEXT* pctx = &gdbctx->context; + dbg_ctx_t ctx; + dbg_ctx_t *pctx = &gdbctx->context; const char* ptr;
assert(gdbctx->in_trap); @@ -1479,7 +1478,7 @@ static enum packet_return packet_write_registers(struct gdb_context* gdbctx) for (i = 0; i < cpu_num_regs; i++) cpu_register_hex_from(pctx, i, &ptr);
- if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, pctx)) + if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, &pctx->ctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", gdbctx->other_thread->tid); @@ -1616,8 +1615,8 @@ static enum packet_return packet_write_memory(struct gdb_context* gdbctx) static enum packet_return packet_read_register(struct gdb_context* gdbctx) { unsigned reg; - CONTEXT ctx; - CONTEXT* pctx = &gdbctx->context; + dbg_ctx_t ctx; + dbg_ctx_t *pctx = &gdbctx->context;
assert(gdbctx->in_trap); reg = hex_to_int(gdbctx->in_packet, gdbctx->in_packet_len); @@ -1650,8 +1649,8 @@ static enum packet_return packet_write_register(struct gdb_context* gdbctx) { unsigned reg; char* ptr; - CONTEXT ctx; - CONTEXT* pctx = &gdbctx->context; + dbg_ctx_t ctx; + dbg_ctx_t *pctx = &gdbctx->context;
assert(gdbctx->in_trap);
@@ -1678,7 +1677,7 @@ static enum packet_return packet_write_register(struct gdb_context* gdbctx) }
cpu_register_hex_from(pctx, reg, (const char**)&ptr); - if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, pctx)) + if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, &pctx->ctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context for thread %04x\n", gdbctx->other_thread->tid); diff --git a/programs/winedbg/memory.c b/programs/winedbg/memory.c index 6e65fa6..f3585f2 100644 --- a/programs/winedbg/memory.c +++ b/programs/winedbg/memory.c @@ -39,7 +39,7 @@ void* be_cpu_linearize(HANDLE hThread, const ADDRESS64* addr) return (void*)(DWORD_PTR)addr->Offset; }
-BOOL be_cpu_build_addr(HANDLE hThread, const CONTEXT* ctx, ADDRESS64* addr, +BOOL be_cpu_build_addr(HANDLE hThread, const dbg_ctx_t *ctx, ADDRESS64* addr, unsigned seg, unsigned long offset) { addr->Mode = AddrModeFlat; diff --git a/programs/winedbg/stack.c b/programs/winedbg/stack.c index 2ab4e60..a036107 100644 --- a/programs/winedbg/stack.c +++ b/programs/winedbg/stack.c @@ -184,14 +184,14 @@ static BOOL CALLBACK stack_read_mem(HANDLE hProc, DWORD64 addr, * * Do a backtrace on the current thread */ -unsigned stack_fetch_frames(const CONTEXT* _ctx) +unsigned stack_fetch_frames(const dbg_ctx_t* _ctx) { STACKFRAME64 sf; unsigned nf = 0; /* as native stackwalk can modify the context passed to it, simply copy * it to avoid any damage */ - CONTEXT ctx = *_ctx; + dbg_ctx_t ctx = *_ctx; BOOL ret;
HeapFree(GetProcessHeap(), 0, dbg_curr_thread->frames); @@ -351,21 +351,21 @@ static void backtrace_tid(struct dbg_process* pcs, DWORD tid) dbg_printf("Unknown thread id (%04x) in process (%04x)\n", tid, pcs->pid); else { - CONTEXT context; + dbg_ctx_t ctx = {0};
dbg_curr_tid = dbg_curr_thread->tid; - memset(&context, 0, sizeof(context)); - context.ContextFlags = CONTEXT_FULL; + + ctx.ctx.ContextFlags = CONTEXT_FULL; if (SuspendThread(dbg_curr_thread->handle) != -1) { - if (!GetThreadContext(dbg_curr_thread->handle, &context)) + if (!GetThreadContext(dbg_curr_thread->handle, &ctx.ctx)) { dbg_printf("Can't get context for thread %04x in current process\n", tid); } else { - stack_fetch_frames(&context); + stack_fetch_frames(&ctx); backtrace(); } ResumeThread(dbg_curr_thread->handle); @@ -386,7 +386,7 @@ static void backtrace_all(void) { struct dbg_process* process = dbg_curr_process; struct dbg_thread* thread = dbg_curr_thread; - CONTEXT ctx = dbg_context; + dbg_ctx_t ctx = dbg_context; DWORD cpid = dbg_curr_pid; THREADENTRY32 entry; HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0); diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index d891cfe..8c94402 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -91,7 +91,7 @@ BOOL dbg_attach_debuggee(DWORD pid, BOOL cofe)
static unsigned dbg_fetch_context(void) { - dbg_context.ContextFlags = CONTEXT_CONTROL + dbg_context.ctx.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER #ifdef CONTEXT_FLOATING_POINT | CONTEXT_FLOATING_POINT @@ -103,7 +103,7 @@ static unsigned dbg_fetch_context(void) | CONTEXT_DEBUG_REGISTERS #endif ; - if (!GetThreadContext(dbg_curr_thread->handle, &dbg_context)) + if (!GetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx)) { WINE_WARN("Can't get thread's context\n"); return FALSE; @@ -356,7 +356,7 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de) de->u.Exception.dwFirstChance); if (cont && dbg_curr_thread) { - SetThreadContext(dbg_curr_thread->handle, &dbg_context); + SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx); } } break; @@ -539,7 +539,7 @@ static void dbg_resume_debuggee(DWORD cont) dbg_curr_thread->exec_count); if (dbg_curr_thread) { - if (!SetThreadContext(dbg_curr_thread->handle, &dbg_context)) + if (!SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx)) dbg_printf("Cannot set ctx on %04lx\n", dbg_curr_tid); } } @@ -1001,7 +1001,7 @@ static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill) dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE); if (dbg_curr_thread->in_exception) { - SetThreadContext(dbg_curr_thread->handle, &dbg_context); + SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx); ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, DBG_CONTINUE); } } diff --git a/programs/winedbg/tgt_minidump.c b/programs/winedbg/tgt_minidump.c index a17f32b..f168633 100644 --- a/programs/winedbg/tgt_minidump.c +++ b/programs/winedbg/tgt_minidump.c @@ -69,7 +69,7 @@ void minidump_write(const char* file, const EXCEPTION_RECORD* rec) mei.ThreadId = dbg_curr_thread->tid; mei.ExceptionPointers = &ep; ep.ExceptionRecord = (EXCEPTION_RECORD*)rec; - ep.ContextRecord = &dbg_context; + ep.ContextRecord = &dbg_context.ctx; mei.ClientPointers = FALSE; } MiniDumpWriteDump(dbg_curr_process->handle, dbg_curr_process->pid, diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c index b32b24c..b5ffd76 100644 --- a/programs/winedbg/winedbg.c +++ b/programs/winedbg/winedbg.c @@ -87,7 +87,7 @@ struct dbg_process* dbg_curr_process = NULL; struct dbg_thread* dbg_curr_thread = NULL; DWORD_PTR dbg_curr_tid = 0; DWORD_PTR dbg_curr_pid = 0; -CONTEXT dbg_context; +dbg_ctx_t dbg_context; BOOL dbg_interactiveP = FALSE; HANDLE dbg_houtput = 0;
This and the next patch remove references to specific context structs or fields elsewhere than in the backends.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/winedbg/be_arm.c | 11 +++++++++++ programs/winedbg/be_arm64.c | 11 +++++++++++ programs/winedbg/be_cpu.h | 3 +++ programs/winedbg/be_i386.c | 7 +++++++ programs/winedbg/be_ppc.c | 11 +++++++++++ programs/winedbg/be_x86_64.c | 11 +++++++++++ programs/winedbg/gdbproxy.c | 2 +- programs/winedbg/stack.c | 4 +--- programs/winedbg/tgt_active.c | 14 +------------- 9 files changed, 57 insertions(+), 17 deletions(-)
diff --git a/programs/winedbg/be_arm.c b/programs/winedbg/be_arm.c index b7e42e1..c320704 100644 --- a/programs/winedbg/be_arm.c +++ b/programs/winedbg/be_arm.c @@ -1889,6 +1889,16 @@ static BOOL be_arm_store_integer(const struct dbg_lvalue* lvalue, unsigned size, return memory_write_value(lvalue, size, &val); }
+static BOOL be_arm_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ +#ifdef __x86_64__ + ctx->ctx.ContextFlags = CONTEXT_ALL; + return GetThreadContext(thread, &ctx->ctx); +#else + WINE_FIXME("Cannot debug an ARM process on this architecture.\n"); +#endif +} + struct backend_cpu be_arm = { IMAGE_FILE_MACHINE_ARMNT, @@ -1915,5 +1925,6 @@ struct backend_cpu be_arm = be_arm_fetch_integer, be_arm_fetch_float, be_arm_store_integer, + be_arm_get_context, }; #endif diff --git a/programs/winedbg/be_arm64.c b/programs/winedbg/be_arm64.c index dfeb552..8ee4fb9 100644 --- a/programs/winedbg/be_arm64.c +++ b/programs/winedbg/be_arm64.c @@ -278,6 +278,16 @@ void be_arm64_disasm_one_insn(ADDRESS64 *addr, int display) dbg_printf("be_arm64_disasm_one_insn: not done\n"); }
+static BOOL be_arm64_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ +#ifdef __x86_64__ + ctx->ctx.ContextFlags = CONTEXT_ALL; + return GetThreadContext(thread, &ctx->ctx); +#else + WINE_FIXME("Cannot debug an ARM64 process on this architecture.\n"); +#endif +} + struct backend_cpu be_arm64 = { IMAGE_FILE_MACHINE_ARM64, @@ -304,5 +314,6 @@ struct backend_cpu be_arm64 = be_arm64_fetch_integer, be_arm64_fetch_float, be_arm64_store_integer, + be_arm64_get_context, }; #endif diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h index 03776d0..aa7d9f0 100644 --- a/programs/winedbg/be_cpu.h +++ b/programs/winedbg/be_cpu.h @@ -21,6 +21,7 @@ enum be_cpu_addr {be_cpu_addr_pc, be_cpu_addr_stack, be_cpu_addr_frame}; enum be_xpoint_type {be_xpoint_break, be_xpoint_watch_exec, be_xpoint_watch_read, be_xpoint_watch_write, be_xpoint_free=-1}; + struct backend_cpu { const DWORD machine; @@ -114,6 +115,8 @@ struct backend_cpu BOOL (*fetch_float)(const struct dbg_lvalue* lvalue, unsigned size, long double*); /* Writes an integer to memory */ BOOL (*store_integer)(const struct dbg_lvalue* lvalue, unsigned size, BOOL is_signed, LONGLONG); + + BOOL (*get_context)(HANDLE thread, dbg_ctx_t *ctx); };
/* some handy functions for non segmented CPUs */ diff --git a/programs/winedbg/be_i386.c b/programs/winedbg/be_i386.c index bdc2ece..c7f5ac1 100644 --- a/programs/winedbg/be_i386.c +++ b/programs/winedbg/be_i386.c @@ -853,6 +853,12 @@ static BOOL be_i386_store_integer(const struct dbg_lvalue* lvalue, unsigned size return memory_write_value(lvalue, size, &val); }
+static BOOL be_i386_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ + ctx->x86.ContextFlags = WOW64_CONTEXT_ALL; + return Wow64GetThreadContext(thread, &ctx->x86); +} + struct backend_cpu be_i386 = { IMAGE_FILE_MACHINE_I386, @@ -879,5 +885,6 @@ struct backend_cpu be_i386 = be_i386_fetch_integer, be_i386_fetch_float, be_i386_store_integer, + be_i386_get_context, }; #endif diff --git a/programs/winedbg/be_ppc.c b/programs/winedbg/be_ppc.c index f1543bf..baf77dc 100644 --- a/programs/winedbg/be_ppc.c +++ b/programs/winedbg/be_ppc.c @@ -180,6 +180,16 @@ static BOOL be_ppc_store_integer(const struct dbg_lvalue* lvalue, unsigned size, return FALSE; }
+static BOOL be_ppc_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ +#ifdef __powerpc__ + ctx->ctx.ContextFlags = CONTEXT_ALL; + return GetThreadContext(thread, &ctx->ctx); +#else + WINE_FIXME("Cannot debug a PowerPC process on this architecture.\n"); +#endif +} + struct backend_cpu be_ppc = { IMAGE_FILE_MACHINE_POWERPC, @@ -206,5 +216,6 @@ struct backend_cpu be_ppc = be_ppc_fetch_integer, be_ppc_fetch_float, be_ppc_store_integer, + be_ppc_get_context, }; #endif diff --git a/programs/winedbg/be_x86_64.c b/programs/winedbg/be_x86_64.c index 450cc87..434f007 100644 --- a/programs/winedbg/be_x86_64.c +++ b/programs/winedbg/be_x86_64.c @@ -674,6 +674,16 @@ static BOOL be_x86_64_store_integer(const struct dbg_lvalue* lvalue, unsigned si return memory_write_value(lvalue, size, &val); }
+static BOOL be_x86_64_get_context(HANDLE thread, dbg_ctx_t *ctx) +{ +#ifdef __x86_64__ + ctx->ctx.ContextFlags = CONTEXT_ALL; + return GetThreadContext(thread, &ctx->ctx); +#else + WINE_FIXME("Cannot debug an x86-64 process on this architecture.\n"); +#endif +} + struct backend_cpu be_x86_64 = { IMAGE_FILE_MACHINE_AMD64, @@ -700,5 +710,6 @@ struct backend_cpu be_x86_64 = be_x86_64_fetch_integer, be_x86_64_fetch_float, be_x86_64_store_integer, + be_x86_64_get_context, }; #endif diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index d5786b2..b11a8b0 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -552,7 +552,7 @@ static inline void cpu_register_hex_from(dbg_ctx_t* ctx, unsigned idx, const cha
static BOOL fetch_context(struct gdb_context *gdbctx, HANDLE h, dbg_ctx_t *ctx) { - if (!GetThreadContext(h, &ctx->ctx)) + if (!gdbctx->process->be_cpu->get_context(h, ctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Can't get thread's context\n"); diff --git a/programs/winedbg/stack.c b/programs/winedbg/stack.c index a036107..820200d 100644 --- a/programs/winedbg/stack.c +++ b/programs/winedbg/stack.c @@ -354,11 +354,9 @@ static void backtrace_tid(struct dbg_process* pcs, DWORD tid) dbg_ctx_t ctx = {0};
dbg_curr_tid = dbg_curr_thread->tid; - - ctx.ctx.ContextFlags = CONTEXT_FULL; if (SuspendThread(dbg_curr_thread->handle) != -1) { - if (!GetThreadContext(dbg_curr_thread->handle, &ctx.ctx)) + if (!pcs->be_cpu->get_context(dbg_curr_thread->handle, &ctx)) { dbg_printf("Can't get context for thread %04x in current process\n", tid); diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index 8c94402..fccae0c 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -91,19 +91,7 @@ BOOL dbg_attach_debuggee(DWORD pid, BOOL cofe)
static unsigned dbg_fetch_context(void) { - dbg_context.ctx.ContextFlags = CONTEXT_CONTROL - | CONTEXT_INTEGER -#ifdef CONTEXT_FLOATING_POINT - | CONTEXT_FLOATING_POINT -#endif -#ifdef CONTEXT_SEGMENTS - | CONTEXT_SEGMENTS -#endif -#ifdef CONTEXT_DEBUG_REGISTERS - | CONTEXT_DEBUG_REGISTERS -#endif - ; - if (!GetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx)) + if (!dbg_curr_process->be_cpu->get_context(dbg_curr_thread->handle, &dbg_context)) { WINE_WARN("Can't get thread's context\n"); return FALSE;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- programs/winedbg/be_arm.c | 5 +++++ programs/winedbg/be_arm64.c | 5 +++++ programs/winedbg/be_cpu.h | 1 + programs/winedbg/be_i386.c | 6 ++++++ programs/winedbg/be_ppc.c | 6 ++++++ programs/winedbg/be_x86_64.c | 6 ++++++ programs/winedbg/gdbproxy.c | 10 ++++++---- programs/winedbg/tgt_active.c | 6 +++--- programs/winedbg/tgt_minidump.c | 8 ++++++++ 9 files changed, 46 insertions(+), 7 deletions(-)
diff --git a/programs/winedbg/be_arm.c b/programs/winedbg/be_arm.c index c320704..4aa7260 100644 --- a/programs/winedbg/be_arm.c +++ b/programs/winedbg/be_arm.c @@ -1899,6 +1899,11 @@ static BOOL be_arm_get_context(HANDLE thread, dbg_ctx_t *ctx) #endif }
+static BOOL be_arm_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return SetThreadContext(thread, &ctx->ctx); +} + struct backend_cpu be_arm = { IMAGE_FILE_MACHINE_ARMNT, diff --git a/programs/winedbg/be_arm64.c b/programs/winedbg/be_arm64.c index 8ee4fb9..9cc05bb 100644 --- a/programs/winedbg/be_arm64.c +++ b/programs/winedbg/be_arm64.c @@ -288,6 +288,11 @@ static BOOL be_arm64_get_context(HANDLE thread, dbg_ctx_t *ctx) #endif }
+static BOOL be_arm64_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return SetThreadContext(thread, &ctx->ctx); +} + struct backend_cpu be_arm64 = { IMAGE_FILE_MACHINE_ARM64, diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h index aa7d9f0..1a67c06 100644 --- a/programs/winedbg/be_cpu.h +++ b/programs/winedbg/be_cpu.h @@ -117,6 +117,7 @@ struct backend_cpu BOOL (*store_integer)(const struct dbg_lvalue* lvalue, unsigned size, BOOL is_signed, LONGLONG);
BOOL (*get_context)(HANDLE thread, dbg_ctx_t *ctx); + BOOL (*set_context)(HANDLE thread, const dbg_ctx_t *ctx); };
/* some handy functions for non segmented CPUs */ diff --git a/programs/winedbg/be_i386.c b/programs/winedbg/be_i386.c index c7f5ac1..f46ebb1 100644 --- a/programs/winedbg/be_i386.c +++ b/programs/winedbg/be_i386.c @@ -859,6 +859,11 @@ static BOOL be_i386_get_context(HANDLE thread, dbg_ctx_t *ctx) return Wow64GetThreadContext(thread, &ctx->x86); }
+static BOOL be_i386_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return Wow64SetThreadContext(thread, &ctx->x86); +} + struct backend_cpu be_i386 = { IMAGE_FILE_MACHINE_I386, @@ -886,5 +891,6 @@ struct backend_cpu be_i386 = be_i386_fetch_float, be_i386_store_integer, be_i386_get_context, + be_i386_set_context, }; #endif diff --git a/programs/winedbg/be_ppc.c b/programs/winedbg/be_ppc.c index baf77dc..40aee55 100644 --- a/programs/winedbg/be_ppc.c +++ b/programs/winedbg/be_ppc.c @@ -190,6 +190,11 @@ static BOOL be_ppc_get_context(HANDLE thread, dbg_ctx_t *ctx) #endif }
+static BOOL be_ppc_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return SetThreadContext(thread, &ctx->ctx); +} + struct backend_cpu be_ppc = { IMAGE_FILE_MACHINE_POWERPC, @@ -217,5 +222,6 @@ struct backend_cpu be_ppc = be_ppc_fetch_float, be_ppc_store_integer, be_ppc_get_context, + be_ppc_set_context, }; #endif diff --git a/programs/winedbg/be_x86_64.c b/programs/winedbg/be_x86_64.c index 434f007..15f84a6 100644 --- a/programs/winedbg/be_x86_64.c +++ b/programs/winedbg/be_x86_64.c @@ -684,6 +684,11 @@ static BOOL be_x86_64_get_context(HANDLE thread, dbg_ctx_t *ctx) #endif }
+static BOOL be_x86_64_set_context(HANDLE thread, const dbg_ctx_t *ctx) +{ + return SetThreadContext(thread, &ctx->ctx); +} + struct backend_cpu be_x86_64 = { IMAGE_FILE_MACHINE_AMD64, @@ -711,5 +716,6 @@ struct backend_cpu be_x86_64 = be_x86_64_fetch_float, be_x86_64_store_integer, be_x86_64_get_context, + be_x86_64_set_context, }; #endif diff --git a/programs/winedbg/gdbproxy.c b/programs/winedbg/gdbproxy.c index b11a8b0..81cd7de 100644 --- a/programs/winedbg/gdbproxy.c +++ b/programs/winedbg/gdbproxy.c @@ -768,7 +768,7 @@ static void resume_debuggee(struct gdb_context* gdbctx, DWORD cont) { if (dbg_curr_thread) { - if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context.ctx)) + if (!gdbctx->process->be_cpu->set_context(dbg_curr_thread->handle, &gdbctx->context)) if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", dbg_curr_thread->tid); if (!ContinueDebugEvent(gdbctx->process->pid, dbg_curr_thread->tid, cont)) @@ -788,7 +788,7 @@ static void resume_debuggee_thread(struct gdb_context* gdbctx, DWORD cont, unsig { if(dbg_curr_thread->tid == threadid){ /* Windows debug and GDB don't seem to work well here, windows only likes ContinueDebugEvent being used on the reporter of the event */ - if (!SetThreadContext(dbg_curr_thread->handle, &gdbctx->context.ctx)) + if (!gdbctx->process->be_cpu->set_context(dbg_curr_thread->handle, &gdbctx->context)) if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", dbg_curr_thread->tid); if (!ContinueDebugEvent(gdbctx->process->pid, dbg_curr_thread->tid, cont)) @@ -1478,7 +1478,8 @@ static enum packet_return packet_write_registers(struct gdb_context* gdbctx) for (i = 0; i < cpu_num_regs; i++) cpu_register_hex_from(pctx, i, &ptr);
- if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, &pctx->ctx)) + if (pctx != &gdbctx->context && + !gdbctx->process->be_cpu->set_context(gdbctx->other_thread->handle, pctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context on thread %04x\n", gdbctx->other_thread->tid); @@ -1677,7 +1678,8 @@ static enum packet_return packet_write_register(struct gdb_context* gdbctx) }
cpu_register_hex_from(pctx, reg, (const char**)&ptr); - if (pctx != &gdbctx->context && !SetThreadContext(gdbctx->other_thread->handle, &pctx->ctx)) + if (pctx != &gdbctx->context && + !gdbctx->process->be_cpu->set_context(gdbctx->other_thread->handle, pctx)) { if (gdbctx->trace & GDBPXY_TRC_WIN32_ERROR) fprintf(stderr, "Cannot set context for thread %04x\n", gdbctx->other_thread->tid); diff --git a/programs/winedbg/tgt_active.c b/programs/winedbg/tgt_active.c index fccae0c..e5fd07d 100644 --- a/programs/winedbg/tgt_active.c +++ b/programs/winedbg/tgt_active.c @@ -344,7 +344,7 @@ static unsigned dbg_handle_debug_event(DEBUG_EVENT* de) de->u.Exception.dwFirstChance); if (cont && dbg_curr_thread) { - SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx); + dbg_curr_process->be_cpu->set_context(dbg_curr_thread->handle, &dbg_context); } } break; @@ -527,7 +527,7 @@ static void dbg_resume_debuggee(DWORD cont) dbg_curr_thread->exec_count); if (dbg_curr_thread) { - if (!SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx)) + if (!dbg_curr_process->be_cpu->set_context(dbg_curr_thread->handle, &dbg_context)) dbg_printf("Cannot set ctx on %04lx\n", dbg_curr_tid); } } @@ -989,7 +989,7 @@ static BOOL tgt_process_active_close_process(struct dbg_process* pcs, BOOL kill) dbg_curr_process->be_cpu->single_step(&dbg_context, FALSE); if (dbg_curr_thread->in_exception) { - SetThreadContext(dbg_curr_thread->handle, &dbg_context.ctx); + dbg_curr_process->be_cpu->set_context(dbg_curr_thread->handle, &dbg_context); ContinueDebugEvent(dbg_curr_pid, dbg_curr_tid, DBG_CONTINUE); } } diff --git a/programs/winedbg/tgt_minidump.c b/programs/winedbg/tgt_minidump.c index f168633..95af7a6 100644 --- a/programs/winedbg/tgt_minidump.c +++ b/programs/winedbg/tgt_minidump.c @@ -59,6 +59,14 @@ void minidump_write(const char* file, const EXCEPTION_RECORD* rec) MINIDUMP_EXCEPTION_INFORMATION mei; EXCEPTION_POINTERS ep;
+#ifdef __x86_64__ + if (dbg_curr_process->be_cpu->machine != IMAGE_FILE_MACHINE_AMD64) + { + FIXME("Cannot write minidump for 32-bit process using 64-bit winedbg\n"); + return; + } +#endif + hFile = CreateFileA(file, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);