[PATCH 04/18] programs/winedbg: introduce dbg_lg(u)int_t and migrate all integral computations on this type

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


as a side effect, the internal 'long int' type is now always 8 byte wide

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

---
 programs/winedbg/dbg.y      |    6 +++---
 programs/winedbg/debug.l    |    8 ++++----
 programs/winedbg/debugger.h |   26 ++++++++++++++++++++++----
 programs/winedbg/expr.c     |   40 ++++++++++++++++++++--------------------
 programs/winedbg/memory.c   |    2 +-
 programs/winedbg/types.c    |   14 +++++++-------
 programs/winedbg/winedbg.c  |    3 +--
 7 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/programs/winedbg/dbg.y b/programs/winedbg/dbg.y
index c5e7b2b43ca..46a643bfb47 100644
--- a/programs/winedbg/dbg.y
+++ b/programs/winedbg/dbg.y
@@ -39,7 +39,7 @@ static void parser(const char*);
 {
     struct dbg_lvalue   lvalue;
     char*               string;
-    INT_PTR             integer;
+    dbg_lgint_t         integer;
     IMAGEHLP_LINE64     listing;
     struct expr*        expression;
     struct type_expr_t  type;
@@ -286,9 +286,9 @@ info_command:
     | tINFO tCLASS              { info_win32_class(NULL, NULL); }
     | tINFO tCLASS tSTRING     	{ info_win32_class(NULL, $3); }
     | tINFO tWND                { info_win32_window(NULL, FALSE); }
-    | tINFO tWND expr_rvalue    { info_win32_window((HWND)$3, FALSE); }
+    | tINFO tWND expr_rvalue    { info_win32_window((HWND)(DWORD_PTR)$3, FALSE); }
     | tINFO '*' tWND            { info_win32_window(NULL, TRUE); }
-    | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)$4, TRUE); }
+    | tINFO '*' tWND expr_rvalue { info_win32_window((HWND)(DWORD_PTR)$4, TRUE); }
     | tINFO tPROCESS            { info_win32_processes(); }
     | tINFO tTHREAD             { info_win32_threads(); }
     | tINFO tFRAME              { info_win32_frame_exceptions(dbg_curr_tid); }
diff --git a/programs/winedbg/debug.l b/programs/winedbg/debug.l
index dc93901a71c..5c87f05abe5 100644
--- a/programs/winedbg/debug.l
+++ b/programs/winedbg/debug.l
@@ -139,11 +139,11 @@ STRING     \"(\\[^\n]|[^\\"\n])*\"
 "["					{ return *yytext; }
 "]"					{ return *yytext; }
 
-"0x"{HEXDIGIT}+      			{ sscanf(yytext, "%Ix", &dbg_lval.integer); return tNUM; }
-{DIGIT}+             			{ sscanf(yytext, "%Id", &dbg_lval.integer); return tNUM; }
+"0x"{HEXDIGIT}+      			{ sscanf(yytext, "%I64x", &dbg_lval.integer); return tNUM; }
+{DIGIT}+             			{ sscanf(yytext, "%I64d", &dbg_lval.integer); return tNUM; }
 "'\\''"                                 { dbg_lval.integer = '\''; return tNUM;}
-"'\\0"{OCTDIGIT}*"'"                    { sscanf(yytext + 3, "%Io", &dbg_lval.integer); return tNUM;}
-"'\\x"{HEXDIGIT}+"'"                    { sscanf(yytext + 3, "%Ix", &dbg_lval.integer); return tNUM;}
+"'\\0"{OCTDIGIT}*"'"                    { sscanf(yytext + 3, "%I64o", &dbg_lval.integer); return tNUM;}
+"'\\x"{HEXDIGIT}+"'"                    { sscanf(yytext + 3, "%I64x", &dbg_lval.integer); return tNUM;}
 "'\\"[a-z]"'"                           { dbg_lval.integer = yytext[2] - 'a'; return tNUM;}
 "'"."'"                                 { dbg_lval.integer = yytext[1]; return tNUM;}
 
diff --git a/programs/winedbg/debugger.h b/programs/winedbg/debugger.h
index 1d3156bf8a3..8c909361a58 100644
--- a/programs/winedbg/debugger.h
+++ b/programs/winedbg/debugger.h
@@ -65,6 +65,13 @@ enum dbg_line_status
     dbg_in_a_thunk,
 };
 
+/* in all cases (PE32, PE64) for the debugger,
+ * the following integral types have fixed width (in bits):
+ *   char = 8, short = 16, int = 32, long = 64, long long = 128
+ * the following float types have fixed width (in bytes):
+ *   short real = 4, real = 8, long real = 10
+ * Note that PE compiler doesn't support (today) 128 bit integers nor 10 byte reals.
+ */
 enum dbg_internal_types
 {
     dbg_itype_first             = 0xffffff00,
@@ -90,6 +97,17 @@ enum dbg_internal_types
     dbg_itype_none              = 0xffffffff
 };
 
+/* Largest integers the debugger's compiler can support.
+ * It's large enough to store a pointer (in debuggee or debugger's address space).
+ * It can be smaller than the largest integer(s) of the debuggee.
+ * (eg. 64 bit on PE build of debugger, vs 128 int in ELF build of a library)
+ */
+typedef LONG64  dbg_lgint_t;
+typedef ULONG64 dbg_lguint_t;
+/* indicate with internal type represent those largest integers */
+#define dbg_itype_lgint  dbg_itype_signed_long_int
+#define dbg_itype_lguint dbg_itype_unsigned_long_int
+
 /* type description (in the following order):
  * - if 'id' is dbg_itype_none (whatever 'module' value), the type isn't known
  * - if 'module' is 0, it's an internal type (id is one of dbg_itype...)
@@ -329,8 +347,8 @@ extern BOOL             display_enable(int displaynum, int enable);
 extern void             expr_free_all(void);
 extern struct expr*     expr_alloc_internal_var(const char* name);
 extern struct expr*     expr_alloc_symbol(const char* name);
-extern struct expr*     expr_alloc_sconstant(INT_PTR val);
-extern struct expr*     expr_alloc_uconstant(UINT_PTR val);
+extern struct expr*     expr_alloc_sconstant(dbg_lgint_t val);
+extern struct expr*     expr_alloc_uconstant(dbg_lguint_t val);
 extern struct expr*     expr_alloc_string(const char* str);
 extern struct expr*     expr_alloc_binary_op(int oper, struct expr*, struct expr*);
 extern struct expr*     expr_alloc_unary_op(int oper, struct expr*);
@@ -448,8 +466,8 @@ extern enum dbg_start   tgt_module_load(const char* name, BOOL keep);
 extern void             print_value(const struct dbg_lvalue* addr, char format, int level);
 extern BOOL             types_print_type(const struct dbg_type*, BOOL details);
 extern BOOL             print_types(void);
-extern INT_PTR          types_extract_as_integer(const struct dbg_lvalue*);
-extern LONGLONG         types_extract_as_longlong(const struct dbg_lvalue*, unsigned* psize, BOOL *pissigned);
+extern dbg_lgint_t      types_extract_as_integer(const struct dbg_lvalue*);
+extern dbg_lgint_t      types_extract_as_longlong(const struct dbg_lvalue*, unsigned* psize, BOOL *pissigned);
 extern void             types_extract_as_address(const struct dbg_lvalue*, ADDRESS64*);
 extern BOOL             types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from);
 extern BOOL             types_udt_find_element(struct dbg_lvalue* value, const char* name, ULONG *tmpbuf);
diff --git a/programs/winedbg/expr.c b/programs/winedbg/expr.c
index 842fa8e7925..70bf6316785 100644
--- a/programs/winedbg/expr.c
+++ b/programs/winedbg/expr.c
@@ -35,12 +35,12 @@ struct expr
     {
         struct
         {
-            INT_PTR             value;
+            dbg_lgint_t         value;
         } s_const;
 
         struct
         {
-            UINT_PTR            value;
+            dbg_lguint_t        value;
         } u_const;
 
         struct
@@ -62,7 +62,7 @@ struct expr
         {
             int                 unop_type;
             struct expr*        exp1;
-            INT_PTR             result;
+            dbg_lgint_t         result;
         } unop;
 
         struct
@@ -70,7 +70,7 @@ struct expr
             int                 binop_type;
             struct expr*        exp1;
             struct expr*        exp2;
-            INT_PTR             result;
+            dbg_lgint_t         result;
         } binop;
 
         struct
@@ -83,7 +83,7 @@ struct expr
         {
             struct expr*        exp1;
             const char*         element_name;
-            ULONG               result;
+            ULONG /* FIXME */   result;
         } structure;
 
         struct
@@ -91,7 +91,7 @@ struct expr
             const char*         funcname;
             int	                nargs;
             struct expr*        arg[5];
-            ULONG               result;
+            dbg_lguint_t        result;
         } call;
 
     } un;
@@ -163,7 +163,7 @@ struct expr* expr_alloc_symbol(const char* name)
     return ex;
 }
 
-struct expr* expr_alloc_sconstant(INT_PTR value)
+struct expr* expr_alloc_sconstant(dbg_lgint_t value)
 {
     struct expr*        ex;
 
@@ -174,7 +174,7 @@ struct expr* expr_alloc_sconstant(INT_PTR value)
     return ex;
 }
 
-struct expr* expr_alloc_uconstant(UINT_PTR value)
+struct expr* expr_alloc_uconstant(dbg_lguint_t value)
 {
     struct expr*        ex;
 
@@ -347,13 +347,13 @@ struct dbg_lvalue expr_eval(struct expr* exp)
         break;
     case EXPR_TYPE_U_CONST:
         rtn.cookie      = DLV_HOST;
-        rtn.type.id     = dbg_itype_unsigned_long_int;
+        rtn.type.id     = dbg_itype_lguint;
         rtn.type.module = 0;
         rtn.addr.Offset = (ULONG_PTR)&exp->un.u_const.value;
         break;
     case EXPR_TYPE_S_CONST:
         rtn.cookie      = DLV_HOST;
-        rtn.type.id     = dbg_itype_signed_long_int;
+        rtn.type.id     = dbg_itype_lgint;
         rtn.type.module = 0;
         rtn.addr.Offset = (ULONG_PTR)&exp->un.s_const.value;
         break;
@@ -476,7 +476,7 @@ struct dbg_lvalue expr_eval(struct expr* exp)
         exp2 = expr_eval(exp->un.binop.exp2);
         if (exp1.type.id == dbg_itype_none || exp2.type.id == dbg_itype_none)
             RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL);
-        rtn.type.id = dbg_itype_signed_long_int;
+        rtn.type.id = dbg_itype_lgint;
         rtn.type.module = 0;
         rtn.addr.Offset = (ULONG_PTR)&exp->un.binop.result;
         type1 = exp1.type;
@@ -506,8 +506,8 @@ struct dbg_lvalue expr_eval(struct expr* exp)
                 types_get_info(&type2, TI_GET_LENGTH, &scale1);
                 rtn.type = exp2.type;
 	    }
-            exp->un.binop.result = types_extract_as_integer(&exp1) * (DWORD)scale1 +
-                (DWORD)scale2 * types_extract_as_integer(&exp2);
+            exp->un.binop.result = types_extract_as_integer(&exp1) * (dbg_lguint_t)scale1 +
+                (dbg_lguint_t)scale2 * types_extract_as_integer(&exp2);
             break;
 	case EXP_OP_SUB:
             if (!types_get_info(&exp1.type, TI_GET_SYMTAG, &tag) ||
@@ -538,8 +538,8 @@ struct dbg_lvalue expr_eval(struct expr* exp)
                 types_get_info(&type2, TI_GET_LENGTH, &scale1);
                 rtn.type = exp2.type;
 	    }
-            exp->un.binop.result = (types_extract_as_integer(&exp1) * (DWORD)scale1 - 
-                                    types_extract_as_integer(&exp2) * (DWORD)scale2) / (DWORD)scale3;
+            exp->un.binop.result = (types_extract_as_integer(&exp1) * (dbg_lguint_t)scale1 -
+                                    types_extract_as_integer(&exp2) * (dbg_lguint_t)scale2) / (dbg_lguint_t)scale3;
             break;
 	case EXP_OP_SEG:
             rtn.type.id = dbg_itype_segptr;
@@ -581,10 +581,10 @@ struct dbg_lvalue expr_eval(struct expr* exp)
             exp->un.binop.result = (types_extract_as_integer(&exp1) != types_extract_as_integer(&exp2));
             break;
 	case EXP_OP_SHL:
-            exp->un.binop.result = ((UINT_PTR)types_extract_as_integer(&exp1) << types_extract_as_integer(&exp2));
+            exp->un.binop.result = types_extract_as_integer(&exp1) << types_extract_as_integer(&exp2);
             break;
 	case EXP_OP_SHR:
-            exp->un.binop.result = ((UINT_PTR)types_extract_as_integer(&exp1) >> types_extract_as_integer(&exp2));
+            exp->un.binop.result = types_extract_as_integer(&exp1) >> types_extract_as_integer(&exp2);
             break;
 	case EXP_OP_MUL:
             exp->un.binop.result = (types_extract_as_integer(&exp1) * types_extract_as_integer(&exp2));
@@ -609,7 +609,7 @@ struct dbg_lvalue expr_eval(struct expr* exp)
         exp1 = expr_eval(exp->un.unop.exp1);
         if (exp1.type.id == dbg_itype_none) RaiseException(DEBUG_STATUS_BAD_TYPE, 0, 0, NULL);
         rtn.addr.Offset = (ULONG_PTR)&exp->un.unop.result;
-        rtn.type.id     = dbg_itype_signed_long_int;
+        rtn.type.id     = dbg_itype_lgint;
         rtn.type.module = 0;
         switch (exp->un.unop.unop_type)
 	{
@@ -687,10 +687,10 @@ BOOL expr_print(const struct expr* exp)
         dbg_printf("$%s", exp->un.intvar.name);
         break;
     case EXPR_TYPE_U_CONST:
-        dbg_printf("%Iu", exp->un.u_const.value);
+        dbg_printf("%I64u", exp->un.u_const.value);
         break;
     case EXPR_TYPE_S_CONST:
-        dbg_printf("%Id", exp->un.s_const.value);
+        dbg_printf("%I64d", exp->un.s_const.value);
         break;
     case EXPR_TYPE_STRING:
         dbg_printf("\"%s\"", exp->un.string.str);
diff --git a/programs/winedbg/memory.c b/programs/winedbg/memory.c
index 1653736e919..b666b077077 100644
--- a/programs/winedbg/memory.c
+++ b/programs/winedbg/memory.c
@@ -509,7 +509,7 @@ void print_basic(const struct dbg_lvalue* lvalue, char format)
     if (format != 0)
     {
         unsigned size;
-        LONGLONG res = types_extract_as_longlong(lvalue, &size, NULL);
+        dbg_lgint_t res = types_extract_as_longlong(lvalue, &size, NULL);
         WCHAR wch;
 
         switch (format)
diff --git a/programs/winedbg/types.c b/programs/winedbg/types.c
index 9d82171c2c1..3d8f7e7a140 100644
--- a/programs/winedbg/types.c
+++ b/programs/winedbg/types.c
@@ -52,10 +52,10 @@ BOOL types_get_real_type(struct dbg_type* type, DWORD* tag)
  * Given a lvalue, try to get an integral (or pointer/address) value
  * out of it
  */
-LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue,
-                                   unsigned* psize, BOOL *issigned)
+dbg_lgint_t types_extract_as_longlong(const struct dbg_lvalue* lvalue,
+                                      unsigned* psize, BOOL *issigned)
 {
-    LONGLONG            rtn = 0;
+    dbg_lgint_t         rtn = 0;
     DWORD               tag, bt;
     DWORD64             size;
     struct dbg_type     type = lvalue->type;
@@ -136,7 +136,7 @@ LONGLONG types_extract_as_longlong(const struct dbg_lvalue* lvalue,
  * Given a lvalue, try to get an integral (or pointer/address) value
  * out of it
  */
-INT_PTR types_extract_as_integer(const struct dbg_lvalue* lvalue)
+dbg_lgint_t types_extract_as_integer(const struct dbg_lvalue* lvalue)
 {
     return types_extract_as_longlong(lvalue, NULL, NULL);
 }
@@ -161,7 +161,7 @@ void types_extract_as_address(const struct dbg_lvalue* lvalue, ADDRESS64* addr)
 
 BOOL types_store_value(struct dbg_lvalue* lvalue_to, const struct dbg_lvalue* lvalue_from)
 {
-    LONGLONG    val;
+    dbg_lgint_t val;
     DWORD64     size;
     BOOL        is_signed;
 
@@ -781,7 +781,7 @@ BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, v
         switch (ti)
         {
         case TI_GET_SYMTAG:     X(DWORD)   = SymTagBaseType; break;
-        case TI_GET_LENGTH:     X(DWORD64) = ADDRSIZE; break;
+        case TI_GET_LENGTH:     X(DWORD64) = 8; break;
         case TI_GET_BASETYPE:   X(DWORD)   = btUInt; break;
         default: WINE_FIXME("unsupported %u for u-long int\n", ti); return FALSE;
         }
@@ -790,7 +790,7 @@ BOOL types_get_info(const struct dbg_type* type, IMAGEHLP_SYMBOL_TYPE_INFO ti, v
         switch (ti)
         {
         case TI_GET_SYMTAG:     X(DWORD)   = SymTagBaseType; break;
-        case TI_GET_LENGTH:     X(DWORD64) = ADDRSIZE; break;
+        case TI_GET_LENGTH:     X(DWORD64) = 8; break;
         case TI_GET_BASETYPE:   X(DWORD)   = btInt; break;
         default: WINE_FIXME("unsupported %u for s-long int\n", ti); return FALSE;
         }
diff --git a/programs/winedbg/winedbg.c b/programs/winedbg/winedbg.c
index 283b126ba84..3dbe56f74fc 100644
--- a/programs/winedbg/winedbg.c
+++ b/programs/winedbg/winedbg.c
@@ -44,8 +44,7 @@
  * - type management:
  *      + some bits of internal types are missing (like type casts and the address
  *        operator)
- *      + all computations should be made on long long
- *              o expr computations are in int:s
+ *      + all computations should be made on 64bit
  *              o bitfield size is on a 4-bytes
  * - execution:
  *      + set a better fix for gdb (proxy mode) than the step-mode hack




More information about the wine-devel mailing list