aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2/read.c
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2023-09-05 12:29:23 -0600
committerTom Tromey <tromey@adacore.com>2023-09-19 13:28:42 -0600
commit76fc0f62138e0fa1ec1feeefed7e603d52e83af7 (patch)
treeb423516f220f355dc08b7a7c6a802addae61efc5 /gdb/dwarf2/read.c
parent26733fc7477ac675df9215b46bf3f3af1dd80186 (diff)
downloadgdb-76fc0f62138e0fa1ec1feeefed7e603d52e83af7.zip
gdb-76fc0f62138e0fa1ec1feeefed7e603d52e83af7.tar.gz
gdb-76fc0f62138e0fa1ec1feeefed7e603d52e83af7.tar.bz2
Give a language to a type
This changes main_type to hold a language, and updates the debug readers to set this field. This is done by adding the language to the type-allocator object. Note that the non-DWARF readers are changed on a "best effort" basis. This patch also reimplements type::is_array_like to use the type's language, and it adds a new type::is_string_like as well. This in turn lets us change the Python implementation of these methods to simply defer to the type.
Diffstat (limited to 'gdb/dwarf2/read.c')
-rw-r--r--gdb/dwarf2/read.c61
1 files changed, 29 insertions, 32 deletions
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index fc40f49..8757bee 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -5890,8 +5890,8 @@ fixup_go_packaging (struct dwarf2_cu *cu)
struct objfile *objfile = cu->per_objfile->objfile;
const char *saved_package_name = objfile->intern (package_name.get ());
struct type *type
- = type_allocator (objfile).new_type (TYPE_CODE_MODULE, 0,
- saved_package_name);
+ = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE, 0,
+ saved_package_name);
struct symbol *sym;
sym = new (&objfile->objfile_obstack) symbol;
@@ -6077,8 +6077,8 @@ quirk_rust_enum (struct type *type, struct objfile *objfile)
= rust_fully_qualify (&objfile->objfile_obstack, type->name (),
name);
struct type *dataless_type
- = type_allocator (objfile).new_type (TYPE_CODE_VOID, 0,
- dataless_name);
+ = type_allocator (type).new_type (TYPE_CODE_VOID, 0,
+ dataless_name);
type->field (2).set_type (dataless_type);
/* NAME points into the original discriminant name, which
already has the correct lifetime. */
@@ -12215,7 +12215,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
fnp->physname = physname ? physname : "";
}
- fnp->type = type_allocator (objfile).new_type ();
+ fnp->type = type_allocator (objfile, cu->lang ()).new_type ();
this_type = read_type_die (die, cu);
if (this_type && this_type->code () == TYPE_CODE_FUNC)
{
@@ -12446,7 +12446,7 @@ quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile)
return;
self_type = pfn_type->field (0).type ()->target_type ();
- new_type = type_allocator (objfile).new_type ();
+ new_type = type_allocator (type).new_type ();
smash_to_method_type (new_type, self_type, pfn_type->target_type (),
pfn_type->fields (), pfn_type->num_fields (),
pfn_type->has_varargs ());
@@ -12680,15 +12680,8 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu)
return set_die_type (die, type, cu);
}
- type = type_allocator (objfile).new_type ();
- if (cu->lang () == language_rust)
- {
- /* This is currently only needed for types that might be
- slices. */
- INIT_RUST_SPECIFIC (type);
- }
- else
- INIT_CPLUS_SPECIFIC (type);
+ type = type_allocator (objfile, cu->lang ()).new_type ();
+ INIT_CPLUS_SPECIFIC (type);
name = dwarf2_name (die, cu);
if (name != NULL)
@@ -13291,7 +13284,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu)
return set_die_type (die, type, cu);
}
- type = type_allocator (objfile).new_type ();
+ type = type_allocator (objfile, cu->lang ()).new_type ();
type->set_code (TYPE_CODE_ENUM);
name = dwarf2_full_name (NULL, die, cu);
@@ -13621,7 +13614,7 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
range_fields[i + 1].set_name (objfile->intern (name));
}
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
struct type *bounds = alloc.new_type ();
bounds->set_code (TYPE_CODE_STRUCT);
@@ -13645,7 +13638,7 @@ quirk_ada_thick_pointer (struct die_info *die, struct dwarf2_cu *cu,
iter = iter->target_type ();
}
- struct type *result = type_allocator (objfile).new_type ();
+ struct type *result = type_allocator (objfile, cu->lang ()).new_type ();
result->set_code (TYPE_CODE_STRUCT);
result->alloc_fields (2);
@@ -13722,7 +13715,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
if (die->child == NULL)
{
index_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
range_type = create_static_range_type (alloc, index_type, 0, -1);
type = create_array_type_with_stride (alloc, element_type, range_type,
byte_stride_prop, bit_stride);
@@ -13761,7 +13754,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu)
type = element_type;
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
if (read_array_order (die, cu) == DW_ORD_col_major)
{
int i = 0;
@@ -13891,7 +13884,7 @@ read_set_type (struct die_info *die, struct dwarf2_cu *cu)
if (set_type)
return set_type;
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
set_type = create_set_type (alloc, domain_type);
attr = dwarf2_attr (die, DW_AT_byte_size, cu);
@@ -14111,7 +14104,8 @@ read_namespace_type (struct die_info *die, struct dwarf2_cu *cu)
previous_prefix, name, 0, cu);
/* Create the type. */
- type = type_allocator (objfile).new_type (TYPE_CODE_NAMESPACE, 0, name);
+ type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_NAMESPACE,
+ 0, name);
return set_die_type (die, type, cu);
}
@@ -14173,7 +14167,8 @@ read_module_type (struct die_info *die, struct dwarf2_cu *cu)
struct type *type;
module_name = dwarf2_name (die, cu);
- type = type_allocator (objfile).new_type (TYPE_CODE_MODULE, 0, module_name);
+ type = type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_MODULE,
+ 0, module_name);
return set_die_type (die, type, cu);
}
@@ -14328,7 +14323,7 @@ read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu)
else if (check_typedef (to_type)->code () == TYPE_CODE_FUNC)
{
struct type *new_type
- = type_allocator (cu->per_objfile->objfile).new_type ();
+ = type_allocator (cu->per_objfile->objfile, cu->lang ()).new_type ();
smash_to_method_type (new_type, domain, to_type->target_type (),
to_type->fields (), to_type->num_fields (),
@@ -14566,7 +14561,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
}
index_type = builtin_type (objfile)->builtin_int;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
if (length_is_constant)
range_type = create_static_range_type (alloc, index_type, 1, length);
else
@@ -14787,7 +14782,8 @@ read_typedef (struct die_info *die, struct dwarf2_cu *cu)
return this_type;
}
- this_type = type_allocator (objfile).new_type (TYPE_CODE_TYPEDEF, 0, name);
+ type_allocator alloc (objfile, cu->lang ());
+ this_type = alloc.new_type (TYPE_CODE_TYPEDEF, 0, name);
this_type->set_target_is_stub (true);
set_die_type (die, this_type, cu);
if (target_type != this_type)
@@ -15098,7 +15094,7 @@ dwarf2_init_float_type (struct dwarf2_cu *cu, int bits, const char *name,
const struct floatformat **format;
struct type *type;
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
format = gdbarch_floatformat_for_type (gdbarch, name_hint, bits);
if (format)
type = init_float_type (alloc, bits, name, format, byte_order);
@@ -15125,7 +15121,7 @@ dwarf2_init_integer_type (struct dwarf2_cu *cu, int bits, int unsigned_p,
type = builtin_type (objfile)->builtin_void;
else
{
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
type = init_integer_type (alloc, bits, unsigned_p, name);
}
@@ -15311,7 +15307,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
}
}
- type_allocator alloc (objfile);
+ type_allocator alloc (objfile, cu->lang ());
switch (encoding)
{
case DW_ATE_address:
@@ -15800,7 +15796,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
}
}
- type_allocator alloc (cu->per_objfile->objfile);
+ type_allocator alloc (cu->per_objfile->objfile, cu->lang ());
if (attr_byte_stride != nullptr
|| attr_bit_stride != nullptr)
{
@@ -15845,7 +15841,7 @@ read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu)
{
struct type *type;
- type = (type_allocator (cu->per_objfile->objfile)
+ type = (type_allocator (cu->per_objfile->objfile, cu->lang ())
.new_type (TYPE_CODE_VOID, 0, nullptr));
type->set_name (dwarf2_name (die, cu));
@@ -19706,7 +19702,8 @@ build_error_marker_type (struct dwarf2_cu *cu, struct die_info *die)
sect_offset_str (die->sect_off));
saved = obstack_strdup (&objfile->objfile_obstack, message);
- return type_allocator (objfile).new_type (TYPE_CODE_ERROR, 0, saved);
+ return type_allocator (objfile, cu->lang ()).new_type (TYPE_CODE_ERROR,
+ 0, saved);
}
/* Look up the type of DIE in CU using its type attribute ATTR.