From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 03/20] Remove alloc_type_copy
Date: Mon, 13 Mar 2023 16:08:03 -0600 [thread overview]
Message-ID: <20230313-split-objfile-type-allocator-2-v1-3-69ba773ac17b@tromey.com> (raw)
In-Reply-To: <20230313-split-objfile-type-allocator-2-v1-0-69ba773ac17b@tromey.com>
This removes alloc_type_copy, replacing all uses with the new type
allocator.
---
gdb/ada-lang.c | 25 +++++++++++++------------
gdb/gdbtypes.c | 30 ++++++++++--------------------
gdb/gdbtypes.h | 6 +-----
gdb/rust-lang.c | 2 +-
gdb/stabsread.c | 2 +-
5 files changed, 26 insertions(+), 39 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7b07c4f9473..624584e8ee5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2140,8 +2140,9 @@ ada_type_of_array (struct value *arr, int bounds)
return NULL;
while (arity > 0)
{
- struct type *range_type = alloc_type_copy (arr->type ());
- struct type *array_type = alloc_type_copy (arr->type ());
+ type_allocator alloc (arr->type ());
+ struct type *range_type = alloc.new_type ();
+ struct type *array_type = alloc.new_type ();
struct value *low = desc_one_bound (descriptor, arity, 0);
struct value *high = desc_one_bound (descriptor, arity, 1);
@@ -2382,7 +2383,7 @@ constrained_packed_array_type (struct type *type, long *elt_bits)
else
index_type = type->index_type ();
- new_type = alloc_type_copy (type);
+ new_type = type_allocator (type).new_type ();
new_elt_type =
constrained_packed_array_type (ada_check_typedef (type->target_type ()),
elt_bits);
@@ -7816,7 +7817,7 @@ variant_field_index (struct type *type)
static struct type *
empty_record (struct type *templ)
{
- struct type *type = alloc_type_copy (templ);
+ struct type *type = type_allocator (templ).new_type ();
type->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (type);
@@ -7872,7 +7873,7 @@ ada_template_to_fixed_record_type_1 (struct type *type,
nfields++;
}
- rtype = alloc_type_copy (type);
+ rtype = type_allocator (type).new_type ();
rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
rtype->set_num_fields (nfields);
@@ -8123,7 +8124,7 @@ template_to_static_fixed_type (struct type *type0)
/* Clone TYPE0 only the first time we get a new field type. */
if (type == type0)
{
- type = alloc_type_copy (type0);
+ type = type_allocator (type0).new_type ();
type0->set_target_type (type);
type->set_code (type0->code ());
INIT_NONE_SPECIFIC (type);
@@ -8177,7 +8178,7 @@ to_record_with_fixed_variant_part (struct type *type, const gdb_byte *valaddr,
else
dval = dval0;
- rtype = alloc_type_copy (type);
+ rtype = type_allocator (type).new_type ();
rtype->set_code (TYPE_CODE_STRUCT);
INIT_NONE_SPECIFIC (rtype);
rtype->set_num_fields (nfields);
@@ -8470,7 +8471,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
if (elt_type0 == elt_type && !constrained_packed_array_p)
result = type0;
else
- result = create_array_type (alloc_type_copy (type0),
+ result = create_array_type (type_allocator (type0).new_type (),
elt_type, type0->index_type ());
}
else
@@ -8502,7 +8503,7 @@ to_fixed_array_type (struct type *type0, struct value *dval,
struct type *range_type =
to_fixed_range_type (index_type_desc->field (i).type (), dval);
- result = create_array_type (alloc_type_copy (elt_type0),
+ result = create_array_type (type_allocator (elt_type0).new_type (),
result, range_type);
elt_type0 = elt_type0->target_type ();
}
@@ -11514,8 +11515,8 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
if (L < INT_MIN || U > INT_MAX)
return raw_type;
else
- return create_static_range_type (alloc_type_copy (raw_type), raw_type,
- L, U);
+ return create_static_range_type (type_allocator (raw_type).new_type (),
+ raw_type, L, U);
}
else
{
@@ -11566,7 +11567,7 @@ to_fixed_range_type (struct type *raw_type, struct value *dval)
}
}
- type = create_static_range_type (alloc_type_copy (raw_type),
+ type = create_static_range_type (type_allocator (raw_type).new_type (),
base_type, L, U);
/* create_static_range_type alters the resulting type's length
to match the size of the base_type, which is not what we want.
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 1e880edf681..6ad6aadb468 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -258,16 +258,6 @@ alloc_type (struct objfile *objfile)
return type;
}
-/* If TYPE is objfile-associated, allocate a new type structure
- associated with the same objfile. If TYPE is gdbarch-associated,
- allocate a new type structure associated with the same gdbarch. */
-
-struct type *
-alloc_type_copy (const struct type *type)
-{
- return type_allocator (type).new_type ();
-}
-
/* See gdbtypes.h. */
type *
@@ -421,7 +411,7 @@ make_pointer_type (struct type *type, struct type **typeptr)
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
{
- ntype = alloc_type_copy (type);
+ ntype = type_allocator (type).new_type ();
if (typeptr)
*typeptr = ntype;
}
@@ -499,7 +489,7 @@ make_reference_type (struct type *type, struct type **typeptr,
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
{
- ntype = alloc_type_copy (type);
+ ntype = type_allocator (type).new_type ();
if (typeptr)
*typeptr = ntype;
}
@@ -574,7 +564,7 @@ make_function_type (struct type *type, struct type **typeptr)
if (typeptr == 0 || *typeptr == 0) /* We'll need to allocate one. */
{
- ntype = alloc_type_copy (type);
+ ntype = type_allocator (type).new_type ();
if (typeptr)
*typeptr = ntype;
}
@@ -906,7 +896,7 @@ lookup_memberptr_type (struct type *type, struct type *domain)
{
struct type *mtype;
- mtype = alloc_type_copy (type);
+ mtype = type_allocator (type).new_type ();
smash_to_memberptr_type (mtype, domain, type);
return mtype;
}
@@ -918,7 +908,7 @@ lookup_methodptr_type (struct type *to_type)
{
struct type *mtype;
- mtype = alloc_type_copy (to_type);
+ mtype = type_allocator (to_type).new_type ();
smash_to_methodptr_type (mtype, to_type);
return mtype;
}
@@ -981,7 +971,7 @@ create_range_type (struct type *result_type, struct type *index_type,
gdb_assert (index_type->length () > 0);
if (result_type == NULL)
- result_type = alloc_type_copy (index_type);
+ result_type = type_allocator (index_type).new_type ();
result_type->set_code (TYPE_CODE_RANGE);
result_type->set_target_type (index_type);
if (index_type->is_stub ())
@@ -1425,7 +1415,7 @@ create_array_type_with_stride (struct type *result_type,
}
if (result_type == NULL)
- result_type = alloc_type_copy (range_type);
+ result_type = type_allocator (range_type).new_type ();
result_type->set_code (TYPE_CODE_ARRAY);
result_type->set_target_type (element_type);
@@ -1527,7 +1517,7 @@ struct type *
create_set_type (struct type *result_type, struct type *domain_type)
{
if (result_type == NULL)
- result_type = alloc_type_copy (domain_type);
+ result_type = type_allocator (domain_type).new_type ();
result_type->set_code (TYPE_CODE_SET);
result_type->set_num_fields (1);
@@ -3597,7 +3587,7 @@ init_complex_type (const char *name, struct type *target_type)
name = new_name;
}
- t = alloc_type_copy (target_type);
+ t = type_allocator (target_type).new_type ();
set_type_code (t, TYPE_CODE_COMPLEX);
t->set_length (2 * target_type->length ());
t->set_name (name);
@@ -5804,7 +5794,7 @@ copy_type_recursive (struct type *type, htab_t copied_types)
struct type *
copy_type (const struct type *type)
{
- struct type *new_type = alloc_type_copy (type);
+ struct type *new_type = type_allocator (type).new_type ();
new_type->set_instance_flags (type->instance_flags ());
new_type->set_length (type->length ());
memcpy (TYPE_MAIN_TYPE (new_type), TYPE_MAIN_TYPE (type),
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 861d0021d30..03f94709006 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2186,12 +2186,8 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
#define TYPE_ZALLOC(t,size) (memset (TYPE_ALLOC (t, size), 0, size))
-/* Use alloc_type to allocate a type owned by an objfile. Use
- alloc_type_copy to allocate a type with the same owner as a
- pre-existing template type, no matter whether objfile or
- gdbarch. */
+/* Use alloc_type to allocate a type owned by an objfile. */
extern struct type *alloc_type (struct objfile *);
-extern struct type *alloc_type_copy (const struct type *);
/* * This returns the target type (or NULL) of TYPE, also skipping
past typedefs. */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 6fc73b262f5..82004da53d4 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -939,7 +939,7 @@ rust_composite_type (struct type *original,
const char *field1, struct type *type1,
const char *field2, struct type *type2)
{
- struct type *result = alloc_type_copy (original);
+ struct type *result = type_allocator (original).new_type ();
int i, nfields, bitpos;
nfields = 0;
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 73f05c44b23..cfe245325f5 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -1475,7 +1475,7 @@ allocate_stub_method (struct type *type)
{
struct type *mtype;
- mtype = alloc_type_copy (type);
+ mtype = type_allocator (type).new_type ();
mtype->set_code (TYPE_CODE_METHOD);
mtype->set_length (1);
mtype->set_is_stub (true);
--
2.39.1
next prev parent reply other threads:[~2023-03-13 22:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-13 22:08 [PATCH 00/20] Remove objfile_type Tom Tromey
2023-03-13 22:08 ` [PATCH 01/20] Introduce type_allocator Tom Tromey
2023-03-13 22:08 ` [PATCH 02/20] Remove alloc_type_arch Tom Tromey
2023-03-13 22:08 ` Tom Tromey [this message]
2023-03-13 22:08 ` [PATCH 04/20] Remove alloc_type Tom Tromey
2023-03-13 22:08 ` [PATCH 05/20] Reuse existing builtin types Tom Tromey
2023-03-13 22:08 ` [PATCH 06/20] Remove arch_type Tom Tromey
2023-03-13 22:08 ` [PATCH 07/20] Remove init_type Tom Tromey
2023-03-13 22:08 ` [PATCH 08/20] Unify arch_integer_type and init_integer_type Tom Tromey
2023-03-13 22:08 ` [PATCH 09/20] Unify arch_character_type and init_character_type Tom Tromey
2023-03-13 22:08 ` [PATCH 10/20] Unify arch_boolean_type and init_boolean_type Tom Tromey
2023-03-13 22:08 ` [PATCH 11/20] Unify arch_float_type and init_float_type Tom Tromey
2023-03-13 22:08 ` [PATCH 12/20] Unify arch_decfloat_type and init_decfloat_type Tom Tromey
2023-03-13 22:08 ` [PATCH 13/20] Unify arch_pointer_type and init_pointer_type Tom Tromey
2023-03-13 22:08 ` [PATCH 14/20] Use type allocator for range types Tom Tromey
2023-03-14 14:41 ` Simon Marchi
2023-03-18 15:56 ` Tom Tromey
2023-03-13 22:08 ` [PATCH 15/20] Use type allocator for array types Tom Tromey
2023-03-13 22:08 ` [PATCH 16/20] Use type allocator for set types Tom Tromey
2023-03-13 22:08 ` [PATCH 17/20] Use builtin type when appropriate Tom Tromey
2023-03-13 22:08 ` [PATCH 18/20] Rename objfile_type to builtin_type Tom Tromey
2023-03-13 22:08 ` [PATCH 19/20] Add some types to struct builtin_type Tom Tromey
2023-03-13 22:08 ` [PATCH 20/20] Remove objfile_type Tom Tromey
2023-03-14 14:48 ` [PATCH 00/20] " Simon Marchi
2023-03-18 15:57 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230313-split-objfile-type-allocator-2-v1-3-69ba773ac17b@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).