From: Tom Tromey Date: Mon, 13 Mar 2023 18:25:27 +0000 (-0600) Subject: Unify arch_pointer_type and init_pointer_type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9c794d2d46f0605ee033107418aac2ca20f659f8;p=binutils-gdb.git Unify arch_pointer_type and init_pointer_type This unifies arch_pointer_type and init_pointer_type by using a type allocator. Reviewed-By: Simon Marchi --- diff --git a/gdb/avr-tdep.c b/gdb/avr-tdep.c index f9f498bfed2..ce2262c5b1a 100644 --- a/gdb/avr-tdep.c +++ b/gdb/avr-tdep.c @@ -1476,7 +1476,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) type_allocator alloc (gdbarch); tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); tdep->func_void_type = make_function_type (tdep->void_type, NULL); - tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL, + tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL, tdep->func_void_type); set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT); diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index c6824755797..4279f392a07 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -15229,7 +15229,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) case DW_ATE_address: /* Turn DW_ATE_address into a void * pointer. */ type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL); - type = init_pointer_type (objfile, bits, name, type); + type = init_pointer_type (alloc, bits, name, type); break; case DW_ATE_boolean: type = init_boolean_type (alloc, bits, 1, name); diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c index 7182185313f..cac4b9ba6a2 100644 --- a/gdb/ft32-tdep.c +++ b/gdb/ft32-tdep.c @@ -576,7 +576,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) type_allocator alloc (gdbarch); void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); func_void_type = make_function_type (void_type, NULL); - tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL, + tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL, func_void_type); tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags () | TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index df10ffea383..103818fae9b 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -3526,18 +3526,15 @@ init_complex_type (const char *name, struct type *target_type) return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type; } -/* 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. */ +/* See gdbtypes.h. */ struct type * -init_pointer_type (struct objfile *objfile, +init_pointer_type (type_allocator &alloc, int bit, const char *name, struct type *target_type) { struct type *t; - t = type_allocator (objfile).new_type (TYPE_CODE_PTR, bit, name); + t = alloc.new_type (TYPE_CODE_PTR, bit, name); t->set_target_type (target_type); t->set_is_unsigned (true); return t; @@ -5740,23 +5737,6 @@ copy_type (const struct type *type) /* Helper functions to initialize architecture-specific types. */ -/* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH. - 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 * -arch_pointer_type (struct gdbarch *gdbarch, - int bit, const char *name, struct type *target_type) -{ - struct type *t; - - t = type_allocator (gdbarch).new_type (TYPE_CODE_PTR, bit, name); - t->set_target_type (target_type); - t->set_is_unsigned (true); - return t; -} - /* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH. NAME is the type name. BIT is the size of the flag word in bits. */ @@ -6227,7 +6207,7 @@ objfile_type (struct objfile *objfile) objfile_type->nodebug_text_gnu_ifunc_symbol->set_is_gnu_ifunc (true); objfile_type->nodebug_got_plt_symbol - = init_pointer_type (objfile, gdbarch_addr_bit (gdbarch), + = init_pointer_type (alloc, gdbarch_addr_bit (gdbarch), "", objfile_type->nodebug_text_symbol); objfile_type->nodebug_data_symbol diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 88a2270b234..33937dd0fd6 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2335,15 +2335,19 @@ extern struct type *init_decfloat_type (type_allocator &alloc, int bit, extern bool can_create_complex_type (struct type *); extern struct type *init_complex_type (const char *, struct type *); -extern struct type *init_pointer_type (struct objfile *, int, const char *, - struct type *); + +/* Allocate a TYPE_CODE_PTR type structure using ALLOC. + 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. */ + +extern struct type *init_pointer_type (type_allocator &alloc, int bit, + const char *name, + struct type *target_type); + extern struct type *init_fixed_point_type (struct objfile *, int, int, const char *); -/* Helper functions to construct architecture-owned types. */ -extern struct type *arch_pointer_type (struct gdbarch *, int, const char *, - struct type *); - /* Helper functions to construct a struct or record type. An initially empty type is created using arch_composite_type(). Fields are then added using append_composite_type_field*(). A union diff --git a/gdb/m32c-tdep.c b/gdb/m32c-tdep.c index 65d5df330b1..e06dbbe12bf 100644 --- a/gdb/m32c-tdep.c +++ b/gdb/m32c-tdep.c @@ -188,18 +188,19 @@ make_types (struct gdbarch *arch) type_allocator alloc (arch); tdep->voyd = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); tdep->ptr_voyd - = arch_pointer_type (arch, gdbarch_ptr_bit (arch), NULL, tdep->voyd); + = init_pointer_type (alloc, gdbarch_ptr_bit (arch), NULL, tdep->voyd); tdep->func_voyd = lookup_function_type (tdep->voyd); xsnprintf (type_name, sizeof (type_name), "%s_data_addr_t", gdbarch_bfd_arch_info (arch)->printable_name); tdep->data_addr_reg_type - = arch_pointer_type (arch, data_addr_reg_bits, type_name, tdep->voyd); + = init_pointer_type (alloc, data_addr_reg_bits, type_name, tdep->voyd); xsnprintf (type_name, sizeof (type_name), "%s_code_addr_t", gdbarch_bfd_arch_info (arch)->printable_name); tdep->code_addr_reg_type - = arch_pointer_type (arch, code_addr_reg_bits, type_name, tdep->func_voyd); + = init_pointer_type (alloc, code_addr_reg_bits, type_name, + tdep->func_voyd); tdep->uint8 = init_integer_type (alloc, 8, 1, "uint8_t"); tdep->uint16 = init_integer_type (alloc, 16, 1, "uint16_t"); diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c index 64884ac08f9..0c663cb3446 100644 --- a/gdb/mdebugread.c +++ b/gdb/mdebugread.c @@ -1395,7 +1395,7 @@ basic_type (int bt, struct objfile *objfile) break; case btAdr: - tp = init_pointer_type (objfile, 32, "adr_32", + tp = init_pointer_type (alloc, 32, "adr_32", objfile_type (objfile)->builtin_void); break; @@ -1490,7 +1490,7 @@ basic_type (int bt, struct objfile *objfile) break; case btAdr64: - tp = init_pointer_type (objfile, 64, "adr_64", + tp = init_pointer_type (alloc, 64, "adr_64", objfile_type (objfile)->builtin_void); break; diff --git a/gdb/rl78-tdep.c b/gdb/rl78-tdep.c index ccb031bbfde..d01d1fdf0cd 100644 --- a/gdb/rl78-tdep.c +++ b/gdb/rl78-tdep.c @@ -1419,9 +1419,9 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->rl78_int32 = init_integer_type (alloc, 32, 0, "int32_t"); tdep->rl78_data_pointer - = arch_pointer_type (gdbarch, 16, "rl78_data_addr_t", tdep->rl78_void); + = init_pointer_type (alloc, 16, "rl78_data_addr_t", tdep->rl78_void); tdep->rl78_code_pointer - = arch_pointer_type (gdbarch, 32, "rl78_code_addr_t", tdep->rl78_void); + = init_pointer_type (alloc, 32, "rl78_code_addr_t", tdep->rl78_void); /* Registers. */ set_gdbarch_num_regs (gdbarch, RL78_NUM_REGS); diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c index 4a08dd48c65..bc1927049d8 100644 --- a/gdb/windows-tdep.c +++ b/gdb/windows-tdep.c @@ -225,8 +225,8 @@ windows_get_tlb_type (struct gdbarch *gdbarch) wchar_type = init_integer_type (alloc, 16, 1, "wchar_t"); void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void); - wchar_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), - NULL, wchar_type); + wchar_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch), + nullptr, wchar_type); /* list entry */ @@ -319,8 +319,8 @@ windows_get_tlb_type (struct gdbarch *gdbarch) append_composite_type_field (rupp_type, "shell_info", uni_str_type); append_composite_type_field (rupp_type, "runtime_data", uni_str_type); - rupp_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), - NULL, rupp_type); + rupp_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch), + nullptr, rupp_type); /* struct process environment block */ @@ -813,7 +813,7 @@ windows_get_siginfo_type (struct gdbarch *gdbarch) type_allocator alloc (gdbarch); dword_type = init_integer_type (alloc, gdbarch_int_bit (gdbarch), 1, "DWORD"); - pvoid_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), "PVOID", + pvoid_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch), "PVOID", builtin_type (gdbarch)->builtin_void); ulongptr_type = init_integer_type (alloc, gdbarch_ptr_bit (gdbarch), 1, "ULONG_PTR"); @@ -844,8 +844,8 @@ windows_get_siginfo_type (struct gdbarch *gdbarch) siginfo_type = arch_composite_type (gdbarch, "EXCEPTION_RECORD", TYPE_CODE_STRUCT); - siginfo_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), - NULL, siginfo_type); + siginfo_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch), + nullptr, siginfo_type); /* ExceptionCode is documented as type DWORD, but here a helper enum type is used instead to display a human-readable value. */ diff --git a/gdb/z80-tdep.c b/gdb/z80-tdep.c index 78b3827b54d..27cdca1c9c7 100644 --- a/gdb/z80-tdep.c +++ b/gdb/z80-tdep.c @@ -1143,7 +1143,7 @@ z80_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); tdep->func_void_type = make_function_type (tdep->void_type, NULL); - tdep->pc_type = arch_pointer_type (gdbarch, + tdep->pc_type = init_pointer_type (alloc, tdep->addr_length * TARGET_CHAR_BIT, NULL, tdep->func_void_type);