Cell multi-arch type resolution broken (Re: [PATCH 5/6] [PR 17684] add support for primitive types as symbols)

Message ID m3oahoccuc.fsf@sspiff.org
State New, archived
Headers

Commit Message

Doug Evans Aug. 31, 2015, 4:15 a.m. UTC
  Doug Evans <xdje42@gmail.com> writes:
> "Ulrich Weigand" <uweigand@de.ibm.com> writes:
>> Doug Evans wrote:
>>
>>> 2014-12-18  Doug Evans  <xdje42@gmail.com>
>>> 
>>>	* gdbtypes.c (lookup_typename): Call lookup_symbol_in_language.
>>>	Remove call to language_lookup_primitive_type.  No longer necessary.
>>
>>> 	(basic_lookup_symbol_nonlocal): Try looking up the symbol as a
>>> 	primitive type.
>>
>> This seems to have broken per-architecture primitive type resolution for
>> Cell multi-arch debugging.  The problem here is that some primitive types
>> have different properties on SPU than on PowerPC, and so you want e.g.
>>   print sizeof (long double)
>> to print 16 while in a PowerPC frame, but print 8 in a SPU frame.
>>
>> This used to be triggered by the explicit gdbarch argument that was passed
>> to the language_typename routine (and related).  But after your patch, that
>> routine is either no longer called at all, and even where it is, its
>> gdbarch argument to language_typename is now simply ignored.
>>
>> Instead, we have this code in symtab.c:basic_lookup_symbol_nonlocal:
>>
>>> +  /* If we didn't find a definition for a builtin type in the static block,
>>> +     search for it now.  This is actually the right thing to do and can be
>>> +     a massive performance win.  E.g., when debugging a program with lots of
>>> +     shared libraries we could search all of them only to find out the
>>> +     builtin type isn't defined in any of them.  This is common for types
>>> +     like "void".  */
>>> +  if (domain == VAR_DOMAIN)
>>> +    {
>>> +      struct gdbarch *gdbarch;
>>> +
>>> +      if (block == NULL)
>>> +	gdbarch = target_gdbarch ();
>>> +      else
>>> +	gdbarch = block_gdbarch (block);
>>> +      sym = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
>>> +      if (sym != NULL)
>>> +	return sym;
>>> +    }
>>
>> which just uses target_gdbarch.  This is wrong just about always in symbol-
>> related code, and on Cell multi-arch debugging it in effect always uses the
>> PowerPC architecture even while in a SPU frame.
>>
>> Note that while sometime the block architecture is used, this doesn't really
>> help here, since lookup_typename is nearly always called with a NULL block.
>>
>> As a quick fix to get Cell going again, the appended patch works for me
>> (by using get_current_arch () instead of target_gdbarch ()).  But this
>> isn't a real fix either.   I guess we should either:
>>
>> - Pass the intended target architecture alongside the intended language
>>   throughout the symbol resolution stack, or ...
>>
>> - Make sure we always have a current block when calling lookup_typename
>>
>> (Note that latter still isn't quite the same: e.g. when debugging code
>> without debug info, or code outside any objfile, we can never have a
>> current block; but we can still have a proper architecture detected
>> at runtime for the current frame.)
>>
>> Any thoughts on this?
>
> I'd be ok with adding a gdbarch parameter to lookup_symbol,
> and require at least one of block or gdbarch to be non-NULL.
>
> The symbol lookup code is a lot simpler when block == NULL,
> and handling all the different cases in one set of functions
> makes things more complex than they could otherwise be.
> One might then split things up into two paths underneath
> (one for block, one for arch).

I went through and played with adding gdbarch to the
symbol lookup routines. I pushed into some places that I didn't
I need to, just to see the effect.
I'll clean this up and resubmit in a bit.

This patch also allows block == NULL and gdbarch == NULL
in the call to lookup_symbol. Sometimes the caller doesn't have either
one and doesn't need either one. I'd prefer something else though:
It'd be cleaner to remove the choice and require the caller to use
routines that are more explicit.
Otherwise I suspect a subtle bug or two will creep in.
[IOW, if the lookup may be for an arch-specific symbol (e.g., primitive type)
then require the caller to use a routine that requires a non-NULL gdbarch.
Internal to symtab.c we can do whatever we want though.]

This patch also adds some const-correctness to gdbarch.*.
[It'll get split out of course.]
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7e6b6dc..8629984 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -4609,10 +4609,12 @@  standard_lookup (const char *name, const struct block *block,
 {
   /* Initialize it just to avoid a GCC false warning.  */
   struct block_symbol sym = {NULL, NULL};
+  const struct gdbarch *gdbarch = get_current_arch ();
 
   if (lookup_cached_symbol (name, domain, &sym.symbol, NULL))
     return sym.symbol;
-  sym = lookup_symbol_in_language (name, block, domain, language_c, 0);
+  sym = lookup_symbol_in_language (name, block, gdbarch, domain, language_c,
+				   NULL);
   cache_symbol (name, domain, sym.symbol, sym.block);
   return sym.symbol;
 }
@@ -5770,6 +5772,7 @@  static struct block_symbol
 ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			    const char *name,
                             const struct block *block,
+			    const struct gdbarch *gdbarch,
                             const domain_enum domain)
 {
   struct block_symbol sym;
@@ -5790,15 +5793,17 @@  ada_lookup_symbol_nonlocal (const struct language_defn *langdef,
      languages, we search the primitive types this late and only after
      having searched the global symbols without success.  */
 
-  if (domain == VAR_DOMAIN)
+  if (domain == VAR_DOMAIN
+      && (block != NULL || gdbarch != NULL))
     {
-      struct gdbarch *gdbarch;
+      const struct gdbarch *gdbarch_for_lookup;
 
-      if (block == NULL)
-	gdbarch = target_gdbarch ();
+      if (block != NULL)
+	gdbarch_for_lookup = block_gdbarch (block);
       else
-	gdbarch = block_gdbarch (block);
-      sym.symbol = language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
+	gdbarch_for_lookup = gdbarch;
+      sym.symbol = language_lookup_primitive_type_as_symbol
+	(langdef, gdbarch_for_lookup, name);
       if (sym.symbol != NULL)
 	return sym;
     }
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index c97057e..e6f64bc 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -458,6 +458,7 @@  get_tcb_types_info (void)
   struct type *call_type;
   struct atcb_fieldnos fieldnos;
   struct ada_tasks_pspace_data *pspace_data;
+  const struct gdbarch *gdbarch = target_gdbarch ();
 
   const char *atcb_name = "system__tasking__ada_task_control_block___XVE";
   const char *atcb_name_fixed = "system__tasking__ada_task_control_block";
@@ -470,23 +471,23 @@  get_tcb_types_info (void)
      C-like) lookups to get the first match.  */
 
   struct symbol *atcb_sym =
-    lookup_symbol_in_language (atcb_name, NULL, STRUCT_DOMAIN,
-			       language_c, NULL).symbol;
+    lookup_symbol_in_language (atcb_name, NULL, gdbarch,
+			       STRUCT_DOMAIN, language_c, NULL).symbol;
   const struct symbol *common_atcb_sym =
-    lookup_symbol_in_language (common_atcb_name, NULL, STRUCT_DOMAIN,
-			       language_c, NULL).symbol;
+    lookup_symbol_in_language (common_atcb_name, NULL, gdbarch,
+			       STRUCT_DOMAIN, language_c, NULL).symbol;
   const struct symbol *private_data_sym =
-    lookup_symbol_in_language (private_data_name, NULL, STRUCT_DOMAIN,
-			       language_c, NULL).symbol;
+    lookup_symbol_in_language (private_data_name, NULL, gdbarch,
+			       STRUCT_DOMAIN, language_c, NULL).symbol;
   const struct symbol *entry_call_record_sym =
-    lookup_symbol_in_language (entry_call_record_name, NULL, STRUCT_DOMAIN,
-			       language_c, NULL).symbol;
+    lookup_symbol_in_language (entry_call_record_name, NULL, gdbarch,
+			       STRUCT_DOMAIN, language_c, NULL).symbol;
 
   if (atcb_sym == NULL || atcb_sym->type == NULL)
     {
       /* In Ravenscar run-time libs, the  ATCB does not have a dynamic
          size, so the symbol name differs.  */
-      atcb_sym = lookup_symbol_in_language (atcb_name_fixed, NULL,
+      atcb_sym = lookup_symbol_in_language (atcb_name_fixed, NULL, gdbarch,
 					    STRUCT_DOMAIN, language_c,
 					    NULL).symbol;
 
@@ -863,8 +864,9 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = BMSYMBOL_VALUE_ADDRESS (msym);
 
       /* Try to get pointer type and array length from the symtab.  */
-      sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL, VAR_DOMAIN,
-				       language_c, NULL).symbol;
+      sym = lookup_symbol_in_language (KNOWN_TASKS_NAME, NULL,
+				       get_objfile_arch (msym.objfile),
+				       VAR_DOMAIN, language_c, NULL).symbol;
       if (sym != NULL)
 	{
 	  /* Validate.  */
@@ -908,8 +910,9 @@  ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
       data->known_tasks_addr = BMSYMBOL_VALUE_ADDRESS (msym);
       data->known_tasks_length = 1;
 
-      sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL, VAR_DOMAIN,
-				       language_c, NULL).symbol;
+      sym = lookup_symbol_in_language (KNOWN_TASKS_LIST, NULL,
+				       get_objfile_arch (msym.objfile),
+				       VAR_DOMAIN, language_c, NULL).symbol;
       if (sym != NULL && SYMBOL_VALUE_ADDRESS (sym) != 0)
 	{
 	  /* Validate.  */
diff --git a/gdb/alpha-mdebug-tdep.c b/gdb/alpha-mdebug-tdep.c
index a8a511b..4f82b12 100644
--- a/gdb/alpha-mdebug-tdep.c
+++ b/gdb/alpha-mdebug-tdep.c
@@ -107,7 +107,7 @@  find_proc_desc (CORE_ADDR pc)
 	   symbol reading.  */
 	sym = NULL;
       else
-	sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, LABEL_DOMAIN,
+	sym = lookup_symbol (MDEBUG_EFI_SYMBOL_NAME, b, NULL, LABEL_DOMAIN,
 			     0).symbol;
     }
 
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 817fa53..c05d0c4 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1557,7 +1557,8 @@  gen_static_field (struct gdbarch *gdbarch,
   else
     {
       const char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
-      struct symbol *sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0).symbol;
+      struct symbol *sym
+	= lookup_symbol_for_arch (phys_name, gdbarch, VAR_DOMAIN).symbol;
 
       if (sym)
 	{
@@ -1651,7 +1652,7 @@  gen_maybe_namespace_elt (struct expression *exp,
   struct block_symbol sym;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    block_for_pc (ax->scope),
+				    block_for_pc (ax->scope), exp->gdbarch,
 				    VAR_DOMAIN);
 
   if (sym.symbol == NULL)
diff --git a/gdb/c-exp.y b/gdb/c-exp.y
index 351505e..5e80803 100644
--- a/gdb/c-exp.y
+++ b/gdb/c-exp.y
@@ -937,8 +937,8 @@  block	:	BLOCKNAME
 
 block	:	block COLONCOLON name
 			{ struct symbol *tem
-			    = lookup_symbol (copy_name ($3), $1,
-					     VAR_DOMAIN, NULL).symbol;
+			    = lookup_symbol_from_block (copy_name ($3), $1,
+							VAR_DOMAIN).symbol;
 
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
@@ -963,8 +963,8 @@  variable:	name_not_typename ENTRY
 
 variable:	block COLONCOLON name
 			{ struct block_symbol sym
-			    = lookup_symbol (copy_name ($3), $1,
-					     VAR_DOMAIN, NULL);
+			    = lookup_symbol_from_block (copy_name ($3), $1,
+							VAR_DOMAIN);
 
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
@@ -1038,6 +1038,7 @@  variable:	qualified_name
 
 			  sym
 			    = lookup_symbol (name, (const struct block *) NULL,
+					     parse_gdbarch (pstate),
 					     VAR_DOMAIN, NULL).symbol;
 			  if (sym)
 			    {
@@ -1334,7 +1335,8 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 						0); }
 	|	STRUCT name
 			{ $$ = lookup_struct (copy_name ($2),
-					      expression_context_block); }
+					      expression_context_block,
+					      parse_gdbarch (pstate)); }
 	|	STRUCT COMPLETE
 			{
 			  mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
@@ -1348,7 +1350,8 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			}
 	|	CLASS name
 			{ $$ = lookup_struct (copy_name ($2),
-					      expression_context_block); }
+					      expression_context_block,
+					      parse_gdbarch (pstate)); }
 	|	CLASS COMPLETE
 			{
 			  mark_completion_tag (TYPE_CODE_STRUCT, "", 0);
@@ -1362,7 +1365,8 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			}
 	|	UNION name
 			{ $$ = lookup_union (copy_name ($2),
-					     expression_context_block); }
+					     expression_context_block,
+					     parse_gdbarch (pstate)); }
 	|	UNION COMPLETE
 			{
 			  mark_completion_tag (TYPE_CODE_UNION, "", 0);
@@ -1376,7 +1380,8 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			}
 	|	ENUM name
 			{ $$ = lookup_enum (copy_name ($2),
-					    expression_context_block); }
+					    expression_context_block,
+					    parse_gdbarch (pstate)); }
 	|	ENUM COMPLETE
 			{
 			  mark_completion_tag (TYPE_CODE_ENUM, "", 0);
@@ -1408,8 +1413,9 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
                    reduced; template recognition happens by lookahead
                    in the token processing code in yylex. */
 	|	TEMPLATE name '<' type '>'
-			{ $$ = lookup_template_type(copy_name($2), $4,
-						    expression_context_block);
+			{ $$ = lookup_template_type (copy_name($2), $4,
+						     expression_context_block,
+						     parse_gdbarch (pstate));
 			}
 	| const_or_volatile_or_space_identifier_noopt typebase
 			{ $$ = follow_types ($2); }
@@ -1649,6 +1655,7 @@  name_not_typename :	NAME
 			  $$.stoken = $1;
 			  $$.sym = lookup_symbol ($1.ptr,
 						  expression_context_block,
+						  parse_gdbarch (pstate),
 						  VAR_DOMAIN,
 						  &is_a_field_of_this);
 			  $$.is_a_field_of_this
@@ -2812,7 +2819,7 @@  lex_one_token (struct parser_state *par_state, int *is_quoted_name)
 	    struct field_of_this_result is_a_field_of_this;
 
 	    if (lookup_symbol (copy, expression_context_block,
-			       VAR_DOMAIN,
+			       parse_gdbarch (par_state), VAR_DOMAIN,
 			       (parse_language (par_state)->la_language
 			        == language_cplus ? &is_a_field_of_this
 				: NULL)).symbol
@@ -2882,7 +2889,7 @@  classify_name (struct parser_state *par_state, const struct block *block,
      we can refer to it unconditionally below.  */
   memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
-  bsym = lookup_symbol (copy, block, VAR_DOMAIN,
+  bsym = lookup_symbol (copy, block, parse_gdbarch (par_state), VAR_DOMAIN,
 			parse_language (par_state)->la_name_of_this
 			? &is_a_field_of_this : NULL);
 
@@ -2903,10 +2910,8 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	  && TYPE_FN_FIELD_CONSTRUCTOR (is_a_field_of_this.fn_field->fn_fields,
 					0))
 	{
-	  struct field_of_this_result inner_is_a_field_of_this;
-
-	  bsym = lookup_symbol (copy, block, STRUCT_DOMAIN,
-				&inner_is_a_field_of_this);
+	  bsym = lookup_symbol (copy, block, parse_gdbarch (par_state),
+				STRUCT_DOMAIN, NULL);
 	  if (bsym.symbol != NULL)
 	    {
 	      yylval.tsym.type = SYMBOL_TYPE (bsym.symbol);
@@ -2948,7 +2953,8 @@  classify_name (struct parser_state *par_state, const struct block *block,
 	  struct symbol *sym;
 
 	  yylval.theclass.theclass = Class;
-	  sym = lookup_struct_typedef (copy, expression_context_block, 1);
+	  sym = lookup_struct_typedef (copy, expression_context_block,
+				       parse_gdbarch (par_state), 1);
 	  if (sym)
 	    yylval.theclass.type = SYMBOL_TYPE (sym);
 	  return CLASSNAME;
diff --git a/gdb/c-valprint.c b/gdb/c-valprint.c
index 80a75d7..feef955 100644
--- a/gdb/c-valprint.c
+++ b/gdb/c-valprint.c
@@ -203,7 +203,7 @@  print_unpacked_pointer (struct type *type, struct type *elttype,
 
 	  if (msymbol.minsym != NULL)
 	    wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME(msymbol.minsym), block,
-				  VAR_DOMAIN, &is_this_fld).symbol;
+				  gdbarch, VAR_DOMAIN, &is_this_fld).symbol;
 
 	  if (wsym)
 	    {
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 355b063..9684f40 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -29,6 +29,7 @@ 
 #include "exceptions.h"
 #include "gdbtypes.h"
 #include "dwarf2loc.h"
+#include "arch-utils.h"
 
 
 
@@ -330,7 +331,8 @@  convert_symbol_sym (struct compile_c_instance *context, const char *identifier,
     {
       struct block_symbol global_sym;
 
-      global_sym = lookup_symbol (identifier, NULL, domain, NULL);
+      global_sym = lookup_symbol (identifier, NULL,
+				  block_gdbarch (static_block), domain, NULL);
       /* If the outer symbol is in the static block, we ignore it, as
 	 it cannot be referenced.  */
       if (global_sym.symbol != NULL
@@ -446,7 +448,8 @@  gcc_convert_symbol (void *datum,
     {
       struct block_symbol sym;
 
-      sym = lookup_symbol (identifier, context->base.block, domain, NULL);
+      sym = lookup_symbol (identifier, context->base.block,
+			   get_current_arch (), domain, NULL);
       if (sym.symbol != NULL)
 	{
 	  convert_symbol_sym (context, identifier, sym, domain);
@@ -495,7 +498,7 @@  gcc_symbol_address (void *datum, struct gcc_c_context *gcc_context,
       struct symbol *sym;
 
       /* We only need global functions here.  */
-      sym = lookup_symbol (identifier, NULL, VAR_DOMAIN, NULL).symbol;
+      sym = lookup_symbol (identifier, NULL, NULL, VAR_DOMAIN, NULL).symbol;
       if (sym != NULL && SYMBOL_CLASS (sym) == LOC_BLOCK)
 	{
 	  if (compile_debug)
diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 0657a52..9a3b3ac 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -2008,6 +2008,9 @@  cp_new_demangle_parse_info (void)
   struct demangle_parse_info *info;
 
   info = malloc (sizeof (struct demangle_parse_info));
+  /* For our purposes, target_gdbarch should suffice.  We don't need
+     primitive type sizes, just names.  */
+  info->gdbarch = target_gdbarch ();
   info->info = NULL;
   info->tree = NULL;
   obstack_init (&info->obstack);
@@ -2205,7 +2208,7 @@  main (int argc, char **argv)
 	      printf ("%s\n", buf);
 	    continue;
 	  }
-	result = cp_demangled_name_to_comp (str2, &errmsg);
+	result = cp_demangled_name_to_comp (str2, NULL, &errmsg);
 	if (result == NULL)
 	  {
 	    fputs (errmsg, stderr);
@@ -2226,7 +2229,7 @@  main (int argc, char **argv)
       }
   else
     {
-      result = cp_demangled_name_to_comp (argv[arg], &errmsg);
+      result = cp_demangled_name_to_comp (argv[arg], NULL, &errmsg);
       if (result == NULL)
 	{
 	  fputs (errmsg, stderr);
diff --git a/gdb/cp-namespace.c b/gdb/cp-namespace.c
index b8b19ed..3750947 100644
--- a/gdb/cp-namespace.c
+++ b/gdb/cp-namespace.c
@@ -153,15 +153,16 @@  cp_basic_lookup_symbol (const char *name, const struct block *block,
    NAME is guaranteed to not have any scope (no "::") in its name, though
    if for example NAME is a template spec then "::" may appear in the
    argument list.
-   If LANGDEF is non-NULL then try to lookup NAME as a primitive type in
-   that language.  Normally we wouldn't need LANGDEF but fortran also uses
-   this code.
+   If LANGDEF is non-NULL, and either BLOCK or GDBARCH is non-NULL,
+   then try to lookup NAME as a primitive type in that language.
+   Normally we wouldn't need LANGDEF but fortran also uses this code.
    If SEARCH is non-zero then see if we can determine "this" from BLOCK, and
    if so then also search for NAME in that class.  */
 
 static struct block_symbol
 cp_lookup_bare_symbol (const struct language_defn *langdef,
 		       const char *name, const struct block *block,
+		       const struct gdbarch *gdbarch,
 		       const domain_enum domain, int search)
 {
   struct block_symbol sym;
@@ -177,21 +178,29 @@  cp_lookup_bare_symbol (const struct language_defn *langdef,
     return sym;
 
   /* If we didn't find a definition for a builtin type in the static block,
-     search for it now.  This is actually the right thing to do and can be
-     a massive performance win.  E.g., when debugging a program with lots of
-     shared libraries we could search all of them only to find out the
-     builtin type isn't defined in any of them.  This is common for types
-     like "void".  */
-  if (langdef != NULL && domain == VAR_DOMAIN)
+     and we're passed a gdbarch so we can look up its primitive types,
+     search for it now.  This is actually the right thing to do.
+     E.g., imagine a program compiled with -fshort-double or whatever,
+     but this compilation unit wasn't.  If we didn't find the primitive type
+     in the current static block we want to find it now, before searching any
+     other compilation units.
+     And it can be a massive performance win.  E.g., when debugging a program
+     with lots of shared libraries we could search all of them only to find
+     out the builtin type isn't defined in any of them.  This is common for
+     types like "void".  */
+  if (langdef != NULL
+      && domain == VAR_DOMAIN
+      && (block != NULL || gdbarch != NULL))
     {
-      struct gdbarch *gdbarch;
+      const struct gdbarch *gdbarch_for_lookup;
 
-      if (block == NULL)
-	gdbarch = target_gdbarch ();
+      if (block != NULL)
+	gdbarch_for_lookup = block_gdbarch (block);
       else
-	gdbarch = block_gdbarch (block);
+	gdbarch_for_lookup = gdbarch;
       sym.symbol
-	= language_lookup_primitive_type_as_symbol (langdef, gdbarch, name);
+	= language_lookup_primitive_type_as_symbol (langdef,
+						    gdbarch_for_lookup, name);
       sym.block = NULL;
       if (sym.symbol != NULL)
 	return sym;
@@ -299,6 +308,7 @@  cp_search_static_and_baseclasses (const char *name,
 static struct block_symbol
 cp_lookup_symbol_in_namespace (const char *the_namespace, const char *name,
 			       const struct block *block,
+			       const struct gdbarch *gdbarch,
 			       const domain_enum domain, int search)
 {
   char *concatenated_name = NULL;
@@ -318,7 +328,7 @@  cp_lookup_symbol_in_namespace (const char *the_namespace, const char *name,
 
   prefix_len = cp_entire_prefix_len (name);
   if (prefix_len == 0)
-    return cp_lookup_bare_symbol (NULL, name, block, domain, search);
+    return cp_lookup_bare_symbol (NULL, name, block, gdbarch, domain, search);
 
   /* This would be simpler if we just called cp_lookup_nested_symbol
      at this point.  But that would require first looking up the containing
@@ -396,7 +406,7 @@  cp_lookup_symbol_via_imports (const char *scope,
   /* First, try to find the symbol in the given namespace if requested.  */
   if (search_scope_first)
     sym = cp_lookup_symbol_in_namespace (scope, name,
-					 block, domain, 1);
+					 block, NULL, domain, 1);
 
   if (sym.symbol != NULL)
     return sym;
@@ -439,7 +449,7 @@  cp_lookup_symbol_via_imports (const char *scope,
 			 ? current->alias : current->declaration) == 0)
 	    sym = cp_lookup_symbol_in_namespace (current->import_src,
 						 current->declaration,
-						 block, domain, 1);
+						 block, NULL, domain, 1);
 
 	  /* If this is a DECLARATION_ONLY search or a symbol was found
 	     or this import statement was an import declaration, the
@@ -473,7 +483,7 @@  cp_lookup_symbol_via_imports (const char *scope,
 	    {
 	      sym = cp_lookup_symbol_in_namespace (scope,
 						   current->import_src,
-						   block, domain, 1);
+						   block, NULL, domain, 1);
 	    }
 	  else if (current->alias == NULL)
 	    {
@@ -645,6 +655,7 @@  cp_lookup_symbol_via_all_imports (const char *scope, const char *name,
 
 /* Searches for NAME in the current namespace, and by applying
    relevant import statements belonging to BLOCK and its parents.
+   GDBARCH is used when BLOCK is NULL and NAME is a primitive type.
    SCOPE is the namespace scope of the context in which the search is
    being evaluated.  */
 
@@ -652,6 +663,7 @@  struct block_symbol
 cp_lookup_symbol_namespace (const char *scope,
                             const char *name,
                             const struct block *block,
+			    const struct gdbarch *gdbarch,
                             const domain_enum domain)
 {
   struct block_symbol sym;
@@ -665,7 +677,7 @@  cp_lookup_symbol_namespace (const char *scope,
     }
 
   /* First, try to find the symbol in the given namespace.  */
-  sym = cp_lookup_symbol_in_namespace (scope, name, block, domain, 1);
+  sym = cp_lookup_symbol_in_namespace (scope, name, block, gdbarch, domain, 1);
 
   /* Search for name in namespaces imported to this and parent blocks.  */
   if (sym.symbol == NULL)
@@ -700,6 +712,7 @@  static struct block_symbol
 lookup_namespace_scope (const struct language_defn *langdef,
 			const char *name,
 			const struct block *block,
+			const struct gdbarch *gdbarch,
 			const domain_enum domain,
 			const char *scope,
 			int scope_len)
@@ -720,7 +733,7 @@  lookup_namespace_scope (const struct language_defn *langdef,
 	  new_scope_len += 2;
 	}
       new_scope_len += cp_find_first_component (scope + new_scope_len);
-      sym = lookup_namespace_scope (langdef, name, block, domain,
+      sym = lookup_namespace_scope (langdef, name, block, gdbarch, domain,
 				    scope, new_scope_len);
       if (sym.symbol != NULL)
 	return sym;
@@ -731,32 +744,37 @@  lookup_namespace_scope (const struct language_defn *langdef,
 
      If we there is no scope and we know we have a bare symbol, then short
      circuit everything and call cp_lookup_bare_symbol directly.
-     This isn't an optimization, rather it allows us to pass LANGDEF which
-     is needed for primitive type lookup.  The test doesn't have to be
+     This isn't an optimization, rather it allows us to pass LANGDEF, GDBARCH
+     which is needed for primitive type lookup.  The test doesn't have to be
      perfect: if NAME is a bare symbol that our test doesn't catch (e.g., a
      template symbol with "::" in the argument list) then
      cp_lookup_symbol_in_namespace will catch it.  */
 
   if (scope_len == 0 && strchr (name, ':') == NULL)
-    return cp_lookup_bare_symbol (langdef, name, block, domain, 1);
+    return cp_lookup_bare_symbol (langdef, name, block, gdbarch, domain, 1);
 
   the_namespace = alloca (scope_len + 1);
   strncpy (the_namespace, scope, scope_len);
   the_namespace[scope_len] = '\0';
   return cp_lookup_symbol_in_namespace (the_namespace, name,
-					block, domain, 1);
+					block, gdbarch, domain, 1);
 }
 
 /* The C++-specific version of name lookup for static and global
    names.  This makes sure that names get looked for in all namespaces
-   that are in scope.  NAME is the natural name of the symbol that
-   we're looking for, BLOCK is the block that we're searching within,
+   that are in scope.
+   NAME is the natural name of the symbol that we're looking for.
+   BLOCK is the block that we're searching within.
+   GDBARCH is for looking up primitive types and is used if BLOCK is NULL.
+   Both BLOCK and GDBARCH may be NULL, in which case lookup of primitive types
+   is skipped.
    DOMAIN says what kind of symbols we're looking for.  */
 
 struct block_symbol
 cp_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			   const char *name,
 			   const struct block *block,
+			   const struct gdbarch *gdbarch,
 			   const domain_enum domain)
 {
   struct block_symbol sym;
@@ -773,7 +791,8 @@  cp_lookup_symbol_nonlocal (const struct language_defn *langdef,
 
   /* First, try to find the symbol in the given namespace, and all
      containing namespaces.  */
-  sym = lookup_namespace_scope (langdef, name, block, domain, scope, 0);
+  sym = lookup_namespace_scope (langdef, name, block, gdbarch, domain, scope,
+				0);
 
   /* Search for name in namespaces imported to this and parent blocks.  */
   if (sym.symbol == NULL)
diff --git a/gdb/cp-support.c b/gdb/cp-support.c
index d3e26ad..eb03425 100644
--- a/gdb/cp-support.c
+++ b/gdb/cp-support.c
@@ -176,7 +176,7 @@  inspect_type (struct demangle_parse_info *info,
 
   TRY
     {
-      sym = lookup_symbol (name, 0, VAR_DOMAIN, 0).symbol;
+      sym = lookup_symbol (name, 0, info->gdbarch, VAR_DOMAIN, 0).symbol;
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -458,7 +458,8 @@  replace_typedefs (struct demangle_parse_info *info,
 	      sym = NULL;
 	      TRY
 		{
-		  sym = lookup_symbol (local_name, 0, VAR_DOMAIN, 0).symbol;
+		  sym = lookup_symbol (local_name, 0, info->gdbarch,
+				       VAR_DOMAIN, 0).symbol;
 		}
 	      CATCH (except, RETURN_MASK_ALL)
 		{
@@ -1455,7 +1456,7 @@  cp_lookup_rtti_type (const char *name, struct block *block)
 
   /* Use VAR_DOMAIN here as NAME may be a typedef.  PR 18141, 18417.
      Classes "live" in both STRUCT_DOMAIN and VAR_DOMAIN.  */
-  rtti_sym = lookup_symbol (name, block, VAR_DOMAIN, NULL).symbol;
+  rtti_sym = lookup_symbol (name, block, NULL, VAR_DOMAIN, NULL).symbol;
 
   if (rtti_sym == NULL)
     {
diff --git a/gdb/cp-support.h b/gdb/cp-support.h
index 12d8d80..ed72dd3 100644
--- a/gdb/cp-support.h
+++ b/gdb/cp-support.h
@@ -50,6 +50,9 @@  struct using_direct;
 
 struct demangle_parse_info
 {
+  /* The gdbarch, for primitive type lookup.  */
+  const struct gdbarch *gdbarch;
+
   /* The memory used during the parse.  */
   struct demangle_info *info;
 
@@ -106,12 +109,14 @@  extern struct block_symbol cp_lookup_symbol_nonlocal
      (const struct language_defn *langdef,
       const char *name,
       const struct block *block,
+      const struct gdbarch *gdbarch,
       const domain_enum domain);
 
 extern struct block_symbol
   cp_lookup_symbol_namespace (const char *the_namespace,
 			      const char *name,
 			      const struct block *block,
+			      const struct gdbarch *gdbarch,
 			      const domain_enum domain);
 
 extern struct block_symbol cp_lookup_symbol_imports_or_template
diff --git a/gdb/d-exp.y b/gdb/d-exp.y
index dd87d8a..afeb17c 100644
--- a/gdb/d-exp.y
+++ b/gdb/d-exp.y
@@ -471,7 +471,8 @@  PrimaryExpression:
 		  struct block_symbol sym;
 
 		  /* Handle VAR, which could be local or global.  */
-		  sym = lookup_symbol (copy, expression_context_block, VAR_DOMAIN,
+		  sym = lookup_symbol (copy, expression_context_block,
+				       parse_gdbarch (pstate), VAR_DOMAIN,
 				       &is_a_field_of_this);
 		  if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
 		    {
@@ -534,8 +535,9 @@  PrimaryExpression:
 			      make_cleanup (xfree, name);
 
 			      sym =
-				lookup_symbol (name, (const struct block *) NULL,
-					       VAR_DOMAIN, NULL);
+				lookup_symbol_for_arch (name,
+							parse_gdbarch (pstate),
+							VAR_DOMAIN);
 			      if (sym.symbol)
 				{
 				  write_exp_elt_opcode (pstate, OP_VAR_VALUE);
@@ -1407,11 +1409,11 @@  classify_name (struct parser_state *par_state, const struct block *block)
 {
   struct block_symbol sym;
   char *copy;
-  struct field_of_this_result is_a_field_of_this;
 
   copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy, block, parse_gdbarch (par_state), VAR_DOMAIN,
+		       NULL);
   if (sym.symbol && SYMBOL_CLASS (sym.symbol) == LOC_TYPEDEF)
     {
       yylval.tsym.type = SYMBOL_TYPE (sym.symbol);
@@ -1420,9 +1422,11 @@  classify_name (struct parser_state *par_state, const struct block *block)
   else if (sym.symbol == NULL)
     {
       /* Look-up first for a module name, then a type.  */
-      sym = lookup_symbol (copy, block, MODULE_DOMAIN, NULL);
+      sym = lookup_symbol (copy, block, parse_gdbarch (par_state),
+			   MODULE_DOMAIN, NULL);
       if (sym.symbol == NULL)
-	sym = lookup_symbol (copy, block, STRUCT_DOMAIN, NULL);
+	sym = lookup_symbol (copy, block, parse_gdbarch (par_state),
+			     STRUCT_DOMAIN, NULL);
 
       if (sym.symbol != NULL)
 	{
diff --git a/gdb/d-lang.h b/gdb/d-lang.h
index 8b8b5dc..cbdb772 100644
--- a/gdb/d-lang.h
+++ b/gdb/d-lang.h
@@ -73,6 +73,7 @@  extern const struct builtin_d_type *builtin_d_type (struct gdbarch *);
 extern struct block_symbol d_lookup_symbol_nonlocal (const struct language_defn *,
 						     const char *,
 						     const struct block *,
+						     const struct gdbarch *,
 						     const domain_enum);
 
 extern struct block_symbol d_lookup_nested_symbol (struct type *, const char *,
diff --git a/gdb/d-namespace.c b/gdb/d-namespace.c
index bed8d5b..6097873 100644
--- a/gdb/d-namespace.c
+++ b/gdb/d-namespace.c
@@ -549,6 +549,7 @@  struct block_symbol
 d_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			  const char *name,
 			  const struct block *block,
+			  const struct gdbarch *gdbarch,
 			  const domain_enum domain)
 {
   struct block_symbol sym;
diff --git a/gdb/eval.c b/gdb/eval.c
index a668e76..e60a2d2 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1492,6 +1492,7 @@  evaluate_subexp_standard (struct type *expect_type,
 	      function = cp_lookup_symbol_namespace (TYPE_TAG_NAME (type),
 						     name,
 						     get_selected_block (0),
+						     exp->gdbarch,
 						     VAR_DOMAIN).symbol;
 	      if (function == NULL)
 		error (_("No symbol \"%s\" in namespace \"%s\"."), 
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 56629dc..eb32693 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1213,6 +1213,7 @@  yylex (void)
 	memset (&is_a_field_of_this, 0, sizeof (is_a_field_of_this));
 
 	result = lookup_symbol (tmp, expression_context_block,
+				parse_gdbarch (pstate),
 				lookup_domains[i],
 				parse_language (pstate)->la_language
 				== language_cplus
diff --git a/gdb/ft32-tdep.c b/gdb/ft32-tdep.c
index 2e5deca..3e4ddb7 100644
--- a/gdb/ft32-tdep.c
+++ b/gdb/ft32-tdep.c
@@ -250,7 +250,8 @@  ft32_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  plg_end = ft32_analyze_prologue (func_addr,
 					   func_end, &cache, gdbarch);
 	  /* Found a function.  */
-	  sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+	  sym = lookup_symbol (func_name, NULL, gdbarch, VAR_DOMAIN,
+			       NULL).symbol;
 	  /* Don't use line number debug info for assembly source files.  */
 	  if ((sym != NULL) && SYMBOL_LANGUAGE (sym) != language_asm)
 	    {
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 0d4142b..446184d 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -1408,7 +1408,7 @@  gdbarch_tdep (struct gdbarch *gdbarch)
 
 
 const struct bfd_arch_info *
-gdbarch_bfd_arch_info (struct gdbarch *gdbarch)
+gdbarch_bfd_arch_info (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1417,7 +1417,7 @@  gdbarch_bfd_arch_info (struct gdbarch *gdbarch)
 }
 
 enum bfd_endian
-gdbarch_byte_order (struct gdbarch *gdbarch)
+gdbarch_byte_order (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1426,7 +1426,7 @@  gdbarch_byte_order (struct gdbarch *gdbarch)
 }
 
 enum bfd_endian
-gdbarch_byte_order_for_code (struct gdbarch *gdbarch)
+gdbarch_byte_order_for_code (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1435,7 +1435,7 @@  gdbarch_byte_order_for_code (struct gdbarch *gdbarch)
 }
 
 enum gdb_osabi
-gdbarch_osabi (struct gdbarch *gdbarch)
+gdbarch_osabi (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1444,7 +1444,7 @@  gdbarch_osabi (struct gdbarch *gdbarch)
 }
 
 const struct target_desc *
-gdbarch_target_desc (struct gdbarch *gdbarch)
+gdbarch_target_desc (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1453,7 +1453,7 @@  gdbarch_target_desc (struct gdbarch *gdbarch)
 }
 
 int
-gdbarch_bits_big_endian (struct gdbarch *gdbarch)
+gdbarch_bits_big_endian (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of bits_big_endian, invalid_p == 0 */
@@ -1470,7 +1470,7 @@  set_gdbarch_bits_big_endian (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_short_bit (struct gdbarch *gdbarch)
+gdbarch_short_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of short_bit, invalid_p == 0 */
@@ -1487,7 +1487,7 @@  set_gdbarch_short_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_int_bit (struct gdbarch *gdbarch)
+gdbarch_int_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of int_bit, invalid_p == 0 */
@@ -1504,7 +1504,7 @@  set_gdbarch_int_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_long_bit (struct gdbarch *gdbarch)
+gdbarch_long_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of long_bit, invalid_p == 0 */
@@ -1521,7 +1521,7 @@  set_gdbarch_long_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_long_long_bit (struct gdbarch *gdbarch)
+gdbarch_long_long_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of long_long_bit, invalid_p == 0 */
@@ -1538,7 +1538,7 @@  set_gdbarch_long_long_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_long_long_align_bit (struct gdbarch *gdbarch)
+gdbarch_long_long_align_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of long_long_align_bit, invalid_p == 0 */
@@ -1555,7 +1555,7 @@  set_gdbarch_long_long_align_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_half_bit (struct gdbarch *gdbarch)
+gdbarch_half_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of half_bit, invalid_p == 0 */
@@ -1572,7 +1572,7 @@  set_gdbarch_half_bit (struct gdbarch *gdbarch,
 }
 
 const struct floatformat **
-gdbarch_half_format (struct gdbarch *gdbarch)
+gdbarch_half_format (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1588,7 +1588,7 @@  set_gdbarch_half_format (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_float_bit (struct gdbarch *gdbarch)
+gdbarch_float_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of float_bit, invalid_p == 0 */
@@ -1605,7 +1605,7 @@  set_gdbarch_float_bit (struct gdbarch *gdbarch,
 }
 
 const struct floatformat **
-gdbarch_float_format (struct gdbarch *gdbarch)
+gdbarch_float_format (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1621,7 +1621,7 @@  set_gdbarch_float_format (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_double_bit (struct gdbarch *gdbarch)
+gdbarch_double_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of double_bit, invalid_p == 0 */
@@ -1638,7 +1638,7 @@  set_gdbarch_double_bit (struct gdbarch *gdbarch,
 }
 
 const struct floatformat **
-gdbarch_double_format (struct gdbarch *gdbarch)
+gdbarch_double_format (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1654,7 +1654,7 @@  set_gdbarch_double_format (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_long_double_bit (struct gdbarch *gdbarch)
+gdbarch_long_double_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of long_double_bit, invalid_p == 0 */
@@ -1671,7 +1671,7 @@  set_gdbarch_long_double_bit (struct gdbarch *gdbarch,
 }
 
 const struct floatformat **
-gdbarch_long_double_format (struct gdbarch *gdbarch)
+gdbarch_long_double_format (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -1687,7 +1687,7 @@  set_gdbarch_long_double_format (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_ptr_bit (struct gdbarch *gdbarch)
+gdbarch_ptr_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of ptr_bit, invalid_p == 0 */
@@ -1704,7 +1704,7 @@  set_gdbarch_ptr_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_addr_bit (struct gdbarch *gdbarch)
+gdbarch_addr_bit (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -1722,7 +1722,7 @@  set_gdbarch_addr_bit (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch)
+gdbarch_dwarf2_addr_size (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -1740,7 +1740,7 @@  set_gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_char_signed (struct gdbarch *gdbarch)
+gdbarch_char_signed (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -1758,7 +1758,7 @@  set_gdbarch_char_signed (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_read_pc_p (struct gdbarch *gdbarch)
+gdbarch_read_pc_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->read_pc != NULL;
@@ -1782,7 +1782,7 @@  set_gdbarch_read_pc (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_write_pc_p (struct gdbarch *gdbarch)
+gdbarch_write_pc_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->write_pc != NULL;
@@ -1823,7 +1823,7 @@  set_gdbarch_virtual_frame_pointer (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_pseudo_register_read_p (struct gdbarch *gdbarch)
+gdbarch_pseudo_register_read_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->pseudo_register_read != NULL;
@@ -1847,7 +1847,7 @@  set_gdbarch_pseudo_register_read (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_pseudo_register_read_value_p (struct gdbarch *gdbarch)
+gdbarch_pseudo_register_read_value_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->pseudo_register_read_value != NULL;
@@ -1871,7 +1871,7 @@  set_gdbarch_pseudo_register_read_value (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_pseudo_register_write_p (struct gdbarch *gdbarch)
+gdbarch_pseudo_register_write_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->pseudo_register_write != NULL;
@@ -1895,7 +1895,7 @@  set_gdbarch_pseudo_register_write (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_num_regs (struct gdbarch *gdbarch)
+gdbarch_num_regs (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -1913,7 +1913,7 @@  set_gdbarch_num_regs (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_num_pseudo_regs (struct gdbarch *gdbarch)
+gdbarch_num_pseudo_regs (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of num_pseudo_regs, invalid_p == 0 */
@@ -1930,7 +1930,7 @@  set_gdbarch_num_pseudo_regs (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_ax_pseudo_register_collect_p (struct gdbarch *gdbarch)
+gdbarch_ax_pseudo_register_collect_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->ax_pseudo_register_collect != NULL;
@@ -1954,7 +1954,7 @@  set_gdbarch_ax_pseudo_register_collect (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_ax_pseudo_register_push_stack_p (struct gdbarch *gdbarch)
+gdbarch_ax_pseudo_register_push_stack_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->ax_pseudo_register_push_stack != NULL;
@@ -1978,7 +1978,7 @@  set_gdbarch_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_sp_regnum (struct gdbarch *gdbarch)
+gdbarch_sp_regnum (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of sp_regnum, invalid_p == 0 */
@@ -1995,7 +1995,7 @@  set_gdbarch_sp_regnum (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_pc_regnum (struct gdbarch *gdbarch)
+gdbarch_pc_regnum (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of pc_regnum, invalid_p == 0 */
@@ -2012,7 +2012,7 @@  set_gdbarch_pc_regnum (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_ps_regnum (struct gdbarch *gdbarch)
+gdbarch_ps_regnum (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of ps_regnum, invalid_p == 0 */
@@ -2029,7 +2029,7 @@  set_gdbarch_ps_regnum (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_fp0_regnum (struct gdbarch *gdbarch)
+gdbarch_fp0_regnum (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of fp0_regnum, invalid_p == 0 */
@@ -2131,7 +2131,7 @@  set_gdbarch_register_name (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_register_type_p (struct gdbarch *gdbarch)
+gdbarch_register_type_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->register_type != NULL;
@@ -2155,7 +2155,7 @@  set_gdbarch_register_type (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dummy_id_p (struct gdbarch *gdbarch)
+gdbarch_dummy_id_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->dummy_id != NULL;
@@ -2179,7 +2179,7 @@  set_gdbarch_dummy_id (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_deprecated_fp_regnum (struct gdbarch *gdbarch)
+gdbarch_deprecated_fp_regnum (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of deprecated_fp_regnum, invalid_p == 0 */
@@ -2196,7 +2196,7 @@  set_gdbarch_deprecated_fp_regnum (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_push_dummy_call_p (struct gdbarch *gdbarch)
+gdbarch_push_dummy_call_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->push_dummy_call != NULL;
@@ -2220,7 +2220,7 @@  set_gdbarch_push_dummy_call (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_call_dummy_location (struct gdbarch *gdbarch)
+gdbarch_call_dummy_location (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of call_dummy_location, invalid_p == 0 */
@@ -2237,7 +2237,7 @@  set_gdbarch_call_dummy_location (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_push_dummy_code_p (struct gdbarch *gdbarch)
+gdbarch_push_dummy_code_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->push_dummy_code != NULL;
@@ -2295,7 +2295,7 @@  set_gdbarch_print_float_info (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_print_vector_info_p (struct gdbarch *gdbarch)
+gdbarch_print_vector_info_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->print_vector_info != NULL;
@@ -2370,7 +2370,7 @@  set_gdbarch_cannot_store_register (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_get_longjmp_target_p (struct gdbarch *gdbarch)
+gdbarch_get_longjmp_target_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->get_longjmp_target != NULL;
@@ -2394,7 +2394,7 @@  set_gdbarch_get_longjmp_target (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_believe_pcc_promotion (struct gdbarch *gdbarch)
+gdbarch_believe_pcc_promotion (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -2512,7 +2512,7 @@  set_gdbarch_address_to_pointer (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_integer_to_address_p (struct gdbarch *gdbarch)
+gdbarch_integer_to_address_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->integer_to_address != NULL;
@@ -2536,7 +2536,7 @@  set_gdbarch_integer_to_address (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_return_value_p (struct gdbarch *gdbarch)
+gdbarch_return_value_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->return_value != NULL;
@@ -2594,7 +2594,7 @@  set_gdbarch_skip_prologue (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_skip_main_prologue_p (struct gdbarch *gdbarch)
+gdbarch_skip_main_prologue_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->skip_main_prologue != NULL;
@@ -2618,7 +2618,7 @@  set_gdbarch_skip_main_prologue (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_skip_entrypoint_p (struct gdbarch *gdbarch)
+gdbarch_skip_entrypoint_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->skip_entrypoint != NULL;
@@ -2693,7 +2693,7 @@  set_gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch)
+gdbarch_adjust_breakpoint_address_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->adjust_breakpoint_address != NULL;
@@ -2751,7 +2751,7 @@  set_gdbarch_memory_remove_breakpoint (struct gdbarch *gdbarch,
 }
 
 CORE_ADDR
-gdbarch_decr_pc_after_break (struct gdbarch *gdbarch)
+gdbarch_decr_pc_after_break (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of decr_pc_after_break, invalid_p == 0 */
@@ -2768,7 +2768,7 @@  set_gdbarch_decr_pc_after_break (struct gdbarch *gdbarch,
 }
 
 CORE_ADDR
-gdbarch_deprecated_function_start_offset (struct gdbarch *gdbarch)
+gdbarch_deprecated_function_start_offset (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of deprecated_function_start_offset, invalid_p == 0 */
@@ -2802,7 +2802,7 @@  set_gdbarch_remote_register_number (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_fetch_tls_load_module_address_p (struct gdbarch *gdbarch)
+gdbarch_fetch_tls_load_module_address_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->fetch_tls_load_module_address != NULL;
@@ -2826,7 +2826,7 @@  set_gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch,
 }
 
 CORE_ADDR
-gdbarch_frame_args_skip (struct gdbarch *gdbarch)
+gdbarch_frame_args_skip (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of frame_args_skip, invalid_p == 0 */
@@ -2843,7 +2843,7 @@  set_gdbarch_frame_args_skip (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_unwind_pc_p (struct gdbarch *gdbarch)
+gdbarch_unwind_pc_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->unwind_pc != NULL;
@@ -2867,7 +2867,7 @@  set_gdbarch_unwind_pc (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_unwind_sp_p (struct gdbarch *gdbarch)
+gdbarch_unwind_sp_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->unwind_sp != NULL;
@@ -2891,7 +2891,7 @@  set_gdbarch_unwind_sp (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_frame_num_args_p (struct gdbarch *gdbarch)
+gdbarch_frame_num_args_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->frame_num_args != NULL;
@@ -2915,7 +2915,7 @@  set_gdbarch_frame_num_args (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_frame_align_p (struct gdbarch *gdbarch)
+gdbarch_frame_align_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->frame_align != NULL;
@@ -2956,7 +2956,7 @@  set_gdbarch_stabs_argument_has_addr (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_frame_red_zone_size (struct gdbarch *gdbarch)
+gdbarch_frame_red_zone_size (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -3006,7 +3006,7 @@  set_gdbarch_addr_bits_remove (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_software_single_step_p (struct gdbarch *gdbarch)
+gdbarch_software_single_step_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->software_single_step != NULL;
@@ -3030,7 +3030,7 @@  set_gdbarch_software_single_step (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_single_step_through_delay_p (struct gdbarch *gdbarch)
+gdbarch_single_step_through_delay_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->single_step_through_delay != NULL;
@@ -3139,7 +3139,7 @@  set_gdbarch_stack_frame_destroyed_p (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_elf_make_msymbol_special_p (struct gdbarch *gdbarch)
+gdbarch_elf_make_msymbol_special_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->elf_make_msymbol_special != NULL;
@@ -3231,7 +3231,7 @@  set_gdbarch_adjust_dwarf2_line (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_cannot_step_breakpoint (struct gdbarch *gdbarch)
+gdbarch_cannot_step_breakpoint (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of cannot_step_breakpoint, invalid_p == 0 */
@@ -3248,7 +3248,7 @@  set_gdbarch_cannot_step_breakpoint (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch)
+gdbarch_have_nonsteppable_watchpoint (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of have_nonsteppable_watchpoint, invalid_p == 0 */
@@ -3265,7 +3265,7 @@  set_gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_address_class_type_flags_p (struct gdbarch *gdbarch)
+gdbarch_address_class_type_flags_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->address_class_type_flags != NULL;
@@ -3289,7 +3289,7 @@  set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch)
+gdbarch_address_class_type_flags_to_name_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->address_class_type_flags_to_name != NULL;
@@ -3313,7 +3313,7 @@  set_gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_address_class_name_to_type_flags_p (struct gdbarch *gdbarch)
+gdbarch_address_class_name_to_type_flags_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->address_class_name_to_type_flags != NULL;
@@ -3354,7 +3354,7 @@  set_gdbarch_register_reggroup_p (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_fetch_pointer_argument_p (struct gdbarch *gdbarch)
+gdbarch_fetch_pointer_argument_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->fetch_pointer_argument != NULL;
@@ -3378,7 +3378,7 @@  set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch)
+gdbarch_iterate_over_regset_sections_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->iterate_over_regset_sections != NULL;
@@ -3402,7 +3402,7 @@  set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_make_corefile_notes_p (struct gdbarch *gdbarch)
+gdbarch_make_corefile_notes_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->make_corefile_notes != NULL;
@@ -3426,7 +3426,7 @@  set_gdbarch_make_corefile_notes (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_elfcore_write_linux_prpsinfo_p (struct gdbarch *gdbarch)
+gdbarch_elfcore_write_linux_prpsinfo_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->elfcore_write_linux_prpsinfo != NULL;
@@ -3450,7 +3450,7 @@  set_gdbarch_elfcore_write_linux_prpsinfo (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_find_memory_regions_p (struct gdbarch *gdbarch)
+gdbarch_find_memory_regions_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->find_memory_regions != NULL;
@@ -3474,7 +3474,7 @@  set_gdbarch_find_memory_regions (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch)
+gdbarch_core_xfer_shared_libraries_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->core_xfer_shared_libraries != NULL;
@@ -3498,7 +3498,7 @@  set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch)
+gdbarch_core_xfer_shared_libraries_aix_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->core_xfer_shared_libraries_aix != NULL;
@@ -3522,7 +3522,7 @@  set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch)
+gdbarch_core_pid_to_str_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->core_pid_to_str != NULL;
@@ -3546,14 +3546,14 @@  set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch)
+gdbarch_gcore_bfd_target_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->gcore_bfd_target != 0;
 }
 
 const char *
-gdbarch_gcore_bfd_target (struct gdbarch *gdbarch)
+gdbarch_gcore_bfd_target (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -3571,7 +3571,7 @@  set_gdbarch_gcore_bfd_target (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_vtable_function_descriptors (struct gdbarch *gdbarch)
+gdbarch_vtable_function_descriptors (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of vtable_function_descriptors, invalid_p == 0 */
@@ -3588,7 +3588,7 @@  set_gdbarch_vtable_function_descriptors (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_vbit_in_delta (struct gdbarch *gdbarch)
+gdbarch_vbit_in_delta (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of vbit_in_delta, invalid_p == 0 */
@@ -3622,14 +3622,14 @@  set_gdbarch_skip_permanent_breakpoint (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_max_insn_length_p (struct gdbarch *gdbarch)
+gdbarch_max_insn_length_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->max_insn_length != 0;
 }
 
 ULONGEST
-gdbarch_max_insn_length (struct gdbarch *gdbarch)
+gdbarch_max_insn_length (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Check variable changed from pre-default.  */
@@ -3647,7 +3647,7 @@  set_gdbarch_max_insn_length (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch)
+gdbarch_displaced_step_copy_insn_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->displaced_step_copy_insn != NULL;
@@ -3688,7 +3688,7 @@  set_gdbarch_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_displaced_step_fixup_p (struct gdbarch *gdbarch)
+gdbarch_displaced_step_fixup_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->displaced_step_fixup != NULL;
@@ -3747,7 +3747,7 @@  set_gdbarch_displaced_step_location (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_relocate_instruction_p (struct gdbarch *gdbarch)
+gdbarch_relocate_instruction_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->relocate_instruction != NULL;
@@ -3772,7 +3772,7 @@  set_gdbarch_relocate_instruction (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_overlay_update_p (struct gdbarch *gdbarch)
+gdbarch_overlay_update_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->overlay_update != NULL;
@@ -3796,7 +3796,7 @@  set_gdbarch_overlay_update (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_core_read_description_p (struct gdbarch *gdbarch)
+gdbarch_core_read_description_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->core_read_description != NULL;
@@ -3820,7 +3820,7 @@  set_gdbarch_core_read_description (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_static_transform_name_p (struct gdbarch *gdbarch)
+gdbarch_static_transform_name_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->static_transform_name != NULL;
@@ -3844,7 +3844,7 @@  set_gdbarch_static_transform_name (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_sofun_address_maybe_missing (struct gdbarch *gdbarch)
+gdbarch_sofun_address_maybe_missing (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of sofun_address_maybe_missing, invalid_p == 0 */
@@ -3861,7 +3861,7 @@  set_gdbarch_sofun_address_maybe_missing (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_process_record_p (struct gdbarch *gdbarch)
+gdbarch_process_record_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->process_record != NULL;
@@ -3885,7 +3885,7 @@  set_gdbarch_process_record (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_process_record_signal_p (struct gdbarch *gdbarch)
+gdbarch_process_record_signal_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->process_record_signal != NULL;
@@ -3909,7 +3909,7 @@  set_gdbarch_process_record_signal (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_gdb_signal_from_target_p (struct gdbarch *gdbarch)
+gdbarch_gdb_signal_from_target_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->gdb_signal_from_target != NULL;
@@ -3933,7 +3933,7 @@  set_gdbarch_gdb_signal_from_target (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_gdb_signal_to_target_p (struct gdbarch *gdbarch)
+gdbarch_gdb_signal_to_target_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->gdb_signal_to_target != NULL;
@@ -3957,7 +3957,7 @@  set_gdbarch_gdb_signal_to_target (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_get_siginfo_type_p (struct gdbarch *gdbarch)
+gdbarch_get_siginfo_type_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->get_siginfo_type != NULL;
@@ -3981,7 +3981,7 @@  set_gdbarch_get_siginfo_type (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_record_special_symbol_p (struct gdbarch *gdbarch)
+gdbarch_record_special_symbol_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->record_special_symbol != NULL;
@@ -4005,7 +4005,7 @@  set_gdbarch_record_special_symbol (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_get_syscall_number_p (struct gdbarch *gdbarch)
+gdbarch_get_syscall_number_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->get_syscall_number != NULL;
@@ -4029,7 +4029,7 @@  set_gdbarch_get_syscall_number (struct gdbarch *gdbarch,
 }
 
 const char *
-gdbarch_xml_syscall_file (struct gdbarch *gdbarch)
+gdbarch_xml_syscall_file (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of xml_syscall_file, invalid_p == 0 */
@@ -4046,7 +4046,7 @@  set_gdbarch_xml_syscall_file (struct gdbarch *gdbarch,
 }
 
 struct syscalls_info *
-gdbarch_syscalls_info (struct gdbarch *gdbarch)
+gdbarch_syscalls_info (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of syscalls_info, invalid_p == 0 */
@@ -4063,7 +4063,7 @@  set_gdbarch_syscalls_info (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_integer_prefixes (struct gdbarch *gdbarch)
+gdbarch_stap_integer_prefixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_integer_prefixes, invalid_p == 0 */
@@ -4080,7 +4080,7 @@  set_gdbarch_stap_integer_prefixes (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_integer_suffixes (struct gdbarch *gdbarch)
+gdbarch_stap_integer_suffixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_integer_suffixes, invalid_p == 0 */
@@ -4097,7 +4097,7 @@  set_gdbarch_stap_integer_suffixes (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_register_prefixes (struct gdbarch *gdbarch)
+gdbarch_stap_register_prefixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_register_prefixes, invalid_p == 0 */
@@ -4114,7 +4114,7 @@  set_gdbarch_stap_register_prefixes (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_register_suffixes (struct gdbarch *gdbarch)
+gdbarch_stap_register_suffixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_register_suffixes, invalid_p == 0 */
@@ -4131,7 +4131,7 @@  set_gdbarch_stap_register_suffixes (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_register_indirection_prefixes (struct gdbarch *gdbarch)
+gdbarch_stap_register_indirection_prefixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_register_indirection_prefixes, invalid_p == 0 */
@@ -4148,7 +4148,7 @@  set_gdbarch_stap_register_indirection_prefixes (struct gdbarch *gdbarch,
 }
 
 const char *const *
-gdbarch_stap_register_indirection_suffixes (struct gdbarch *gdbarch)
+gdbarch_stap_register_indirection_suffixes (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_register_indirection_suffixes, invalid_p == 0 */
@@ -4165,7 +4165,7 @@  set_gdbarch_stap_register_indirection_suffixes (struct gdbarch *gdbarch,
 }
 
 const char *
-gdbarch_stap_gdb_register_prefix (struct gdbarch *gdbarch)
+gdbarch_stap_gdb_register_prefix (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_gdb_register_prefix, invalid_p == 0 */
@@ -4182,7 +4182,7 @@  set_gdbarch_stap_gdb_register_prefix (struct gdbarch *gdbarch,
 }
 
 const char *
-gdbarch_stap_gdb_register_suffix (struct gdbarch *gdbarch)
+gdbarch_stap_gdb_register_suffix (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of stap_gdb_register_suffix, invalid_p == 0 */
@@ -4199,7 +4199,7 @@  set_gdbarch_stap_gdb_register_suffix (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_stap_is_single_operand_p (struct gdbarch *gdbarch)
+gdbarch_stap_is_single_operand_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->stap_is_single_operand != NULL;
@@ -4223,7 +4223,7 @@  set_gdbarch_stap_is_single_operand (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_stap_parse_special_token_p (struct gdbarch *gdbarch)
+gdbarch_stap_parse_special_token_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->stap_parse_special_token != NULL;
@@ -4247,7 +4247,7 @@  set_gdbarch_stap_parse_special_token (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dtrace_parse_probe_argument_p (struct gdbarch *gdbarch)
+gdbarch_dtrace_parse_probe_argument_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->dtrace_parse_probe_argument != NULL;
@@ -4271,7 +4271,7 @@  set_gdbarch_dtrace_parse_probe_argument (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dtrace_probe_is_enabled_p (struct gdbarch *gdbarch)
+gdbarch_dtrace_probe_is_enabled_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->dtrace_probe_is_enabled != NULL;
@@ -4295,7 +4295,7 @@  set_gdbarch_dtrace_probe_is_enabled (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dtrace_enable_probe_p (struct gdbarch *gdbarch)
+gdbarch_dtrace_enable_probe_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->dtrace_enable_probe != NULL;
@@ -4319,7 +4319,7 @@  set_gdbarch_dtrace_enable_probe (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_dtrace_disable_probe_p (struct gdbarch *gdbarch)
+gdbarch_dtrace_disable_probe_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->dtrace_disable_probe != NULL;
@@ -4343,7 +4343,7 @@  set_gdbarch_dtrace_disable_probe (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_has_global_solist (struct gdbarch *gdbarch)
+gdbarch_has_global_solist (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of has_global_solist, invalid_p == 0 */
@@ -4360,7 +4360,7 @@  set_gdbarch_has_global_solist (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_has_global_breakpoints (struct gdbarch *gdbarch)
+gdbarch_has_global_breakpoints (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of has_global_breakpoints, invalid_p == 0 */
@@ -4445,7 +4445,7 @@  set_gdbarch_auto_wide_charset (struct gdbarch *gdbarch,
 }
 
 const char *
-gdbarch_solib_symbols_extension (struct gdbarch *gdbarch)
+gdbarch_solib_symbols_extension (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   if (gdbarch_debug >= 2)
@@ -4461,7 +4461,7 @@  set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch)
+gdbarch_has_dos_based_file_system (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of has_dos_based_file_system, invalid_p == 0 */
@@ -4495,7 +4495,7 @@  set_gdbarch_gen_return_address (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_info_proc_p (struct gdbarch *gdbarch)
+gdbarch_info_proc_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->info_proc != NULL;
@@ -4519,7 +4519,7 @@  set_gdbarch_info_proc (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_core_info_proc_p (struct gdbarch *gdbarch)
+gdbarch_core_info_proc_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->core_info_proc != NULL;
@@ -4560,7 +4560,7 @@  set_gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *gdbarch,
 }
 
 struct ravenscar_arch_ops *
-gdbarch_ravenscar_ops (struct gdbarch *gdbarch)
+gdbarch_ravenscar_ops (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   /* Skip verify of ravenscar_ops, invalid_p == 0 */
@@ -4628,7 +4628,7 @@  set_gdbarch_insn_is_jump (struct gdbarch *gdbarch,
 }
 
 int
-gdbarch_auxv_parse_p (struct gdbarch *gdbarch)
+gdbarch_auxv_parse_p (const struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
   return gdbarch->auxv_parse != NULL;
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 7df37c9..9464561 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -101,19 +101,19 @@  typedef void (iterate_over_regset_sections_cb)
 
 /* The following are pre-initialized by GDBARCH.  */
 
-extern const struct bfd_arch_info * gdbarch_bfd_arch_info (struct gdbarch *gdbarch);
+extern const struct bfd_arch_info * gdbarch_bfd_arch_info (const struct gdbarch *gdbarch);
 /* set_gdbarch_bfd_arch_info() - not applicable - pre-initialized.  */
 
-extern enum bfd_endian gdbarch_byte_order (struct gdbarch *gdbarch);
+extern enum bfd_endian gdbarch_byte_order (const struct gdbarch *gdbarch);
 /* set_gdbarch_byte_order() - not applicable - pre-initialized.  */
 
-extern enum bfd_endian gdbarch_byte_order_for_code (struct gdbarch *gdbarch);
+extern enum bfd_endian gdbarch_byte_order_for_code (const struct gdbarch *gdbarch);
 /* set_gdbarch_byte_order_for_code() - not applicable - pre-initialized.  */
 
-extern enum gdb_osabi gdbarch_osabi (struct gdbarch *gdbarch);
+extern enum gdb_osabi gdbarch_osabi (const struct gdbarch *gdbarch);
 /* set_gdbarch_osabi() - not applicable - pre-initialized.  */
 
-extern const struct target_desc * gdbarch_target_desc (struct gdbarch *gdbarch);
+extern const struct target_desc * gdbarch_target_desc (const struct gdbarch *gdbarch);
 /* set_gdbarch_target_desc() - not applicable - pre-initialized.  */
 
 
@@ -122,7 +122,7 @@  extern const struct target_desc * gdbarch_target_desc (struct gdbarch *gdbarch);
 /* The bit byte-order has to do just with numbering of bits in debugging symbols
    and such.  Conceptually, it's quite separate from byte/word byte order. */
 
-extern int gdbarch_bits_big_endian (struct gdbarch *gdbarch);
+extern int gdbarch_bits_big_endian (const struct gdbarch *gdbarch);
 extern void set_gdbarch_bits_big_endian (struct gdbarch *gdbarch, int bits_big_endian);
 
 /* Number of bits in a char or unsigned char for the target machine.
@@ -131,29 +131,29 @@  extern void set_gdbarch_bits_big_endian (struct gdbarch *gdbarch, int bits_big_e
   
    Number of bits in a short or unsigned short for the target machine. */
 
-extern int gdbarch_short_bit (struct gdbarch *gdbarch);
+extern int gdbarch_short_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_short_bit (struct gdbarch *gdbarch, int short_bit);
 
 /* Number of bits in an int or unsigned int for the target machine. */
 
-extern int gdbarch_int_bit (struct gdbarch *gdbarch);
+extern int gdbarch_int_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_int_bit (struct gdbarch *gdbarch, int int_bit);
 
 /* Number of bits in a long or unsigned long for the target machine. */
 
-extern int gdbarch_long_bit (struct gdbarch *gdbarch);
+extern int gdbarch_long_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_long_bit (struct gdbarch *gdbarch, int long_bit);
 
 /* Number of bits in a long long or unsigned long long for the target
    machine. */
 
-extern int gdbarch_long_long_bit (struct gdbarch *gdbarch);
+extern int gdbarch_long_long_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_long_long_bit (struct gdbarch *gdbarch, int long_long_bit);
 
 /* Alignment of a long long or unsigned long long for the target
    machine. */
 
-extern int gdbarch_long_long_align_bit (struct gdbarch *gdbarch);
+extern int gdbarch_long_long_align_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_long_long_align_bit (struct gdbarch *gdbarch, int long_long_align_bit);
 
 /* The ABI default bit-size and format for "half", "float", "double", and
@@ -162,28 +162,28 @@  extern void set_gdbarch_long_long_align_bit (struct gdbarch *gdbarch, int long_l
    Each format describes both the big and little endian layouts (if
    useful). */
 
-extern int gdbarch_half_bit (struct gdbarch *gdbarch);
+extern int gdbarch_half_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_half_bit (struct gdbarch *gdbarch, int half_bit);
 
-extern const struct floatformat ** gdbarch_half_format (struct gdbarch *gdbarch);
+extern const struct floatformat ** gdbarch_half_format (const struct gdbarch *gdbarch);
 extern void set_gdbarch_half_format (struct gdbarch *gdbarch, const struct floatformat ** half_format);
 
-extern int gdbarch_float_bit (struct gdbarch *gdbarch);
+extern int gdbarch_float_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_float_bit (struct gdbarch *gdbarch, int float_bit);
 
-extern const struct floatformat ** gdbarch_float_format (struct gdbarch *gdbarch);
+extern const struct floatformat ** gdbarch_float_format (const struct gdbarch *gdbarch);
 extern void set_gdbarch_float_format (struct gdbarch *gdbarch, const struct floatformat ** float_format);
 
-extern int gdbarch_double_bit (struct gdbarch *gdbarch);
+extern int gdbarch_double_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_double_bit (struct gdbarch *gdbarch, int double_bit);
 
-extern const struct floatformat ** gdbarch_double_format (struct gdbarch *gdbarch);
+extern const struct floatformat ** gdbarch_double_format (const struct gdbarch *gdbarch);
 extern void set_gdbarch_double_format (struct gdbarch *gdbarch, const struct floatformat ** double_format);
 
-extern int gdbarch_long_double_bit (struct gdbarch *gdbarch);
+extern int gdbarch_long_double_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_long_double_bit (struct gdbarch *gdbarch, int long_double_bit);
 
-extern const struct floatformat ** gdbarch_long_double_format (struct gdbarch *gdbarch);
+extern const struct floatformat ** gdbarch_long_double_format (const struct gdbarch *gdbarch);
 extern void set_gdbarch_long_double_format (struct gdbarch *gdbarch, const struct floatformat ** long_double_format);
 
 /* For most targets, a pointer on the target and its representation as an
@@ -197,12 +197,12 @@  extern void set_gdbarch_long_double_format (struct gdbarch *gdbarch, const struc
   
    ptr_bit is the size of a pointer on the target */
 
-extern int gdbarch_ptr_bit (struct gdbarch *gdbarch);
+extern int gdbarch_ptr_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_ptr_bit (struct gdbarch *gdbarch, int ptr_bit);
 
 /* addr_bit is the size of a target address as represented in gdb */
 
-extern int gdbarch_addr_bit (struct gdbarch *gdbarch);
+extern int gdbarch_addr_bit (const struct gdbarch *gdbarch);
 extern void set_gdbarch_addr_bit (struct gdbarch *gdbarch, int addr_bit);
 
 /* dwarf2_addr_size is the target address size as used in the Dwarf debug
@@ -219,21 +219,21 @@  extern void set_gdbarch_addr_bit (struct gdbarch *gdbarch, int addr_bit);
    GCC back-end defines a DWARF2_ADDR_SIZE other than the target pointer size,
    and if Dwarf versions < 4 need to be supported. */
 
-extern int gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch);
+extern int gdbarch_dwarf2_addr_size (const struct gdbarch *gdbarch);
 extern void set_gdbarch_dwarf2_addr_size (struct gdbarch *gdbarch, int dwarf2_addr_size);
 
 /* One if `char' acts like `signed char', zero if `unsigned char'. */
 
-extern int gdbarch_char_signed (struct gdbarch *gdbarch);
+extern int gdbarch_char_signed (const struct gdbarch *gdbarch);
 extern void set_gdbarch_char_signed (struct gdbarch *gdbarch, int char_signed);
 
-extern int gdbarch_read_pc_p (struct gdbarch *gdbarch);
+extern int gdbarch_read_pc_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_read_pc_ftype) (struct regcache *regcache);
 extern CORE_ADDR gdbarch_read_pc (struct gdbarch *gdbarch, struct regcache *regcache);
 extern void set_gdbarch_read_pc (struct gdbarch *gdbarch, gdbarch_read_pc_ftype *read_pc);
 
-extern int gdbarch_write_pc_p (struct gdbarch *gdbarch);
+extern int gdbarch_write_pc_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_write_pc_ftype) (struct regcache *regcache, CORE_ADDR val);
 extern void gdbarch_write_pc (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR val);
@@ -247,7 +247,7 @@  typedef void (gdbarch_virtual_frame_pointer_ftype) (struct gdbarch *gdbarch, COR
 extern void gdbarch_virtual_frame_pointer (struct gdbarch *gdbarch, CORE_ADDR pc, int *frame_regnum, LONGEST *frame_offset);
 extern void set_gdbarch_virtual_frame_pointer (struct gdbarch *gdbarch, gdbarch_virtual_frame_pointer_ftype *virtual_frame_pointer);
 
-extern int gdbarch_pseudo_register_read_p (struct gdbarch *gdbarch);
+extern int gdbarch_pseudo_register_read_p (const struct gdbarch *gdbarch);
 
 typedef enum register_status (gdbarch_pseudo_register_read_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, gdb_byte *buf);
 extern enum register_status gdbarch_pseudo_register_read (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, gdb_byte *buf);
@@ -258,19 +258,19 @@  extern void set_gdbarch_pseudo_register_read (struct gdbarch *gdbarch, gdbarch_p
    as appropriate.  If this is defined, then pseudo_register_read will
    never be called. */
 
-extern int gdbarch_pseudo_register_read_value_p (struct gdbarch *gdbarch);
+extern int gdbarch_pseudo_register_read_value_p (const struct gdbarch *gdbarch);
 
 typedef struct value * (gdbarch_pseudo_register_read_value_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum);
 extern struct value * gdbarch_pseudo_register_read_value (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum);
 extern void set_gdbarch_pseudo_register_read_value (struct gdbarch *gdbarch, gdbarch_pseudo_register_read_value_ftype *pseudo_register_read_value);
 
-extern int gdbarch_pseudo_register_write_p (struct gdbarch *gdbarch);
+extern int gdbarch_pseudo_register_write_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_pseudo_register_write_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, const gdb_byte *buf);
 extern void gdbarch_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache, int cookednum, const gdb_byte *buf);
 extern void set_gdbarch_pseudo_register_write (struct gdbarch *gdbarch, gdbarch_pseudo_register_write_ftype *pseudo_register_write);
 
-extern int gdbarch_num_regs (struct gdbarch *gdbarch);
+extern int gdbarch_num_regs (const struct gdbarch *gdbarch);
 extern void set_gdbarch_num_regs (struct gdbarch *gdbarch, int num_regs);
 
 /* This macro gives the number of pseudo-registers that live in the
@@ -278,13 +278,13 @@  extern void set_gdbarch_num_regs (struct gdbarch *gdbarch, int num_regs);
    These pseudo-registers may be aliases for other registers,
    combinations of other registers, or they may be computed by GDB. */
 
-extern int gdbarch_num_pseudo_regs (struct gdbarch *gdbarch);
+extern int gdbarch_num_pseudo_regs (const struct gdbarch *gdbarch);
 extern void set_gdbarch_num_pseudo_regs (struct gdbarch *gdbarch, int num_pseudo_regs);
 
 /* Assemble agent expression bytecode to collect pseudo-register REG.
    Return -1 if something goes wrong, 0 otherwise. */
 
-extern int gdbarch_ax_pseudo_register_collect_p (struct gdbarch *gdbarch);
+extern int gdbarch_ax_pseudo_register_collect_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_ax_pseudo_register_collect_ftype) (struct gdbarch *gdbarch, struct agent_expr *ax, int reg);
 extern int gdbarch_ax_pseudo_register_collect (struct gdbarch *gdbarch, struct agent_expr *ax, int reg);
@@ -294,7 +294,7 @@  extern void set_gdbarch_ax_pseudo_register_collect (struct gdbarch *gdbarch, gdb
    REG on the interpreter stack.
    Return -1 if something goes wrong, 0 otherwise. */
 
-extern int gdbarch_ax_pseudo_register_push_stack_p (struct gdbarch *gdbarch);
+extern int gdbarch_ax_pseudo_register_push_stack_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_ax_pseudo_register_push_stack_ftype) (struct gdbarch *gdbarch, struct agent_expr *ax, int reg);
 extern int gdbarch_ax_pseudo_register_push_stack (struct gdbarch *gdbarch, struct agent_expr *ax, int reg);
@@ -305,16 +305,16 @@  extern void set_gdbarch_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
    all (-1).
    gdbarch_sp_regnum will hopefully be replaced by UNWIND_SP. */
 
-extern int gdbarch_sp_regnum (struct gdbarch *gdbarch);
+extern int gdbarch_sp_regnum (const struct gdbarch *gdbarch);
 extern void set_gdbarch_sp_regnum (struct gdbarch *gdbarch, int sp_regnum);
 
-extern int gdbarch_pc_regnum (struct gdbarch *gdbarch);
+extern int gdbarch_pc_regnum (const struct gdbarch *gdbarch);
 extern void set_gdbarch_pc_regnum (struct gdbarch *gdbarch, int pc_regnum);
 
-extern int gdbarch_ps_regnum (struct gdbarch *gdbarch);
+extern int gdbarch_ps_regnum (const struct gdbarch *gdbarch);
 extern void set_gdbarch_ps_regnum (struct gdbarch *gdbarch, int ps_regnum);
 
-extern int gdbarch_fp0_regnum (struct gdbarch *gdbarch);
+extern int gdbarch_fp0_regnum (const struct gdbarch *gdbarch);
 extern void set_gdbarch_fp0_regnum (struct gdbarch *gdbarch, int fp0_regnum);
 
 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
@@ -349,13 +349,13 @@  extern void set_gdbarch_register_name (struct gdbarch *gdbarch, gdbarch_register
    the register cache should call this function directly; others should
    use "register_type". */
 
-extern int gdbarch_register_type_p (struct gdbarch *gdbarch);
+extern int gdbarch_register_type_p (const struct gdbarch *gdbarch);
 
 typedef struct type * (gdbarch_register_type_ftype) (struct gdbarch *gdbarch, int reg_nr);
 extern struct type * gdbarch_register_type (struct gdbarch *gdbarch, int reg_nr);
 extern void set_gdbarch_register_type (struct gdbarch *gdbarch, gdbarch_register_type_ftype *register_type);
 
-extern int gdbarch_dummy_id_p (struct gdbarch *gdbarch);
+extern int gdbarch_dummy_id_p (const struct gdbarch *gdbarch);
 
 typedef struct frame_id (gdbarch_dummy_id_ftype) (struct gdbarch *gdbarch, struct frame_info *this_frame);
 extern struct frame_id gdbarch_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame);
@@ -364,19 +364,19 @@  extern void set_gdbarch_dummy_id (struct gdbarch *gdbarch, gdbarch_dummy_id_ftyp
 /* Implement DUMMY_ID and PUSH_DUMMY_CALL, then delete
    deprecated_fp_regnum. */
 
-extern int gdbarch_deprecated_fp_regnum (struct gdbarch *gdbarch);
+extern int gdbarch_deprecated_fp_regnum (const struct gdbarch *gdbarch);
 extern void set_gdbarch_deprecated_fp_regnum (struct gdbarch *gdbarch, int deprecated_fp_regnum);
 
-extern int gdbarch_push_dummy_call_p (struct gdbarch *gdbarch);
+extern int gdbarch_push_dummy_call_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_push_dummy_call_ftype) (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr);
 extern CORE_ADDR gdbarch_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct regcache *regcache, CORE_ADDR bp_addr, int nargs, struct value **args, CORE_ADDR sp, int struct_return, CORE_ADDR struct_addr);
 extern void set_gdbarch_push_dummy_call (struct gdbarch *gdbarch, gdbarch_push_dummy_call_ftype *push_dummy_call);
 
-extern int gdbarch_call_dummy_location (struct gdbarch *gdbarch);
+extern int gdbarch_call_dummy_location (const struct gdbarch *gdbarch);
 extern void set_gdbarch_call_dummy_location (struct gdbarch *gdbarch, int call_dummy_location);
 
-extern int gdbarch_push_dummy_code_p (struct gdbarch *gdbarch);
+extern int gdbarch_push_dummy_code_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_push_dummy_code_ftype) (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr, struct value **args, int nargs, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr, struct regcache *regcache);
 extern CORE_ADDR gdbarch_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr, struct value **args, int nargs, struct type *value_type, CORE_ADDR *real_pc, CORE_ADDR *bp_addr, struct regcache *regcache);
@@ -390,7 +390,7 @@  typedef void (gdbarch_print_float_info_ftype) (struct gdbarch *gdbarch, struct u
 extern void gdbarch_print_float_info (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, const char *args);
 extern void set_gdbarch_print_float_info (struct gdbarch *gdbarch, gdbarch_print_float_info_ftype *print_float_info);
 
-extern int gdbarch_print_vector_info_p (struct gdbarch *gdbarch);
+extern int gdbarch_print_vector_info_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_print_vector_info_ftype) (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, const char *args);
 extern void gdbarch_print_vector_info (struct gdbarch *gdbarch, struct ui_file *file, struct frame_info *frame, const char *args);
@@ -416,13 +416,13 @@  extern void set_gdbarch_cannot_store_register (struct gdbarch *gdbarch, gdbarch_
   
    FRAME corresponds to the longjmp frame. */
 
-extern int gdbarch_get_longjmp_target_p (struct gdbarch *gdbarch);
+extern int gdbarch_get_longjmp_target_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_get_longjmp_target_ftype) (struct frame_info *frame, CORE_ADDR *pc);
 extern int gdbarch_get_longjmp_target (struct gdbarch *gdbarch, struct frame_info *frame, CORE_ADDR *pc);
 extern void set_gdbarch_get_longjmp_target (struct gdbarch *gdbarch, gdbarch_get_longjmp_target_ftype *get_longjmp_target);
 
-extern int gdbarch_believe_pcc_promotion (struct gdbarch *gdbarch);
+extern int gdbarch_believe_pcc_promotion (const struct gdbarch *gdbarch);
 extern void set_gdbarch_believe_pcc_promotion (struct gdbarch *gdbarch, int believe_pcc_promotion);
 
 typedef int (gdbarch_convert_register_p_ftype) (struct gdbarch *gdbarch, int regnum, struct type *type);
@@ -454,7 +454,7 @@  typedef void (gdbarch_address_to_pointer_ftype) (struct gdbarch *gdbarch, struct
 extern void gdbarch_address_to_pointer (struct gdbarch *gdbarch, struct type *type, gdb_byte *buf, CORE_ADDR addr);
 extern void set_gdbarch_address_to_pointer (struct gdbarch *gdbarch, gdbarch_address_to_pointer_ftype *address_to_pointer);
 
-extern int gdbarch_integer_to_address_p (struct gdbarch *gdbarch);
+extern int gdbarch_integer_to_address_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_integer_to_address_ftype) (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf);
 extern CORE_ADDR gdbarch_integer_to_address (struct gdbarch *gdbarch, struct type *type, const gdb_byte *buf);
@@ -471,7 +471,7 @@  extern void set_gdbarch_integer_to_address (struct gdbarch *gdbarch, gdbarch_int
    to force the value returned by a function (see the "return" command
    for instance). */
 
-extern int gdbarch_return_value_p (struct gdbarch *gdbarch);
+extern int gdbarch_return_value_p (const struct gdbarch *gdbarch);
 
 typedef enum return_value_convention (gdbarch_return_value_ftype) (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
 extern enum return_value_convention gdbarch_return_value (struct gdbarch *gdbarch, struct value *function, struct type *valtype, struct regcache *regcache, gdb_byte *readbuf, const gdb_byte *writebuf);
@@ -491,7 +491,7 @@  typedef CORE_ADDR (gdbarch_skip_prologue_ftype) (struct gdbarch *gdbarch, CORE_A
 extern CORE_ADDR gdbarch_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR ip);
 extern void set_gdbarch_skip_prologue (struct gdbarch *gdbarch, gdbarch_skip_prologue_ftype *skip_prologue);
 
-extern int gdbarch_skip_main_prologue_p (struct gdbarch *gdbarch);
+extern int gdbarch_skip_main_prologue_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_skip_main_prologue_ftype) (struct gdbarch *gdbarch, CORE_ADDR ip);
 extern CORE_ADDR gdbarch_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR ip);
@@ -509,7 +509,7 @@  extern void set_gdbarch_skip_main_prologue (struct gdbarch *gdbarch, gdbarch_ski
    by GDB common code even when debugging optimized code, where skip_prologue
    is not used. */
 
-extern int gdbarch_skip_entrypoint_p (struct gdbarch *gdbarch);
+extern int gdbarch_skip_entrypoint_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_skip_entrypoint_ftype) (struct gdbarch *gdbarch, CORE_ADDR ip);
 extern CORE_ADDR gdbarch_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR ip);
@@ -531,7 +531,7 @@  typedef void (gdbarch_remote_breakpoint_from_pc_ftype) (struct gdbarch *gdbarch,
 extern void gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr, int *kindptr);
 extern void set_gdbarch_remote_breakpoint_from_pc (struct gdbarch *gdbarch, gdbarch_remote_breakpoint_from_pc_ftype *remote_breakpoint_from_pc);
 
-extern int gdbarch_adjust_breakpoint_address_p (struct gdbarch *gdbarch);
+extern int gdbarch_adjust_breakpoint_address_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_adjust_breakpoint_address_ftype) (struct gdbarch *gdbarch, CORE_ADDR bpaddr);
 extern CORE_ADDR gdbarch_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr);
@@ -545,7 +545,7 @@  typedef int (gdbarch_memory_remove_breakpoint_ftype) (struct gdbarch *gdbarch, s
 extern int gdbarch_memory_remove_breakpoint (struct gdbarch *gdbarch, struct bp_target_info *bp_tgt);
 extern void set_gdbarch_memory_remove_breakpoint (struct gdbarch *gdbarch, gdbarch_memory_remove_breakpoint_ftype *memory_remove_breakpoint);
 
-extern CORE_ADDR gdbarch_decr_pc_after_break (struct gdbarch *gdbarch);
+extern CORE_ADDR gdbarch_decr_pc_after_break (const struct gdbarch *gdbarch);
 extern void set_gdbarch_decr_pc_after_break (struct gdbarch *gdbarch, CORE_ADDR decr_pc_after_break);
 
 /* A function can be addressed by either it's "pointer" (possibly a
@@ -556,7 +556,7 @@  extern void set_gdbarch_decr_pc_after_break (struct gdbarch *gdbarch, CORE_ADDR
    corresponds to the "function pointer" and the function's start
    corresponds to the "function entry point" - and hence is redundant. */
 
-extern CORE_ADDR gdbarch_deprecated_function_start_offset (struct gdbarch *gdbarch);
+extern CORE_ADDR gdbarch_deprecated_function_start_offset (const struct gdbarch *gdbarch);
 extern void set_gdbarch_deprecated_function_start_offset (struct gdbarch *gdbarch, CORE_ADDR deprecated_function_start_offset);
 
 /* Return the remote protocol register number associated with this
@@ -568,22 +568,22 @@  extern void set_gdbarch_remote_register_number (struct gdbarch *gdbarch, gdbarch
 
 /* Fetch the target specific address used to represent a load module. */
 
-extern int gdbarch_fetch_tls_load_module_address_p (struct gdbarch *gdbarch);
+extern int gdbarch_fetch_tls_load_module_address_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_fetch_tls_load_module_address_ftype) (struct objfile *objfile);
 extern CORE_ADDR gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch, struct objfile *objfile);
 extern void set_gdbarch_fetch_tls_load_module_address (struct gdbarch *gdbarch, gdbarch_fetch_tls_load_module_address_ftype *fetch_tls_load_module_address);
 
-extern CORE_ADDR gdbarch_frame_args_skip (struct gdbarch *gdbarch);
+extern CORE_ADDR gdbarch_frame_args_skip (const struct gdbarch *gdbarch);
 extern void set_gdbarch_frame_args_skip (struct gdbarch *gdbarch, CORE_ADDR frame_args_skip);
 
-extern int gdbarch_unwind_pc_p (struct gdbarch *gdbarch);
+extern int gdbarch_unwind_pc_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_unwind_pc_ftype) (struct gdbarch *gdbarch, struct frame_info *next_frame);
 extern CORE_ADDR gdbarch_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame);
 extern void set_gdbarch_unwind_pc (struct gdbarch *gdbarch, gdbarch_unwind_pc_ftype *unwind_pc);
 
-extern int gdbarch_unwind_sp_p (struct gdbarch *gdbarch);
+extern int gdbarch_unwind_sp_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_unwind_sp_ftype) (struct gdbarch *gdbarch, struct frame_info *next_frame);
 extern CORE_ADDR gdbarch_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame);
@@ -592,13 +592,13 @@  extern void set_gdbarch_unwind_sp (struct gdbarch *gdbarch, gdbarch_unwind_sp_ft
 /* DEPRECATED_FRAME_LOCALS_ADDRESS as been replaced by the per-frame
    frame-base.  Enable frame-base before frame-unwind. */
 
-extern int gdbarch_frame_num_args_p (struct gdbarch *gdbarch);
+extern int gdbarch_frame_num_args_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_frame_num_args_ftype) (struct frame_info *frame);
 extern int gdbarch_frame_num_args (struct gdbarch *gdbarch, struct frame_info *frame);
 extern void set_gdbarch_frame_num_args (struct gdbarch *gdbarch, gdbarch_frame_num_args_ftype *frame_num_args);
 
-extern int gdbarch_frame_align_p (struct gdbarch *gdbarch);
+extern int gdbarch_frame_align_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_frame_align_ftype) (struct gdbarch *gdbarch, CORE_ADDR address);
 extern CORE_ADDR gdbarch_frame_align (struct gdbarch *gdbarch, CORE_ADDR address);
@@ -608,7 +608,7 @@  typedef int (gdbarch_stabs_argument_has_addr_ftype) (struct gdbarch *gdbarch, st
 extern int gdbarch_stabs_argument_has_addr (struct gdbarch *gdbarch, struct type *type);
 extern void set_gdbarch_stabs_argument_has_addr (struct gdbarch *gdbarch, gdbarch_stabs_argument_has_addr_ftype *stabs_argument_has_addr);
 
-extern int gdbarch_frame_red_zone_size (struct gdbarch *gdbarch);
+extern int gdbarch_frame_red_zone_size (const struct gdbarch *gdbarch);
 extern void set_gdbarch_frame_red_zone_size (struct gdbarch *gdbarch, int frame_red_zone_size);
 
 typedef CORE_ADDR (gdbarch_convert_from_func_ptr_addr_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr, struct target_ops *targ);
@@ -643,7 +643,7 @@  extern void set_gdbarch_addr_bits_remove (struct gdbarch *gdbarch, gdbarch_addr_
    A return value of 1 means that the software_single_step breakpoints
    were inserted; 0 means they were not. */
 
-extern int gdbarch_software_single_step_p (struct gdbarch *gdbarch);
+extern int gdbarch_software_single_step_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_software_single_step_ftype) (struct frame_info *frame);
 extern int gdbarch_software_single_step (struct gdbarch *gdbarch, struct frame_info *frame);
@@ -652,7 +652,7 @@  extern void set_gdbarch_software_single_step (struct gdbarch *gdbarch, gdbarch_s
 /* Return non-zero if the processor is executing a delay slot and a
    further single-step is needed before the instruction finishes. */
 
-extern int gdbarch_single_step_through_delay_p (struct gdbarch *gdbarch);
+extern int gdbarch_single_step_through_delay_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_single_step_through_delay_ftype) (struct gdbarch *gdbarch, struct frame_info *frame);
 extern int gdbarch_single_step_through_delay (struct gdbarch *gdbarch, struct frame_info *frame);
@@ -705,7 +705,7 @@  extern void set_gdbarch_stack_frame_destroyed_p (struct gdbarch *gdbarch, gdbarc
    that they can be treated in the appropriate manner in the processing of
    the main symbol table and DWARF-2 records. */
 
-extern int gdbarch_elf_make_msymbol_special_p (struct gdbarch *gdbarch);
+extern int gdbarch_elf_make_msymbol_special_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_elf_make_msymbol_special_ftype) (asymbol *sym, struct minimal_symbol *msym);
 extern void gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym);
@@ -754,19 +754,19 @@  typedef CORE_ADDR (gdbarch_adjust_dwarf2_line_ftype) (CORE_ADDR addr, int rel);
 extern CORE_ADDR gdbarch_adjust_dwarf2_line (struct gdbarch *gdbarch, CORE_ADDR addr, int rel);
 extern void set_gdbarch_adjust_dwarf2_line (struct gdbarch *gdbarch, gdbarch_adjust_dwarf2_line_ftype *adjust_dwarf2_line);
 
-extern int gdbarch_cannot_step_breakpoint (struct gdbarch *gdbarch);
+extern int gdbarch_cannot_step_breakpoint (const struct gdbarch *gdbarch);
 extern void set_gdbarch_cannot_step_breakpoint (struct gdbarch *gdbarch, int cannot_step_breakpoint);
 
-extern int gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch);
+extern int gdbarch_have_nonsteppable_watchpoint (const struct gdbarch *gdbarch);
 extern void set_gdbarch_have_nonsteppable_watchpoint (struct gdbarch *gdbarch, int have_nonsteppable_watchpoint);
 
-extern int gdbarch_address_class_type_flags_p (struct gdbarch *gdbarch);
+extern int gdbarch_address_class_type_flags_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_address_class_type_flags_ftype) (int byte_size, int dwarf2_addr_class);
 extern int gdbarch_address_class_type_flags (struct gdbarch *gdbarch, int byte_size, int dwarf2_addr_class);
 extern void set_gdbarch_address_class_type_flags (struct gdbarch *gdbarch, gdbarch_address_class_type_flags_ftype *address_class_type_flags);
 
-extern int gdbarch_address_class_type_flags_to_name_p (struct gdbarch *gdbarch);
+extern int gdbarch_address_class_type_flags_to_name_p (const struct gdbarch *gdbarch);
 
 typedef const char * (gdbarch_address_class_type_flags_to_name_ftype) (struct gdbarch *gdbarch, int type_flags);
 extern const char * gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags);
@@ -776,7 +776,7 @@  extern void set_gdbarch_address_class_type_flags_to_name (struct gdbarch *gdbarc
    This function should return 1 if the address class was recognized and
    type_flags was set, zero otherwise. */
 
-extern int gdbarch_address_class_name_to_type_flags_p (struct gdbarch *gdbarch);
+extern int gdbarch_address_class_name_to_type_flags_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_address_class_name_to_type_flags_ftype) (struct gdbarch *gdbarch, const char *name, int *type_flags_ptr);
 extern int gdbarch_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name, int *type_flags_ptr);
@@ -790,7 +790,7 @@  extern void set_gdbarch_register_reggroup_p (struct gdbarch *gdbarch, gdbarch_re
 
 /* Fetch the pointer to the ith function argument. */
 
-extern int gdbarch_fetch_pointer_argument_p (struct gdbarch *gdbarch);
+extern int gdbarch_fetch_pointer_argument_p (const struct gdbarch *gdbarch);
 
 typedef CORE_ADDR (gdbarch_fetch_pointer_argument_ftype) (struct frame_info *frame, int argi, struct type *type);
 extern CORE_ADDR gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, struct frame_info *frame, int argi, struct type *type);
@@ -803,7 +803,7 @@  extern void set_gdbarch_fetch_pointer_argument (struct gdbarch *gdbarch, gdbarch
    values.  Otherwise it should enumerate all supported register note
    sections. */
 
-extern int gdbarch_iterate_over_regset_sections_p (struct gdbarch *gdbarch);
+extern int gdbarch_iterate_over_regset_sections_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_iterate_over_regset_sections_ftype) (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
 extern void gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, iterate_over_regset_sections_cb *cb, void *cb_data, const struct regcache *regcache);
@@ -811,7 +811,7 @@  extern void set_gdbarch_iterate_over_regset_sections (struct gdbarch *gdbarch, g
 
 /* Create core file notes */
 
-extern int gdbarch_make_corefile_notes_p (struct gdbarch *gdbarch);
+extern int gdbarch_make_corefile_notes_p (const struct gdbarch *gdbarch);
 
 typedef char * (gdbarch_make_corefile_notes_ftype) (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
 extern char * gdbarch_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size);
@@ -823,7 +823,7 @@  extern void set_gdbarch_make_corefile_notes (struct gdbarch *gdbarch, gdbarch_ma
    call the Linux generic routines in bfd to write prpsinfo notes by
    default. */
 
-extern int gdbarch_elfcore_write_linux_prpsinfo_p (struct gdbarch *gdbarch);
+extern int gdbarch_elfcore_write_linux_prpsinfo_p (const struct gdbarch *gdbarch);
 
 typedef char * (gdbarch_elfcore_write_linux_prpsinfo_ftype) (bfd *obfd, char *note_data, int *note_size, const struct elf_internal_linux_prpsinfo *info);
 extern char * gdbarch_elfcore_write_linux_prpsinfo (struct gdbarch *gdbarch, bfd *obfd, char *note_data, int *note_size, const struct elf_internal_linux_prpsinfo *info);
@@ -831,7 +831,7 @@  extern void set_gdbarch_elfcore_write_linux_prpsinfo (struct gdbarch *gdbarch, g
 
 /* Find core file memory regions */
 
-extern int gdbarch_find_memory_regions_p (struct gdbarch *gdbarch);
+extern int gdbarch_find_memory_regions_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_find_memory_regions_ftype) (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data);
 extern int gdbarch_find_memory_regions (struct gdbarch *gdbarch, find_memory_region_ftype func, void *data);
@@ -842,7 +842,7 @@  extern void set_gdbarch_find_memory_regions (struct gdbarch *gdbarch, gdbarch_fi
    (zero indicates failure).
    failed, otherwise, return the red length of READBUF. */
 
-extern int gdbarch_core_xfer_shared_libraries_p (struct gdbarch *gdbarch);
+extern int gdbarch_core_xfer_shared_libraries_p (const struct gdbarch *gdbarch);
 
 typedef ULONGEST (gdbarch_core_xfer_shared_libraries_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 extern ULONGEST gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
@@ -852,7 +852,7 @@  extern void set_gdbarch_core_xfer_shared_libraries (struct gdbarch *gdbarch, gdb
    libraries list from core file into buffer READBUF with length LEN.
    Return the number of bytes read (zero indicates failure). */
 
-extern int gdbarch_core_xfer_shared_libraries_aix_p (struct gdbarch *gdbarch);
+extern int gdbarch_core_xfer_shared_libraries_aix_p (const struct gdbarch *gdbarch);
 
 typedef ULONGEST (gdbarch_core_xfer_shared_libraries_aix_ftype) (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
 extern ULONGEST gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch, gdb_byte *readbuf, ULONGEST offset, ULONGEST len);
@@ -860,7 +860,7 @@  extern void set_gdbarch_core_xfer_shared_libraries_aix (struct gdbarch *gdbarch,
 
 /* How the core target converts a PTID from a core file to a string. */
 
-extern int gdbarch_core_pid_to_str_p (struct gdbarch *gdbarch);
+extern int gdbarch_core_pid_to_str_p (const struct gdbarch *gdbarch);
 
 typedef char * (gdbarch_core_pid_to_str_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
 extern char * gdbarch_core_pid_to_str (struct gdbarch *gdbarch, ptid_t ptid);
@@ -868,22 +868,22 @@  extern void set_gdbarch_core_pid_to_str (struct gdbarch *gdbarch, gdbarch_core_p
 
 /* BFD target to use when generating a core file. */
 
-extern int gdbarch_gcore_bfd_target_p (struct gdbarch *gdbarch);
+extern int gdbarch_gcore_bfd_target_p (const struct gdbarch *gdbarch);
 
-extern const char * gdbarch_gcore_bfd_target (struct gdbarch *gdbarch);
+extern const char * gdbarch_gcore_bfd_target (const struct gdbarch *gdbarch);
 extern void set_gdbarch_gcore_bfd_target (struct gdbarch *gdbarch, const char * gcore_bfd_target);
 
 /* If the elements of C++ vtables are in-place function descriptors rather
    than normal function pointers (which may point to code or a descriptor),
    set this to one. */
 
-extern int gdbarch_vtable_function_descriptors (struct gdbarch *gdbarch);
+extern int gdbarch_vtable_function_descriptors (const struct gdbarch *gdbarch);
 extern void set_gdbarch_vtable_function_descriptors (struct gdbarch *gdbarch, int vtable_function_descriptors);
 
 /* Set if the least significant bit of the delta is used instead of the least
    significant bit of the pfn for pointers to virtual member functions. */
 
-extern int gdbarch_vbit_in_delta (struct gdbarch *gdbarch);
+extern int gdbarch_vbit_in_delta (const struct gdbarch *gdbarch);
 extern void set_gdbarch_vbit_in_delta (struct gdbarch *gdbarch, int vbit_in_delta);
 
 /* Advance PC to next instruction in order to skip a permanent breakpoint. */
@@ -894,9 +894,9 @@  extern void set_gdbarch_skip_permanent_breakpoint (struct gdbarch *gdbarch, gdba
 
 /* The maximum length of an instruction on this architecture in bytes. */
 
-extern int gdbarch_max_insn_length_p (struct gdbarch *gdbarch);
+extern int gdbarch_max_insn_length_p (const struct gdbarch *gdbarch);
 
-extern ULONGEST gdbarch_max_insn_length (struct gdbarch *gdbarch);
+extern ULONGEST gdbarch_max_insn_length (const struct gdbarch *gdbarch);
 extern void set_gdbarch_max_insn_length (struct gdbarch *gdbarch, ULONGEST max_insn_length);
 
 /* Copy the instruction at FROM to TO, and make any adjustments
@@ -929,7 +929,7 @@  extern void set_gdbarch_max_insn_length (struct gdbarch *gdbarch, ULONGEST max_i
    core falls back to stepping past the instruction in-line instead in
    that case. */
 
-extern int gdbarch_displaced_step_copy_insn_p (struct gdbarch *gdbarch);
+extern int gdbarch_displaced_step_copy_insn_p (const struct gdbarch *gdbarch);
 
 typedef struct displaced_step_closure * (gdbarch_displaced_step_copy_insn_ftype) (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern struct displaced_step_closure * gdbarch_displaced_step_copy_insn (struct gdbarch *gdbarch, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
@@ -966,7 +966,7 @@  extern void set_gdbarch_displaced_step_hw_singlestep (struct gdbarch *gdbarch, g
    For a general explanation of displaced stepping and how GDB uses it,
    see the comments in infrun.c. */
 
-extern int gdbarch_displaced_step_fixup_p (struct gdbarch *gdbarch);
+extern int gdbarch_displaced_step_fixup_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_displaced_step_fixup_ftype) (struct gdbarch *gdbarch, struct displaced_step_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
 extern void gdbarch_displaced_step_fixup (struct gdbarch *gdbarch, struct displaced_step_closure *closure, CORE_ADDR from, CORE_ADDR to, struct regcache *regs);
@@ -1011,7 +1011,7 @@  extern void set_gdbarch_displaced_step_location (struct gdbarch *gdbarch, gdbarc
    relative branches, and other PC-relative instructions need the
    offset adjusted; etc. */
 
-extern int gdbarch_relocate_instruction_p (struct gdbarch *gdbarch);
+extern int gdbarch_relocate_instruction_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_relocate_instruction_ftype) (struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from);
 extern void gdbarch_relocate_instruction (struct gdbarch *gdbarch, CORE_ADDR *to, CORE_ADDR from);
@@ -1019,13 +1019,13 @@  extern void set_gdbarch_relocate_instruction (struct gdbarch *gdbarch, gdbarch_r
 
 /* Refresh overlay mapped state for section OSECT. */
 
-extern int gdbarch_overlay_update_p (struct gdbarch *gdbarch);
+extern int gdbarch_overlay_update_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_overlay_update_ftype) (struct obj_section *osect);
 extern void gdbarch_overlay_update (struct gdbarch *gdbarch, struct obj_section *osect);
 extern void set_gdbarch_overlay_update (struct gdbarch *gdbarch, gdbarch_overlay_update_ftype *overlay_update);
 
-extern int gdbarch_core_read_description_p (struct gdbarch *gdbarch);
+extern int gdbarch_core_read_description_p (const struct gdbarch *gdbarch);
 
 typedef const struct target_desc * (gdbarch_core_read_description_ftype) (struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd);
 extern const struct target_desc * gdbarch_core_read_description (struct gdbarch *gdbarch, struct target_ops *target, bfd *abfd);
@@ -1033,7 +1033,7 @@  extern void set_gdbarch_core_read_description (struct gdbarch *gdbarch, gdbarch_
 
 /* Handle special encoding of static variables in stabs debug info. */
 
-extern int gdbarch_static_transform_name_p (struct gdbarch *gdbarch);
+extern int gdbarch_static_transform_name_p (const struct gdbarch *gdbarch);
 
 typedef const char * (gdbarch_static_transform_name_ftype) (const char *name);
 extern const char * gdbarch_static_transform_name (struct gdbarch *gdbarch, const char *name);
@@ -1041,7 +1041,7 @@  extern void set_gdbarch_static_transform_name (struct gdbarch *gdbarch, gdbarch_
 
 /* Set if the address in N_SO or N_FUN stabs may be zero. */
 
-extern int gdbarch_sofun_address_maybe_missing (struct gdbarch *gdbarch);
+extern int gdbarch_sofun_address_maybe_missing (const struct gdbarch *gdbarch);
 extern void set_gdbarch_sofun_address_maybe_missing (struct gdbarch *gdbarch, int sofun_address_maybe_missing);
 
 /* Parse the instruction at ADDR storing in the record execution log
@@ -1049,7 +1049,7 @@  extern void set_gdbarch_sofun_address_maybe_missing (struct gdbarch *gdbarch, in
    the instruction executes, along with their current values.
    Return -1 if something goes wrong, 0 otherwise. */
 
-extern int gdbarch_process_record_p (struct gdbarch *gdbarch);
+extern int gdbarch_process_record_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_process_record_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr);
 extern int gdbarch_process_record (struct gdbarch *gdbarch, struct regcache *regcache, CORE_ADDR addr);
@@ -1058,7 +1058,7 @@  extern void set_gdbarch_process_record (struct gdbarch *gdbarch, gdbarch_process
 /* Save process state after a signal.
    Return -1 if something goes wrong, 0 otherwise. */
 
-extern int gdbarch_process_record_signal_p (struct gdbarch *gdbarch);
+extern int gdbarch_process_record_signal_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_process_record_signal_ftype) (struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal);
 extern int gdbarch_process_record_signal (struct gdbarch *gdbarch, struct regcache *regcache, enum gdb_signal signal);
@@ -1072,7 +1072,7 @@  extern void set_gdbarch_process_record_signal (struct gdbarch *gdbarch, gdbarch_
    "Live" targets hide the translation behind the target interface
    (target_wait, target_resume, etc.). */
 
-extern int gdbarch_gdb_signal_from_target_p (struct gdbarch *gdbarch);
+extern int gdbarch_gdb_signal_from_target_p (const struct gdbarch *gdbarch);
 
 typedef enum gdb_signal (gdbarch_gdb_signal_from_target_ftype) (struct gdbarch *gdbarch, int signo);
 extern enum gdb_signal gdbarch_gdb_signal_from_target (struct gdbarch *gdbarch, int signo);
@@ -1086,7 +1086,7 @@  extern void set_gdbarch_gdb_signal_from_target (struct gdbarch *gdbarch, gdbarch
    Return the target signal number if found, or -1 if the GDB internal
    signal number is invalid. */
 
-extern int gdbarch_gdb_signal_to_target_p (struct gdbarch *gdbarch);
+extern int gdbarch_gdb_signal_to_target_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_gdb_signal_to_target_ftype) (struct gdbarch *gdbarch, enum gdb_signal signal);
 extern int gdbarch_gdb_signal_to_target (struct gdbarch *gdbarch, enum gdb_signal signal);
@@ -1096,7 +1096,7 @@  extern void set_gdbarch_gdb_signal_to_target (struct gdbarch *gdbarch, gdbarch_g
   
    Return a type suitable to inspect extra signal information. */
 
-extern int gdbarch_get_siginfo_type_p (struct gdbarch *gdbarch);
+extern int gdbarch_get_siginfo_type_p (const struct gdbarch *gdbarch);
 
 typedef struct type * (gdbarch_get_siginfo_type_ftype) (struct gdbarch *gdbarch);
 extern struct type * gdbarch_get_siginfo_type (struct gdbarch *gdbarch);
@@ -1104,7 +1104,7 @@  extern void set_gdbarch_get_siginfo_type (struct gdbarch *gdbarch, gdbarch_get_s
 
 /* Record architecture-specific information from the symbol table. */
 
-extern int gdbarch_record_special_symbol_p (struct gdbarch *gdbarch);
+extern int gdbarch_record_special_symbol_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_record_special_symbol_ftype) (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym);
 extern void gdbarch_record_special_symbol (struct gdbarch *gdbarch, struct objfile *objfile, asymbol *sym);
@@ -1113,7 +1113,7 @@  extern void set_gdbarch_record_special_symbol (struct gdbarch *gdbarch, gdbarch_
 /* Function for the 'catch syscall' feature.
    Get architecture-specific system calls information from registers. */
 
-extern int gdbarch_get_syscall_number_p (struct gdbarch *gdbarch);
+extern int gdbarch_get_syscall_number_p (const struct gdbarch *gdbarch);
 
 typedef LONGEST (gdbarch_get_syscall_number_ftype) (struct gdbarch *gdbarch, ptid_t ptid);
 extern LONGEST gdbarch_get_syscall_number (struct gdbarch *gdbarch, ptid_t ptid);
@@ -1121,12 +1121,12 @@  extern void set_gdbarch_get_syscall_number (struct gdbarch *gdbarch, gdbarch_get
 
 /* The filename of the XML syscall for this architecture. */
 
-extern const char * gdbarch_xml_syscall_file (struct gdbarch *gdbarch);
+extern const char * gdbarch_xml_syscall_file (const struct gdbarch *gdbarch);
 extern void set_gdbarch_xml_syscall_file (struct gdbarch *gdbarch, const char * xml_syscall_file);
 
 /* Information about system calls from this architecture */
 
-extern struct syscalls_info * gdbarch_syscalls_info (struct gdbarch *gdbarch);
+extern struct syscalls_info * gdbarch_syscalls_info (const struct gdbarch *gdbarch);
 extern void set_gdbarch_syscalls_info (struct gdbarch *gdbarch, struct syscalls_info * syscalls_info);
 
 /* SystemTap related fields and functions.
@@ -1138,13 +1138,13 @@  extern void set_gdbarch_syscalls_info (struct gdbarch *gdbarch, struct syscalls_
   
    in this case, this prefix would be the character `$'. */
 
-extern const char *const * gdbarch_stap_integer_prefixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_integer_prefixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_integer_prefixes (struct gdbarch *gdbarch, const char *const * stap_integer_prefixes);
 
 /* A NULL-terminated array of suffixes used to mark an integer constant
    on the architecture's assembly. */
 
-extern const char *const * gdbarch_stap_integer_suffixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_integer_suffixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_integer_suffixes (struct gdbarch *gdbarch, const char *const * stap_integer_suffixes);
 
 /* A NULL-terminated array of prefixes used to mark a register name on
@@ -1155,13 +1155,13 @@  extern void set_gdbarch_stap_integer_suffixes (struct gdbarch *gdbarch, const ch
   
    in this case, this prefix would be the character `%'. */
 
-extern const char *const * gdbarch_stap_register_prefixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_register_prefixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_register_prefixes (struct gdbarch *gdbarch, const char *const * stap_register_prefixes);
 
 /* A NULL-terminated array of suffixes used to mark a register name on
    the architecture's assembly. */
 
-extern const char *const * gdbarch_stap_register_suffixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_register_suffixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_register_suffixes (struct gdbarch *gdbarch, const char *const * stap_register_suffixes);
 
 /* A NULL-terminated array of prefixes used to mark a register
@@ -1175,7 +1175,7 @@  extern void set_gdbarch_stap_register_suffixes (struct gdbarch *gdbarch, const c
    Please note that we use the indirection prefix also for register
    displacement, e.g., `4(%eax)' on x86. */
 
-extern const char *const * gdbarch_stap_register_indirection_prefixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_register_indirection_prefixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_register_indirection_prefixes (struct gdbarch *gdbarch, const char *const * stap_register_indirection_prefixes);
 
 /* A NULL-terminated array of suffixes used to mark a register
@@ -1189,7 +1189,7 @@  extern void set_gdbarch_stap_register_indirection_prefixes (struct gdbarch *gdba
    Please note that we use the indirection suffix also for register
    displacement, e.g., `4(%eax)' on x86. */
 
-extern const char *const * gdbarch_stap_register_indirection_suffixes (struct gdbarch *gdbarch);
+extern const char *const * gdbarch_stap_register_indirection_suffixes (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_register_indirection_suffixes (struct gdbarch *gdbarch, const char *const * stap_register_indirection_suffixes);
 
 /* Prefix(es) used to name a register using GDB's nomenclature.
@@ -1199,12 +1199,12 @@  extern void set_gdbarch_stap_register_indirection_suffixes (struct gdbarch *gdba
    inside GDB this same register has an `r' appended to its name, so the 10th
    register would be represented as `r10' internally. */
 
-extern const char * gdbarch_stap_gdb_register_prefix (struct gdbarch *gdbarch);
+extern const char * gdbarch_stap_gdb_register_prefix (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_gdb_register_prefix (struct gdbarch *gdbarch, const char * stap_gdb_register_prefix);
 
 /* Suffix used to name a register using GDB's nomenclature. */
 
-extern const char * gdbarch_stap_gdb_register_suffix (struct gdbarch *gdbarch);
+extern const char * gdbarch_stap_gdb_register_suffix (const struct gdbarch *gdbarch);
 extern void set_gdbarch_stap_gdb_register_suffix (struct gdbarch *gdbarch, const char * stap_gdb_register_suffix);
 
 /* Check if S is a single operand.
@@ -1220,7 +1220,7 @@  extern void set_gdbarch_stap_gdb_register_suffix (struct gdbarch *gdbarch, const
    as much info as you can from the string, i.e., if you have to match
    something like `(%', do not match just the `('. */
 
-extern int gdbarch_stap_is_single_operand_p (struct gdbarch *gdbarch);
+extern int gdbarch_stap_is_single_operand_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_stap_is_single_operand_ftype) (struct gdbarch *gdbarch, const char *s);
 extern int gdbarch_stap_is_single_operand (struct gdbarch *gdbarch, const char *s);
@@ -1248,7 +1248,7 @@  extern void set_gdbarch_stap_is_single_operand (struct gdbarch *gdbarch, gdbarch
    zero means that the special parser is deferring the parsing to the generic
    parser), and should advance the buffer pointer (p->arg). */
 
-extern int gdbarch_stap_parse_special_token_p (struct gdbarch *gdbarch);
+extern int gdbarch_stap_parse_special_token_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_stap_parse_special_token_ftype) (struct gdbarch *gdbarch, struct stap_parse_info *p);
 extern int gdbarch_stap_parse_special_token (struct gdbarch *gdbarch, struct stap_parse_info *p);
@@ -1258,7 +1258,7 @@  extern void set_gdbarch_stap_parse_special_token (struct gdbarch *gdbarch, gdbar
    The expression to compute the NARTGth+1 argument to a DTrace USDT probe.
    NARG must be >= 0. */
 
-extern int gdbarch_dtrace_parse_probe_argument_p (struct gdbarch *gdbarch);
+extern int gdbarch_dtrace_parse_probe_argument_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_dtrace_parse_probe_argument_ftype) (struct gdbarch *gdbarch, struct parser_state *pstate, int narg);
 extern void gdbarch_dtrace_parse_probe_argument (struct gdbarch *gdbarch, struct parser_state *pstate, int narg);
@@ -1267,7 +1267,7 @@  extern void set_gdbarch_dtrace_parse_probe_argument (struct gdbarch *gdbarch, gd
 /* True if the given ADDR does not contain the instruction sequence
    corresponding to a disabled DTrace is-enabled probe. */
 
-extern int gdbarch_dtrace_probe_is_enabled_p (struct gdbarch *gdbarch);
+extern int gdbarch_dtrace_probe_is_enabled_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_dtrace_probe_is_enabled_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern int gdbarch_dtrace_probe_is_enabled (struct gdbarch *gdbarch, CORE_ADDR addr);
@@ -1275,7 +1275,7 @@  extern void set_gdbarch_dtrace_probe_is_enabled (struct gdbarch *gdbarch, gdbarc
 
 /* Enable a DTrace is-enabled probe at ADDR. */
 
-extern int gdbarch_dtrace_enable_probe_p (struct gdbarch *gdbarch);
+extern int gdbarch_dtrace_enable_probe_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_dtrace_enable_probe_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern void gdbarch_dtrace_enable_probe (struct gdbarch *gdbarch, CORE_ADDR addr);
@@ -1283,7 +1283,7 @@  extern void set_gdbarch_dtrace_enable_probe (struct gdbarch *gdbarch, gdbarch_dt
 
 /* Disable a DTrace is-enabled probe at ADDR. */
 
-extern int gdbarch_dtrace_disable_probe_p (struct gdbarch *gdbarch);
+extern int gdbarch_dtrace_disable_probe_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_dtrace_disable_probe_ftype) (struct gdbarch *gdbarch, CORE_ADDR addr);
 extern void gdbarch_dtrace_disable_probe (struct gdbarch *gdbarch, CORE_ADDR addr);
@@ -1295,7 +1295,7 @@  extern void set_gdbarch_dtrace_disable_probe (struct gdbarch *gdbarch, gdbarch_d
    an address space, will see the same set of symbols at the same
    addresses. */
 
-extern int gdbarch_has_global_solist (struct gdbarch *gdbarch);
+extern int gdbarch_has_global_solist (const struct gdbarch *gdbarch);
 extern void set_gdbarch_has_global_solist (struct gdbarch *gdbarch, int has_global_solist);
 
 /* On some targets, even though each inferior has its own private
@@ -1303,7 +1303,7 @@  extern void set_gdbarch_has_global_solist (struct gdbarch *gdbarch, int has_glob
    visible to all address spaces automatically.  For such cases,
    this property should be set to true. */
 
-extern int gdbarch_has_global_breakpoints (struct gdbarch *gdbarch);
+extern int gdbarch_has_global_breakpoints (const struct gdbarch *gdbarch);
 extern void set_gdbarch_has_global_breakpoints (struct gdbarch *gdbarch, int has_global_breakpoints);
 
 /* True if inferiors share an address space (e.g., uClinux). */
@@ -1337,14 +1337,14 @@  extern void set_gdbarch_auto_wide_charset (struct gdbarch *gdbarch, gdbarch_auto
    where the names of the files run on the target differ in extension
    compared to the names of the files GDB should load for debug info. */
 
-extern const char * gdbarch_solib_symbols_extension (struct gdbarch *gdbarch);
+extern const char * gdbarch_solib_symbols_extension (const struct gdbarch *gdbarch);
 extern void set_gdbarch_solib_symbols_extension (struct gdbarch *gdbarch, const char * solib_symbols_extension);
 
 /* If true, the target OS has DOS-based file system semantics.  That
    is, absolute paths include a drive name, and the backslash is
    considered a directory separator. */
 
-extern int gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch);
+extern int gdbarch_has_dos_based_file_system (const struct gdbarch *gdbarch);
 extern void set_gdbarch_has_dos_based_file_system (struct gdbarch *gdbarch, int has_dos_based_file_system);
 
 /* Generate bytecodes to collect the return address in a frame.
@@ -1359,7 +1359,7 @@  extern void set_gdbarch_gen_return_address (struct gdbarch *gdbarch, gdbarch_gen
 
 /* Implement the "info proc" command. */
 
-extern int gdbarch_info_proc_p (struct gdbarch *gdbarch);
+extern int gdbarch_info_proc_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_info_proc_ftype) (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
 extern void gdbarch_info_proc (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
@@ -1369,7 +1369,7 @@  extern void set_gdbarch_info_proc (struct gdbarch *gdbarch, gdbarch_info_proc_ft
    are two "info_proc"-like methods on gdbarch -- one for core files,
    one for live targets. */
 
-extern int gdbarch_core_info_proc_p (struct gdbarch *gdbarch);
+extern int gdbarch_core_info_proc_p (const struct gdbarch *gdbarch);
 
 typedef void (gdbarch_core_info_proc_ftype) (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
 extern void gdbarch_core_info_proc (struct gdbarch *gdbarch, const char *args, enum info_proc_what what);
@@ -1395,7 +1395,7 @@  extern void set_gdbarch_iterate_over_objfiles_in_search_order (struct gdbarch *g
 
 /* Ravenscar arch-dependent ops. */
 
-extern struct ravenscar_arch_ops * gdbarch_ravenscar_ops (struct gdbarch *gdbarch);
+extern struct ravenscar_arch_ops * gdbarch_ravenscar_ops (const struct gdbarch *gdbarch);
 extern void set_gdbarch_ravenscar_ops (struct gdbarch *gdbarch, struct ravenscar_arch_ops * ravenscar_ops);
 
 /* Return non-zero if the instruction at ADDR is a call; zero otherwise. */
@@ -1421,7 +1421,7 @@  extern void set_gdbarch_insn_is_jump (struct gdbarch *gdbarch, gdbarch_insn_is_j
    Return -1 if there is insufficient buffer for a whole entry.
    Return 1 if an entry was read into *TYPEP and *VALP. */
 
-extern int gdbarch_auxv_parse_p (struct gdbarch *gdbarch);
+extern int gdbarch_auxv_parse_p (const struct gdbarch *gdbarch);
 
 typedef int (gdbarch_auxv_parse_ftype) (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
 extern int gdbarch_auxv_parse (struct gdbarch *gdbarch, gdb_byte **readptr, gdb_byte *endptr, CORE_ADDR *typep, CORE_ADDR *valp);
diff --git a/gdb/gdbarch.sh b/gdb/gdbarch.sh
index 34e6a74..9338c24 100755
--- a/gdb/gdbarch.sh
+++ b/gdb/gdbarch.sh
@@ -1291,7 +1291,7 @@  do
     if class_is_info_p
     then
 	printf "\n"
-	printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
+	printf "extern ${returntype} gdbarch_${function} (const struct gdbarch *gdbarch);\n"
 	printf "/* set_gdbarch_${function}() - not applicable - pre-initialized.  */\n"
     fi
 done
@@ -1313,12 +1313,12 @@  do
     if class_is_predicate_p
     then
 	printf "\n"
-	printf "extern int gdbarch_${function}_p (struct gdbarch *gdbarch);\n"
+	printf "extern int gdbarch_${function}_p (const struct gdbarch *gdbarch);\n"
     fi
     if class_is_variable_p
     then
 	printf "\n"
-	printf "extern ${returntype} gdbarch_${function} (struct gdbarch *gdbarch);\n"
+	printf "extern ${returntype} gdbarch_${function} (const struct gdbarch *gdbarch);\n"
 	printf "extern void set_gdbarch_${function} (struct gdbarch *gdbarch, ${returntype} ${function});\n"
     fi
     if class_is_function_p
@@ -1957,7 +1957,7 @@  do
     then
 	printf "\n"
 	printf "int\n"
-	printf "gdbarch_${function}_p (struct gdbarch *gdbarch)\n"
+	printf "gdbarch_${function}_p (const struct gdbarch *gdbarch)\n"
 	printf "{\n"
         printf "  gdb_assert (gdbarch != NULL);\n"
 	printf "  return ${predicate};\n"
@@ -2017,7 +2017,7 @@  do
     then
 	printf "\n"
 	printf "${returntype}\n"
-	printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
+	printf "gdbarch_${function} (const struct gdbarch *gdbarch)\n"
 	printf "{\n"
         printf "  gdb_assert (gdbarch != NULL);\n"
 	if [ "x${invalid_p}" = "x0" ]
@@ -2047,7 +2047,7 @@  do
     then
 	printf "\n"
 	printf "${returntype}\n"
-	printf "gdbarch_${function} (struct gdbarch *gdbarch)\n"
+	printf "gdbarch_${function} (const struct gdbarch *gdbarch)\n"
 	printf "{\n"
         printf "  gdb_assert (gdbarch != NULL);\n"
 	printf "  if (gdbarch_debug >= 2)\n"
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 8204d39..404f38b 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1413,13 +1413,13 @@  type_name_no_tag_or_error (struct type *type)
 
 struct type *
 lookup_typename (const struct language_defn *language,
-		 struct gdbarch *gdbarch, const char *name,
+		 const struct gdbarch *gdbarch, const char *name,
 		 const struct block *block, int noerr)
 {
   struct symbol *sym;
   struct type *type;
 
-  sym = lookup_symbol_in_language (name, block, VAR_DOMAIN,
+  sym = lookup_symbol_in_language (name, block, gdbarch, VAR_DOMAIN,
 				   language->la_language, NULL).symbol;
   if (sym != NULL && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
     return SYMBOL_TYPE (sym);
@@ -1460,11 +1460,12 @@  lookup_signed_typename (const struct language_defn *language,
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_struct (const char *name, const struct block *block)
+lookup_struct (const char *name, const struct block *block,
+	       const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, gdbarch, STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -1482,12 +1483,13 @@  lookup_struct (const char *name, const struct block *block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_union (const char *name, const struct block *block)
+lookup_union (const char *name, const struct block *block,
+	      const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
   struct type *t;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, gdbarch, STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     error (_("No union type named %s."), name);
@@ -1506,11 +1508,12 @@  lookup_union (const char *name, const struct block *block)
    visible in lexical block BLOCK.  */
 
 struct type *
-lookup_enum (const char *name, const struct block *block)
+lookup_enum (const char *name, const struct block *block,
+	     const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, gdbarch, STRUCT_DOMAIN, 0).symbol;
   if (sym == NULL)
     {
       error (_("No enum type named %s."), name);
@@ -1528,7 +1531,8 @@  lookup_enum (const char *name, const struct block *block)
 
 struct type *
 lookup_template_type (char *name, struct type *type, 
-		      const struct block *block)
+		      const struct block *block,
+		      const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
   char *nam = (char *) 
@@ -1539,7 +1543,7 @@  lookup_template_type (char *name, struct type *type,
   strcat (nam, TYPE_NAME (type));
   strcat (nam, " >");	/* FIXME, extra space still introduced in gcc?  */
 
-  sym = lookup_symbol (nam, block, VAR_DOMAIN, 0).symbol;
+  sym = lookup_symbol (nam, block, gdbarch, VAR_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -2257,7 +2261,8 @@  check_typedef (struct type *type)
 	      stub_noname_complaint ();
 	      return make_qualified_type (type, instance_flags, NULL);
 	    }
-	  sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
+	  sym = lookup_symbol (name, 0, get_type_arch (type), STRUCT_DOMAIN,
+			       0).symbol;
 	  if (sym)
 	    TYPE_TARGET_TYPE (type) = SYMBOL_TYPE (sym);
 	  else					/* TYPE_CODE_UNDEF */
@@ -2348,7 +2353,8 @@  check_typedef (struct type *type)
 	  stub_noname_complaint ();
 	  return make_qualified_type (type, instance_flags, NULL);
 	}
-      sym = lookup_symbol (name, 0, STRUCT_DOMAIN, 0).symbol;
+      sym = lookup_symbol (name, 0, get_type_arch (type), STRUCT_DOMAIN,
+			   0).symbol;
       if (sym)
         {
           /* Same as above for opaque types, we can replace the stub
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index f270855..f134083 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1816,11 +1816,12 @@  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 gdbarch *, const char *,
 				     const struct block *, int);
 
 extern struct type *lookup_template_type (char *, struct type *,
-					  const struct block *);
+					  const struct block *,
+					  const struct gdbarch *);
 
 extern int get_vptr_fieldno (struct type *, struct type **);
 
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 3b6cc77..8f3c1fb 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -1061,8 +1061,8 @@  gnuv3_get_typeid_type (struct gdbarch *gdbarch)
   struct symbol *typeinfo;
   struct type *typeinfo_type;
 
-  typeinfo = lookup_symbol ("std::type_info", NULL, STRUCT_DOMAIN,
-			    NULL).symbol;
+  typeinfo = lookup_symbol_for_arch ("std::type_info", gdbarch,
+				     STRUCT_DOMAIN).symbol;
   if (typeinfo == NULL)
     typeinfo_type = gdbarch_data (gdbarch, std_type_info_gdbarch_data);
   else
diff --git a/gdb/go-exp.y b/gdb/go-exp.y
index 4e017fe..1ede04f 100644
--- a/gdb/go-exp.y
+++ b/gdb/go-exp.y
@@ -1374,12 +1374,11 @@  build_packaged_name (const char *package, int package_len,
    to mean the global scope.  */
 
 static int
-package_name_p (const char *name, const struct block *block)
+package_name_p (const char *name, const struct block *block,
+		const struct gdbarch *gdbarch)
 {
-  struct symbol *sym;
-  struct field_of_this_result is_a_field_of_this;
-
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, &is_a_field_of_this).symbol;
+  struct symbol *sym = lookup_symbol (name, block, gdbarch, STRUCT_DOMAIN,
+				      NULL).symbol;
 
   if (sym
       && SYMBOL_CLASS (sym) == LOC_TYPEDEF
@@ -1414,7 +1413,8 @@  classify_unsafe_function (struct stoken function_name)
    The result is one of NAME, NAME_OR_INT, or TYPENAME.  */
 
 static int
-classify_packaged_name (const struct block *block)
+classify_packaged_name (const struct block *block,
+			const struct gdbarch *gdbarch)
 {
   char *copy;
   struct block_symbol sym;
@@ -1422,7 +1422,7 @@  classify_packaged_name (const struct block *block)
 
   copy = copy_name (yylval.sval);
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy, block, gdbarch, VAR_DOMAIN, &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1466,7 +1466,8 @@  classify_name (struct parser_state *par_state, const struct block *block)
 
   /* TODO: What about other types?  */
 
-  sym = lookup_symbol (copy, block, VAR_DOMAIN, &is_a_field_of_this);
+  sym = lookup_symbol (copy, block, parse_gdbarch (par_state), VAR_DOMAIN,
+		       &is_a_field_of_this);
 
   if (sym.symbol)
     {
@@ -1491,8 +1492,8 @@  classify_name (struct parser_state *par_state, const struct block *block)
 			       copy, strlen (copy));
 
 	xfree (current_package_name);
-	sym = lookup_symbol (sval.ptr, block, VAR_DOMAIN,
-			     &is_a_field_of_this);
+	sym = lookup_symbol (sval.ptr, block, parse_gdbarch (par_state),
+			     VAR_DOMAIN, &is_a_field_of_this);
 	if (sym.symbol)
 	  {
 	    yylval.ssym.stoken = sval;
@@ -1580,14 +1581,16 @@  yylex (void)
 	      return classify_unsafe_function (name2.value.sval);
 	    }
 
-	  if (package_name_p (copy, expression_context_block))
+	  if (package_name_p (copy, expression_context_block,
+			      parse_gdbarch (pstate)))
 	    {
 	      popping = 1;
 	      yylval.sval = build_packaged_name (current.value.sval.ptr,
 						 current.value.sval.length,
 						 name2.value.sval.ptr,
 						 name2.value.sval.length);
-	      return classify_packaged_name (expression_context_block);
+	      return classify_packaged_name (expression_context_block,
+					     parse_gdbarch (pstate));
 	    }
 	}
 
diff --git a/gdb/guile/scm-frame.c b/gdb/guile/scm-frame.c
index de77c21..f175f2d 100644
--- a/gdb/guile/scm-frame.c
+++ b/gdb/guile/scm-frame.c
@@ -911,10 +911,14 @@  gdbscm_frame_read_var (SCM self, SCM symbol_scm, SCM rest)
       TRY
 	{
 	  struct block_symbol lookup_sym;
+	  const struct gdbarch *gdbarch = NULL;
 
 	  if (block == NULL)
 	    block = get_frame_block (frame, NULL);
-	  lookup_sym = lookup_symbol (var_name, block, VAR_DOMAIN, NULL);
+	  if (block == NULL)
+	    gdbarch = get_frame_arch (frame);
+	  lookup_sym
+	    = lookup_symbol (var_name, block, gdbarch, VAR_DOMAIN, NULL);
 	  var = lookup_sym.symbol;
 	  block = lookup_sym.block;
 	}
diff --git a/gdb/guile/scm-symbol.c b/gdb/guile/scm-symbol.c
index 0970a72..6fd732f 100644
--- a/gdb/guile/scm-symbol.c
+++ b/gdb/guile/scm-symbol.c
@@ -576,6 +576,7 @@  gdbscm_lookup_symbol (SCM name_scm, SCM rest)
   char *name;
   SCM keywords[] = { block_keyword, domain_keyword, SCM_BOOL_F };
   const struct block *block = NULL;
+  const struct gdbarch *gdbarch = NULL;
   SCM block_scm = SCM_BOOL_F;
   int domain = VAR_DOMAIN;
   int block_arg_pos = -1, domain_arg_pos = -1;
@@ -611,6 +612,8 @@  gdbscm_lookup_symbol (SCM name_scm, SCM rest)
 	{
 	  selected_frame = get_selected_frame (_("no frame selected"));
 	  block = get_frame_block (selected_frame, NULL);
+	  if (block == NULL)
+	    gdbarch = get_frame_arch (selected_frame);
 	}
       CATCH (except, RETURN_MASK_ALL)
 	{
@@ -621,7 +624,8 @@  gdbscm_lookup_symbol (SCM name_scm, SCM rest)
 
   TRY
     {
-      symbol = lookup_symbol (name, block, domain, &is_a_field_of_this).symbol;
+      symbol = lookup_symbol (name, block, gdbarch, domain,
+			      &is_a_field_of_this).symbol;
     }
   CATCH (ex, RETURN_MASK_ALL)
     {
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index fa0c213..18fc0b1 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -1243,17 +1243,18 @@  static struct type *
 tyscm_lookup_typename (const char *type_name, const struct block *block)
 {
   struct type *type = NULL;
+  const struct gdbarch *gdbarch = get_current_arch ();
 
   TRY
     {
       if (startswith (type_name, "struct "))
-	type = lookup_struct (type_name + 7, NULL);
+	type = lookup_struct (type_name + 7, block, gdbarch);
       else if (startswith (type_name, "union "))
-	type = lookup_union (type_name + 6, NULL);
+	type = lookup_union (type_name + 6, block, gdbarch);
       else if (startswith (type_name, "enum "))
-	type = lookup_enum (type_name + 5, NULL);
+	type = lookup_enum (type_name + 5, block, gdbarch);
       else
-	type = lookup_typename (current_language, get_current_arch (),
+	type = lookup_typename (current_language, gdbarch,
 				type_name, block, 0);
     }
   CATCH (except, RETURN_MASK_ALL)
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 70dffca..d9c2cbc 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7212,7 +7212,8 @@  insert_exception_resume_breakpoint (struct thread_info *tp,
       CORE_ADDR handler;
       struct breakpoint *bp;
 
-      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b, VAR_DOMAIN, NULL);
+      vsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym), b,
+			    get_frame_arch (frame), VAR_DOMAIN, NULL);
       value = read_var_value (vsym.symbol, vsym.block, frame);
       /* If the value was optimized out, revert to the old behavior.  */
       if (! value_optimized_out (value))
diff --git a/gdb/jv-exp.y b/gdb/jv-exp.y
index 60b7d2e..ad490e4 100644
--- a/gdb/jv-exp.y
+++ b/gdb/jv-exp.y
@@ -122,7 +122,7 @@  static int yylex (void);
 
 void yyerror (char *);
 
-static struct type *java_type_from_name (struct stoken);
+static struct type *java_type_from_name (struct parser_state *, struct stoken);
 static void push_expression_name (struct parser_state *, struct stoken);
 static void push_fieldnames (struct parser_state *, struct stoken);
 
@@ -316,7 +316,7 @@  ReferenceType:
 
 ClassOrInterfaceType:
 	Name
-		{ $$ = java_type_from_name ($1); }
+		{ $$ = java_type_from_name (pstate, $1); }
 ;
 
 ClassType:
@@ -327,7 +327,7 @@  ArrayType:
 	PrimitiveType Dims
 		{ $$ = java_array_type ($1, $2); }
 |	Name Dims
-		{ $$ = java_array_type (java_type_from_name ($1), $2); }
+		{ $$ = java_array_type (java_type_from_name (pstate, $1), $2); }
 ;
 
 Name:
@@ -593,7 +593,7 @@  CastExpression:
 		{ write_exp_elt_opcode (pstate, UNOP_CAST);
 		  write_exp_elt_type (pstate,
 				      java_array_type (java_type_from_name
-						       ($2), $3));
+						       (pstate, $2), $3));
 		  write_exp_elt_opcode (pstate, UNOP_CAST); }
 ;
 
@@ -1253,10 +1253,11 @@  yyerror (char *msg)
 }
 
 static struct type *
-java_type_from_name (struct stoken name)
+java_type_from_name (struct parser_state *par_state, struct stoken name)
 {
   char *tmp = copy_name (name);
-  struct type *typ = java_lookup_class (tmp);
+  struct type *typ = java_lookup_class (tmp, parse_gdbarch (par_state));
+
   if (typ == NULL || TYPE_CODE (typ) != TYPE_CODE_STRUCT)
     error (_("No class named `%s'"), tmp);
   return typ;
@@ -1272,7 +1273,8 @@  push_variable (struct parser_state *par_state, struct stoken name)
   struct field_of_this_result is_a_field_of_this;
   struct block_symbol sym;
 
-  sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN,
+  sym = lookup_symbol (tmp, expression_context_block,
+		       parse_gdbarch (par_state), VAR_DOMAIN,
 		       &is_a_field_of_this);
   if (sym.symbol && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
     {
@@ -1359,7 +1361,7 @@  push_qualified_expression_name (struct parser_state *par_state,
     {
       token.length = dot_index;
       tmp = copy_name (token);
-      typ = java_lookup_class (tmp);
+      typ = java_lookup_class (tmp, parse_gdbarch (par_state));
       if (typ != NULL)
 	{
 	  if (dot_index == name.length)
@@ -1424,7 +1426,7 @@  push_expression_name (struct parser_state *par_state, struct stoken name)
   if (push_variable (par_state, name))
     return;
   tmp = copy_name (name);
-  typ = java_lookup_class (tmp);
+  typ = java_lookup_class (tmp, parse_gdbarch (par_state));
   if (typ != NULL)
     {
       write_exp_elt_opcode (par_state, OP_TYPE);
diff --git a/gdb/jv-lang.c b/gdb/jv-lang.c
index 73df044..71f50aa 100644
--- a/gdb/jv-lang.c
+++ b/gdb/jv-lang.c
@@ -198,11 +198,11 @@  add_class_symbol (struct type *type, CORE_ADDR addr)
 }
 
 struct type *
-java_lookup_class (char *name)
+java_lookup_class (char *name, const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, expression_context_block, STRUCT_DOMAIN,
+  sym = lookup_symbol (name, expression_context_block, gdbarch, STRUCT_DOMAIN,
 		       NULL).symbol;
   if (sym != NULL)
     return SYMBOL_TYPE (sym);
@@ -239,7 +239,7 @@  java_class_from_object (struct value *obj_val)
 
   if (TYPE_CODE (value_type (obj_val)) == TYPE_CODE_PTR
       && TYPE_LENGTH (TYPE_TARGET_TYPE (value_type (obj_val))) == 0)
-    obj_val = value_at (get_java_object_type (),
+    obj_val = value_at (get_java_object_type (get_value_arch (obj_val)),
 			value_as_address (obj_val));
 
   vtable_val = value_struct_elt (&obj_val, NULL, "vtable", NULL, "structure");
@@ -300,7 +300,7 @@  type_from_class (struct gdbarch *gdbarch, struct value *clas)
 	*nptr = '.';
     }
 
-  type = java_lookup_class (name);
+  type = java_lookup_class (name, gdbarch);
   if (type != NULL)
     return type;
 
@@ -362,7 +362,7 @@  java_link_class_type (struct gdbarch *gdbarch,
   temp = value_struct_elt (&temp, NULL, "superclass", NULL, "structure");
   if (strcmp (name, "java.lang.Object") == 0)
     {
-      tsuper = get_java_object_type ();
+      tsuper = get_java_object_type (gdbarch);
       if (tsuper && TYPE_CODE (tsuper) == TYPE_CODE_PTR)
 	tsuper = TYPE_TARGET_TYPE (tsuper);
       type_is_object = 1;
@@ -481,7 +481,8 @@  java_link_class_type (struct gdbarch *gdbarch,
 	SET_FIELD_BITPOS (TYPE_FIELD (type, i), 8 * boffset);
       if (accflags & 0x8000)	/* FIELD_UNRESOLVED_FLAG */
 	{
-	  TYPE_FIELD_TYPE (type, i) = get_java_object_type ();	/* FIXME */
+	  TYPE_FIELD_TYPE (type, i)
+	    = get_java_object_type (gdbarch); /* FIXME */
 	}
       else
 	{
@@ -587,11 +588,12 @@  java_link_class_type (struct gdbarch *gdbarch,
 }
 
 struct type *
-get_java_object_type (void)
+get_java_object_type (const struct gdbarch *gdbarch)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol ("java.lang.Object", NULL, STRUCT_DOMAIN, NULL).symbol;
+  sym = lookup_symbol ("java.lang.Object", NULL, gdbarch, STRUCT_DOMAIN,
+		       NULL).symbol;
   if (sym == NULL)
     error (_("cannot find java.lang.Object"));
   return SYMBOL_TYPE (sym);
@@ -600,7 +602,7 @@  get_java_object_type (void)
 int
 get_java_object_header_size (struct gdbarch *gdbarch)
 {
-  struct type *objtype = get_java_object_type ();
+  struct type *objtype = get_java_object_type (gdbarch);
 
   if (objtype == NULL)
     return (2 * gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
diff --git a/gdb/jv-lang.h b/gdb/jv-lang.h
index d34998a..bf3daef 100644
--- a/gdb/jv-lang.h
+++ b/gdb/jv-lang.h
@@ -62,10 +62,10 @@  extern struct type *java_primitive_type_from_name (struct gdbarch *,
 
 extern struct type *java_array_type (struct type *, int);
 
-extern struct type *get_java_object_type (void);
+extern struct type *get_java_object_type (const struct gdbarch *);
 extern int get_java_object_header_size (struct gdbarch *);
 
-extern struct type *java_lookup_class (char *);
+extern struct type *java_lookup_class (char *, const struct gdbarch *);
 
 extern int is_object_type (struct type *);
 
diff --git a/gdb/language.c b/gdb/language.c
index 121e8ad..3dd7d0e 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -992,7 +992,7 @@  language_bool_type (const struct language_defn *la,
       struct symbol *sym;
 
       sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol,
-			   NULL, VAR_DOMAIN, NULL).symbol;
+			   NULL, gdbarch, VAR_DOMAIN, NULL).symbol;
       if (sym)
 	{
 	  struct type *type = SYMBOL_TYPE (sym);
@@ -1102,9 +1102,11 @@  language_init_primitive_type_symbols (struct language_arch_info *lai,
 
 struct symbol *
 language_lookup_primitive_type_as_symbol (const struct language_defn *la,
-					  struct gdbarch *gdbarch,
+					  const struct gdbarch *c_gdbarch,
 					  const char *name)
 {
+  /* Internally gdbarch is mutable.  */
+  struct gdbarch *gdbarch = (struct gdbarch *) c_gdbarch;
   struct language_gdbarch *ld = gdbarch_data (gdbarch,
 					      language_gdbarch_data);
   struct language_arch_info *lai = &ld->arch_info[la->la_language];
diff --git a/gdb/language.h b/gdb/language.h
index 8b579a2..2aabe47 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -277,6 +277,7 @@  struct language_defn
       (const struct language_defn *,
        const char *,
        const struct block *,
+       const struct gdbarch *,
        const domain_enum);
 
     /* Find the definition of the type with the given name.  */
@@ -460,7 +461,7 @@  struct type *language_lookup_primitive_type (const struct language_defn *l,
 
 struct symbol *
   language_lookup_primitive_type_as_symbol (const struct language_defn *l,
-					    struct gdbarch *gdbarch,
+					    const struct gdbarch *gdbarch,
 					    const char *name);
 
 
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 8f102fa..66b410e 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2734,6 +2734,7 @@  decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
   const char *new_argptr;
   struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
 					  &symbol_names);
+  const struct gdbarch *gdbarch = target_gdbarch ();
 
   info.state = self;
   info.file_symtabs = NULL;
@@ -2744,7 +2745,7 @@  decode_objc (struct linespec_state *self, linespec_p ls, const char *arg)
   values.nelts = 0;
   values.sals = NULL;
 
-  new_argptr = find_imps (arg, &symbol_names);
+  new_argptr = find_imps (arg, gdbarch, &symbol_names);
   if (VEC_empty (const_char_ptr, symbol_names))
     {
       do_cleanups (cleanup);
@@ -3176,6 +3177,7 @@  find_function_symbols (struct linespec_state *state,
   VEC (const_char_ptr) *symbol_names = NULL;
   struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
 					  &symbol_names);
+  const struct gdbarch *gdbarch = target_gdbarch ();
 
   info.state = state;
   info.result.symbols = NULL;
@@ -3183,7 +3185,7 @@  find_function_symbols (struct linespec_state *state,
   info.file_symtabs = file_symtabs;
 
   /* Try NAME as an Objective-C selector.  */
-  find_imps (name, &symbol_names);
+  find_imps (name, gdbarch, &symbol_names);
   if (!VEC_empty (const_char_ptr, symbol_names))
     add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
   else
@@ -3355,7 +3357,7 @@  find_label_symbols (struct linespec_state *self,
 	return NULL;
       fn_sym = BLOCK_FUNCTION (block);
 
-      sym = lookup_symbol (name, block, LABEL_DOMAIN, 0).symbol;
+      sym = lookup_symbol (name, block, NULL, LABEL_DOMAIN, 0).symbol;
 
       if (sym != NULL)
 	{
@@ -3370,7 +3372,7 @@  find_label_symbols (struct linespec_state *self,
 	{
 	  set_current_program_space (SYMTAB_PSPACE (symbol_symtab (fn_sym)));
 	  block = SYMBOL_BLOCK_VALUE (fn_sym);
-	  sym = lookup_symbol (name, block, LABEL_DOMAIN, 0).symbol;
+	  sym = lookup_symbol (name, block, NULL, LABEL_DOMAIN, 0).symbol;
 
 	  if (sym != NULL)
 	    {
diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index 360fdea..283b216 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -564,6 +564,7 @@  fblock	:	BLOCKNAME
 			{ struct symbol *sym
 			    = lookup_symbol (copy_name ($1),
 					     expression_context_block,
+					     parse_gdbarch (pstate),
 					     VAR_DOMAIN, 0).symbol;
 			  $$ = sym;}
 	;
@@ -573,6 +574,7 @@  fblock	:	BLOCKNAME
 fblock	:	block COLONCOLON BLOCKNAME
 			{ struct symbol *tem
 			    = lookup_symbol (copy_name ($3), $1,
+					     parse_gdbarch (pstate),
 					     VAR_DOMAIN, 0).symbol;
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
@@ -597,6 +599,7 @@  variable:	INTERNAL_VAR
 variable:	block COLONCOLON NAME
 			{ struct block_symbol sym
 			    = lookup_symbol (copy_name ($3), $1,
+					     parse_gdbarch (pstate),
 					     VAR_DOMAIN, 0);
 
 			  if (sym.symbol == 0)
@@ -623,6 +626,7 @@  variable:	NAME
 
 			  sym = lookup_symbol (copy_name ($1),
 					       expression_context_block,
+					       parse_gdbarch (pstate),
 					       VAR_DOMAIN,
 					       &is_a_field_of_this);
 
@@ -1026,7 +1030,8 @@  yylex (void)
 
     if (lookup_symtab (tmp))
       return BLOCKNAME;
-    sym = lookup_symbol (tmp, expression_context_block, VAR_DOMAIN, 0).symbol;
+    sym = lookup_symbol (tmp, expression_context_block, parse_gdbarch (pstate),
+			 VAR_DOMAIN, 0).symbol;
     if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
       return BLOCKNAME;
     if (lookup_typename (parse_language (pstate), parse_gdbarch (pstate),
diff --git a/gdb/mi/mi-cmd-stack.c b/gdb/mi/mi-cmd-stack.c
index 520db2b..8717038 100644
--- a/gdb/mi/mi-cmd-stack.c
+++ b/gdb/mi/mi-cmd-stack.c
@@ -646,9 +646,8 @@  list_args_or_locals (enum what_to_list what, enum print_values values,
 	      struct frame_arg arg, entryarg;
 
 	      if (SYMBOL_IS_ARGUMENT (sym))
-		sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
-				      block, VAR_DOMAIN,
-				      NULL).symbol;
+		sym2 = lookup_symbol_from_block (SYMBOL_LINKAGE_NAME (sym),
+						 block, VAR_DOMAIN).symbol;
 	      else
 		sym2 = sym;
 	      gdb_assert (sym2 != NULL);
diff --git a/gdb/moxie-tdep.c b/gdb/moxie-tdep.c
index 9496314..a915db3 100644
--- a/gdb/moxie-tdep.c
+++ b/gdb/moxie-tdep.c
@@ -241,7 +241,8 @@  moxie_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
 	  plg_end = moxie_analyze_prologue (func_addr, 
 					    func_end, &cache, gdbarch);
 	  /* Found a function.  */
-	  sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+	  sym = lookup_symbol (func_name, NULL, gdbarch, VAR_DOMAIN,
+			       NULL).symbol;
 	  /* Don't use line number debug info for assembly source
 	     files.  */
 	  if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
diff --git a/gdb/mt-tdep.c b/gdb/mt-tdep.c
index ddc9522..9876067 100644
--- a/gdb/mt-tdep.c
+++ b/gdb/mt-tdep.c
@@ -415,7 +415,7 @@  mt_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
       struct symbol *sym;
 
       /* Found a function.  */
-      sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+      sym = lookup_symbol (func_name, NULL, gdbarch, VAR_DOMAIN, NULL).symbol;
       if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
 	{
 	  /* Don't use this trick for assembly source files.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 44dfed7..abfcbec 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -81,11 +81,12 @@  static const struct objfile_data *objc_objfile_data;
    suitably defined.  */
 
 struct symbol *
-lookup_struct_typedef (char *name, const struct block *block, int noerr)
+lookup_struct_typedef (char *name, const struct block *block,
+		       const struct gdbarch *gdbarch, int noerr)
 {
   struct symbol *sym;
 
-  sym = lookup_symbol (name, block, STRUCT_DOMAIN, 0).symbol;
+  sym = lookup_symbol (name, block, gdbarch, STRUCT_DOMAIN, 0).symbol;
 
   if (sym == NULL)
     {
@@ -203,9 +204,9 @@  value_nsstring (struct gdbarch *gdbarch, char *ptr, int len)
   else
     error (_("NSString: internal error -- no way to create new NSString"));
 
-  sym = lookup_struct_typedef("NSString", 0, 1);
+  sym = lookup_struct_typedef ("NSString", 0, gdbarch, 1);
   if (sym == NULL)
-    sym = lookup_struct_typedef("NXString", 0, 1);
+    sym = lookup_struct_typedef ("NXString", 0, gdbarch, 1);
   if (sym == NULL)
     type = builtin_type (gdbarch)->builtin_data_ptr;
   else
@@ -1107,7 +1108,8 @@  uniquify_strings (VEC (const_char_ptr) **strings)
  */
 
 const char *
-find_imps (const char *method, VEC (const_char_ptr) **symbol_names)
+find_imps (const char *method, const struct gdbarch *gdbarch,
+	   VEC (const_char_ptr) **symbol_names)
 {
   char type = '\0';
   char *theclass = NULL;
@@ -1142,7 +1144,7 @@  find_imps (const char *method, VEC (const_char_ptr) **symbol_names)
      add the selector itself as a symbol, if it exists.  */
   if (selector_case && !VEC_empty (const_char_ptr, *symbol_names))
     {
-      struct symbol *sym = lookup_symbol (selector, NULL, VAR_DOMAIN,
+      struct symbol *sym = lookup_symbol (selector, NULL, gdbarch, VAR_DOMAIN,
 					  0).symbol;
 
       if (sym != NULL) 
diff --git a/gdb/objc-lang.h b/gdb/objc-lang.h
index 464c49b..21e651a 100644
--- a/gdb/objc-lang.h
+++ b/gdb/objc-lang.h
@@ -37,8 +37,9 @@  extern char *objc_demangle (const char *mangled, int options);
 
 extern int find_objc_msgcall (CORE_ADDR pc, CORE_ADDR *new_pc);
 
-extern const char *
-  find_imps (const char *method, VEC (const_char_ptr) **symbol_names);
+extern const char *find_imps (const char *method,
+			      const struct gdbarch *gdbarch,
+			      VEC (const_char_ptr) **symbol_names);
 
 extern struct value *value_nsstring (struct gdbarch *gdbarch,
 				     char *ptr, int len);
@@ -49,6 +50,6 @@  extern void add_msglist (struct stoken *str, int addcolon);
 extern int end_msglist (struct parser_state *);
 
 struct symbol *lookup_struct_typedef (char *name, const struct block *block,
-				      int noerr);
+				      const struct gdbarch *, int noerr);
 
 #endif
diff --git a/gdb/p-exp.y b/gdb/p-exp.y
index c255a57..ef11558 100644
--- a/gdb/p-exp.y
+++ b/gdb/p-exp.y
@@ -686,8 +686,8 @@  block	:	BLOCKNAME
 
 block	:	block COLONCOLON name
 			{ struct symbol *tem
-			    = lookup_symbol (copy_name ($3), $1,
-					     VAR_DOMAIN, NULL).symbol;
+			    = lookup_symbol_from_block (copy_name ($3), $1,
+							VAR_DOMAIN).symbol;
 
 			  if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
 			    error (_("No function \"%s\" in specified context."),
@@ -696,10 +696,10 @@  block	:	block COLONCOLON name
 	;
 
 variable:	block COLONCOLON name
-			{ struct block_symbol sym;
+			{ struct block_symbol sym
+			    = lookup_symbol_from_block (copy_name ($3), $1,
+							VAR_DOMAIN);
 
-			  sym = lookup_symbol (copy_name ($3), $1,
-					       VAR_DOMAIN, NULL);
 			  if (sym.symbol == 0)
 			    error (_("No symbol \"%s\" in specified context."),
 				   copy_name ($3));
@@ -735,6 +735,7 @@  variable:	qualified_name
 
 			  sym =
 			    lookup_symbol (name, (const struct block *) NULL,
+					   parse_gdbarch (pstate),
 					   VAR_DOMAIN, NULL).symbol;
 			  if (sym)
 			    {
@@ -848,10 +849,12 @@  typebase  /* Implements (approximately): (type-qualifier)* type-specifier */
 			{ $$ = $1.type; }
 	|	STRUCT name
 			{ $$ = lookup_struct (copy_name ($2),
-					      expression_context_block); }
+					      expression_context_block,
+					      parse_gdbarch (pstate)); }
 	|	CLASS name
 			{ $$ = lookup_struct (copy_name ($2),
-					      expression_context_block); }
+					      expression_context_block,
+					      parse_gdbarch (pstate)); }
 	/* "const" and "volatile" are curently ignored.  A type qualifier
 	   after the type is handled in the ptype rule.  I think these could
 	   be too.  */
@@ -1507,7 +1510,7 @@  yylex (void)
 	  static const char this_name[] = "this";
 
 	  if (lookup_symbol (this_name, expression_context_block,
-			     VAR_DOMAIN, NULL).symbol)
+			     parse_gdbarch (pstate), VAR_DOMAIN, NULL).symbol)
 	    {
 	      free (uptokstart);
 	      return THIS;
@@ -1557,7 +1560,8 @@  yylex (void)
       sym = NULL;
     else
       sym = lookup_symbol (tmp, expression_context_block,
-			   VAR_DOMAIN, &is_a_field_of_this).symbol;
+			   parse_gdbarch (pstate), VAR_DOMAIN,
+			   &is_a_field_of_this).symbol;
     /* second chance uppercased (as Free Pascal does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
       {
@@ -1572,7 +1576,8 @@  yylex (void)
 	 sym = NULL;
        else
 	 sym = lookup_symbol (tmp, expression_context_block,
-			      VAR_DOMAIN, &is_a_field_of_this).symbol;
+			      parse_gdbarch (pstate), VAR_DOMAIN,
+			      &is_a_field_of_this).symbol;
       }
     /* Third chance Capitalized (as GPC does).  */
     if (!sym && is_a_field_of_this.type == NULL && !is_a_field)
@@ -1594,7 +1599,8 @@  yylex (void)
 	 sym = NULL;
        else
 	 sym = lookup_symbol (tmp, expression_context_block,
-			      VAR_DOMAIN, &is_a_field_of_this).symbol;
+			      parse_gdbarch (pstate), VAR_DOMAIN,
+			      &is_a_field_of_this).symbol;
       }
 
     if (is_a_field || (is_a_field_of_this.type != NULL))
@@ -1687,6 +1693,7 @@  yylex (void)
 		      memcpy (tmp1, namestart, p - namestart);
 		      tmp1[p - namestart] = '\0';
 		      cur_sym = lookup_symbol (ncopy, expression_context_block,
+					       parse_gdbarch (pstate),
 					       VAR_DOMAIN, NULL).symbol;
 		      if (cur_sym)
 			{
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index a0b99f8..00eed0d 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -249,7 +249,7 @@  pascal_val_print (struct type *type, const gdb_byte *valaddr,
 
 	      if (msymbol.minsym != NULL)
 		wsym = lookup_symbol (MSYMBOL_LINKAGE_NAME (msymbol.minsym),
-				      block,
+				      block, gdbarch,
 				      VAR_DOMAIN, &is_this_fld).symbol;
 
 	      if (wsym)
diff --git a/gdb/parse.c b/gdb/parse.c
index acd48a5..46edfaf 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -671,7 +671,7 @@  write_dollar_variable (struct parser_state *ps, struct stoken str)
      have names beginning with $ or $$.  Check for those, first.  */
 
   sym = lookup_symbol (copy_name (str), (struct block *) NULL,
-		       VAR_DOMAIN, NULL);
+		       parse_gdbarch (ps), VAR_DOMAIN, NULL);
   if (sym.symbol)
     {
       write_exp_elt_opcode (ps, OP_VAR_VALUE);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 5729b24..906dc7e 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1207,7 +1207,8 @@  address_info (char *exp, int from_tty)
   if (exp == 0)
     error (_("Argument required."));
 
-  sym = lookup_symbol (exp, get_selected_block (&context_pc), VAR_DOMAIN,
+  sym = lookup_symbol (exp, get_selected_block (&context_pc),
+		       get_current_arch (), VAR_DOMAIN,
 		       &is_a_field_of_this).symbol;
   if (sym == NULL)
     {
diff --git a/gdb/python/py-frame.c b/gdb/python/py-frame.c
index b448686..dfe93cd 100644
--- a/gdb/python/py-frame.c
+++ b/gdb/python/py-frame.c
@@ -537,11 +537,16 @@  frapy_read_var (PyObject *self, PyObject *args)
       TRY
 	{
 	  struct block_symbol lookup_sym;
+	  const struct gdbarch *gdbarch = NULL;
+
 	  FRAPY_REQUIRE_VALID (self, frame);
 
-	  if (!block)
+	  if (block == NULL)
 	    block = get_frame_block (frame, NULL);
-	  lookup_sym = lookup_symbol (var_name, block, VAR_DOMAIN, NULL);
+	  if (block == NULL)
+	    gdbarch = get_frame_arch (frame);
+	  lookup_sym
+	    = lookup_symbol (var_name, block, gdbarch, VAR_DOMAIN, NULL);
 	  var = lookup_sym.symbol;
 	  block = lookup_sym.block;
 	}
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c
index 3d2fa91..a35d80b 100644
--- a/gdb/python/py-symbol.c
+++ b/gdb/python/py-symbol.c
@@ -375,6 +375,7 @@  gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
   struct symbol *symbol = NULL;
   PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
   const struct block *block = NULL;
+  const struct gdbarch *gdbarch = NULL;
 
   if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
 				     &block_object_type, &block_obj, &domain))
@@ -390,6 +391,8 @@  gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
 	{
 	  selected_frame = get_selected_frame (_("No frame selected."));
 	  block = get_frame_block (selected_frame, NULL);
+	  if (block == NULL)
+	    gdbarch = get_frame_arch (selected_frame);
 	}
       CATCH (except, RETURN_MASK_ALL)
 	{
@@ -400,7 +403,7 @@  gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw)
 
   TRY
     {
-      symbol = lookup_symbol (name, block, (domain_enum) domain,
+      symbol = lookup_symbol (name, block, gdbarch, (domain_enum) domain,
 			      &is_a_field_of_this).symbol;
     }
   CATCH (except, RETURN_MASK_ALL)
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index e202c83..3b95e56 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -778,11 +778,11 @@  typy_lookup_typename (const char *type_name, const struct block *block)
   TRY
     {
       if (startswith (type_name, "struct "))
-	type = lookup_struct (type_name + 7, NULL);
+	type = lookup_struct (type_name + 7, block, python_gdbarch);
       else if (startswith (type_name, "union "))
-	type = lookup_union (type_name + 6, NULL);
+	type = lookup_union (type_name + 6, block, python_gdbarch);
       else if (startswith (type_name, "enum "))
-	type = lookup_enum (type_name + 5, NULL);
+	type = lookup_enum (type_name + 5, block, python_gdbarch);
       else
 	type = lookup_typename (python_language, python_gdbarch,
 				type_name, block, 0);
diff --git a/gdb/skip.c b/gdb/skip.c
index a1cdd72..f6840c0 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -112,6 +112,7 @@  static void
 skip_function_command (char *arg, int from_tty)
 {
   const char *name = NULL;
+  const struct gdbarch *gdbarch = get_current_arch ();
 
   /* Default to the current function if no argument is given.  */
   if (arg == NULL)
@@ -125,13 +126,13 @@  skip_function_command (char *arg, int from_tty)
       if (!find_pc_partial_function (pc, &name, NULL, NULL))
 	{
 	  error (_("No function found containing current program point %s."),
-		  paddress (get_current_arch (), pc));
+		  paddress (gdbarch, pc));
 	}
       skip_function (name);
     }
   else
     {
-      if (lookup_symbol (arg, NULL, VAR_DOMAIN, NULL).symbol == NULL)
+      if (lookup_symbol (arg, NULL, gdbarch, VAR_DOMAIN, NULL).symbol == NULL)
         {
 	  fprintf_filtered (gdb_stderr,
 			    _("No function found named %s.\n"), arg);
diff --git a/gdb/source.c b/gdb/source.c
index fab974c..5041cb9 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -274,7 +274,7 @@  select_source_symtab (struct symtab *s)
 
   /* Make the default place to list be the function `main'
      if one exists.  */
-  if (lookup_symbol (main_name (), 0, VAR_DOMAIN, 0).symbol)
+  if (lookup_symbol (main_name (), 0, target_gdbarch (), VAR_DOMAIN, 0).symbol)
     {
       sals = decode_line_with_current_source (main_name (),
 					      DECODE_LINE_FUNFIRSTLINE);
diff --git a/gdb/stack.c b/gdb/stack.c
index 7d37dd1..9e3838d 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -621,7 +621,7 @@  print_frame_args (struct symbol *func, struct frame_info *frame,
 	      struct symbol *nsym;
 
 	      nsym = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
-				    b, VAR_DOMAIN, NULL).symbol;
+				    b, NULL, VAR_DOMAIN, NULL).symbol;
 	      gdb_assert (nsym != NULL);
 	      if (SYMBOL_CLASS (nsym) == LOC_REGISTER
 		  && !SYMBOL_IS_ARGUMENT (nsym))
@@ -2156,7 +2156,7 @@  iterate_over_block_arg_vars (const struct block *b,
 	     are not combined in symbol-reading.  */
 
 	  sym2 = lookup_symbol (SYMBOL_LINKAGE_NAME (sym),
-				b, VAR_DOMAIN, NULL).symbol;
+				b, NULL, VAR_DOMAIN, NULL).symbol;
 	  (*cb) (SYMBOL_PRINT_NAME (sym), sym2, cb_data);
 	}
     }
diff --git a/gdb/symfile.c b/gdb/symfile.c
index cbb6d25..a27eeb4 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1695,7 +1695,8 @@  set_initial_language (void)
   if (lang == language_unknown)
     {
       char *name = main_name ();
-      struct symbol *sym = lookup_symbol (name, NULL, VAR_DOMAIN, NULL).symbol;
+      struct symbol *sym = lookup_symbol (name, NULL, get_current_arch (),
+					  VAR_DOMAIN, NULL).symbol;
 
       if (sym != NULL)
 	lang = SYMBOL_LANGUAGE (sym);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 1ba691e..b799512 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -71,6 +71,7 @@  static int find_line_common (struct linetable *, int, int *, int);
 static struct block_symbol
   lookup_symbol_aux (const char *name,
 		     const struct block *block,
+		     const struct gdbarch *gdbarch,
 		     const domain_enum domain,
 		     enum language language,
 		     struct field_of_this_result *);
@@ -1951,6 +1952,7 @@  demangle_for_lookup (const char *name, enum language lang,
 
 struct block_symbol
 lookup_symbol_in_language (const char *name, const struct block *block,
+			   const struct gdbarch *gdbarch,
 			   const domain_enum domain, enum language lang,
 			   struct field_of_this_result *is_a_field_of_this)
 {
@@ -1958,7 +1960,7 @@  lookup_symbol_in_language (const char *name, const struct block *block,
   struct block_symbol returnval;
   struct cleanup *cleanup = demangle_for_lookup (name, lang, &modified_name);
 
-  returnval = lookup_symbol_aux (modified_name, block, domain, lang,
+  returnval = lookup_symbol_aux (modified_name, block, gdbarch, domain, lang,
 				 is_a_field_of_this);
   do_cleanups (cleanup);
 
@@ -1969,10 +1971,10 @@  lookup_symbol_in_language (const char *name, const struct block *block,
 
 struct block_symbol
 lookup_symbol (const char *name, const struct block *block,
-	       domain_enum domain,
+	       const struct gdbarch *gdbarch, domain_enum domain,
 	       struct field_of_this_result *is_a_field_of_this)
 {
-  return lookup_symbol_in_language (name, block, domain,
+  return lookup_symbol_in_language (name, block, gdbarch, domain,
 				    current_language->la_language,
 				    is_a_field_of_this);
 }
@@ -1980,6 +1982,34 @@  lookup_symbol (const char *name, const struct block *block,
 /* See symtab.h.  */
 
 struct block_symbol
+lookup_symbol_from_block (const char *name, const struct block *block,
+			  domain_enum domain)
+{
+  /* While lookup_symbol_in_language can handle both BLOCK,GDBARCH being NULL,
+     that is not the API we present.  */
+  gdb_assert (block != NULL);
+
+  return lookup_symbol_in_language (name, block, NULL, domain,
+				    current_language->la_language, NULL);
+}
+
+/* See symtab.h.  */
+
+struct block_symbol
+lookup_symbol_for_arch (const char *name, const struct gdbarch *gdbarch,
+			domain_enum domain)
+{
+  /* While lookup_symbol_in_language can handle both BLOCK,GDBARCH being NULL,
+     that is not the API we present.  */
+  gdb_assert (gdbarch != NULL);
+
+  return lookup_symbol_in_language (name, NULL, gdbarch, domain,
+				    current_language->la_language, NULL);
+}
+
+/* See symtab.h.  */
+
+struct block_symbol
 lookup_language_this (const struct language_defn *lang,
 		      const struct block *block)
 {
@@ -2072,6 +2102,7 @@  check_field (struct type *type, const char *name,
 
 static struct block_symbol
 lookup_symbol_aux (const char *name, const struct block *block,
+		   const struct gdbarch *gdbarch,
 		   const domain_enum domain, enum language language,
 		   struct field_of_this_result *is_a_field_of_this)
 {
@@ -2083,10 +2114,12 @@  lookup_symbol_aux (const char *name, const struct block *block,
       struct objfile *objfile = lookup_objfile_from_block (block);
 
       fprintf_unfiltered (gdb_stdlog,
-			  "lookup_symbol_aux (%s, %s (objfile %s), %s, %s)\n",
+			  "lookup_symbol_aux (%s, %s (objfile %s),"
+			  " %s, %s, %s)\n",
 			  name, host_address_to_string (block),
 			  objfile != NULL
 			  ? objfile_debug_name (objfile) : "NULL",
+			  gdbarch_bfd_arch_info (gdbarch)->printable_name,
 			  domain_name (domain), language_str (language));
     }
 
@@ -2154,7 +2187,8 @@  lookup_symbol_aux (const char *name, const struct block *block,
   /* Now do whatever is appropriate for LANGUAGE to look
      up static and global variables.  */
 
-  result = langdef->la_lookup_symbol_nonlocal (langdef, name, block, domain);
+  result = langdef->la_lookup_symbol_nonlocal (langdef, name, block, gdbarch,
+					       domain);
   if (result.symbol != NULL)
     {
       if (symbol_lookup_debug)
@@ -2483,6 +2517,7 @@  struct block_symbol
 basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
 			      const char *name,
 			      const struct block *block,
+			      const struct gdbarch *gdbarch,
 			      const domain_enum domain)
 {
   struct block_symbol result;
@@ -2524,21 +2559,28 @@  basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
     return result;
 
   /* If we didn't find a definition for a builtin type in the static block,
-     search for it now.  This is actually the right thing to do and can be
-     a massive performance win.  E.g., when debugging a program with lots of
-     shared libraries we could search all of them only to find out the
-     builtin type isn't defined in any of them.  This is common for types
-     like "void".  */
-  if (domain == VAR_DOMAIN)
-    {
-      struct gdbarch *gdbarch;
-
-      if (block == NULL)
-	gdbarch = target_gdbarch ();
+     and we're passed a gdbarch so we can look up its primitive types,
+     search for it now.  This is actually the right thing to do.
+     E.g., imagine a program compiled with -fshort-double or whatever,
+     but this compilation unit wasn't.  If we didn't find the primitive type
+     in the current static block we want to find it now, before searching any
+     other compilation units.
+     And it can be a massive performance win.  E.g., when debugging a program
+     with lots of shared libraries we could search all of them only to find
+     out the builtin type isn't defined in any of them.  This is common for
+     types like "void".  */
+  if (domain == VAR_DOMAIN
+      && (block != NULL || gdbarch != NULL))
+    {
+      const struct gdbarch *gdbarch_for_lookup;
+
+      if (block != NULL)
+	gdbarch_for_lookup = block_gdbarch (block);
       else
-	gdbarch = block_gdbarch (block);
-      result.symbol = language_lookup_primitive_type_as_symbol (langdef,
-								gdbarch, name);
+	gdbarch_for_lookup = gdbarch;
+      result.symbol
+	= language_lookup_primitive_type_as_symbol (langdef,
+						    gdbarch_for_lookup, name);
       result.block = NULL;
       if (result.symbol != NULL)
 	return result;
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 4ff8ae7..0162f91 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1227,6 +1227,11 @@  struct field_of_this_result
 /* Find the definition for a specified symbol name NAME
    in domain DOMAIN in language LANGUAGE, visible from lexical block BLOCK
    if non-NULL or from global/static blocks if BLOCK is NULL.
+   If BLOCK is NULL and GDBARCH is non-NULL then use GDBARCH for
+   architecture-dependent lookups.  If GDBARCH is also NULL then skip all
+   arch-dependent lookups (primitive types).
+   If both BLOCK and GDBARCH are non-NULL, then the architecture of BLOCK
+   is used and GDBARCH is ignored.
    Returns the struct symbol pointer, or NULL if no symbol is found.
    C++: if IS_A_FIELD_OF_THIS is non-NULL on entry, check to see if
    NAME is a field of the current implied argument `this'.  If so fill in the
@@ -1236,6 +1241,7 @@  struct field_of_this_result
 extern struct block_symbol
   lookup_symbol_in_language (const char *,
 			     const struct block *,
+			     const struct gdbarch *,
 			     const domain_enum,
 			     enum language,
 			     struct field_of_this_result *);
@@ -1244,9 +1250,27 @@  extern struct block_symbol
 
 extern struct block_symbol lookup_symbol (const char *,
 					  const struct block *,
+					  const struct gdbarch *,
 					  const domain_enum,
 					  struct field_of_this_result *);
 
+/* Same as lookup_symbol_in_language, for when the block is known.
+   BLOCK must not be NULL.
+   The returned symbol doesn't necessarily live in BLOCK, it is only used
+   as a starting point for the search.  LANGUAGE, FIELD_OF_THIS_RESULT are
+   elided for simplicity.  */
+
+extern struct block_symbol lookup_symbol_from_block
+  (const char *, const struct block *, const domain_enum);
+
+/* Same as lookup_symbol_in_language, for when the architecture is known and
+   the block is not.
+   GDBARCH must not be NULL.
+   LANGUAGE, FIELD_OF_THIS_RESULT are elided for simplicity.  */
+
+extern struct block_symbol lookup_symbol_for_arch
+  (const char *, const struct gdbarch *, const domain_enum);
+
 /* A default version of lookup_symbol_nonlocal for use by languages
    that can't think of anything better to do.
    This implements the C lookup rules.  */
@@ -1255,6 +1279,7 @@  extern struct block_symbol
   basic_lookup_symbol_nonlocal (const struct language_defn *langdef,
 				const char *,
 				const struct block *,
+				const struct gdbarch *,
 				const domain_enum);
 
 /* Some helper functions for languages that need to write their own
@@ -1308,11 +1333,14 @@  extern struct block_symbol
 
 /* Lookup a [struct, union, enum] by name, within a specified block.  */
 
-extern struct type *lookup_struct (const char *, const struct block *);
+extern struct type *lookup_struct (const char *, const struct block *,
+				   const struct gdbarch *);
 
-extern struct type *lookup_union (const char *, const struct block *);
+extern struct type *lookup_union (const char *, const struct block *,
+				  const struct gdbarch *);
 
-extern struct type *lookup_enum (const char *, const struct block *);
+extern struct type *lookup_enum (const char *, const struct block *,
+				 const struct gdbarch *);
 
 /* from blockframe.c: */
 
diff --git a/gdb/utils.c b/gdb/utils.c
index 3ce88b9..d9b9429 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2739,7 +2739,7 @@  When set, debugging messages will be marked with seconds and microseconds."),
 }
 
 const char *
-paddress (struct gdbarch *gdbarch, CORE_ADDR addr)
+paddress (const struct gdbarch *gdbarch, CORE_ADDR addr)
 {
   /* Truncate address to the size of a target address, avoiding shifts
      larger or equal than the width of a CORE_ADDR.  The local
diff --git a/gdb/utils.h b/gdb/utils.h
index 995a1cf..8a148c2 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -250,7 +250,7 @@  extern void gdb_print_host_address (const void *addr, struct ui_file *stream);
 
 /* Convert CORE_ADDR to string in platform-specific manner.
    This is usually formatted similar to 0x%lx.  */
-extern const char *paddress (struct gdbarch *gdbarch, CORE_ADDR addr);
+extern const char *paddress (const struct gdbarch *gdbarch, CORE_ADDR addr);
 
 /* Return a string representation in hexadecimal notation of ADDRESS,
    which is suitable for printing.  */
diff --git a/gdb/valops.c b/gdb/valops.c
index 173ef4e..b327331 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -39,6 +39,7 @@ 
 #include "observer.h"
 #include "objfiles.h"
 #include "extension.h"
+#include "arch-utils.h"
 
 extern unsigned int overload_debug;
 /* Local functions.  */
@@ -129,7 +130,7 @@  find_function_in_inferior (const char *name, struct objfile **objf_p)
 {
   struct block_symbol sym;
 
-  sym = lookup_symbol (name, 0, VAR_DOMAIN, 0);
+  sym = lookup_symbol (name, 0, get_current_arch (), VAR_DOMAIN, 0);
   if (sym.symbol != NULL)
     {
       if (SYMBOL_CLASS (sym.symbol) != LOC_BLOCK)
@@ -3441,7 +3442,7 @@  value_struct_elt_for_reference (struct type *domain, int offset,
 	    {
 	      struct symbol *s = 
 		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+			       0, get_type_arch (t), VAR_DOMAIN, 0).symbol;
 
 	      if (s == NULL)
 		return NULL;
@@ -3472,7 +3473,7 @@  value_struct_elt_for_reference (struct type *domain, int offset,
 	    {
 	      struct symbol *s = 
 		lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, j),
-			       0, VAR_DOMAIN, 0).symbol;
+			       0, get_type_arch (t), VAR_DOMAIN, 0).symbol;
 
 	      if (s == NULL)
 		return NULL;
@@ -3552,7 +3553,8 @@  value_maybe_namespace_elt (const struct type *curtype,
   struct value *result;
 
   sym = cp_lookup_symbol_namespace (namespace_name, name,
-				    get_selected_block (0), VAR_DOMAIN);
+				    get_selected_block (0),
+				    get_type_arch (curtype), VAR_DOMAIN);
 
   if (sym.symbol == NULL)
     return NULL;
diff --git a/gdb/value.c b/gdb/value.c
index 91bf49e..74ecfa2 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2949,7 +2949,9 @@  value_static_field (struct type *type, int fieldno)
     {
       const char *phys_name = TYPE_FIELD_STATIC_PHYSNAME (type, fieldno);
       /* TYPE_FIELD_NAME (type, fieldno); */
-      struct block_symbol sym = lookup_symbol (phys_name, 0, VAR_DOMAIN, 0);
+      struct block_symbol sym = lookup_symbol (phys_name, NULL,
+					       get_current_arch (), VAR_DOMAIN,
+					       NULL);
 
       if (sym.symbol == NULL)
 	{
@@ -3137,7 +3139,8 @@  value_fn_field (struct value **arg1p, struct fn_field *f,
   struct symbol *sym;
   struct bound_minimal_symbol msym;
 
-  sym = lookup_symbol (physname, 0, VAR_DOMAIN, 0).symbol;
+  sym = lookup_symbol (physname, 0, get_type_arch (ftype), VAR_DOMAIN,
+		       0).symbol;
   if (sym != NULL)
     {
       memset (&msym, 0, sizeof (msym));
diff --git a/gdb/xstormy16-tdep.c b/gdb/xstormy16-tdep.c
index 05b3039..138ff4d 100644
--- a/gdb/xstormy16-tdep.c
+++ b/gdb/xstormy16-tdep.c
@@ -433,7 +433,7 @@  xstormy16_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
         return plg_end;
 
       /* Found a function.  */
-      sym = lookup_symbol (func_name, NULL, VAR_DOMAIN, NULL).symbol;
+      sym = lookup_symbol (func_name, NULL, gdbarch, VAR_DOMAIN, NULL).symbol;
       /* Don't use line number debug info for assembly source files.  */
       if (sym && SYMBOL_LANGUAGE (sym) != language_asm)
 	{