/* 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. */
entries. */
int i;
- *lowp = *highp = TYPE_FIELD_BITPOS (type, 0);
+ *lowp = *highp = TYPE_FIELD_ENUMVAL (type, 0);
for (i = 0; i < TYPE_NFIELDS (type); i++)
{
- if (TYPE_FIELD_BITPOS (type, i) < *lowp)
- *lowp = TYPE_FIELD_BITPOS (type, i);
- if (TYPE_FIELD_BITPOS (type, i) > *highp)
- *highp = TYPE_FIELD_BITPOS (type, i);
+ if (TYPE_FIELD_ENUMVAL (type, i) < *lowp)
+ *lowp = TYPE_FIELD_ENUMVAL (type, i);
+ if (TYPE_FIELD_ENUMVAL (type, i) > *highp)
+ *highp = TYPE_FIELD_ENUMVAL (type, i);
}
/* Set unsigned indicator if warranted. */
/* 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)
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);
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))
{
{
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_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");
for (idx = 0; idx < TYPE_NFIELDS (type); idx++)
{
- printfi_filtered (spaces + 2,
- "[%d] bitpos %d bitsize %d type ",
- idx, TYPE_FIELD_BITPOS (type, idx),
- TYPE_FIELD_BITSIZE (type, idx));
+ if (TYPE_CODE (type) == TYPE_CODE_ENUM)
+ printfi_filtered (spaces + 2,
+ "[%d] enumval %s type ",
+ idx, plongest (TYPE_FIELD_ENUMVAL (type, idx)));
+ else
+ printfi_filtered (spaces + 2,
+ "[%d] bitpos %d bitsize %d type ",
+ idx, TYPE_FIELD_BITPOS (type, idx),
+ TYPE_FIELD_BITSIZE (type, idx));
gdb_print_host_address (TYPE_FIELD_TYPE (type, idx), gdb_stdout);
printf_filtered (" name '%s' (",
TYPE_FIELD_NAME (type, idx) != NULL
SET_FIELD_BITPOS (TYPE_FIELD (new_type, i),
TYPE_FIELD_BITPOS (type, i));
break;
+ case FIELD_LOC_KIND_ENUMVAL:
+ SET_FIELD_ENUMVAL (TYPE_FIELD (new_type, i),
+ TYPE_FIELD_ENUMVAL (type, i));
+ break;
case FIELD_LOC_KIND_PHYSADDR:
SET_FIELD_PHYSADDR (TYPE_FIELD (new_type, i),
TYPE_FIELD_STATIC_PHYSADDR (type, i));
if (name)
{
TYPE_FIELD_NAME (type, bitpos) = xstrdup (name);
- TYPE_FIELD_BITPOS (type, bitpos) = bitpos;
+ SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), bitpos);
}
else
{
/* Don't show this field to the user. */
- TYPE_FIELD_BITPOS (type, bitpos) = -1;
+ SET_FIELD_BITPOS (TYPE_FIELD (type, bitpos), -1);
}
}
TYPE_LENGTH (t) = TYPE_LENGTH (t) + TYPE_LENGTH (field);
if (TYPE_NFIELDS (t) > 1)
{
- FIELD_BITPOS (f[0]) = (FIELD_BITPOS (f[-1])
- + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
- * TARGET_CHAR_BIT));
+ SET_FIELD_BITPOS (f[0],
+ (FIELD_BITPOS (f[-1])
+ + (TYPE_LENGTH (FIELD_TYPE (f[-1]))
+ * TARGET_CHAR_BIT)));
if (alignment)
{
if (left)
{
- FIELD_BITPOS (f[0]) += (alignment - left);
+ SET_FIELD_BITPOS (f[0], FIELD_BITPOS (f[0]) + (alignment - left));
TYPE_LENGTH (t) += (alignment - left) / TARGET_CHAR_BIT;
}
}