diff mbox

[2/2] Re: Crash regression(?) printing Fortran strings in bt [Re: [V2 00/23] Fortran dynamic array support]

Message ID 20140801210437.GA26082@host2.jankratochvil.net
State New
Headers show

Commit Message

Jan Kratochvil Aug. 1, 2014, 9:04 p.m. UTC
Hi Keven,

in this patch I have tried to implement some sanity checking so that there
cannot happen what happened.

Unfortunately it has many regression in normal testcases, it would need to be
tuned more.  But IMO it would be worth to implement some such checks, it is
easy to forget calling some dynamic-resolve.


Thanks,
Jan
diff mbox

Patch

diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index fbf13ce..145445f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -14272,8 +14272,8 @@  read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
         }
       else
         {
-          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
           TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
+          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
         }
     }
   else
@@ -14283,13 +14283,13 @@  read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
       attr = dwarf2_attr (die, DW_AT_byte_size, cu);
       if (attr)
         {
-          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
           TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
+          TYPE_HIGH_BOUND (range_type) = DW_UNSND (attr);
         }
       else
         {
-          TYPE_HIGH_BOUND (range_type) = 1;
           TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST;
+          TYPE_HIGH_BOUND (range_type) = 1;
         }
     }
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 53cae2c..cf7ac26 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2001,6 +2002,16 @@  resolve_dynamic_type (struct type *type, CORE_ADDR addr)
   return resolve_dynamic_type_internal (type, addr, 1);
 }
 
+/* See gdbtypes.h  */
+
+LONGEST *
+dynamic_prop_get_const_val_ptr (struct dynamic_prop *prop)
+{
+  gdb_assert (prop->kind == PROP_CONST);
+
+  return &prop->data.const_val;
+}
+
 /* Find the real type of TYPE.  This function returns the real type,
    after removing all layers of typedefs, and completing opaque or stub
    types.  Completion changes the TYPE argument, but stripping of
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 436edf8..78c8003 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1212,9 +1212,9 @@  extern void allocate_gnat_aux_type (struct type *);
 #define TYPE_INDEX_TYPE(type) TYPE_FIELD_TYPE (type, 0)
 #define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
 #define TYPE_LOW_BOUND(range_type) \
-  TYPE_RANGE_DATA(range_type)->low.data.const_val
+  (*dynamic_prop_get_const_val_ptr (&TYPE_RANGE_DATA(range_type)->low))
 #define TYPE_HIGH_BOUND(range_type) \
-  TYPE_RANGE_DATA(range_type)->high.data.const_val
+  (*dynamic_prop_get_const_val_ptr (&TYPE_RANGE_DATA(range_type)->high))
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
   (TYPE_RANGE_DATA(range_type)->low.kind == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
@@ -1224,13 +1224,7 @@  extern void allocate_gnat_aux_type (struct type *);
 #define TYPE_LOW_BOUND_KIND(range_type) \
   TYPE_RANGE_DATA(range_type)->low.kind
 #define TYPE_BYTE_STRIDE(range_type) \
-  TYPE_RANGE_DATA(range_type)->stride.data.const_val
-#define TYPE_BYTE_STRIDE_BLOCK(range_type) \
-  TYPE_RANGE_DATA(range_type)->stride.data.locexpr
-#define TYPE_BYTE_STRIDE_LOCLIST(range_type) \
-  TYPE_RANGE_DATA(range_type)->stride.data.loclist
-#define TYPE_BYTE_STRIDE_KIND(range_type) \
-  TYPE_RANGE_DATA(range_type)->stride.kind
+  (*dynamic_prop_get_const_val_ptr (&TYPE_RANGE_DATA(range_type)->stride))
 
 
 /* Attribute accessors for the type data location.  */
@@ -1767,6 +1761,10 @@  extern struct type *resolve_dynamic_type (struct type *type, CORE_ADDR addr);
 /* * Predicate if the type has dynamic values, which are not resolved yet.  */
 extern int is_dynamic_type (struct type *type);
 
+/* Fetch const_val reference from PROP.  It is never dynamically resolved,
+   the correct KIND is checked by gdb_assert.  */
+extern LONGEST *dynamic_prop_get_const_val_ptr (struct dynamic_prop *prop);
+
 extern struct type *check_typedef (struct type *);
 
 #define CHECK_TYPEDEF(TYPE)			\