Eric Pouech : dbghelp: Tidy up internals for array type.

Alexandre Julliard julliard at winehq.org
Wed Sep 1 15:45:10 CDT 2021


Module: wine
Branch: master
Commit: 35c45857aeb39d8bf63863585aca553bd3496344
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=35c45857aeb39d8bf63863585aca553bd3496344

Author: Eric Pouech <eric.pouech at gmail.com>
Date:   Tue Aug 31 14:13:26 2021 +0200

dbghelp: Tidy up internals for array type.

Mainly remove hackish storage of information with negative value and
use a uniform min/count pair for all debug formats.

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dbghelp/dbghelp_private.h |  4 ++--
 dlls/dbghelp/dwarf.c           | 12 ++++++------
 dlls/dbghelp/msc.c             | 10 +++++++++-
 dlls/dbghelp/stabs.c           |  2 +-
 dlls/dbghelp/type.c            | 23 ++++-------------------
 5 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/dlls/dbghelp/dbghelp_private.h b/dlls/dbghelp/dbghelp_private.h
index 2906a5df6c3..2b0365bc386 100644
--- a/dlls/dbghelp/dbghelp_private.h
+++ b/dlls/dbghelp/dbghelp_private.h
@@ -254,7 +254,7 @@ struct symt_array
 {
     struct symt                 symt;
     int		                start;
-    int		                end;            /* end index if > 0, or -array_len (in bytes) if < 0 */
+    DWORD                       count;
     struct symt*                base_type;
     struct symt*                index_type;
 };
@@ -812,7 +812,7 @@ extern BOOL         symt_add_enum_element(struct module* module,
                                           struct symt_enum* enum_type, 
                                           const char* name, int value) DECLSPEC_HIDDEN;
 extern struct symt_array*
-                    symt_new_array(struct module* module, int min, int max, 
+                    symt_new_array(struct module* module, int min, DWORD count,
                                    struct symt* base, struct symt* index) DECLSPEC_HIDDEN;
 extern struct symt_function_signature*
                     symt_new_function_signature(struct module* module, 
diff --git a/dlls/dbghelp/dwarf.c b/dlls/dbghelp/dwarf.c
index 375a0d6d728..93baf10ba44 100644
--- a/dlls/dbghelp/dwarf.c
+++ b/dlls/dbghelp/dwarf.c
@@ -1266,7 +1266,7 @@ static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
         /* FIXME: int4 even on 64bit machines??? */
         idx_type = ctx->symt_cache[sc_int4];
         min.u.uvalue = 0;
-        max.u.uvalue = -1;
+        cnt.u.uvalue = 0;
     }
     else for (i = 0; i < vector_length(children); i++)
     {
@@ -1277,10 +1277,10 @@ static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
             idx_type = dwarf2_lookup_type(ctx, child);
             if (!dwarf2_find_attribute(ctx, child, DW_AT_lower_bound, &min))
                 min.u.uvalue = 0;
-            if (!dwarf2_find_attribute(ctx, child, DW_AT_upper_bound, &max))
-                max.u.uvalue = 0;
-            if (dwarf2_find_attribute(ctx, child, DW_AT_count, &cnt))
-                max.u.uvalue = min.u.uvalue + cnt.u.uvalue;
+            if (dwarf2_find_attribute(ctx, child, DW_AT_upper_bound, &max))
+                cnt.u.uvalue = max.u.uvalue + 1 - min.u.uvalue;
+            else if (!dwarf2_find_attribute(ctx, child, DW_AT_count, &cnt))
+                cnt.u.uvalue = 0;
             break;
         default:
             FIXME("Unhandled Tag type 0x%lx at %s, for %s\n",
@@ -1288,7 +1288,7 @@ static struct symt* dwarf2_parse_array_type(dwarf2_parse_context_t* ctx,
             break;
         }
     }
-    di->symt = &symt_new_array(ctx->module, min.u.uvalue, max.u.uvalue, ref_type, idx_type)->symt;
+    di->symt = &symt_new_array(ctx->module, min.u.uvalue, cnt.u.uvalue, ref_type, idx_type)->symt;
     return di->symt;
 }
 
diff --git a/dlls/dbghelp/msc.c b/dlls/dbghelp/msc.c
index 18535b9d151..905e3b0eaf1 100644
--- a/dlls/dbghelp/msc.c
+++ b/dlls/dbghelp/msc.c
@@ -671,8 +671,16 @@ static struct symt* codeview_add_type_array(struct codeview_type_parse* ctp,
 {
     struct symt*        elem = codeview_fetch_type(ctp, elemtype, FALSE);
     struct symt*        index = codeview_fetch_type(ctp, indextype, FALSE);
+    DWORD64             elem_size;
+    DWORD               count = 0;
 
-    return &symt_new_array(ctp->module, 0, -arr_len, elem, index)->symt;
+    if (symt_get_info(ctp->module, elem, TI_GET_LENGTH, &elem_size) && elem_size)
+    {
+        if (arr_len % (DWORD)elem_size)
+            FIXME("array size should be a multiple of element size %u %u\n", arr_len, (DWORD)elem_size);
+        count = arr_len / (unsigned)elem_size;
+    }
+    return &symt_new_array(ctp->module, 0, count, elem, index)->symt;
 }
 
 static BOOL codeview_add_type_enum_field_list(struct module* module,
diff --git a/dlls/dbghelp/stabs.c b/dlls/dbghelp/stabs.c
index f51ba962186..b011c123482 100644
--- a/dlls/dbghelp/stabs.c
+++ b/dlls/dbghelp/stabs.c
@@ -758,7 +758,7 @@ static inline int stabs_pts_read_array(struct ParseTypedefData* ptd,
 
     PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &base_dt) == -1);
 
-    *adt = &symt_new_array(ptd->module, lo, hi, base_dt, range_dt)->symt;
+    *adt = &symt_new_array(ptd->module, lo, hi - lo + 1, base_dt, range_dt)->symt;
     return 0;
 }
 
diff --git a/dlls/dbghelp/type.c b/dlls/dbghelp/type.c
index 0fa3b669467..7ce85531162 100644
--- a/dlls/dbghelp/type.c
+++ b/dlls/dbghelp/type.c
@@ -350,7 +350,7 @@ BOOL symt_add_enum_element(struct module* module, struct symt_enum* enum_type,
     return TRUE;
 }
 
-struct symt_array* symt_new_array(struct module* module, int min, int max, 
+struct symt_array* symt_new_array(struct module* module, int min, DWORD cnt,
                                   struct symt* base, struct symt* index)
 {
     struct symt_array*  sym;
@@ -359,7 +359,7 @@ struct symt_array* symt_new_array(struct module* module, int min, int max,
     {
         sym->symt.tag   = SymTagArrayType;
         sym->start      = min;
-        sym->end        = max;
+        sym->count      = cnt;
         sym->base_type  = base;
         sym->index_type = index;
         symt_add_type(module, &sym->symt);
@@ -367,21 +367,6 @@ struct symt_array* symt_new_array(struct module* module, int min, int max,
     return sym;
 }
 
-static inline DWORD symt_array_count(struct module* module, const struct symt_array* array)
-{
-    if (array->end < 0)
-    {
-        DWORD64 elem_size;
-        /* One could want to also set the array->end field in array, but we won't do it
-         * as long as all the get_type() helpers use const objects
-         */
-        if (symt_get_info(module, array->base_type, TI_GET_LENGTH, &elem_size) && elem_size)
-            return -array->end / (DWORD)elem_size;
-        return 0;
-    }
-    return array->end - array->start + 1;
-}
-
 struct symt_function_signature* symt_new_function_signature(struct module* module, 
                                                             struct symt* ret_type,
                                                             enum CV_call_e call_conv)
@@ -630,7 +615,7 @@ BOOL symt_get_info(struct module* module, const struct symt* type,
         switch (type->tag)
         {
         case SymTagArrayType:
-            X(DWORD) = symt_array_count(module, (const struct symt_array*)type);
+            X(DWORD) = ((const struct symt_array*)type)->count;
             break;
         case SymTagFunctionType:
             /* this seems to be wrong for (future) C++ methods, where 'this' parameter
@@ -676,7 +661,7 @@ BOOL symt_get_info(struct module* module, const struct symt* type,
             if (!symt_get_info(module, ((const struct symt_array*)type)->base_type,
                                TI_GET_LENGTH, pInfo))
                 return FALSE;
-            X(DWORD64) *= symt_array_count(module, (const struct symt_array*)type);
+            X(DWORD64) *= ((const struct symt_array*)type)->count;
             break;
         case SymTagPublicSymbol:
             X(DWORD64) = ((const struct symt_public*)type)->size;




More information about the wine-cvs mailing list