[PATCH 5/5] winedbg: Add a backend-specific vector for setting a thread's context.

Zebediah Figura zfigura at codeweavers.com
Tue Jun 12 17:53:20 CDT 2018


Signed-off-by: Zebediah Figura <zfigura at 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);
 
-- 
2.7.4




More information about the wine-devel mailing list