Remove gdbarch parameter of lookup_typename

Message ID 20191205050916.230459-1-simon.marchi@polymtl.ca
State New, archived
Headers

Commit Message

Simon Marchi Dec. 5, 2019, 5:09 a.m. UTC
  I noticed that the gdbarch parameter of lookup_typename was unused, so I
removed it (as well as from lookup_signed_typename and
lookup_unsigned_typename) and updated all callers.

Tested by rebuilding.

gdb/ChangeLog:

	* c-exp.y: Update calls to lookup_typename,
	lookup_signed_typename and lookup_unsigned_typename.
	* c-lang.c (evaluate_subexp_c): Likewise.
	* cp-namespace.c (cp_lookup_symbol_imports_or_template):
	Likewise.
	* eval.c (binop_promote): Likewise.
	* gdbtypes.c (lookup_typename): Remove gdbarch parameter.
	(lookup_unsigned_typename): Likewise.
	(lookup_signed_typename): Likewise.
	* gdbtypes.h (lookup_unsigned_typename): Likewise.
	(lookup_signed_typename): Likewise.
	(lookup_typename): Likewise.
	* guile/scm-type.c (tyscm_lookup_typename): Update calls to
	lookup_typename, lookup_signed_typename,
	lookup_unsigned_typename.
	* m2-exp.y: Likewise.
	* printcmd.c (printf_wide_c_string): Likewise.
	(ui_printf): Likewise.
	* python/py-type.c (typy_lookup_typename): Likewise.
	* python/py-xmethods.c (python_xmethod_worker::invoke):
	Likewise.
	* rust-exp.y: Likewise.
---
 gdb/c-exp.y              | 36 ------------------------------------
 gdb/c-lang.c             |  9 +++------
 gdb/cp-namespace.c       |  3 +--
 gdb/eval.c               | 12 ++++++------
 gdb/gdbtypes.c           | 13 ++++++-------
 gdb/gdbtypes.h           |  7 +++----
 gdb/guile/scm-type.c     |  2 +-
 gdb/m2-exp.y             |  3 +--
 gdb/printcmd.c           |  4 ++--
 gdb/python/py-type.c     |  2 +-
 gdb/python/py-xmethods.c |  2 +-
 gdb/rust-exp.y           |  2 +-
 12 files changed, 26 insertions(+), 69 deletions(-)
  

Comments

Tom Tromey Dec. 5, 2019, 2:40 p.m. UTC | #1
>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:

Simon> I noticed that the gdbarch parameter of lookup_typename was unused, so I
Simon> removed it (as well as from lookup_signed_typename and
Simon> lookup_unsigned_typename) and updated all callers.

This looks fine to me.  Thanks for doing this.

I do wonder a bit why the parameter was there in the first place.  Maybe
this code used to look at the per-arch types?

Tom
  
Simon Marchi Dec. 5, 2019, 6:47 p.m. UTC | #2
On 2019-12-05 9:40 a.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi <simon.marchi@polymtl.ca> writes:
> 
> Simon> I noticed that the gdbarch parameter of lookup_typename was unused, so I
> Simon> removed it (as well as from lookup_signed_typename and
> Simon> lookup_unsigned_typename) and updated all callers.
> 
> This looks fine to me.  Thanks for doing this.
> 
> I do wonder a bit why the parameter was there in the first place.  Maybe
> this code used to look at the per-arch types?
> 
> Tom
> 

I looked up the commit that removed the use of gdbarch, here it is:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=1994afbf19892c9e614a034fbf1a5233e9addce3

This seems to  be the corresponding message on gdb-patches:

https://sourceware.org/ml/gdb-patches/2014-12/msg00521.html

It looks like the series may have been pushed as one squashed commit?

Anyway, it looks indeed like were looking up primitive types using the gdbarch
before, I can't explain why that changed without digging deeper, but I'll suppose
that change was correct.

I will push the patch as soon as I confirmed it's still building.

Simon
  

Patch

diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 0ec6b193dc64..fb806a80bebc 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -824,7 +824,6 @@  exp	:	SIZEOF '(' type ')'	%prec UNARY
 			  write_exp_elt_opcode (pstate, OP_LONG);
 			  write_exp_elt_type (pstate, lookup_signed_typename
 					      (pstate->language (),
-					       pstate->gdbarch (),
 					       "int"));
 			  type = check_typedef (type);
 
@@ -1301,117 +1300,89 @@  typebase
 			{ $$ = $1.type; }
 	|	INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "int"); }
 	|	LONG
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long"); }
 	|	SHORT
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "short"); }
 	|	LONG INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long"); }
 	|	LONG SIGNED_KEYWORD INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long"); }
 	|	LONG SIGNED_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long"); }
 	|	SIGNED_KEYWORD LONG INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long"); }
 	|	UNSIGNED LONG INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long"); }
 	|	LONG UNSIGNED INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long"); }
 	|	LONG UNSIGNED
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long"); }
 	|	LONG LONG
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	LONG LONG INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	LONG LONG SIGNED_KEYWORD INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	LONG LONG SIGNED_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	SIGNED_KEYWORD LONG LONG
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	SIGNED_KEYWORD LONG LONG INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "long long"); }
 	|	UNSIGNED LONG LONG
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long long"); }
 	|	UNSIGNED LONG LONG INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long long"); }
 	|	LONG LONG UNSIGNED
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long long"); }
 	|	LONG LONG UNSIGNED INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "long long"); }
 	|	SHORT INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "short"); }
 	|	SHORT SIGNED_KEYWORD INT_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "short"); }
 	|	SHORT SIGNED_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "short"); }
 	|	UNSIGNED SHORT INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "short"); }
 	|	SHORT UNSIGNED
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "short"); }
 	|	SHORT UNSIGNED INT_KEYWORD
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "short"); }
 	|	DOUBLE_KEYWORD
 			{ $$ = lookup_typename (pstate->language (),
-						pstate->gdbarch (),
 						"double",
 						NULL,
 						0); }
 	|	LONG DOUBLE_KEYWORD
 			{ $$ = lookup_typename (pstate->language (),
-						pstate->gdbarch (),
 						"long double",
 						NULL,
 						0); }
@@ -1483,19 +1454,15 @@  typebase
 			}
 	|	UNSIGNED type_name
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 TYPE_NAME($2.type)); }
 	|	UNSIGNED
 			{ $$ = lookup_unsigned_typename (pstate->language (),
-							 pstate->gdbarch (),
 							 "int"); }
 	|	SIGNED_KEYWORD type_name
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       TYPE_NAME($2.type)); }
 	|	SIGNED_KEYWORD
 			{ $$ = lookup_signed_typename (pstate->language (),
-						       pstate->gdbarch (),
 						       "int"); }
                 /* It appears that this rule for templates is never
                    reduced; template recognition happens by lookahead
@@ -1517,7 +1484,6 @@  type_name:	TYPENAME
 		  $$.stoken.ptr = "int";
 		  $$.stoken.length = 3;
 		  $$.type = lookup_signed_typename (pstate->language (),
-						    pstate->gdbarch (),
 						    "int");
 		}
 	|	LONG
@@ -1525,7 +1491,6 @@  type_name:	TYPENAME
 		  $$.stoken.ptr = "long";
 		  $$.stoken.length = 4;
 		  $$.type = lookup_signed_typename (pstate->language (),
-						    pstate->gdbarch (),
 						    "long");
 		}
 	|	SHORT
@@ -1533,7 +1498,6 @@  type_name:	TYPENAME
 		  $$.stoken.ptr = "short";
 		  $$.stoken.length = 5;
 		  $$.type = lookup_signed_typename (pstate->language (),
-						    pstate->gdbarch (),
 						    "short");
 		}
 	;
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 1de44f7efb5b..846970af7b92 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -611,16 +611,13 @@  evaluate_subexp_c (struct type *expect_type, struct expression *exp,
 					      exp->gdbarch);
 	    break;
 	  case C_WIDE_STRING:
-	    type = lookup_typename (exp->language_defn, exp->gdbarch,
-				    "wchar_t", NULL, 0);
+	    type = lookup_typename (exp->language_defn, "wchar_t", NULL, 0);
 	    break;
 	  case C_STRING_16:
-	    type = lookup_typename (exp->language_defn, exp->gdbarch,
-				    "char16_t", NULL, 0);
+	    type = lookup_typename (exp->language_defn, "char16_t", NULL, 0);
 	    break;
 	  case C_STRING_32:
-	    type = lookup_typename (exp->language_defn, exp->gdbarch,
-				    "char32_t", NULL, 0);
+	    type = lookup_typename (exp->language_defn, "char32_t", NULL, 0);
 	    break;
 	  default:
 	    internal_error (__FILE__, __LINE__, _("unhandled c_string_type"));
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index 2b3f014253ac..d813d050733c 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -547,7 +547,6 @@  cp_lookup_symbol_imports_or_template (const char *scope,
 	  struct type *context;
 	  std::string name_copy (function->natural_name ());
 	  const struct language_defn *lang = language_def (language_cplus);
-	  struct gdbarch *arch = symbol_arch (function);
 	  const struct block *parent = BLOCK_SUPERBLOCK (block);
 	  struct symbol *sym;
 
@@ -561,7 +560,7 @@  cp_lookup_symbol_imports_or_template (const char *scope,
 	      else
 		{
 		  name_copy.erase (prefix_len);
-		  context = lookup_typename (lang, arch,
+		  context = lookup_typename (lang,
 					     name_copy.c_str (),
 					     parent, 1);
 		}
diff --git a/gdb/eval.c b/gdb/eval.c
index 87874420dc86..8c93c7a0b103 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -562,20 +562,20 @@  binop_promote (const struct language_defn *language, struct gdbarch *gdbarch,
 	  break;
 	case language_opencl:
 	  if (result_len <= TYPE_LENGTH (lookup_signed_typename
-					 (language, gdbarch, "int")))
+					 (language, "int")))
 	    {
 	      promoted_type =
 		(unsigned_operation
-		 ? lookup_unsigned_typename (language, gdbarch, "int")
-		 : lookup_signed_typename (language, gdbarch, "int"));
+		 ? lookup_unsigned_typename (language, "int")
+		 : lookup_signed_typename (language, "int"));
 	    }
 	  else if (result_len <= TYPE_LENGTH (lookup_signed_typename
-					      (language, gdbarch, "long")))
+					      (language, "long")))
 	    {
 	      promoted_type =
 		(unsigned_operation
-		 ? lookup_unsigned_typename (language, gdbarch, "long")
-		 : lookup_signed_typename (language, gdbarch,"long"));
+		 ? lookup_unsigned_typename (language, "long")
+		 : lookup_signed_typename (language,"long"));
 	    }
 	  break;
 	default:
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 775e8c18f911..4854f49e4842 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1555,7 +1555,7 @@  type_name_or_error (struct type *type)
 
 struct type *
 lookup_typename (const struct language_defn *language,
-		 struct gdbarch *gdbarch, const char *name,
+		 const char *name,
 		 const struct block *block, int noerr)
 {
   struct symbol *sym;
@@ -1572,29 +1572,28 @@  lookup_typename (const struct language_defn *language,
 
 struct type *
 lookup_unsigned_typename (const struct language_defn *language,
-			  struct gdbarch *gdbarch, const char *name)
+			  const char *name)
 {
   char *uns = (char *) alloca (strlen (name) + 10);
 
   strcpy (uns, "unsigned ");
   strcpy (uns + 9, name);
-  return lookup_typename (language, gdbarch, uns, NULL, 0);
+  return lookup_typename (language, uns, NULL, 0);
 }
 
 struct type *
-lookup_signed_typename (const struct language_defn *language,
-			struct gdbarch *gdbarch, const char *name)
+lookup_signed_typename (const struct language_defn *language, const char *name)
 {
   struct type *t;
   char *uns = (char *) alloca (strlen (name) + 8);
 
   strcpy (uns, "signed ");
   strcpy (uns + 7, name);
-  t = lookup_typename (language, gdbarch, uns, NULL, 1);
+  t = lookup_typename (language, uns, NULL, 1);
   /* If we don't find "signed FOO" just try again with plain "FOO".  */
   if (t != NULL)
     return t;
-  return lookup_typename (language, gdbarch, name, NULL, 0);
+  return lookup_typename (language, name, NULL, 0);
 }
 
 /* Lookup a structure type named "struct NAME",
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index e399f5f5bc37..0dd7333371b6 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -2005,10 +2005,10 @@  extern struct type *lookup_string_range_type (struct type *, LONGEST, LONGEST);
 extern struct type *create_set_type (struct type *, struct type *);
 
 extern struct type *lookup_unsigned_typename (const struct language_defn *,
-					      struct gdbarch *, const char *);
+					      const char *);
 
 extern struct type *lookup_signed_typename (const struct language_defn *,
-					    struct gdbarch *, const char *);
+					    const char *);
 
 extern void get_unsigned_type_max (struct type *, ULONGEST *);
 
@@ -2048,8 +2048,7 @@  extern void check_stub_method_group (struct type *, int);
 extern char *gdb_mangle_name (struct type *, int, int);
 
 extern struct type *lookup_typename (const struct language_defn *,
-				     struct gdbarch *, const char *,
-				     const struct block *, int);
+				     const char *, const struct block *, int);
 
 extern struct type *lookup_template_type (const char *, struct type *,
 					  const struct block *);
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index 953e17bf0e41..d5b289d11c29 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -1245,7 +1245,7 @@  tyscm_lookup_typename (const char *type_name, const struct block *block)
       else if (startswith (type_name, "enum "))
 	type = lookup_enum (type_name + 5, NULL);
       else
-	type = lookup_typename (current_language, get_current_arch (),
+	type = lookup_typename (current_language,
 				type_name, block, 0);
     }
   catch (const gdb_exception &except)
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 6a0173b251de..243f3023d322 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -599,7 +599,6 @@  type
 	:	TYPENAME
 			{ $$
 			    = lookup_typename (pstate->language (),
-					       pstate->gdbarch (),
 					       copy_name ($1).c_str (),
 					       pstate->expression_context_block,
 					       0);
@@ -974,7 +973,7 @@  yylex (void)
 			 VAR_DOMAIN, 0).symbol;
     if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
       return BLOCKNAME;
-    if (lookup_typename (pstate->language (), pstate->gdbarch (),
+    if (lookup_typename (pstate->language (),
 			 tmp.c_str (), pstate->expression_context_block, 1))
       return TYPENAME;
 
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index fe0efd371a53..f7674cf1d010 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2326,7 +2326,7 @@  printf_wide_c_string (struct ui_file *stream, const char *format,
   const gdb_byte *str;
   size_t len;
   struct gdbarch *gdbarch = get_type_arch (value_type (value));
-  struct type *wctype = lookup_typename (current_language, gdbarch,
+  struct type *wctype = lookup_typename (current_language,
 					 "wchar_t", NULL, 0);
   int wcwidth = TYPE_LENGTH (wctype);
 
@@ -2601,7 +2601,7 @@  ui_printf (const char *arg, struct ui_file *stream)
 	    {
 	      struct gdbarch *gdbarch
 		= get_type_arch (value_type (val_args[i]));
-	      struct type *wctype = lookup_typename (current_language, gdbarch,
+	      struct type *wctype = lookup_typename (current_language,
 						     "wchar_t", NULL, 0);
 	      struct type *valtype;
 	      const gdb_byte *bytes;
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index e4350993dd4f..5a6c2691f023 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -758,7 +758,7 @@  typy_lookup_typename (const char *type_name, const struct block *block)
       else if (startswith (type_name, "enum "))
 	type = lookup_enum (type_name + 5, NULL);
       else
-	type = lookup_typename (python_language, python_gdbarch,
+	type = lookup_typename (python_language,
 				type_name, block, 0);
     }
   catch (const gdb_exception &except)
diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c
index 8606f4097502..650666eda2bb 100644
--- a/gdb/python/py-xmethods.c
+++ b/gdb/python/py-xmethods.c
@@ -580,7 +580,7 @@  python_xmethod_worker::invoke (struct value *obj,
     }
   else
     {
-      res = allocate_value (lookup_typename (python_language, python_gdbarch,
+      res = allocate_value (lookup_typename (python_language,
 					     "void", NULL, 0));
     }
 
diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y
index a15e0de12fd2..5587ebf5d7fc 100644
--- a/gdb/rust-exp.y
+++ b/gdb/rust-exp.y
@@ -2024,7 +2024,7 @@  rust_parser::rust_lookup_type (const char *name, const struct block *block)
       return SYMBOL_TYPE (result.symbol);
     }
 
-  type = lookup_typename (language (), arch (), name, NULL, 1);
+  type = lookup_typename (language (), name, NULL, 1);
   if (type != NULL)
     return type;