From cf349cea69a7da9ac8381be776b74c0509559a7f Mon Sep 17 00:00:00 2001 From: Zebediah Figura Date: Tue, 12 Jun 2018 17:53:20 -0500 Subject: [PATCH] winedbg: Add a backend-specific vector for setting a thread's context. Signed-off-by: Zebediah Figura Signed-off-by: Alexandre Julliard --- 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 a0e8027afdb..9883476b69c 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 6aa26a6b92b..418d6e0f5f5 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 aa7d9f08cb4..1a67c066919 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 c7f5ac1ba19..f46ebb1a17f 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 baf77dcda4e..40aee551b57 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 434f0074724..15f84a635b1 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 b11a8b07add..81cd7dec63b 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 fccae0c6cf8..e5fd07da925 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 f1686338da6..95af7a601e5 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);