[PATCH 05/18] programs/winedbg: remove methods for fetching/storing integers in CPU backends

Eric Pouech eric.pouech at gmail.com
Fri Dec 3 09:57:29 CST 2021


all integer code assume CPU of debuggee encode integers:
- little endian
- 2 complement for signed integers

so remove methods related to integer storage from CPU backends
(they're all the same anyway)

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 programs/winedbg/be_arm.c    |   30 ------------------------------
 programs/winedbg/be_arm64.c  |   30 ------------------------------
 programs/winedbg/be_cpu.h    |    4 ----
 programs/winedbg/be_i386.c   |   30 ------------------------------
 programs/winedbg/be_x86_64.c |   30 ------------------------------
 programs/winedbg/debugger.h  |    3 +++
 programs/winedbg/memory.c    |   40 ++++++++++++++++++++++++++++++++++------
 programs/winedbg/types.c     |   15 +++++++--------
 8 files changed, 44 insertions(+), 138 deletions(-)

diff --git a/programs/winedbg/be_arm.c b/programs/winedbg/be_arm.c
index 435dad2e3cc..02f72e9c789 100644
--- a/programs/winedbg/be_arm.c
+++ b/programs/winedbg/be_arm.c
@@ -1831,27 +1831,6 @@ static int be_arm_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way)
     return step;
 }
 
-static BOOL be_arm_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                 BOOL is_signed, LONGLONG* ret)
-{
-    /* size must fit in ret and be a power of two */
-    if (size > sizeof(*ret) || (size & (size - 1))) return FALSE;
-
-    memset(ret, 0, sizeof(*ret)); /* clear unread bytes */
-    /* FIXME: this assumes that debuggee and debugger use the same
-     * integral representation
-     */
-    if (!memory_read_value(lvalue, size, ret)) return FALSE;
-
-    /* propagate sign information */
-    if (is_signed && size < 8 && (*ret >> (size * 8 - 1)) != 0)
-    {
-        ULONGLONG neg = -1;
-        *ret |= neg << (size * 8);
-    }
-    return TRUE;
-}
-
 static BOOL be_arm_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, double *ret)
 {
     char tmp[sizeof(double)];
@@ -1869,13 +1848,6 @@ static BOOL be_arm_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, d
     return TRUE;
 }
 
-static BOOL be_arm_store_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                 BOOL is_signed, LONGLONG val)
-{
-    /* this is simple if we're on a little endian CPU */
-    return memory_write_value(lvalue, size, &val);
-}
-
 static BOOL be_arm_get_context(HANDLE thread, dbg_ctx_t *ctx)
 {
     ctx->ctx.ContextFlags = CONTEXT_ALL;
@@ -1932,9 +1904,7 @@ struct backend_cpu be_arm =
     be_arm_is_watchpoint_set,
     be_arm_clear_watchpoint,
     be_arm_adjust_pc_for_break,
-    be_arm_fetch_integer,
     be_arm_fetch_float,
-    be_arm_store_integer,
     be_arm_get_context,
     be_arm_set_context,
     be_arm_gdb_register_map,
diff --git a/programs/winedbg/be_arm64.c b/programs/winedbg/be_arm64.c
index 39f17c7d67d..8ca54e6c461 100644
--- a/programs/winedbg/be_arm64.c
+++ b/programs/winedbg/be_arm64.c
@@ -228,27 +228,6 @@ static int be_arm64_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way)
     return 4;
 }
 
-static BOOL be_arm64_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                   BOOL is_signed, LONGLONG* ret)
-{
-    /* size must fit in ret and be a power of two */
-    if (size > sizeof(*ret) || (size & (size - 1))) return FALSE;
-
-    memset(ret, 0, sizeof(*ret)); /* clear unread bytes */
-    /* FIXME: this assumes that debuggee and debugger use the same
-     * integral representation
-     */
-    if (!memory_read_value(lvalue, size, ret)) return FALSE;
-
-    /* propagate sign information */
-    if (is_signed && size < 8 && (*ret >> (size * 8 - 1)) != 0)
-    {
-        ULONGLONG neg = -1;
-        *ret |= neg << (size * 8);
-    }
-    return TRUE;
-}
-
 static BOOL be_arm64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, double *ret)
 {
     char tmp[sizeof(double)];
@@ -266,13 +245,6 @@ static BOOL be_arm64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size,
     return TRUE;
 }
 
-static BOOL be_arm64_store_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                   BOOL is_signed, LONGLONG val)
-{
-    /* this is simple if we're on a little endian CPU */
-    return memory_write_value(lvalue, size, &val);
-}
-
 void be_arm64_disasm_one_insn(ADDRESS64 *addr, int display)
 {
     dbg_printf("be_arm64_disasm_one_insn: not done\n");
@@ -351,9 +323,7 @@ struct backend_cpu be_arm64 =
     be_arm64_is_watchpoint_set,
     be_arm64_clear_watchpoint,
     be_arm64_adjust_pc_for_break,
-    be_arm64_fetch_integer,
     be_arm64_fetch_float,
-    be_arm64_store_integer,
     be_arm64_get_context,
     be_arm64_set_context,
     be_arm64_gdb_register_map,
diff --git a/programs/winedbg/be_cpu.h b/programs/winedbg/be_cpu.h
index 14746d6665b..69e3e148f75 100644
--- a/programs/winedbg/be_cpu.h
+++ b/programs/winedbg/be_cpu.h
@@ -118,12 +118,8 @@ struct backend_cpu
     /* -------------------------------------------------------------------------------
      * basic type read/write 
      * -------------------------------------------------------------------------------*/
-    /* Reads an integer from memory and stores it inside a long long int */
-    BOOL                (*fetch_integer)(const struct dbg_lvalue* lvalue, unsigned size, BOOL is_signed, LONGLONG*);
     /* Reads a real from memory and stores it inside a long double */
     BOOL                (*fetch_float)(const struct dbg_lvalue* lvalue, unsigned size, 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);
     BOOL                (*set_context)(HANDLE thread, const dbg_ctx_t *ctx);
diff --git a/programs/winedbg/be_i386.c b/programs/winedbg/be_i386.c
index 8902185d0b0..9b3c615092c 100644
--- a/programs/winedbg/be_i386.c
+++ b/programs/winedbg/be_i386.c
@@ -777,27 +777,6 @@ static int be_i386_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way)
     return 1;
 }
 
-static BOOL be_i386_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                  BOOL is_signed, LONGLONG* ret)
-{
-    /* size must fit in ret and be a power of two */
-    if (size > sizeof(*ret) || (size & (size - 1))) return FALSE;
-
-    memset(ret, 0, sizeof(*ret)); /* clear unread bytes */
-    /* FIXME: this assumes that debuggee and debugger use the same
-     * integral representation
-     */
-    if (!memory_read_value(lvalue, size, ret)) return FALSE;
-
-    /* propagate sign information */
-    if (is_signed && size < 8 && (*ret >> (size * 8 - 1)) != 0)
-    {
-        ULONGLONG neg = -1;
-        *ret |= neg << (size * 8);
-    }
-    return TRUE;
-}
-
 static BOOL be_i386_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, double *ret)
 {
     char tmp[sizeof(double)];
@@ -815,13 +794,6 @@ static BOOL be_i386_fetch_float(const struct dbg_lvalue* lvalue, unsigned size,
     return TRUE;
 }
 
-static BOOL be_i386_store_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                  BOOL is_signed, LONGLONG val)
-{
-    /* this is simple as we're on a little endian CPU */
-    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;
@@ -903,9 +875,7 @@ struct backend_cpu be_i386 =
     be_i386_is_watchpoint_set,
     be_i386_clear_watchpoint,
     be_i386_adjust_pc_for_break,
-    be_i386_fetch_integer,
     be_i386_fetch_float,
-    be_i386_store_integer,
     be_i386_get_context,
     be_i386_set_context,
     be_i386_gdb_register_map,
diff --git a/programs/winedbg/be_x86_64.c b/programs/winedbg/be_x86_64.c
index af9f7284685..169a31a584d 100644
--- a/programs/winedbg/be_x86_64.c
+++ b/programs/winedbg/be_x86_64.c
@@ -699,27 +699,6 @@ static int be_x86_64_adjust_pc_for_break(dbg_ctx_t *ctx, BOOL way)
     return 1;
 }
 
-static BOOL be_x86_64_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                    BOOL is_signed, LONGLONG* ret)
-{
-    /* size must fit in ret and be a power of two */
-    if (size > sizeof(*ret) || (size & (size - 1))) return FALSE;
-
-    memset(ret, 0, sizeof(*ret)); /* clear unread bytes */
-    /* FIXME: this assumes that debuggee and debugger use the same
-     * integral representation
-     */
-    if (!memory_read_value(lvalue, size, ret)) return FALSE;
-
-    /* propagate sign information */
-    if (is_signed && size < sizeof(*ret) && (*ret >> (size * 8 - 1)) != 0)
-    {
-        ULONGLONG neg = -1;
-        *ret |= neg << (size * 8);
-    }
-    return TRUE;
-}
-
 static BOOL be_x86_64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size, double *ret)
 {
     char tmp[sizeof(double)];
@@ -737,13 +716,6 @@ static BOOL be_x86_64_fetch_float(const struct dbg_lvalue* lvalue, unsigned size
     return TRUE;
 }
 
-static BOOL be_x86_64_store_integer(const struct dbg_lvalue* lvalue, unsigned size,
-                                    BOOL is_signed, LONGLONG val)
-{
-    /* this is simple as we're on a little endian CPU */
-    return memory_write_value(lvalue, size, &val);
-}
-
 static BOOL be_x86_64_get_context(HANDLE thread, dbg_ctx_t *ctx)
 {
     ctx->ctx.ContextFlags = CONTEXT_ALL;
@@ -841,9 +813,7 @@ struct backend_cpu be_x86_64 =
     be_x86_64_is_watchpoint_set,
     be_x86_64_clear_watchpoint,
     be_x86_64_adjust_pc_for_break,
-    be_x86_64_fetch_integer,
     be_x86_64_fetch_float,
-    be_x86_64_store_integer,
     be_x86_64_get_context,
     be_x86_64_set_context,
     be_x86_64_gdb_register_map,
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h
index 8c909361a58..9952e1425f3 100644
--- a/programs/winedbg/debugger.h
+++ b/programs/winedbg/debugger.h
@@ -378,6 +378,9 @@ extern void             info_wine_dbg_channel(BOOL add, const char* chnl, const
   /* memory.c */
 extern BOOL             memory_read_value(const struct dbg_lvalue* lvalue, DWORD size, void* result);
 extern BOOL             memory_write_value(const struct dbg_lvalue* val, DWORD size, void* value);
+extern BOOL             memory_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
+                                             BOOL is_signed, dbg_lgint_t* ret);
+extern BOOL             memory_store_integer(const struct dbg_lvalue* lvalue, dbg_lgint_t val);
 extern void             memory_examine(const struct dbg_lvalue *lvalue, int count, char format);
 extern void*            memory_to_linear_addr(const ADDRESS64* address);
 extern BOOL             memory_get_current_pc(ADDRESS64* address);
diff --git a/programs/winedbg/memory.c b/programs/winedbg/memory.c
index b666b077077..4fb62e9e9d5 100644
--- a/programs/winedbg/memory.c
+++ b/programs/winedbg/memory.c
@@ -231,6 +231,34 @@ void memory_examine(const struct dbg_lvalue *lvalue, int count, char format)
     }
 }
 
+BOOL memory_fetch_integer(const struct dbg_lvalue* lvalue, unsigned size,
+                          BOOL is_signed, dbg_lgint_t* ret)
+{
+    /* size must fit in ret and be a power of two */
+    if (size > sizeof(*ret) || (size & (size - 1))) return FALSE;
+
+    /* we are on little endian CPU */
+    memset(ret, 0, sizeof(*ret)); /* clear unread bytes */
+    if (!memory_read_value(lvalue, size, ret)) return FALSE;
+
+    /* propagate sign information */
+    if (is_signed && size < 8 && (*ret >> (size * 8 - 1)) != 0)
+    {
+        dbg_lguint_t neg = -1;
+        *ret |= neg << (size * 8);
+    }
+    return TRUE;
+}
+
+BOOL memory_store_integer(const struct dbg_lvalue* lvalue, dbg_lgint_t val)
+{
+    DWORD64 size;
+    if (!types_get_info(&lvalue->type, TI_GET_LENGTH, &size)) return FALSE;
+    /* this is simple if we're on a little endian CPU */
+    return memory_write_value(lvalue, (unsigned)size, &val);
+}
+
+
 BOOL memory_get_string(struct dbg_process* pcs, void* addr, BOOL in_debuggee,
                        BOOL unicode, char* buffer, int size)
 {
@@ -343,7 +371,7 @@ static void dbg_print_hex(DWORD size, ULONGLONG sv)
 
 static void print_typed_basic(const struct dbg_lvalue* lvalue)
 {
-    LONGLONG            val_int;
+    dbg_lgint_t         val_int;
     void*               val_ptr;
     double              val_real;
     DWORD64             size64;
@@ -369,13 +397,13 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue)
         {
         case btInt:
         case btLong:
-            if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
+            if (!memory_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 (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, FALSE, &val_int)) return;
+            if (!memory_fetch_integer(lvalue, size, FALSE, &val_int)) return;
             dbg_print_hex(size, val_int);
             break;
         case btFloat:
@@ -387,7 +415,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 (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
+            if (!memory_fetch_integer(lvalue, size, TRUE, &val_int)) return;
         print_char:
             if ((size == 1 && isprint((char)val_int)) ||
                  (size == 2 && val_int < 127 && isprint((char)val_int)))
@@ -396,7 +424,7 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue)
                 dbg_printf("%d", (int)val_int);
             break;
         case btBool:
-            if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, size, TRUE, &val_int)) return;
+            if (!memory_fetch_integer(lvalue, size, TRUE, &val_int)) return;
             dbg_printf("%s", val_int ? "true" : "false");
             break;
         default:
@@ -441,7 +469,7 @@ static void print_typed_basic(const struct dbg_lvalue* lvalue)
             BOOL        ok = FALSE;
 
             if (!types_get_info(&type, TI_GET_LENGTH, &size64) ||
-                !dbg_curr_process->be_cpu->fetch_integer(lvalue, size64, TRUE, &val_int)) return;
+                !memory_fetch_integer(lvalue, size64, TRUE, &val_int)) return;
 
             if (types_get_info(&type, TI_GET_CHILDRENCOUNT, &count))
             {
diff --git a/programs/winedbg/types.c b/programs/winedbg/types.c
index 3d8f7e7a140..1df20252f11 100644
--- a/programs/winedbg/types.c
+++ b/programs/winedbg/types.c
@@ -91,11 +91,11 @@ dbg_lgint_t types_extract_as_longlong(const struct dbg_lvalue* lvalue,
         {
         case btChar:
         case btInt:
-            if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn))
+            if (!memory_fetch_integer(lvalue, (unsigned)size, s = TRUE, &rtn))
                 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
             break;
         case btUInt:
-            if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
+            if (!memory_fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
                 RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
             break;
         case btFloat:
@@ -106,17 +106,17 @@ dbg_lgint_t types_extract_as_longlong(const struct dbg_lvalue* lvalue,
         break;
     case SymTagPointerType:
         if (!types_get_info(&type, TI_GET_LENGTH, &size) ||
-            !dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
+            !memory_fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
             RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
         break;
     case SymTagArrayType:
     case SymTagUDT:
-        if (!dbg_curr_process->be_cpu->fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
+        if (!memory_fetch_integer(lvalue, sizeof(unsigned), s = FALSE, &rtn))
             RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
         break;
     case SymTagEnum:
         if (!types_get_info(&type, TI_GET_LENGTH, &size) ||
-            !dbg_curr_process->be_cpu->fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
+            !memory_fetch_integer(lvalue, (unsigned)size, s = FALSE, &rtn))
             RaiseException(DEBUG_STATUS_INTERNAL_ERROR, 0, 0, NULL);
         break;
     case SymTagFunctionType:
@@ -163,7 +163,6 @@ BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lv
 {
     dbg_lgint_t val;
     DWORD64     size;
-    BOOL        is_signed;
 
     if (!types_get_info(&lvalue_to->type, TI_GET_LENGTH, &size)) return FALSE;
     if (sizeof(val) < size)
@@ -172,8 +171,8 @@ BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lv
         return FALSE;
     }
     /* FIXME: should support floats as well */
-    val = types_extract_as_longlong(lvalue_from, NULL, &is_signed);
-    return dbg_curr_process->be_cpu->store_integer(lvalue_to, size, is_signed, val);
+    val = types_extract_as_integer(lvalue_from);
+    return memory_store_integer(lvalue_to, val);
 }
 
 /******************************************************************




More information about the wine-devel mailing list