/* Support routines for manipulating internal types for GDB.
- Copyright (C) 1992-2018 Free Software Foundation, Inc.
+ Copyright (C) 1992-2019 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
{
int len = TYPE_FN_FIELDLIST_LENGTH (type, method_id);
struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
- int j, found_stub = 0;
- for (j = 0; j < len; j++)
- if (TYPE_FN_FIELD_STUB (f, j))
- {
- found_stub = 1;
- check_stub_method (type, method_id, j);
- }
-
- /* GNU v3 methods with incorrect names were corrected when we read
- in type information, because it was cheaper to do it then. The
- only GNU v2 methods with incorrect method names are operators and
- destructors; destructors were also corrected when we read in type
- information.
-
- Therefore the only thing we need to handle here are v2 operator
- names. */
- if (found_stub && !startswith (TYPE_FN_FIELD_PHYSNAME (f, 0), "_Z"))
+ for (int j = 0; j < len; j++)
{
- int ret;
- char dem_opname[256];
-
- ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
- method_id),
- dem_opname, DMGL_ANSI);
- if (!ret)
- ret = cplus_demangle_opname (TYPE_FN_FIELDLIST_NAME (type,
- method_id),
- dem_opname, 0);
- if (ret)
- TYPE_FN_FIELDLIST_NAME (type, method_id) = xstrdup (dem_opname);
+ if (TYPE_FN_FIELD_STUB (f, j))
+ check_stub_method (type, method_id, j);
}
}
unsigned
type_align (struct type *type)
{
+ /* Check alignment provided in the debug information. */
unsigned raw_align = type_raw_align (type);
if (raw_align != 0)
return raw_align;
- ULONGEST align = 0;
+ /* Allow the architecture to provide an alignment. */
+ struct gdbarch *arch = get_type_arch (type);
+ ULONGEST align = gdbarch_type_align (arch, type);
+ if (align != 0)
+ return align;
+
switch (TYPE_CODE (type))
{
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
case TYPE_CODE_FLAGS:
case TYPE_CODE_INT:
+ case TYPE_CODE_RANGE:
case TYPE_CODE_FLT:
case TYPE_CODE_ENUM:
case TYPE_CODE_REF:
case TYPE_CODE_CHAR:
case TYPE_CODE_BOOL:
case TYPE_CODE_DECFLOAT:
- {
- struct gdbarch *arch = get_type_arch (type);
- align = gdbarch_type_align (arch, type);
- }
+ case TYPE_CODE_METHODPTR:
+ case TYPE_CODE_MEMBERPTR:
+ align = type_length_units (check_typedef (type));
break;
case TYPE_CODE_ARRAY:
}
for (unsigned i = 0; i < TYPE_NFIELDS (type); ++i)
{
- ULONGEST f_align = type_align (TYPE_FIELD_TYPE (type, i));
- if (f_align == 0)
+ if (!field_is_static (&TYPE_FIELD (type, i)))
{
- /* Don't pretend we know something we don't. */
- align = 0;
- break;
+ ULONGEST f_align = type_align (TYPE_FIELD_TYPE (type, i));
+ if (f_align == 0)
+ {
+ /* Don't pretend we know something we don't. */
+ align = 0;
+ break;
+ }
+ if (f_align > align)
+ align = f_align;
}
- if (f_align > align)
- align = f_align;
}
}
break;
case TYPE_CODE_SET:
- case TYPE_CODE_RANGE:
case TYPE_CODE_STRING:
/* Not sure what to do here, and these can't appear in C or C++
anyway. */
break;
- case TYPE_CODE_METHODPTR:
- case TYPE_CODE_MEMBERPTR:
- align = type_length_units (type);
- break;
-
case TYPE_CODE_VOID:
align = 1;
break;
3 => A is worse than B */
int
-compare_badness (struct badness_vector *a, struct badness_vector *b)
+compare_badness (const badness_vector &a, const badness_vector &b)
{
int i;
int tmp;
short found_pos = 0; /* any positives in c? */
short found_neg = 0; /* any negatives in c? */
- /* differing lengths => incomparable */
- if (a->length != b->length)
+ /* differing sizes => incomparable */
+ if (a.size () != b.size ())
return 1;
/* Subtract b from a */
- for (i = 0; i < a->length; i++)
+ for (i = 0; i < a.size (); i++)
{
- tmp = compare_ranks (b->rank[i], a->rank[i]);
+ tmp = compare_ranks (b[i], a[i]);
if (tmp > 0)
found_pos = 1;
else if (tmp < 0)
}
/* Rank a function by comparing its parameter types (PARMS), to the
- types of an argument list (ARGS). Return a pointer to a badness
- vector. This has ARGS.size() + 1 entries. */
+ types of an argument list (ARGS). Return the badness vector. This
+ has ARGS.size() + 1 entries. */
-struct badness_vector *
+badness_vector
rank_function (gdb::array_view<type *> parms,
gdb::array_view<value *> args)
{
- int i;
- struct badness_vector *bv = XNEW (struct badness_vector);
- size_t min_len = std::min (parms.size (), args.size ());
-
- bv->length = args.size () + 1; /* add 1 for the length-match rank. */
- bv->rank = XNEWVEC (struct rank, args.size () + 1);
+ /* add 1 for the length-match rank. */
+ badness_vector bv;
+ bv.reserve (1 + args.size ());
/* First compare the lengths of the supplied lists.
If there is a mismatch, set it to a high value. */
arguments and ellipsis parameter lists, we should consider those
and rank the length-match more finely. */
- LENGTH_MATCH (bv) = (args.size () != parms.size ())
- ? LENGTH_MISMATCH_BADNESS
- : EXACT_MATCH_BADNESS;
+ bv.push_back ((args.size () != parms.size ())
+ ? LENGTH_MISMATCH_BADNESS
+ : EXACT_MATCH_BADNESS);
/* Now rank all the parameters of the candidate function. */
- for (i = 1; i <= min_len; i++)
- bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
- args[i - 1]);
+ size_t min_len = std::min (parms.size (), args.size ());
+
+ for (size_t i = 0; i < min_len; i++)
+ bv.push_back (rank_one_type (parms[i], value_type (args[i]),
+ args[i]));
/* If more arguments than parameters, add dummy entries. */
- for (i = min_len + 1; i <= args.size (); i++)
- bv->rank[i] = TOO_FEW_PARAMS_BADNESS;
+ for (size_t i = min_len; i < args.size (); i++)
+ bv.push_back (TOO_FEW_PARAMS_BADNESS);
return bv;
}
/* If the type pair has already been visited, we know it is
ok. */
- bcache_full (&entry, sizeof (entry), cache, &added);
+ cache->insert (&entry, sizeof (entry), &added);
if (!added)
continue;
bool
types_deeply_equal (struct type *type1, struct type *type2)
{
- struct gdb_exception except = exception_none;
- bool result = false;
- struct bcache *cache;
std::vector<type_equality_entry> worklist;
gdb_assert (type1 != NULL && type2 != NULL);
if (type1 == type2)
return true;
- cache = bcache_xmalloc (NULL, NULL);
-
+ struct bcache cache (nullptr, nullptr);
worklist.emplace_back (type1, type2);
-
- /* check_types_worklist calls several nested helper functions, some
- of which can raise a GDB exception, so we just check and rethrow
- here. If there is a GDB exception, a comparison is not capable
- (or trusted), so exit. */
- TRY
- {
- result = check_types_worklist (&worklist, cache);
- }
- CATCH (ex, RETURN_MASK_ALL)
- {
- except = ex;
- }
- END_CATCH
-
- bcache_xfree (cache);
-
- /* Rethrow if there was a problem. */
- if (except.reason < 0)
- throw_exception (except);
-
- return result;
+ return check_types_worklist (&worklist, &cache);
}
/* Allocated status of type TYPE. Return zero if type TYPE is allocated.
return (prop && TYPE_DYN_PROP_KIND (prop) == PROP_CONST
&& !TYPE_DYN_PROP_ADDR (prop));
}
-\f
+
+/* rank_one_type helper for when PARM's type code is TYPE_CODE_PTR. */
+
+static struct rank
+rank_one_type_parm_ptr (struct type *parm, struct type *arg, struct value *value)
+{
+ struct rank rank = {0,0};
+
+ switch (TYPE_CODE (arg))
+ {
+ case TYPE_CODE_PTR:
+
+ /* Allowed pointer conversions are:
+ (a) pointer to void-pointer conversion. */
+ if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
+ return VOID_PTR_CONVERSION_BADNESS;
+
+ /* (b) pointer to ancestor-pointer conversion. */
+ rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
+ TYPE_TARGET_TYPE (arg),
+ 0);
+ if (rank.subrank >= 0)
+ return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
+
+ return INCOMPATIBLE_TYPE_BADNESS;
+ case TYPE_CODE_ARRAY:
+ {
+ struct type *t1 = TYPE_TARGET_TYPE (parm);
+ struct type *t2 = TYPE_TARGET_TYPE (arg);
+
+ if (types_equal (t1, t2))
+ {
+ /* Make sure they are CV equal. */
+ if (TYPE_CONST (t1) != TYPE_CONST (t2))
+ rank.subrank |= CV_CONVERSION_CONST;
+ if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
+ rank.subrank |= CV_CONVERSION_VOLATILE;
+ if (rank.subrank != 0)
+ return sum_ranks (CV_CONVERSION_BADNESS, rank);
+ return EXACT_MATCH_BADNESS;
+ }
+ return INCOMPATIBLE_TYPE_BADNESS;
+ }
+ case TYPE_CODE_FUNC:
+ return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
+ case TYPE_CODE_INT:
+ if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
+ {
+ if (value_as_long (value) == 0)
+ {
+ /* Null pointer conversion: allow it to be cast to a pointer.
+ [4.10.1 of C++ standard draft n3290] */
+ return NULL_POINTER_CONVERSION_BADNESS;
+ }
+ else
+ {
+ /* If type checking is disabled, allow the conversion. */
+ if (!strict_type_checking)
+ return NS_INTEGER_POINTER_CONVERSION_BADNESS;
+ }
+ }
+ /* fall through */
+ case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
+ case TYPE_CODE_CHAR:
+ case TYPE_CODE_RANGE:
+ case TYPE_CODE_BOOL:
+ default:
+ return INCOMPATIBLE_TYPE_BADNESS;
+ }
+}
+
+/* rank_one_type helper for when PARM's type code is TYPE_CODE_ARRAY. */
+
+static struct rank
+rank_one_type_parm_array (struct type *parm, struct type *arg, struct value *value)
+{
+ switch (TYPE_CODE (arg))
+ {
+ case TYPE_CODE_PTR:
+ case TYPE_CODE_ARRAY:
+ return rank_one_type (TYPE_TARGET_TYPE (parm),
+ TYPE_TARGET_TYPE (arg), NULL);
+ default:
+ return INCOMPATIBLE_TYPE_BADNESS;
+ }
+}
+
+/* rank_one_type helper for when PARM's type code is TYPE_CODE_FUNC. */
+
+static struct rank
+rank_one_type_parm_func (struct type *parm, struct type *arg, struct value *value)
+{
+ switch (TYPE_CODE (arg))
+ {
+ case TYPE_CODE_PTR: /* funcptr -> func */
+ return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
+ default:
+ return INCOMPATIBLE_TYPE_BADNESS;
+ }
+}
+
+/* rank_one_type helper for when PARM's type code is TYPE_CODE_INT. */
+
+static struct rank
+rank_one_type_parm_int (struct type *parm, struct type *arg, struct value *value)
+{
+ switch (TYPE_CODE (arg))
+ {
+ case TYPE_CODE_INT:
+ if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
+ {
+ /* Deal with signed, unsigned, and plain chars and
+ signed and unsigned ints. */
+ if (TYPE_NOSIGN (parm))
+ {
+ /* This case only for character types. */
+ if (TYPE_NOSIGN (arg))
+ return EXACT_MATCH_BADNESS; /* plain char -> plain char */
+ else /* signed/unsigned char -> plain char */
+ return INTEGER_CONVERSION_BADNESS;
+ }
+ else if (TYPE_UNSIGNED (parm))
+ {
+ if (TYPE_UNSIGNED (arg))
+ {
+ /* unsigned int -> unsigned int, or
+ unsigned long -> unsigned long */
+ if (integer_types_same_name_p (TYPE_NAME (parm),
+ TYPE_NAME (arg)))
+ return EXACT_MATCH_BADNESS;
+ else if (integer_types_same_name_p (TYPE_NAME (arg),
+ "int")
+ && integer_types_same_name_p (TYPE_NAME (parm),
+ "long"))
+ /* unsigned int -> unsigned long */
+ return INTEGER_PROMOTION_BADNESS;
+ else
+ /* unsigned long -> unsigned int */
+ return INTEGER_CONVERSION_BADNESS;
+ }
+ else
+ {
+ if (integer_types_same_name_p (TYPE_NAME (arg),
+ "long")
+ && integer_types_same_name_p (TYPE_NAME (parm),
+ "int"))
+ /* signed long -> unsigned int */
+ return INTEGER_CONVERSION_BADNESS;
+ else
+ /* signed int/long -> unsigned int/long */
+ return INTEGER_CONVERSION_BADNESS;
+ }
+ }
+ else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
+ {
+ if (integer_types_same_name_p (TYPE_NAME (parm),
+ TYPE_NAME (arg)))
+ return EXACT_MATCH_BADNESS;
+ else if (integer_types_same_name_p (TYPE_NAME (arg),
+ "int")
+ && integer_types_same_name_p (TYPE_NAME (parm),
+ "long"))
+ return INTEGER_PROMOTION_BADNESS;
+ else
+ return INTEGER_CONVERSION_BADNESS;
+ }
+ else
+ return INTEGER_CONVERSION_BADNESS;
+ }
+ else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
+ return INTEGER_PROMOTION_BADNESS;
+ else
+ return INTEGER_CONVERSION_BADNESS;
+ case TYPE_CODE_ENUM:
+ case TYPE_CODE_FLAGS:
+ case TYPE_CODE_CHAR:
+ case TYPE_CODE_RANGE:
+ case TYPE_CODE_BOOL:
+ if (TYPE_DECLARED_CLASS (arg))
+ return INCOMPATIBLE_TYPE_BADNESS;
+ return INTEGER_PROMOTION_BADNESS;
+ case TYPE_CODE_FLT:
+ return INT_FLOAT_CONVERSION_BADNESS;
+ case TYPE_CODE_PTR:
+ return NS_POINTER_CONVERSION_BADNESS;
+ default:
+ return INCOMPATIBLE_TYPE_BADNESS;
+ }
+}
+
/* Compare one type (PARM) for compatibility with another (ARG).
* PARM is intended to be the parameter type of a function; and
* ARG is the supplied argument's type. This function tests if
switch (TYPE_CODE (parm))
{
case TYPE_CODE_PTR:
- switch (TYPE_CODE (arg))
- {
- case TYPE_CODE_PTR:
-
- /* Allowed pointer conversions are:
- (a) pointer to void-pointer conversion. */
- if (TYPE_CODE (TYPE_TARGET_TYPE (parm)) == TYPE_CODE_VOID)
- return VOID_PTR_CONVERSION_BADNESS;
-
- /* (b) pointer to ancestor-pointer conversion. */
- rank.subrank = distance_to_ancestor (TYPE_TARGET_TYPE (parm),
- TYPE_TARGET_TYPE (arg),
- 0);
- if (rank.subrank >= 0)
- return sum_ranks (BASE_PTR_CONVERSION_BADNESS, rank);
-
- return INCOMPATIBLE_TYPE_BADNESS;
- case TYPE_CODE_ARRAY:
- {
- struct type *t1 = TYPE_TARGET_TYPE (parm);
- struct type *t2 = TYPE_TARGET_TYPE (arg);
-
- if (types_equal (t1, t2))
- {
- /* Make sure they are CV equal. */
- if (TYPE_CONST (t1) != TYPE_CONST (t2))
- rank.subrank |= CV_CONVERSION_CONST;
- if (TYPE_VOLATILE (t1) != TYPE_VOLATILE (t2))
- rank.subrank |= CV_CONVERSION_VOLATILE;
- if (rank.subrank != 0)
- return sum_ranks (CV_CONVERSION_BADNESS, rank);
- return EXACT_MATCH_BADNESS;
- }
- return INCOMPATIBLE_TYPE_BADNESS;
- }
- case TYPE_CODE_FUNC:
- return rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL);
- case TYPE_CODE_INT:
- if (value != NULL && TYPE_CODE (value_type (value)) == TYPE_CODE_INT)
- {
- if (value_as_long (value) == 0)
- {
- /* Null pointer conversion: allow it to be cast to a pointer.
- [4.10.1 of C++ standard draft n3290] */
- return NULL_POINTER_CONVERSION_BADNESS;
- }
- else
- {
- /* If type checking is disabled, allow the conversion. */
- if (!strict_type_checking)
- return NS_INTEGER_POINTER_CONVERSION_BADNESS;
- }
- }
- /* fall through */
- case TYPE_CODE_ENUM:
- case TYPE_CODE_FLAGS:
- case TYPE_CODE_CHAR:
- case TYPE_CODE_RANGE:
- case TYPE_CODE_BOOL:
- default:
- return INCOMPATIBLE_TYPE_BADNESS;
- }
+ return rank_one_type_parm_ptr (parm, arg, value);
case TYPE_CODE_ARRAY:
- switch (TYPE_CODE (arg))
- {
- case TYPE_CODE_PTR:
- case TYPE_CODE_ARRAY:
- return rank_one_type (TYPE_TARGET_TYPE (parm),
- TYPE_TARGET_TYPE (arg), NULL);
- default:
- return INCOMPATIBLE_TYPE_BADNESS;
- }
+ return rank_one_type_parm_array (parm, arg, value);
case TYPE_CODE_FUNC:
- switch (TYPE_CODE (arg))
- {
- case TYPE_CODE_PTR: /* funcptr -> func */
- return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
- default:
- return INCOMPATIBLE_TYPE_BADNESS;
- }
+ return rank_one_type_parm_func (parm, arg, value);
case TYPE_CODE_INT:
- switch (TYPE_CODE (arg))
- {
- case TYPE_CODE_INT:
- if (TYPE_LENGTH (arg) == TYPE_LENGTH (parm))
- {
- /* Deal with signed, unsigned, and plain chars and
- signed and unsigned ints. */
- if (TYPE_NOSIGN (parm))
- {
- /* This case only for character types. */
- if (TYPE_NOSIGN (arg))
- return EXACT_MATCH_BADNESS; /* plain char -> plain char */
- else /* signed/unsigned char -> plain char */
- return INTEGER_CONVERSION_BADNESS;
- }
- else if (TYPE_UNSIGNED (parm))
- {
- if (TYPE_UNSIGNED (arg))
- {
- /* unsigned int -> unsigned int, or
- unsigned long -> unsigned long */
- if (integer_types_same_name_p (TYPE_NAME (parm),
- TYPE_NAME (arg)))
- return EXACT_MATCH_BADNESS;
- else if (integer_types_same_name_p (TYPE_NAME (arg),
- "int")
- && integer_types_same_name_p (TYPE_NAME (parm),
- "long"))
- /* unsigned int -> unsigned long */
- return INTEGER_PROMOTION_BADNESS;
- else
- /* unsigned long -> unsigned int */
- return INTEGER_CONVERSION_BADNESS;
- }
- else
- {
- if (integer_types_same_name_p (TYPE_NAME (arg),
- "long")
- && integer_types_same_name_p (TYPE_NAME (parm),
- "int"))
- /* signed long -> unsigned int */
- return INTEGER_CONVERSION_BADNESS;
- else
- /* signed int/long -> unsigned int/long */
- return INTEGER_CONVERSION_BADNESS;
- }
- }
- else if (!TYPE_NOSIGN (arg) && !TYPE_UNSIGNED (arg))
- {
- if (integer_types_same_name_p (TYPE_NAME (parm),
- TYPE_NAME (arg)))
- return EXACT_MATCH_BADNESS;
- else if (integer_types_same_name_p (TYPE_NAME (arg),
- "int")
- && integer_types_same_name_p (TYPE_NAME (parm),
- "long"))
- return INTEGER_PROMOTION_BADNESS;
- else
- return INTEGER_CONVERSION_BADNESS;
- }
- else
- return INTEGER_CONVERSION_BADNESS;
- }
- else if (TYPE_LENGTH (arg) < TYPE_LENGTH (parm))
- return INTEGER_PROMOTION_BADNESS;
- else
- return INTEGER_CONVERSION_BADNESS;
- case TYPE_CODE_ENUM:
- case TYPE_CODE_FLAGS:
- case TYPE_CODE_CHAR:
- case TYPE_CODE_RANGE:
- case TYPE_CODE_BOOL:
- if (TYPE_DECLARED_CLASS (arg))
- return INCOMPATIBLE_TYPE_BADNESS;
- return INTEGER_PROMOTION_BADNESS;
- case TYPE_CODE_FLT:
- return INT_FLOAT_CONVERSION_BADNESS;
- case TYPE_CODE_PTR:
- return NS_POINTER_CONVERSION_BADNESS;
- default:
- return INCOMPATIBLE_TYPE_BADNESS;
- }
- break;
+ return rank_one_type_parm_int (parm, arg, value);
case TYPE_CODE_ENUM:
switch (TYPE_CODE (arg))
{