public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/3] gdb: add owner-related methods to struct type
@ 2021-01-21  3:24 Simon Marchi
  2021-01-21  3:24 ` [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro Simon Marchi
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Simon Marchi @ 2021-01-21  3:24 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Add the following methods to struct type:

 * is_objfile_owned
 * set_owner (objfile and gdbarch overloads)
 * objfile and arch getters

Rename the fields in main_type to ensure no other code accesses them
directly.  As usual, we can't make them actually private, but giving
them the `m_` prefix will help making sure they are not accessed when
not supposed to, by convention.

Remove the TYPE_OWNER macro to ensure no code uses the type_owner struct
directly.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_OBJFILE_OWNED): Adjust.
	(TYPE_OWNER): Remove.
	(TYPE_OBJFILE): Adjust.
	(struct main_type) <flag_objfile_owned>: Rename to...
	<m_flag_objfile_owned>: ... this.
	<owner>: Rename to...
	<m_owner>: ... this.
	(struct type) <is_objfile_owned, set_owner, objfile, arch>: New
	methods.
	(TYPE_ALLOC): Adjust.
	* gdbtypes.c (alloc_type): Adjust.
	(alloc_type_arch): Adjust.
	(alloc_type_copy): Adjust.
	(get_type_arch): Adjust.
	(smash_type): Adjust.
	(lookup_array_range_type): Adjust.
	(recursive_dump_type): Adjust.
	(copy_type_recursive): Adjust.
	* compile/compile-c-types.c (convert_func): Adjust.
	(convert_type_basic): Adjust.
	* compile/compile-cplus-types.c (compile_cplus_convert_func):
	Adjust.
	* language.c
	(language_arch_info::type_and_symbol::alloc_type_symbol):
	Adjust.

Change-Id: I7f92e869d9f92e2402a3d3007dd0832e05aa6ac8
---
 gdb/compile/compile-c-types.c     |  8 ++---
 gdb/compile/compile-cplus-types.c |  4 +--
 gdb/gdbtypes.c                    | 38 +++++++++++----------
 gdb/gdbtypes.h                    | 56 +++++++++++++++++++++++++++----
 gdb/language.c                    |  2 +-
 5 files changed, 76 insertions(+), 32 deletions(-)

diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index eea084469a8d..90de2084c85c 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -165,9 +165,9 @@ convert_func (compile_c_instance *context, struct type *type)
   if (target_type == NULL)
     {
       if (TYPE_OBJFILE_OWNED (type))
-	target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+	target_type = objfile_type (type->objfile ())->builtin_int;
       else
-	target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+	target_type = builtin_type (type->arch ())->builtin_int;
       warning (_("function has unknown return type; assuming int"));
     }
 
@@ -324,9 +324,9 @@ convert_type_basic (compile_c_instance *context, struct type *type)
 	   built-in parser used to do, but at least warn.  */
 	struct type *fallback;
 	if (TYPE_OBJFILE_OWNED (type))
-	  fallback = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+	  fallback = objfile_type (type->objfile ())->builtin_int;
 	else
-	  fallback = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+	  fallback = builtin_type (type->arch ())->builtin_int;
 	warning (_("variable has unknown type; assuming int"));
 	return convert_int (context, fallback);
       }
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 5289f6f45924..ddb0d8a03682 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -971,9 +971,9 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
   if (target_type == nullptr)
     {
       if (TYPE_OBJFILE_OWNED (type))
-	target_type = objfile_type (TYPE_OWNER (type).objfile)->builtin_int;
+	target_type = objfile_type (type->objfile ())->builtin_int;
       else
-	target_type = builtin_type (TYPE_OWNER (type).gdbarch)->builtin_int;
+	target_type = builtin_type (type->arch ())->builtin_int;
       warning (_("function has unknown return type; assuming int"));
     }
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index d9842817462a..e2f8837dcb4d 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -183,8 +183,7 @@ alloc_type (struct objfile *objfile)
 					  struct main_type);
   OBJSTAT (objfile, n_types++);
 
-  TYPE_OBJFILE_OWNED (type) = 1;
-  TYPE_OWNER (type).objfile = objfile;
+  type->set_owner (objfile);
 
   /* Initialize the fields that might not be zero.  */
 
@@ -210,8 +209,7 @@ alloc_type_arch (struct gdbarch *gdbarch)
   type = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct type);
   TYPE_MAIN_TYPE (type) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct main_type);
 
-  TYPE_OBJFILE_OWNED (type) = 0;
-  TYPE_OWNER (type).gdbarch = gdbarch;
+  type->set_owner (gdbarch);
 
   /* Initialize the fields that might not be zero.  */
 
@@ -229,9 +227,9 @@ struct type *
 alloc_type_copy (const struct type *type)
 {
   if (TYPE_OBJFILE_OWNED (type))
-    return alloc_type (TYPE_OWNER (type).objfile);
+    return alloc_type (type->objfile ());
   else
-    return alloc_type_arch (TYPE_OWNER (type).gdbarch);
+    return alloc_type_arch (type->arch ());
 }
 
 /* If TYPE is gdbarch-associated, return that architecture.
@@ -243,9 +241,9 @@ get_type_arch (const struct type *type)
   struct gdbarch *arch;
 
   if (TYPE_OBJFILE_OWNED (type))
-    arch = TYPE_OWNER (type).objfile->arch ();
+    arch = type->objfile ()->arch ();
   else
-    arch = TYPE_OWNER (type).gdbarch;
+    arch = type->arch ();
 
   /* The ARCH can be NULL if TYPE is associated with neither an objfile nor
      a gdbarch, however, this is very rare, and even then, in most cases
@@ -311,14 +309,17 @@ alloc_type_instance (struct type *oldtype)
 static void
 smash_type (struct type *type)
 {
-  int objfile_owned = TYPE_OBJFILE_OWNED (type);
-  union type_owner owner = TYPE_OWNER (type);
+  bool objfile_owned = type->is_objfile_owned ();
+  objfile *objfile = type->objfile ();
+  gdbarch *arch = type->arch ();
 
   memset (TYPE_MAIN_TYPE (type), 0, sizeof (struct main_type));
 
   /* Restore owner information.  */
-  TYPE_OBJFILE_OWNED (type) = objfile_owned;
-  TYPE_OWNER (type) = owner;
+  if (objfile_owned)
+    type->set_owner (objfile);
+  else
+    type->set_owner (arch);
 
   /* For now, delete the rings.  */
   TYPE_CHAIN (type) = type;
@@ -1429,9 +1430,10 @@ lookup_array_range_type (struct type *element_type,
   struct type *range_type;
 
   if (TYPE_OBJFILE_OWNED (element_type))
-    index_type = objfile_type (TYPE_OWNER (element_type).objfile)->builtin_int;
+    index_type = objfile_type (element_type->objfile ())->builtin_int;
   else
-    index_type = builtin_type (get_type_arch (element_type))->builtin_int;
+    index_type = builtin_type (element_type->arch ())->builtin_int;
+
   range_type = create_static_range_type (NULL, index_type,
 					 low_bound, high_bound);
 
@@ -5190,12 +5192,12 @@ recursive_dump_type (struct type *type, int spaces)
   if (TYPE_OBJFILE_OWNED (type))
     {
       printf_filtered ("%*sobjfile ", spaces, "");
-      gdb_print_host_address (TYPE_OWNER (type).objfile, gdb_stdout);
+      gdb_print_host_address (type->objfile (), gdb_stdout);
     }
   else
     {
       printf_filtered ("%*sgdbarch ", spaces, "");
-      gdb_print_host_address (TYPE_OWNER (type).gdbarch, gdb_stdout);
+      gdb_print_host_address (type->arch (), gdb_stdout);
     }
   printf_filtered ("\n");
   printf_filtered ("%*starget_type ", spaces, "");
@@ -5515,8 +5517,8 @@ copy_type_recursive (struct objfile *objfile,
   /* Copy the common fields of types.  For the main type, we simply
      copy the entire thing and then update specific fields as needed.  */
   *TYPE_MAIN_TYPE (new_type) = *TYPE_MAIN_TYPE (type);
-  TYPE_OBJFILE_OWNED (new_type) = 0;
-  TYPE_OWNER (new_type).gdbarch = get_type_arch (type);
+
+  new_type->set_owner (type->arch ());
 
   if (type->name ())
     new_type->set_name (xstrdup (type->name ()));
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index c74098826b8b..51f603157ba7 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -224,9 +224,8 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
    the objfile retrieved as TYPE_OBJFILE.  Otherwise, the type is
    owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
 
-#define TYPE_OBJFILE_OWNED(t) (TYPE_MAIN_TYPE (t)->flag_objfile_owned)
-#define TYPE_OWNER(t) TYPE_MAIN_TYPE(t)->owner
-#define TYPE_OBJFILE(t) (TYPE_OBJFILE_OWNED(t)? TYPE_OWNER(t).objfile : NULL)
+#define TYPE_OBJFILE_OWNED(t) ((t)->is_objfile_owned ())
+#define TYPE_OBJFILE(t) ((t)->objfile ())
 
 /* * True if this type was declared using the "class" keyword.  This is
    only valid for C++ structure and enum types.  If false, a structure
@@ -817,7 +816,7 @@ struct main_type
   unsigned int m_flag_stub_supported : 1;
   unsigned int m_flag_gnu_ifunc : 1;
   unsigned int m_flag_fixed_instance : 1;
-  unsigned int flag_objfile_owned : 1;
+  unsigned int m_flag_objfile_owned : 1;
   unsigned int m_flag_endianity_not_default : 1;
 
   /* * True if this type was declared with "class" rather than
@@ -860,7 +859,7 @@ struct main_type
      this is somewhat ugly, but without major overhaul of the internal
      type system, it can't be avoided for now.  */
 
-  union type_owner owner;
+  union type_owner m_owner;
 
   /* * For a pointer type, describes the type of object pointed to.
      - For an array type, describes the type of the elements.
@@ -1243,6 +1242,49 @@ struct type
   /* * Remove dynamic property of kind KIND from this type, if it exists.  */
   void remove_dyn_prop (dynamic_prop_node_kind kind);
 
+  /* Return true if this type is owned by an objfile.  Return false if it is
+     owned by an architecture.  */
+  bool is_objfile_owned () const
+  {
+    return this->main_type->m_flag_objfile_owned;
+  }
+
+  /* Set the owner of the type to be OBJFILE.  */
+  void set_owner (objfile *objfile)
+  {
+    this->main_type->m_owner.objfile = objfile;
+    this->main_type->m_flag_objfile_owned = true;
+  }
+
+  /* Set the owner of the type to be ARCH.  */
+  void set_owner (gdbarch *arch)
+  {
+    this->main_type->m_owner.gdbarch = arch;
+    this->main_type->m_flag_objfile_owned = false;
+  }
+
+  /* Return the objfile owner of this type.
+
+     Return nullptr if this type is not objfile-owned.  */
+  struct objfile *objfile () const
+  {
+    if (!this->is_objfile_owned ())
+      return nullptr;
+
+    return this->main_type->m_owner.objfile;
+  }
+
+  gdbarch *arch () const
+  {
+    if (this->is_objfile_owned ())
+      return nullptr;
+
+  /* Return the gdbarch owner of this type.
+
+     Return nullptr if this type is not gdbarch-owned.  */
+    return this->main_type->m_owner.gdbarch;
+  }
+
   /* * Return true if this is an integer type whose logical (bit) size
      differs from its storage size; false otherwise.  Always return
      false for non-integer (i.e., non-TYPE_SPECIFIC_INT) types.  */
@@ -2201,8 +2243,8 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
 
 #define TYPE_ALLOC(t,size)                                              \
   (obstack_alloc ((TYPE_OBJFILE_OWNED (t)                               \
-		   ? &TYPE_OBJFILE (t)->objfile_obstack                 \
-		   : gdbarch_obstack (TYPE_OWNER (t).gdbarch)),         \
+		   ? &((t)->objfile ()->objfile_obstack)                \
+		   : gdbarch_obstack ((t)->arch ())),                   \
 		  size))
 
 
diff --git a/gdb/language.c b/gdb/language.c
index 1770ba1f8e1e..d4b84911f8b5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1037,7 +1037,7 @@ language_arch_info::type_and_symbol::alloc_type_symbol
   struct symbol *symbol;
   struct gdbarch *gdbarch;
   gdb_assert (!TYPE_OBJFILE_OWNED (type));
-  gdbarch = TYPE_OWNER (type).gdbarch;
+  gdbarch = type->arch ();
   symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
   symbol->m_name = type->name ();
   symbol->set_language (lang, nullptr);
-- 
2.30.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro
  2021-01-21  3:24 [PATCH 1/3] gdb: add owner-related methods to struct type Simon Marchi
@ 2021-01-21  3:24 ` Simon Marchi
  2021-01-22 15:33   ` Tom Tromey
  2021-01-21  3:24 ` [PATCH 3/3] gdb: remove TYPE_OBJFILE macro Simon Marchi
  2021-01-22 15:31 ` [PATCH 1/3] gdb: add owner-related methods to struct type Tom Tromey
  2 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2021-01-21  3:24 UTC (permalink / raw)
  To: gdb-patches

Update all users to use the type::is_objfile_owned method.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_OBJFILE_OWNED): Remove, update all users to
	use the type::is_objfile_owned method.

Change-Id: Icae84d136393ab9f756f50a33ac3cedda13c5ba2
---
 gdb/compile/compile-c-types.c     |  4 ++--
 gdb/compile/compile-cplus-types.c |  2 +-
 gdb/gdbtypes.c                    | 18 +++++++++---------
 gdb/gdbtypes.h                    |  9 ++++-----
 gdb/language.c                    |  2 +-
 5 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 90de2084c85c..104e619f16d3 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -164,7 +164,7 @@ convert_func (compile_c_instance *context, struct type *type)
      GDB's parser used to do.  */
   if (target_type == NULL)
     {
-      if (TYPE_OBJFILE_OWNED (type))
+      if (type->is_objfile_owned ())
 	target_type = objfile_type (type->objfile ())->builtin_int;
       else
 	target_type = builtin_type (type->arch ())->builtin_int;
@@ -323,7 +323,7 @@ convert_type_basic (compile_c_instance *context, struct type *type)
 	   built-in parser does.  For now, assume "int" like GDB's
 	   built-in parser used to do, but at least warn.  */
 	struct type *fallback;
-	if (TYPE_OBJFILE_OWNED (type))
+	if (type->is_objfile_owned ())
 	  fallback = objfile_type (type->objfile ())->builtin_int;
 	else
 	  fallback = builtin_type (type->arch ())->builtin_int;
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index ddb0d8a03682..0f32b0e1adea 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -970,7 +970,7 @@ compile_cplus_convert_func (compile_cplus_instance *instance,
      GDB's parser used to do.  */
   if (target_type == nullptr)
     {
-      if (TYPE_OBJFILE_OWNED (type))
+      if (type->is_objfile_owned ())
 	target_type = objfile_type (type->objfile ())->builtin_int;
       else
 	target_type = builtin_type (type->arch ())->builtin_int;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index e2f8837dcb4d..a4ae0d7a1a61 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -226,7 +226,7 @@ alloc_type_arch (struct gdbarch *gdbarch)
 struct type *
 alloc_type_copy (const struct type *type)
 {
-  if (TYPE_OBJFILE_OWNED (type))
+  if (type->is_objfile_owned ())
     return alloc_type (type->objfile ());
   else
     return alloc_type_arch (type->arch ());
@@ -240,7 +240,7 @@ get_type_arch (const struct type *type)
 {
   struct gdbarch *arch;
 
-  if (TYPE_OBJFILE_OWNED (type))
+  if (type->is_objfile_owned ())
     arch = type->objfile ()->arch ();
   else
     arch = type->arch ();
@@ -290,7 +290,7 @@ alloc_type_instance (struct type *oldtype)
 
   /* Allocate the structure.  */
 
-  if (! TYPE_OBJFILE_OWNED (oldtype))
+  if (!oldtype->is_objfile_owned ())
     type = GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype), struct type);
   else
     type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
@@ -1429,7 +1429,7 @@ lookup_array_range_type (struct type *element_type,
   struct type *index_type;
   struct type *range_type;
 
-  if (TYPE_OBJFILE_OWNED (element_type))
+  if (element_type->is_objfile_owned ())
     index_type = objfile_type (element_type->objfile ())->builtin_int;
   else
     index_type = builtin_type (element_type->arch ())->builtin_int;
@@ -2798,7 +2798,7 @@ type::add_dyn_prop (dynamic_prop_node_kind prop_kind, dynamic_prop prop)
 {
   struct dynamic_prop_list *temp;
 
-  gdb_assert (TYPE_OBJFILE_OWNED (this));
+  gdb_assert (this->is_objfile_owned ());
 
   temp = XOBNEW (&TYPE_OBJFILE (this)->objfile_obstack,
 		 struct dynamic_prop_list);
@@ -5189,7 +5189,7 @@ recursive_dump_type (struct type *type, int spaces)
   puts_filtered ("\n");
   printf_filtered ("%*slength %s\n", spaces, "",
 		   pulongest (TYPE_LENGTH (type)));
-  if (TYPE_OBJFILE_OWNED (type))
+  if (type->is_objfile_owned ())
     {
       printf_filtered ("%*sobjfile ", spaces, "");
       gdb_print_host_address (type->objfile (), gdb_stdout);
@@ -5492,7 +5492,7 @@ copy_type_recursive (struct objfile *objfile,
   void **slot;
   struct type *new_type;
 
-  if (! TYPE_OBJFILE_OWNED (type))
+  if (!type->is_objfile_owned ())
     return type;
 
   /* This type shouldn't be pointing to any types in other objfiles;
@@ -5658,7 +5658,7 @@ copy_type (const struct type *type)
 {
   struct type *new_type;
 
-  gdb_assert (TYPE_OBJFILE_OWNED (type));
+  gdb_assert (type->is_objfile_owned ());
 
   new_type = alloc_type_copy (type);
   new_type->set_instance_flags (type->instance_flags ());
@@ -5960,7 +5960,7 @@ allocate_fixed_point_type_info (struct type *type)
   std::unique_ptr<fixed_point_type_info> up (new fixed_point_type_info);
   fixed_point_type_info *info;
 
-  if (TYPE_OBJFILE_OWNED (type))
+  if (type->is_objfile_owned ())
     {
       fixed_point_type_storage *storage
 	= fixed_point_objfile_key.get (TYPE_OBJFILE (type));
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 51f603157ba7..9037f41b6dba 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -224,7 +224,6 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
    the objfile retrieved as TYPE_OBJFILE.  Otherwise, the type is
    owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
 
-#define TYPE_OBJFILE_OWNED(t) ((t)->is_objfile_owned ())
 #define TYPE_OBJFILE(t) ((t)->objfile ())
 
 /* * True if this type was declared using the "class" keyword.  This is
@@ -1274,14 +1273,14 @@ struct type
     return this->main_type->m_owner.objfile;
   }
 
+  /* Return the gdbarch owner of this type.
+
+     Return nullptr if this type is not gdbarch-owned.  */
   gdbarch *arch () const
   {
     if (this->is_objfile_owned ())
       return nullptr;
 
-  /* Return the gdbarch owner of this type.
-
-     Return nullptr if this type is not gdbarch-owned.  */
     return this->main_type->m_owner.gdbarch;
   }
 
@@ -2242,7 +2241,7 @@ extern const struct floatformat *floatformats_bfloat16[BFD_ENDIAN_UNKNOWN];
    when it is no longer needed.  */
 
 #define TYPE_ALLOC(t,size)                                              \
-  (obstack_alloc ((TYPE_OBJFILE_OWNED (t)                               \
+  (obstack_alloc (((t)->is_objfile_owned ()                             \
 		   ? &((t)->objfile ()->objfile_obstack)                \
 		   : gdbarch_obstack ((t)->arch ())),                   \
 		  size))
diff --git a/gdb/language.c b/gdb/language.c
index d4b84911f8b5..6b4be71c3f25 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -1036,7 +1036,7 @@ language_arch_info::type_and_symbol::alloc_type_symbol
 {
   struct symbol *symbol;
   struct gdbarch *gdbarch;
-  gdb_assert (!TYPE_OBJFILE_OWNED (type));
+  gdb_assert (!type->is_objfile_owned ());
   gdbarch = type->arch ();
   symbol = new (gdbarch_obstack (gdbarch)) struct symbol ();
   symbol->m_name = type->name ();
-- 
2.30.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] gdb: remove TYPE_OBJFILE macro
  2021-01-21  3:24 [PATCH 1/3] gdb: add owner-related methods to struct type Simon Marchi
  2021-01-21  3:24 ` [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro Simon Marchi
@ 2021-01-21  3:24 ` Simon Marchi
  2021-01-22 15:34   ` Tom Tromey
  2021-01-22 15:31 ` [PATCH 1/3] gdb: add owner-related methods to struct type Tom Tromey
  2 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2021-01-21  3:24 UTC (permalink / raw)
  To: gdb-patches

Change all users to use the type::objfile method instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_OBJFILE): Remove, change all users to use the
	type::objfile method instead.

Change-Id: I6b3f580913fb1fb0cf986b176dba8db68e1fabf9
---
 gdb/ada-lang.c       |  4 ++--
 gdb/gdbtypes.c       | 26 +++++++++++++-------------
 gdb/gdbtypes.h       |  6 ------
 gdb/guile/scm-type.c |  4 ++--
 gdb/parse.c          |  7 ++++---
 gdb/python/py-type.c | 10 +++++-----
 gdb/rust-lang.c      |  2 +-
 gdb/value.c          |  6 +++---
 8 files changed, 30 insertions(+), 35 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c898ccb683cf..e2befe1d82e7 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13253,8 +13253,8 @@ ada_operator_check (struct expression *exp, int pos,
 
   /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
 
-  if (type && TYPE_OBJFILE (type)
-      && (*objfile_func) (TYPE_OBJFILE (type), data))
+  if (type != nullptr && type->objfile () != nullptr
+      && objfile_func (type->objfile (), data))
     return 1;
 
   return 0;
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index a4ae0d7a1a61..115f078787bc 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -293,7 +293,7 @@ alloc_type_instance (struct type *oldtype)
   if (!oldtype->is_objfile_owned ())
     type = GDBARCH_OBSTACK_ZALLOC (get_type_arch (oldtype), struct type);
   else
-    type = OBSTACK_ZALLOC (&TYPE_OBJFILE (oldtype)->objfile_obstack,
+    type = OBSTACK_ZALLOC (&oldtype->objfile ()->objfile_obstack,
 			   struct type);
 
   TYPE_MAIN_TYPE (type) = TYPE_MAIN_TYPE (oldtype);
@@ -648,7 +648,7 @@ make_qualified_type (struct type *type, type_instance_flags new_flags,
 	 as TYPE.  Otherwise, we can't link it into TYPE's cv chain:
 	 if one objfile is freed and the other kept, we'd have
 	 dangling pointers.  */
-      gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
+      gdb_assert (type->objfile () == storage->objfile ());
 
       ntype = storage;
       TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
@@ -738,7 +738,7 @@ make_cv_type (int cnst, int voltl,
 	 can't have inter-objfile pointers.  The only thing to do is
 	 to leave stub types as stub types, and look them up afresh by
 	 name each time you encounter them.  */
-      gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
+      gdb_assert ((*typeptr)->objfile () == type->objfile ());
     }
   
   ntype = make_qualified_type (type, new_flags, 
@@ -804,7 +804,7 @@ replace_type (struct type *ntype, struct type *type)
      the assignment of one type's main type structure to the other
      will produce a type with references to objects (names; field
      lists; etc.) allocated on an objfile other than its own.  */
-  gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (type));
+  gdb_assert (ntype->objfile () == type->objfile ());
 
   *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
 
@@ -1681,7 +1681,7 @@ type_name_or_error (struct type *type)
     return name;
 
   name = saved_type->name ();
-  objfile = TYPE_OBJFILE (saved_type);
+  objfile = saved_type->objfile ();
   error (_("Invalid anonymous type %s [in module %s], GCC PR debug/47510 bug?"),
 	 name ? name : "<anonymous>",
 	 objfile ? objfile_name (objfile) : "<arch>");
@@ -2027,7 +2027,7 @@ get_vptr_fieldno (struct type *type, struct type **basetypep)
 	    {
 	      /* If the type comes from a different objfile we can't cache
 		 it, it may have a different lifetime.  PR 2384 */
-	      if (TYPE_OBJFILE (type) == TYPE_OBJFILE (basetype))
+	      if (type->objfile () == basetype->objfile ())
 		{
 		  set_type_vptr_fieldno (type, fieldno);
 		  set_type_vptr_basetype (type, basetype);
@@ -2800,7 +2800,7 @@ type::add_dyn_prop (dynamic_prop_node_kind prop_kind, dynamic_prop prop)
 
   gdb_assert (this->is_objfile_owned ());
 
-  temp = XOBNEW (&TYPE_OBJFILE (this)->objfile_obstack,
+  temp = XOBNEW (&this->objfile ()->objfile_obstack,
 		 struct dynamic_prop_list);
   temp->prop_kind = prop_kind;
   temp->prop = prop;
@@ -2969,7 +2969,7 @@ check_typedef (struct type *type)
 	     TYPE's objfile is pointless, too, since you'll have to
 	     move over any other types NEWTYPE refers to, which could
 	     be an unbounded amount of stuff.  */
-	  if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
+	  if (newtype->objfile () == type->objfile ())
 	    type = make_qualified_type (newtype, type->instance_flags (), type);
 	  else
 	    type = newtype;
@@ -2995,7 +2995,7 @@ check_typedef (struct type *type)
 	  /* Same as above for opaque types, we can replace the stub
 	     with the complete type only if they are in the same
 	     objfile.  */
-	  if (TYPE_OBJFILE (SYMBOL_TYPE (sym)) == TYPE_OBJFILE (type))
+	  if (SYMBOL_TYPE (sym)->objfile () == type->objfile ())
 	    type = make_qualified_type (SYMBOL_TYPE (sym),
 					type->instance_flags (), type);
 	  else
@@ -5497,7 +5497,7 @@ copy_type_recursive (struct objfile *objfile,
 
   /* This type shouldn't be pointing to any types in other objfiles;
      if it did, the type might disappear unexpectedly.  */
-  gdb_assert (TYPE_OBJFILE (type) == objfile);
+  gdb_assert (type->objfile () == objfile);
 
   struct type_pair pair (type, nullptr);
 
@@ -5667,7 +5667,7 @@ copy_type (const struct type *type)
 	  sizeof (struct main_type));
   if (type->main_type->dyn_prop_list != NULL)
     new_type->main_type->dyn_prop_list
-      = copy_dynamic_prop_list (&TYPE_OBJFILE (type) -> objfile_obstack,
+      = copy_dynamic_prop_list (&type->objfile ()->objfile_obstack,
 				type->main_type->dyn_prop_list);
 
   return new_type;
@@ -5963,9 +5963,9 @@ allocate_fixed_point_type_info (struct type *type)
   if (type->is_objfile_owned ())
     {
       fixed_point_type_storage *storage
-	= fixed_point_objfile_key.get (TYPE_OBJFILE (type));
+	= fixed_point_objfile_key.get (type->objfile ());
       if (storage == nullptr)
-	storage = fixed_point_objfile_key.emplace (TYPE_OBJFILE (type));
+	storage = fixed_point_objfile_key.emplace (type->objfile ());
       info = up.get ();
       storage->push_back (std::move (up));
     }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 9037f41b6dba..30e8ac542604 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -220,12 +220,6 @@ DEF_ENUM_FLAGS_TYPE (enum type_instance_flag_value, type_instance_flags);
 
 #define TYPE_NOTTEXT(t)	(((t)->instance_flags ()) & TYPE_INSTANCE_FLAG_NOTTEXT)
 
-/* * Type owner.  If TYPE_OBJFILE_OWNED is true, the type is owned by
-   the objfile retrieved as TYPE_OBJFILE.  Otherwise, the type is
-   owned by an architecture; TYPE_OBJFILE is NULL in this case.  */
-
-#define TYPE_OBJFILE(t) ((t)->objfile ())
-
 /* * True if this type was declared using the "class" keyword.  This is
    only valid for C++ structure and enum types.  If false, a structure
    was declared as a "struct"; if true it was declared "class".  For
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 86f701f10f4e..936639c8a473 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -151,7 +151,7 @@ tyscm_eq_type_smob (const void *ap, const void *bp)
 static htab_t
 tyscm_type_map (struct type *type)
 {
-  struct objfile *objfile = TYPE_OBJFILE (type);
+  struct objfile *objfile = type->objfile ();
   htab_t htab;
 
   if (objfile == NULL)
@@ -351,7 +351,7 @@ tyscm_copy_type_recursive (void **slot, void *info)
 {
   type_smob *t_smob = (type_smob *) *slot;
   htab_t copied_types = (htab_t) info;
-  struct objfile *objfile = TYPE_OBJFILE (t_smob->type);
+  struct objfile *objfile = t_smob->type->objfile ();
   htab_t htab;
   eqable_gdb_smob **new_slot;
   type_smob t_smob_for_lookup;
diff --git a/gdb/parse.c b/gdb/parse.c
index b3cd91d2730c..7fd520493ac4 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1320,7 +1320,7 @@ operator_check_standard (struct expression *exp, int pos,
 	for (arg = 0; arg < nargs; arg++)
 	  {
 	    struct type *inst_type = elts[pos + 3 + arg].type;
-	    struct objfile *inst_objfile = TYPE_OBJFILE (inst_type);
+	    struct objfile *inst_objfile = inst_type->objfile ();
 
 	    if (inst_objfile && (*objfile_func) (inst_objfile, data))
 	      return 1;
@@ -1351,9 +1351,10 @@ operator_check_standard (struct expression *exp, int pos,
 
   /* Invoke callbacks for TYPE and OBJFILE if they were set as non-NULL.  */
 
-  if (type && TYPE_OBJFILE (type)
-      && (*objfile_func) (TYPE_OBJFILE (type), data))
+  if (type != nullptr && type->objfile () != nullptr
+      && objfile_func (type->objfile (), data))
     return 1;
+
   if (objfile && (*objfile_func) (objfile, data))
     return 1;
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index f05c3bcb6cfe..878304f716ca 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -418,7 +418,7 @@ static PyObject *
 typy_get_objfile (PyObject *self, void *closure)
 {
   struct type *type = ((type_object *) self)->type;
-  struct objfile *objfile = TYPE_OBJFILE (type);
+  struct objfile *objfile = type->objfile ();
 
   if (objfile == nullptr)
     Py_RETURN_NONE;
@@ -1098,9 +1098,9 @@ set_type (type_object *obj, struct type *type)
 {
   obj->type = type;
   obj->prev = NULL;
-  if (type && TYPE_OBJFILE (type))
+  if (type != nullptr && type->objfile () != nullptr)
     {
-      struct objfile *objfile = TYPE_OBJFILE (type);
+      struct objfile *objfile = type->objfile ();
 
       obj->next = ((type_object *)
 		   objfile_data (objfile, typy_objfile_data_key));
@@ -1119,10 +1119,10 @@ typy_dealloc (PyObject *obj)
 
   if (type->prev)
     type->prev->next = type->next;
-  else if (type->type && TYPE_OBJFILE (type->type))
+  else if (type->type != nullptr && type->type->objfile () != nullptr)
     {
       /* Must reset head of list.  */
-      struct objfile *objfile = TYPE_OBJFILE (type->type);
+      struct objfile *objfile = type->type->objfile ();
 
       if (objfile)
 	set_objfile_data (objfile, typy_objfile_data_key, type->next);
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index e9827ff15f7f..fc572ce96efb 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1825,7 +1825,7 @@ rust_operator_check (struct expression *exp, int pos,
     case OP_AGGREGATE:
       {
 	struct type *type = exp->elts[pos + 1].type;
-	struct objfile *objfile = TYPE_OBJFILE (type);
+	struct objfile *objfile = type->objfile ();
 
 	if (objfile != NULL && (*objfile_func) (objfile, data))
 	  return 1;
diff --git a/gdb/value.c b/gdb/value.c
index c84698d25e04..6f4ee5453117 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2514,10 +2514,10 @@ void
 preserve_one_value (struct value *value, struct objfile *objfile,
 		    htab_t copied_types)
 {
-  if (TYPE_OBJFILE (value->type) == objfile)
+  if (value->type->objfile () == objfile)
     value->type = copy_type_recursive (objfile, value->type, copied_types);
 
-  if (TYPE_OBJFILE (value->enclosing_type) == objfile)
+  if (value->enclosing_type->objfile () == objfile)
     value->enclosing_type = copy_type_recursive (objfile,
 						 value->enclosing_type,
 						 copied_types);
@@ -2532,7 +2532,7 @@ preserve_one_internalvar (struct internalvar *var, struct objfile *objfile,
   switch (var->kind)
     {
     case INTERNALVAR_INTEGER:
-      if (var->u.integer.type && TYPE_OBJFILE (var->u.integer.type) == objfile)
+      if (var->u.integer.type && var->u.integer.type->objfile () == objfile)
 	var->u.integer.type
 	  = copy_type_recursive (objfile, var->u.integer.type, copied_types);
       break;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gdb: add owner-related methods to struct type
  2021-01-21  3:24 [PATCH 1/3] gdb: add owner-related methods to struct type Simon Marchi
  2021-01-21  3:24 ` [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro Simon Marchi
  2021-01-21  3:24 ` [PATCH 3/3] gdb: remove TYPE_OBJFILE macro Simon Marchi
@ 2021-01-22 15:31 ` Tom Tromey
  2021-01-22 17:21   ` Simon Marchi
  2 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2021-01-22 15:31 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi, Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> From: Simon Marchi <simon.marchi@efficios.com>
Simon> Add the following methods to struct type:

Simon>  * is_objfile_owned
Simon>  * set_owner (objfile and gdbarch overloads)
Simon>  * objfile and arch getters

Simon> Rename the fields in main_type to ensure no other code accesses them
Simon> directly.  As usual, we can't make them actually private, but giving
Simon> them the `m_` prefix will help making sure they are not accessed when
Simon> not supposed to, by convention.

Simon> Remove the TYPE_OWNER macro to ensure no code uses the type_owner struct
Simon> directly.

Looks good, with one small nit.

Simon> +  gdbarch *arch () const
Simon> +  {
Simon> +    if (this->is_objfile_owned ())
Simon> +      return nullptr;
Simon> +
Simon> +  /* Return the gdbarch owner of this type.
Simon> +
Simon> +     Return nullptr if this type is not gdbarch-owned.  */
Simon> +    return this->main_type->m_owner.gdbarch;
Simon> +  }

This comment got misplaced into the middle of the method.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro
  2021-01-21  3:24 ` [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro Simon Marchi
@ 2021-01-22 15:33   ` Tom Tromey
  0 siblings, 0 replies; 9+ messages in thread
From: Tom Tromey @ 2021-01-22 15:33 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Update all users to use the type::is_objfile_owned method.
Simon> gdb/ChangeLog:

Simon> 	* gdbtypes.h (TYPE_OBJFILE_OWNED): Remove, update all users to
Simon> 	use the type::is_objfile_owned method.

Looks good.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: remove TYPE_OBJFILE macro
  2021-01-21  3:24 ` [PATCH 3/3] gdb: remove TYPE_OBJFILE macro Simon Marchi
@ 2021-01-22 15:34   ` Tom Tromey
  2021-01-22 17:25     ` Simon Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Tom Tromey @ 2021-01-22 15:34 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Change all users to use the type::objfile method instead.
Simon> gdb/ChangeLog:

Simon> 	* gdbtypes.h (TYPE_OBJFILE): Remove, change all users to use the
Simon> 	type::objfile method instead.

Thank you.  This looks good to me.

Tom

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gdb: add owner-related methods to struct type
  2021-01-22 15:31 ` [PATCH 1/3] gdb: add owner-related methods to struct type Tom Tromey
@ 2021-01-22 17:21   ` Simon Marchi
  2021-01-22 19:42     ` Simon Marchi
  0 siblings, 1 reply; 9+ messages in thread
From: Simon Marchi @ 2021-01-22 17:21 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 2021-01-22 10:31 a.m., Tom Tromey wrote:
> This comment got misplaced into the middle of the method.

Oh, I did spot this before sending, I thought I fixed it, apparently
not.  Fixed now, thanks.

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] gdb: remove TYPE_OBJFILE macro
  2021-01-22 15:34   ` Tom Tromey
@ 2021-01-22 17:25     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2021-01-22 17:25 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches



On 2021-01-22 10:34 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Change all users to use the type::objfile method instead.
> Simon> gdb/ChangeLog:
> 
> Simon> 	* gdbtypes.h (TYPE_OBJFILE): Remove, change all users to use the
> Simon> 	type::objfile method instead.
> 
> Thank you.  This looks good to me.
> 
> Tom
> 

Thanks, I pushed the series.

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] gdb: add owner-related methods to struct type
  2021-01-22 17:21   ` Simon Marchi
@ 2021-01-22 19:42     ` Simon Marchi
  0 siblings, 0 replies; 9+ messages in thread
From: Simon Marchi @ 2021-01-22 19:42 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi

On 2021-01-22 12:21 p.m., Simon Marchi via Gdb-patches wrote:
> On 2021-01-22 10:31 a.m., Tom Tromey wrote:
>> This comment got misplaced into the middle of the method.
> 
> Oh, I did spot this before sending, I thought I fixed it, apparently
> not.  Fixed now, thanks.
> 
> Simon
> 

Oh, I didn't test this properly, I now see some regressions, for example in
gdb.base/jit-reader-simple.exp.  Looking at that now.

Simon

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-01-22 19:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21  3:24 [PATCH 1/3] gdb: add owner-related methods to struct type Simon Marchi
2021-01-21  3:24 ` [PATCH 2/3] gdb: remove TYPE_OBJFILE_OWNED macro Simon Marchi
2021-01-22 15:33   ` Tom Tromey
2021-01-21  3:24 ` [PATCH 3/3] gdb: remove TYPE_OBJFILE macro Simon Marchi
2021-01-22 15:34   ` Tom Tromey
2021-01-22 17:25     ` Simon Marchi
2021-01-22 15:31 ` [PATCH 1/3] gdb: add owner-related methods to struct type Tom Tromey
2021-01-22 17:21   ` Simon Marchi
2021-01-22 19:42     ` Simon Marchi

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).