winedbg: Remove methods for fetching/storing integers in CPU backends.

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

Signed-off-by: Eric Pouech <eric.pouech@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Eric Pouech 2021-12-07 18:45:45 +01:00 committed by Alexandre Julliard
parent 53ae7824b6
commit e656c29e59
8 changed files with 44 additions and 138 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -373,6 +373,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);

View File

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

View File

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