winedbg: Add a backend-specific vector for setting a thread's context.

Signed-off-by: Zebediah Figura <zfigura@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2018-06-12 17:53:20 -05:00 committed by Alexandre Julliard
parent 2326179312
commit cf349cea69
9 changed files with 46 additions and 7 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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 */

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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);
}
}

View file

@ -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);