aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbtypes.c
diff options
context:
space:
mode:
authorUlrich Weigand <ulrich.weigand@de.ibm.com>2016-09-06 17:27:55 +0200
committerUlrich Weigand <ulrich.weigand@de.ibm.com>2016-09-06 17:27:55 +0200
commit19f392bc2a93d9e64d063b884cd6eca547c8dad0 (patch)
tree64968dc1b18a4cad8872489c2e9c39f5b5a7edcc /gdb/gdbtypes.c
parent88dfca6c43c11dea69db24cfb87e6821e63e29b2 (diff)
downloadfsf-binutils-gdb-19f392bc2a93d9e64d063b884cd6eca547c8dad0.zip
fsf-binutils-gdb-19f392bc2a93d9e64d063b884cd6eca547c8dad0.tar.gz
fsf-binutils-gdb-19f392bc2a93d9e64d063b884cd6eca547c8dad0.tar.bz2
Unify init_type and arch_type interface and helpers
This adds a number of helper routines for creating objfile-owned types; these correspond 1:1 to the already existing helper routines for creating gdbarch-owned types, and are intended to be used instead of init_type. A shared fragment of init_float_type and arch_float_type is extracted into a separate subroutine verify_subroutine. The commit also brings the interface of init_type in line with the one for arch_type. In particular, this means removing the FLAGS argument; callers now set the required flags directly. (Since most callers use the new helper routines, very few callers actually need to set any additional flags directly any more.) Note that this means all the TYPE_FLAGS_... defined are no longer needed anywhere; they will be removed by a follow-on commit. All users of init_type are changed to use on of the new helpers where possible. No functional change intended. gdb/ChangeLog: * gdbtypes.h (init_type): Remove FLAGS argument. Move OBJFILE argument to first position. (init_integer_type): New prototype. (init_character_type): Likewise. (init_boolean_type): Likewise. (init_float_type): Likewise. (init_decfloat_type): Likewise. (init_complex_type): Likewise. (init_pointer_type): Likewise. * gdbtypes.c (verify_floatflormat): New function. (init_type): Remove FLAGS argument and processing. Move OBJFILE argument to first position. (init_integer_type): New function. (init_character_type): Likewise. (init_boolean_type): Likewise. (init_float_type): Likewise. (init_decfloat_type): Likewise. (init_complex_type): Likewise. (init_pointer_type): Likewise. (arch_float_type): Use verify_floatflormat. (objfile_type): Use init_..._type helpers instead of calling init_type directly. * dwarf2read.c (fixup_go_packaging): Update to changed init_type prototype. (read_namespace_type): Likewise. (read_module_type): Likewise. (read_typedef): Likewise. (read_unspecified_type): Likewise. (build_error_marker_type): Likewise. (read_base_type): Use init_..._type helpers. * mdebugread.c (basic_type): Use init_..._type helpers. (parse_type): Update to changed init_type prototype. (cross_ref): Likewise. * stabsread.c (rs6000_builtin_type): Use init_..._type helpers. (read_sun_builtin_type): Likewise. (read_sun_floating_type): Likewise. (read_range_type): Likewise. Also update to changed init_type prototype. Signed-off-by: Ulrich Weigand <ulrich.weigand@de.ibm.com>
Diffstat (limited to 'gdb/gdbtypes.c')
-rw-r--r--gdb/gdbtypes.c311
1 files changed, 190 insertions, 121 deletions
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 45fdf84..c4cc3e3 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -2705,6 +2705,32 @@ set_type_code (struct type *type, enum type_code code)
}
}
+/* Helper function to verify floating-point format and size.
+ BIT is the type size in bits; if BIT equals -1, the size is
+ determined by the floatformat. Returns size to be used. */
+
+static int
+verify_floatformat (int bit, const struct floatformat **floatformats)
+{
+ if (bit == -1)
+ {
+ gdb_assert (floatformats != NULL);
+ gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
+ bit = floatformats[0]->totalsize;
+ }
+ gdb_assert (bit >= 0);
+
+ if (floatformats != NULL)
+ {
+ size_t len = bit / TARGET_CHAR_BIT;
+
+ gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
+ gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
+ }
+
+ return bit;
+}
+
/* Helper function to initialize the standard scalar types.
If NAME is non-NULL, then it is used to initialize the type name.
@@ -2712,41 +2738,14 @@ set_type_code (struct type *type, enum type_code code)
least as long as OBJFILE. */
struct type *
-init_type (enum type_code code, int length, int flags,
- const char *name, struct objfile *objfile)
+init_type (struct objfile *objfile, enum type_code code, int length,
+ const char *name)
{
struct type *type;
type = alloc_type (objfile);
set_type_code (type, code);
TYPE_LENGTH (type) = length;
-
- gdb_assert (!(flags & (TYPE_FLAG_MIN - 1)));
- if (flags & TYPE_FLAG_UNSIGNED)
- TYPE_UNSIGNED (type) = 1;
- if (flags & TYPE_FLAG_NOSIGN)
- TYPE_NOSIGN (type) = 1;
- if (flags & TYPE_FLAG_STUB)
- TYPE_STUB (type) = 1;
- if (flags & TYPE_FLAG_TARGET_STUB)
- TYPE_TARGET_STUB (type) = 1;
- if (flags & TYPE_FLAG_STATIC)
- TYPE_STATIC (type) = 1;
- if (flags & TYPE_FLAG_PROTOTYPED)
- TYPE_PROTOTYPED (type) = 1;
- if (flags & TYPE_FLAG_INCOMPLETE)
- TYPE_INCOMPLETE (type) = 1;
- if (flags & TYPE_FLAG_VARARGS)
- TYPE_VARARGS (type) = 1;
- if (flags & TYPE_FLAG_VECTOR)
- TYPE_VECTOR (type) = 1;
- if (flags & TYPE_FLAG_STUB_SUPPORTED)
- 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;
-
TYPE_NAME (type) = name;
/* C++ fancies. */
@@ -2756,6 +2755,121 @@ init_type (enum type_code code, int length, int flags,
return type;
}
+
+/* Allocate a TYPE_CODE_INT type structure associated with OBJFILE.
+ BIT is the type size in bits. If UNSIGNED_P is non-zero, set
+ the type's TYPE_UNSIGNED flag. NAME is the type name. */
+
+struct type *
+init_integer_type (struct objfile *objfile,
+ int bit, int unsigned_p, const char *name)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+ if (unsigned_p)
+ TYPE_UNSIGNED (t) = 1;
+
+ return t;
+}
+
+/* Allocate a TYPE_CODE_CHAR type structure associated with OBJFILE.
+ BIT is the type size in bits. If UNSIGNED_P is non-zero, set
+ the type's TYPE_UNSIGNED flag. NAME is the type name. */
+
+struct type *
+init_character_type (struct objfile *objfile,
+ int bit, int unsigned_p, const char *name)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+ if (unsigned_p)
+ TYPE_UNSIGNED (t) = 1;
+
+ return t;
+}
+
+/* Allocate a TYPE_CODE_BOOL type structure associated with OBJFILE.
+ BIT is the type size in bits. If UNSIGNED_P is non-zero, set
+ the type's TYPE_UNSIGNED flag. NAME is the type name. */
+
+struct type *
+init_boolean_type (struct objfile *objfile,
+ int bit, int unsigned_p, const char *name)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+ if (unsigned_p)
+ TYPE_UNSIGNED (t) = 1;
+
+ return t;
+}
+
+/* Allocate a TYPE_CODE_FLT type structure associated with OBJFILE.
+ BIT is the type size in bits; if BIT equals -1, the size is
+ determined by the floatformat. NAME is the type name. Set the
+ TYPE_FLOATFORMAT from FLOATFORMATS. */
+
+struct type *
+init_float_type (struct objfile *objfile,
+ int bit, const char *name,
+ const struct floatformat **floatformats)
+{
+ struct type *t;
+
+ bit = verify_floatformat (bit, floatformats);
+ t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
+ TYPE_FLOATFORMAT (t) = floatformats;
+
+ return t;
+}
+
+/* Allocate a TYPE_CODE_DECFLOAT type structure associated with OBJFILE.
+ BIT is the type size in bits. NAME is the type name. */
+
+struct type *
+init_decfloat_type (struct objfile *objfile, int bit, const char *name)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+ return t;
+}
+
+/* Allocate a TYPE_CODE_COMPLEX type structure associated with OBJFILE.
+ NAME is the type name. TARGET_TYPE is the component float type. */
+
+struct type *
+init_complex_type (struct objfile *objfile,
+ const char *name, struct type *target_type)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_COMPLEX,
+ 2 * TYPE_LENGTH (target_type), name);
+ TYPE_TARGET_TYPE (t) = target_type;
+ return t;
+}
+
+/* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
+ BIT is the pointer type size in bits. NAME is the type name.
+ TARGET_TYPE is the pointer target type. Always sets the pointer type's
+ TYPE_UNSIGNED flag. */
+
+struct type *
+init_pointer_type (struct objfile *objfile,
+ int bit, const char *name, struct type *target_type)
+{
+ struct type *t;
+
+ t = init_type (objfile, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+ TYPE_TARGET_TYPE (t) = target_type;
+ TYPE_UNSIGNED (t) = 1;
+ return t;
+}
+
/* Queries on types. */
@@ -4718,25 +4832,10 @@ arch_float_type (struct gdbarch *gdbarch,
{
struct type *t;
- if (bit == -1)
- {
- gdb_assert (floatformats != NULL);
- gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
- bit = floatformats[0]->totalsize;
- }
- gdb_assert (bit >= 0);
-
+ bit = verify_floatformat (bit, floatformats);
t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
TYPE_FLOATFORMAT (t) = floatformats;
- if (floatformats != NULL)
- {
- size_t len = TYPE_LENGTH (t);
-
- gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
- gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
- }
-
return t;
}
@@ -5090,109 +5189,80 @@ objfile_type (struct objfile *objfile)
/* Basic types. */
objfile_type->builtin_void
- = init_type (TYPE_CODE_VOID, 1,
- 0,
- "void", objfile);
-
+ = init_type (objfile, TYPE_CODE_VOID, 1, "void");
objfile_type->builtin_char
- = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
- (TYPE_FLAG_NOSIGN
- | (gdbarch_char_signed (gdbarch) ? 0 : TYPE_FLAG_UNSIGNED)),
- "char", objfile);
+ = init_integer_type (objfile, TARGET_CHAR_BIT,
+ !gdbarch_char_signed (gdbarch), "char");
objfile_type->builtin_signed_char
- = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
- 0,
- "signed char", objfile);
+ = init_integer_type (objfile, TARGET_CHAR_BIT,
+ 0, "signed char");
objfile_type->builtin_unsigned_char
- = init_type (TYPE_CODE_INT, TARGET_CHAR_BIT / TARGET_CHAR_BIT,
- TYPE_FLAG_UNSIGNED,
- "unsigned char", objfile);
+ = init_integer_type (objfile, TARGET_CHAR_BIT,
+ 1, "unsigned char");
objfile_type->builtin_short
- = init_type (TYPE_CODE_INT,
- gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "short", objfile);
+ = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
+ 0, "short");
objfile_type->builtin_unsigned_short
- = init_type (TYPE_CODE_INT,
- gdbarch_short_bit (gdbarch) / TARGET_CHAR_BIT,
- TYPE_FLAG_UNSIGNED, "unsigned short", objfile);
+ = init_integer_type (objfile, gdbarch_short_bit (gdbarch),
+ 1, "unsigned short");
objfile_type->builtin_int
- = init_type (TYPE_CODE_INT,
- gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "int", objfile);
+ = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
+ 0, "int");
objfile_type->builtin_unsigned_int
- = init_type (TYPE_CODE_INT,
- gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT,
- TYPE_FLAG_UNSIGNED, "unsigned int", objfile);
+ = init_integer_type (objfile, gdbarch_int_bit (gdbarch),
+ 1, "unsigned int");
objfile_type->builtin_long
- = init_type (TYPE_CODE_INT,
- gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "long", objfile);
+ = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
+ 0, "long");
objfile_type->builtin_unsigned_long
- = init_type (TYPE_CODE_INT,
- gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT,
- TYPE_FLAG_UNSIGNED, "unsigned long", objfile);
+ = init_integer_type (objfile, gdbarch_long_bit (gdbarch),
+ 1, "unsigned long");
objfile_type->builtin_long_long
- = init_type (TYPE_CODE_INT,
- gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "long long", objfile);
+ = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
+ 0, "long long");
objfile_type->builtin_unsigned_long_long
- = init_type (TYPE_CODE_INT,
- gdbarch_long_long_bit (gdbarch) / TARGET_CHAR_BIT,
- TYPE_FLAG_UNSIGNED, "unsigned long long", objfile);
-
+ = init_integer_type (objfile, gdbarch_long_long_bit (gdbarch),
+ 1, "unsigned long long");
objfile_type->builtin_float
- = init_type (TYPE_CODE_FLT,
- gdbarch_float_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "float", objfile);
- TYPE_FLOATFORMAT (objfile_type->builtin_float)
- = gdbarch_float_format (gdbarch);
+ = init_float_type (objfile, gdbarch_float_bit (gdbarch),
+ "float", gdbarch_float_format (gdbarch));
objfile_type->builtin_double
- = init_type (TYPE_CODE_FLT,
- gdbarch_double_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "double", objfile);
- TYPE_FLOATFORMAT (objfile_type->builtin_double)
- = gdbarch_double_format (gdbarch);
+ = init_float_type (objfile, gdbarch_double_bit (gdbarch),
+ "double", gdbarch_double_format (gdbarch));
objfile_type->builtin_long_double
- = init_type (TYPE_CODE_FLT,
- gdbarch_long_double_bit (gdbarch) / TARGET_CHAR_BIT,
- 0, "long double", objfile);
- TYPE_FLOATFORMAT (objfile_type->builtin_long_double)
- = gdbarch_long_double_format (gdbarch);
+ = init_float_type (objfile, gdbarch_long_double_bit (gdbarch),
+ "long double", gdbarch_long_double_format (gdbarch));
/* This type represents a type that was unrecognized in symbol read-in. */
objfile_type->builtin_error
- = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>", objfile);
+ = init_type (objfile, TYPE_CODE_ERROR, 0, "<unknown type>");
/* The following set of types is used for symbols with no
debug information. */
objfile_type->nodebug_text_symbol
- = init_type (TYPE_CODE_FUNC, 1, 0,
- "<text variable, no debug info>", objfile);
+ = init_type (objfile, TYPE_CODE_FUNC, 1,
+ "<text variable, no debug info>");
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);
+ = init_type (objfile, TYPE_CODE_FUNC, 1,
+ "<text gnu-indirect-function variable, no debug info>");
TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
= objfile_type->nodebug_text_symbol;
+ TYPE_GNU_IFUNC (objfile_type->nodebug_text_gnu_ifunc_symbol) = 1;
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;
+ = init_pointer_type (objfile, gdbarch_addr_bit (gdbarch),
+ "<text from jump slot in .got.plt, no debug info>",
+ objfile_type->nodebug_text_symbol);
objfile_type->nodebug_data_symbol
- = init_type (TYPE_CODE_INT,
- gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
- "<data variable, no debug info>", objfile);
+ = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
+ "<data variable, no debug info>");
objfile_type->nodebug_unknown_symbol
- = init_type (TYPE_CODE_INT, 1, 0,
- "<variable (not text or data), no debug info>", objfile);
+ = init_integer_type (objfile, TARGET_CHAR_BIT, 0,
+ "<variable (not text or data), no debug info>");
objfile_type->nodebug_tls_symbol
- = init_type (TYPE_CODE_INT,
- gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT, 0,
- "<thread local variable, no debug info>", objfile);
+ = init_integer_type (objfile, gdbarch_int_bit (gdbarch), 0,
+ "<thread local variable, no debug info>");
/* NOTE: on some targets, addresses and pointers are not necessarily
the same.
@@ -5214,9 +5284,8 @@ objfile_type (struct objfile *objfile)
are indeed in the unified virtual address space. */
objfile_type->builtin_core_addr
- = init_type (TYPE_CODE_INT,
- gdbarch_addr_bit (gdbarch) / 8,
- TYPE_FLAG_UNSIGNED, "__CORE_ADDR", objfile);
+ = init_integer_type (objfile, gdbarch_addr_bit (gdbarch), 1,
+ "__CORE_ADDR");
set_objfile_data (objfile, objfile_type_data, objfile_type);
return objfile_type;