winedbg: Add a backend-specific vector for retrieving 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 19:01:50 -05:00 committed by Alexandre Julliard
parent 45e0654591
commit 2326179312
9 changed files with 57 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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