This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfc][21/37] Eliminate builtin_type_ macros: Platform-neutral builtin_type_void


Hello,

builtin_type_void is currently per-gdbarch type macro, even though the
"void" type conceptually does not depend on the architecture.

The rationale for this is that types derived from it (e.g. pointer to
void or function returning void) *are* gdbarch-specific, and pointers
to those are cached in the type data structure.

However, this problem can be fixed by simply making sure that noone
ever calls lookup_pointer_type, lookup_reference_type, or lookup_function_type
on the platform-neutral builtin_type_void type.

This is nearly everywhere already the case, since we have the per-
gdbarch builtin_data_ptr and builtin_func_ptr for these purposes.

This patch fixes the remaining uses, and converts builtin_type_void
back to a global platform-neutral variable.  This allows other parts
of GDB to continue using builtin_type_void in platform-neutral code.

Bye,
Ulrich


ChangeLog:

	* gdbtypes.h (builtin_type_void): Remove macro, add declaration.
	(builtin_type_f_void): Remove macro.
	* gdbtypes.c (builtin_type_void): New global variable.
	(_initialize_gdbtypes): Initialize it.

	* gnu-v3-abi.c (build_gdb_vtable_type): Do not call
	lookup_pointer_type or lookup_function_type on builtin_type_void.
	* printcmd.c (set_next_address): Likewise.
	* objc-lang.c (value_nsstring): Likewise.
	* mt-tdep.c (mt_copro_register_type): Likewise.
	* xtensa-tdep.c (xtensa_register_type): Likewise.

	* symfile.c (syms_from_objfile): Remove special handling
	of builtin_type_void and builtin_type_char.


Index: gdb-head/gdb/gdbtypes.c
===================================================================
--- gdb-head.orig/gdb/gdbtypes.c
+++ gdb-head/gdb/gdbtypes.c
@@ -108,6 +108,9 @@ struct type *builtin_type_arm_ext;
 struct type *builtin_type_ia64_spill;
 struct type *builtin_type_ia64_quad;
 
+/* Platform-neutral void type.  */
+struct type *builtin_type_void;
+
 
 int opaque_type_resolution = 1;
 static void
@@ -3330,6 +3333,11 @@ _initialize_gdbtypes (void)
   builtin_type_ia64_quad =
     build_flt (-1, "builtin_type_ia64_quad", floatformats_ia64_quad);
 
+  builtin_type_void =
+    init_type (TYPE_CODE_VOID, 1,
+	       0,
+	       "void", (struct objfile *) NULL);
+
   add_setshow_zinteger_cmd ("overload", no_class, &overload_debug, _("\
 Set debugging of C++ overloading."), _("\
 Show debugging of C++ overloading."), _("\
Index: gdb-head/gdb/gdbtypes.h
===================================================================
--- gdb-head.orig/gdb/gdbtypes.h
+++ gdb-head/gdb/gdbtypes.h
@@ -1020,8 +1020,6 @@ extern const struct builtin_type *builti
 	(builtin_type (current_gdbarch)->builtin_core_addr)
 #define builtin_type_true_char \
 	(builtin_type (current_gdbarch)->builtin_true_char)
-#define builtin_type_void \
-	(builtin_type (current_gdbarch)->builtin_void)
 #define builtin_type_char \
 	(builtin_type (current_gdbarch)->builtin_char)
 #define builtin_type_short \
@@ -1096,9 +1094,13 @@ extern struct type *builtin_type_arm_ext
 extern struct type *builtin_type_ia64_spill;
 extern struct type *builtin_type_ia64_quad;
 
+/* Platform-neutral void type.  Never attempt to construct a pointer
+   or reference type to this, because those cannot be platform-neutral.
+   You must use builtin_type (...)->builtin_void in those cases.  */
+extern struct type *builtin_type_void;
+
 /* This type represents a type that was unrecognized in symbol
    read-in.  */
-
 extern struct type *builtin_type_error;
 
 
@@ -1176,8 +1178,6 @@ extern const struct builtin_f_type *buil
 	(builtin_f_type (current_gdbarch)->builtin_complex_s16)
 #define builtin_type_f_complex_s32 \
 	(builtin_f_type (current_gdbarch)->builtin_complex_s32)
-#define builtin_type_f_void \
-	(builtin_f_type (current_gdbarch)->builtin_void)
 
 
 /* RTTI for C++ */
Index: gdb-head/gdb/gnu-v3-abi.c
===================================================================
--- gdb-head.orig/gdb/gnu-v3-abi.c
+++ gdb-head/gdb/gnu-v3-abi.c
@@ -107,9 +107,9 @@ build_gdb_vtable_type (struct gdbarch *a
   int offset;
 
   struct type *void_ptr_type
-    = lookup_pointer_type (builtin_type_void);
+    = builtin_type (arch)->builtin_data_ptr;
   struct type *ptr_to_void_fn_type
-    = lookup_pointer_type (lookup_function_type (builtin_type_void));
+    = builtin_type (arch)->builtin_func_ptr;
 
   /* ARCH can't give us the true ptrdiff_t type, so we guess.  */
   struct type *ptrdiff_type
Index: gdb-head/gdb/mt-tdep.c
===================================================================
--- gdb-head.orig/gdb/mt-tdep.c
+++ gdb-head/gdb/mt-tdep.c
@@ -251,19 +251,13 @@ mt_copro_register_type (struct gdbarch *
 static struct type *
 mt_register_type (struct gdbarch *arch, int regnum)
 {
-  static struct type *void_func_ptr = NULL;
-  static struct type *void_ptr = NULL;
-  static struct type *copro_type;
+  static struct type *copro_type = NULL;
 
   if (regnum >= 0 && regnum < MT_NUM_REGS + MT_NUM_PSEUDO_REGS)
     {
-      if (void_func_ptr == NULL)
+      if (copro_type == NULL)
 	{
 	  struct type *temp;
-
-	  void_ptr = lookup_pointer_type (builtin_type_void);
-	  void_func_ptr =
-	    lookup_pointer_type (lookup_function_type (builtin_type_void));
 	  temp = create_range_type (NULL, builtin_type_unsigned_int, 0, 1);
 	  copro_type = create_array_type (NULL, builtin_type_int16, temp);
 	}
@@ -272,10 +266,10 @@ mt_register_type (struct gdbarch *arch, 
 	case MT_PC_REGNUM:
 	case MT_RA_REGNUM:
 	case MT_IRA_REGNUM:
-	  return void_func_ptr;
+	  return builtin_type (arch)->builtin_func_ptr;
 	case MT_SP_REGNUM:
 	case MT_FP_REGNUM:
-	  return void_ptr;
+	  return builtin_type (arch)->builtin_data_ptr;
 	case MT_COPRO_REGNUM:
 	case MT_COPRO_PSEUDOREG_REGNUM:
 	  return copro_type;
Index: gdb-head/gdb/objc-lang.c
===================================================================
--- gdb-head.orig/gdb/objc-lang.c
+++ gdb-head/gdb/objc-lang.c
@@ -173,7 +173,7 @@ value_nsstring (char *ptr, int len)
   if (sym == NULL)
     sym = lookup_struct_typedef("NXString", 0, 1);
   if (sym == NULL)
-    type = lookup_pointer_type(builtin_type_void);
+    type = builtin_type_void_data_ptr;
   else
     type = lookup_pointer_type(SYMBOL_TYPE (sym));
 
Index: gdb-head/gdb/printcmd.c
===================================================================
--- gdb-head.orig/gdb/printcmd.c
+++ gdb-head/gdb/printcmd.c
@@ -513,8 +513,7 @@ set_next_address (CORE_ADDR addr)
 
   /* Make address available to the user as $_.  */
   set_internalvar (lookup_internalvar ("_"),
-		   value_from_pointer (lookup_pointer_type (builtin_type_void),
-				       addr));
+		   value_from_pointer (builtin_type_void_data_ptr, addr));
 }
 
 /* Optionally print address ADDR symbolically as <SYMBOL+OFFSET> on STREAM,
Index: gdb-head/gdb/symfile.c
===================================================================
--- gdb-head.orig/gdb/symfile.c
+++ gdb-head/gdb/symfile.c
@@ -898,14 +898,6 @@ syms_from_objfile (struct objfile *objfi
 
   (*objfile->sf->sym_read) (objfile, mainline);
 
-  /* Don't allow char * to have a typename (else would get caddr_t).
-     Ditto void *.  FIXME: Check whether this is now done by all the
-     symbol readers themselves (many of them now do), and if so remove
-     it from here.  */
-
-  TYPE_NAME (lookup_pointer_type (builtin_type_char)) = 0;
-  TYPE_NAME (lookup_pointer_type (builtin_type_void)) = 0;
-
   /* Mark the objfile has having had initial symbol read attempted.  Note
      that this does not mean we found any symbols... */
 
Index: gdb-head/gdb/xtensa-tdep.c
===================================================================
--- gdb-head.orig/gdb/xtensa-tdep.c
+++ gdb-head/gdb/xtensa-tdep.c
@@ -233,7 +233,7 @@ xtensa_register_type (struct gdbarch *gd
 
   if (regnum == gdbarch_pc_regnum (gdbarch)
       || regnum == gdbarch_tdep (gdbarch)->a0_base + 1)
-    return lookup_pointer_type (builtin_type_void);
+    return builtin_type (gdbarch)->builtin_data_ptr;
 
   /* Return the stored type for all other registers.  */
   else if (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch)

-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]