/* Support routines for manipulating internal types for GDB.
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002,
- 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
#include "demangle.h"
#include "complaints.h"
#include "gdbcmd.h"
-#include "wrapper.h"
#include "cp-abi.h"
#include "gdb_assert.h"
#include "hashtab.h"
-
+#include "exceptions.h"
/* Initialize BADNESS constants. */
const struct rank BOOL_PTR_CONVERSION_BADNESS = {3,0};
const struct rank BASE_CONVERSION_BADNESS = {2,0};
const struct rank REFERENCE_CONVERSION_BADNESS = {2,0};
-
+const struct rank NULL_POINTER_CONVERSION_BADNESS = {2,0};
const struct rank NS_POINTER_CONVERSION_BADNESS = {10,0};
/* Floatformat pairs. */
TYPE_LENGTH (ntype) = 1;
TYPE_CODE (ntype) = TYPE_CODE_FUNC;
+ INIT_FUNC_SPECIFIC (ntype);
+
return ntype;
}
/* Return a typename for a struct/union/enum type without "struct ",
"union ", or "enum ". If the type has a NULL name, return NULL. */
-char *
+const char *
type_name_no_tag (const struct type *type)
{
if (TYPE_TAG_NAME (type) != NULL)
return TYPE_NAME (type);
}
+/* A wrapper of type_name_no_tag which calls error if the type is anonymous.
+ Since GCC PR debug/47510 DWARF provides associated information to detect the
+ anonymous class linkage name from its typedef.
+
+ Parameter TYPE should not yet have CHECK_TYPEDEF applied, this function will
+ apply it itself. */
+
+const char *
+type_name_no_tag_or_error (struct type *type)
+{
+ struct type *saved_type = type;
+ const char *name;
+ struct objfile *objfile;
+
+ CHECK_TYPEDEF (type);
+
+ name = type_name_no_tag (type);
+ if (name != NULL)
+ return name;
+
+ name = type_name_no_tag (saved_type);
+ objfile = TYPE_OBJFILE (saved_type);
+ error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
+ name ? name : "<anonymous>", objfile ? objfile->name : "<arch>");
+}
+
/* Lookup a typedef or primitive type named NAME, visible in lexical
block BLOCK. If NOERR is nonzero, return zero if NAME is not
suitably defined. */
struct type *
lookup_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, char *name,
+ struct gdbarch *gdbarch, const char *name,
const struct block *block, int noerr)
{
struct symbol *sym;
struct type *
lookup_unsigned_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, char *name)
+ struct gdbarch *gdbarch, const char *name)
{
char *uns = alloca (strlen (name) + 10);
struct type *
lookup_signed_typename (const struct language_defn *language,
- struct gdbarch *gdbarch, char *name)
+ struct gdbarch *gdbarch, const char *name)
{
struct type *t;
char *uns = alloca (strlen (name) + 8);
visible in lexical block BLOCK. */
struct type *
-lookup_struct (char *name, struct block *block)
+lookup_struct (const char *name, struct block *block)
{
struct symbol *sym;
visible in lexical block BLOCK. */
struct type *
-lookup_union (char *name, struct block *block)
+lookup_union (const char *name, struct block *block)
{
struct symbol *sym;
struct type *t;
visible in lexical block BLOCK. */
struct type *
-lookup_enum (char *name, struct block *block)
+lookup_enum (const char *name, struct block *block)
{
struct symbol *sym;
for (i = TYPE_NFIELDS (type) - 1; i >= TYPE_N_BASECLASSES (type); i--)
{
- char *t_field_name = TYPE_FIELD_NAME (type, i);
+ const char *t_field_name = TYPE_FIELD_NAME (type, i);
if (t_field_name && (strcmp_iw (t_field_name, name) == 0))
{
not been computed and we're either in the middle of reading symbols, or
there was no name for the typedef in the debug info.
+ NOTE: Lookup of opaque types can throw errors for invalid symbol files.
+ QUITs in the symbol reading code can also throw.
+ Thus this function can throw an exception.
+
If TYPE is a TYPE_CODE_TYPEDEF, its length is updated to the length of
the target type.
{
if (!TYPE_TARGET_TYPE (type))
{
- char *name;
+ const char *name;
struct symbol *sym;
/* It is dangerous to call lookup_symbol if we are currently
&& opaque_type_resolution
&& !currently_reading_symtab)
{
- char *name = type_name_no_tag (type);
+ const char *name = type_name_no_tag (type);
struct type *newtype;
if (name == NULL)
types. */
else if (TYPE_STUB (type) && !currently_reading_symtab)
{
- char *name = type_name_no_tag (type);
+ const char *name = type_name_no_tag (type);
/* FIXME: shouldn't we separately check the TYPE_NAME and the
TYPE_TAG_NAME, and look in STRUCT_DOMAIN and/or VAR_DOMAIN
as appropriate? (this code was written before TYPE_NAME and
safe_parse_type (struct gdbarch *gdbarch, char *p, int length)
{
struct ui_file *saved_gdb_stderr;
- struct type *type;
+ struct type *type = NULL; /* Initialize to keep gcc happy. */
+ volatile struct gdb_exception except;
/* Suppress error messages. */
saved_gdb_stderr = gdb_stderr;
gdb_stderr = ui_file_new ();
/* Call parse_and_eval_type() without fear of longjmp()s. */
- if (!gdb_parse_and_eval_type (p, length, &type))
+ TRY_CATCH (except, RETURN_MASK_ERROR)
+ {
+ type = parse_and_eval_type (p, length);
+ }
+
+ if (except.reason < 0)
type = builtin_type (gdbarch)->builtin_void;
/* Stop suppressing error messages. */
TYPE_STUB_SUPPORTED (type) = 1;
if (flags & TYPE_FLAG_FIXED_INSTANCE)
TYPE_FIXED_INSTANCE (type) = 1;
+ if (flags & TYPE_FLAG_GNU_IFUNC)
+ TYPE_GNU_IFUNC (type) = 1;
if (name)
TYPE_NAME (type) = obsavestring (name, strlen (name),
TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_FLOATFORMAT;
break;
case TYPE_CODE_FUNC:
- TYPE_SPECIFIC_FIELD (type) = TYPE_SPECIFIC_CALLING_CONVENTION;
+ INIT_FUNC_SPECIFIC (type);
break;
}
return type;
}
/* Return true if T is scalar, or a composite type which in practice has
- the memory layout of a scalar type. E.g., an array or struct with only one
- scalar element inside it, or a union with only scalar elements. */
+ the memory layout of a scalar type. E.g., an array or struct with only
+ one scalar element inside it, or a union with only scalar elements. */
int
is_scalar_type_recursive (struct type *t)
static int
is_unique_ancestor_worker (struct type *base, struct type *dclass,
int *offset,
- const bfd_byte *contents, CORE_ADDR address)
+ const gdb_byte *valaddr, int embedded_offset,
+ CORE_ADDR address, struct value *val)
{
int i, count = 0;
for (i = 0; i < TYPE_N_BASECLASSES (dclass) && count < 2; ++i)
{
- struct type *iter = check_typedef (TYPE_BASECLASS (dclass, i));
- int this_offset = baseclass_offset (dclass, i, contents, address);
+ struct type *iter;
+ int this_offset;
+
+ iter = check_typedef (TYPE_BASECLASS (dclass, i));
- if (this_offset == -1)
- error (_("virtual baseclass botch"));
+ this_offset = baseclass_offset (dclass, i, valaddr, embedded_offset,
+ address, val);
if (class_types_same_p (base, iter))
{
}
else
count += is_unique_ancestor_worker (base, iter, offset,
- contents + this_offset,
- address + this_offset);
+ valaddr,
+ embedded_offset + this_offset,
+ address, val);
}
return count;
int offset = -1;
return is_unique_ancestor_worker (base, value_type (val), &offset,
- value_contents (val),
- value_address (val)) == 1;
+ value_contents_for_printing (val),
+ value_embedded_offset (val),
+ value_address (val), val) == 1;
}
\f
struct badness_vector *
rank_function (struct type **parms, int nparms,
- struct type **args, int nargs)
+ struct value **args, int nargs)
{
int i;
struct badness_vector *bv;
/* 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], args[i-1]);
+ bv->rank[i] = rank_one_type (parms[i - 1], value_type (args[i - 1]),
+ args[i - 1]);
/* If more arguments than parameters, add dummy entries. */
for (i = min_len + 1; i <= nargs; i++)
* PARM is intended to be the parameter type of a function; and
* ARG is the supplied argument's type. This function tests if
* the latter can be converted to the former.
+ * VALUE is the argument's value or NULL if none (or called recursively)
*
* Return 0 if they are identical types;
* Otherwise, return an integer which corresponds to how compatible
* Generally the "bad" conversions are all uniformly assigned a 100. */
struct rank
-rank_one_type (struct type *parm, struct type *arg)
+rank_one_type (struct type *parm, struct type *arg, struct value *value)
{
struct rank rank = {0,0};
/* See through references, since we can almost make non-references
references. */
if (TYPE_CODE (arg) == TYPE_CODE_REF)
- return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg)),
+ return (sum_ranks (rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL),
REFERENCE_CONVERSION_BADNESS));
if (TYPE_CODE (parm) == TYPE_CODE_REF)
- return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg),
+ return (sum_ranks (rank_one_type (TYPE_TARGET_TYPE (parm), arg, NULL),
REFERENCE_CONVERSION_BADNESS));
if (overload_debug)
/* Debugging only. */
return EXACT_MATCH_BADNESS;
return INCOMPATIBLE_TYPE_BADNESS;
case TYPE_CODE_FUNC:
- return rank_one_type (TYPE_TARGET_TYPE (parm), arg);
+ 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
+ && 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;
+ }
+ /* fall through */
case TYPE_CODE_ENUM:
case TYPE_CODE_FLAGS:
case TYPE_CODE_CHAR:
case TYPE_CODE_PTR:
case TYPE_CODE_ARRAY:
return rank_one_type (TYPE_TARGET_TYPE (parm),
- TYPE_TARGET_TYPE (arg));
+ TYPE_TARGET_TYPE (arg), NULL);
default:
return INCOMPATIBLE_TYPE_BADNESS;
}
switch (TYPE_CODE (arg))
{
case TYPE_CODE_PTR: /* funcptr -> func */
- return rank_one_type (parm, TYPE_TARGET_TYPE (arg));
+ return rank_one_type (parm, TYPE_TARGET_TYPE (arg), NULL);
default:
return INCOMPATIBLE_TYPE_BADNESS;
}
/* Not in C++ */
case TYPE_CODE_SET:
return rank_one_type (TYPE_FIELD_TYPE (parm, 0),
- TYPE_FIELD_TYPE (arg, 0));
+ TYPE_FIELD_TYPE (arg, 0), NULL);
default:
return INCOMPATIBLE_TYPE_BADNESS;
}
TYPE_N_BASECLASSES (type));
printfi_filtered (spaces, "nfn_fields %d\n",
TYPE_NFN_FIELDS (type));
- printfi_filtered (spaces, "nfn_fields_total %d\n",
- TYPE_NFN_FIELDS_TOTAL (type));
if (TYPE_N_BASECLASSES (type) > 0)
{
printfi_filtered (spaces, "virtual_field_bits (%d bits at *",
puts_filtered ("\n");
break;
- case TYPE_SPECIFIC_CALLING_CONVENTION:
+ case TYPE_SPECIFIC_FUNC:
printfi_filtered (spaces, "calling_convention %d\n",
TYPE_CALLING_CONVENTION (type));
+ /* tail_call_list is not printed. */
break;
}
if (alignment)
{
- int left = FIELD_BITPOS (f[0]) % (alignment * TARGET_CHAR_BIT);
+ int left;
+
+ alignment *= TARGET_CHAR_BIT;
+ left = FIELD_BITPOS (f[0]) % alignment;
if (left)
{
- FIELD_BITPOS (f[0]) += left;
- TYPE_LENGTH (t) += left / TARGET_CHAR_BIT;
+ FIELD_BITPOS (f[0]) += (alignment - left);
+ TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
}
}
}
= lookup_pointer_type (builtin_type->builtin_void);
builtin_type->builtin_func_ptr
= lookup_pointer_type (lookup_function_type (builtin_type->builtin_void));
+ builtin_type->builtin_func_func
+ = lookup_function_type (builtin_type->builtin_func_ptr);
/* This type represents a GDB internal function. */
builtin_type->internal_fn
"<text variable, no debug info>", objfile);
TYPE_TARGET_TYPE (objfile_type->nodebug_text_symbol)
= objfile_type->builtin_int;
+ objfile_type->nodebug_text_gnu_ifunc_symbol
+ = init_type (TYPE_CODE_FUNC, 1, TYPE_FLAG_GNU_IFUNC,
+ "<text gnu-indirect-function variable, no debug info>",
+ objfile);
+ TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
+ = objfile_type->nodebug_text_symbol;
+ objfile_type->nodebug_got_plt_symbol
+ = init_type (TYPE_CODE_PTR, gdbarch_addr_bit (gdbarch) / 8, 0,
+ "<text from jump slot in .got.plt, no debug info>",
+ objfile);
+ TYPE_TARGET_TYPE (objfile_type->nodebug_got_plt_symbol)
+ = objfile_type->nodebug_text_symbol;
objfile_type->nodebug_data_symbol
= init_type (TYPE_CODE_INT,
gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,