[rfc] Introduce "per-objfile" gdbarch

Ulrich Weigand uweigand@de.ibm.com
Sun Dec 9 20:32:00 GMT 2007


Hello,

when trying to prepare for multi-architecture debugging, one problem that
hasn't really been addressed until now is how to provide architecture-
specific information to those parts of GDB common code that are not
directly target-related, e.g the symbol reader code.

For the other parts, there is mostly a natural way to associate architecture
data with the current target, either the target connection itself, or entities
like the current thread, register cache, or stack frame.

However, for the symbol readers this does not really work out.  But those 
parts still need a certain amount of per-architecture information, e.g. 
about default data types and sizes, or about specific compiler quirks etc.
This is today available as gdbarch data, and used by symbol readers via
the "current_gdbarch" global.  This however will no longer work as soon
as we actually read symbols from object files belonging to different
architectures in a single inferior process.

One way to solve this would be add the notion of "per-objfile" gdbarch.
This is simply the gdbarch that corresponds to the BFD associated with
the objfile, as recognized by the gdbarch_from_bfd sniffers.  (Of course,
per-target information like extended register sets would not be reflected
here.)

This can be determined whenever an objfile is first created, and does not
require an established connection to a target.  The symbol readers could
then use this "per-objfile gdbarch" to access per-architecture configuration
parameters like default data types.

Of course, one potentially problematic point is that these per-objfile
gdbarch structures will generally *differ* from the per-target gdbarch
that is determined later.  If not used properly, the per-objfile gdbarch
can yield surprising results.  For example, gdbarch functions related
to register numbers will typically not be useful as the numbering of the
actual target registers may be different from those in the per-objfile
gdbarch.

However, at least a subset of gdbarch should be completely determined
already by the objfile.  This would include:

- Data types (char_signed, short_bit, int_bit, long_bit, long_long_bit,
  float_bit, float_format, double_bit, double_format, long_double_bit,
  long_double_format;  builtin_type, language_arch_info etc.)

- Pointers & addresses (ptr_bit, addr_bit, pointer_to_address,
  address_to_pointer, integer_to_address, addr_bits_remove, smash_text_address,
  address_class_type_flags, address_class_type_flags_to_name,
  address_class_name_to_type_flags)

- C++ ABI (vtable_function_descriptors, vbit_in_delta)

- Compiler characteristics (believe_pcc_promotion, static_transform_name,
  sofun_address_maybe_missing, stabs_argument_has_addr, 
  elf_make_msymbol_special, coff_make_msymbol_special)

- Code analysis (skip_prologue, deprecated_function_start_offset,
  in_function_epilogue_p, skip_trampoline_code, skip_solib_resolver,
  in_solib_return_trampoline)

- Disassembly (print_insn)


The following patch implements this by adding a "get_objfile_arch" routine
that returns the per-objfile gdbarch as described above.  It also goes and
uses this new function to replace most instances of "current_gdbarch"
throughout the symbol readers.

The only instances that remain are related to:

- Register numbering (gdbarch_XXX_reg_to_regnum)

  This is somewhat of a fundamental problem: if we allow GDB register numbers
  to depend on per-target information, having symbol classes like LOC_REGISTER
  simply makes no sense, as during symbol reading the GDB register numbers 
  are not really well-defined yet.

  This is not an issue with DWARF-2, as it always uses LOC_COMPUTED instead.
  Maybe it would be good to change the other symbol readers in a similar way?

- _initialize_mdebugread uses current_gdbarch in an init function to 
  define data types.  This is just broken ...

- dwarf2_tracepoint_var_ref calls gdbarch_virtual_frame_pointer.  I guess that
  gdbarch callback really needs to be eliminated.


Note that the patch makes no effort to *enforce* that the per-objfile 
gdbarch is used only for the subset of functions described above.  I'm
not sure whether we should do so (and how?), or whether this is simply
a matter of proper documentation ...

What do you think about this approach?

(Patch requires the DWARF-2 address size patch.  Tested together with it
on amd64-linux with no regression, both when using DWARF-2 and when using
stabs+ debug info.)

Bye,
Ulrich


ChangeLog:

        * objfiles.h (struct objfile): New GDBARCH member.
        (get_objfile_arch): Add prototype.
        * objfiles.c: Include "arch-utils.h".
        (allocate_objfile): Look up gdbarch associated with bfd.
        (get_objfile_arch): New function.
        * Makefile (objfiles.o): Update dependencies.

        * dwarf2-frame.c (size_of_encoded_value): Add UNIT parameter.
        Retrieve target pointer size from unit->objfile.
        (read_encoded_value): Update call to size_of_encoded_value.
        (decode_frame_entry_1): Retrieve target pointer size from
        unit->objfile.  Replace current_gdbarch by objfile arch.

        * dwarf2loc.c (find_location_expression): Replace current_gdbarch
        by objfile arch.
        (dwarf_expr_read_reg): Replace current_gdbarch by frame arch.
        (dwarf2_loc_desc_needs_frame): Add OBJFILE parameter.  Replace
        current_gdbarch by objfile arch.
        (locexpr_read_needs_frame): Update call.
        (locexpr_describe_location): Replace current_gdbarch by
        objfile arch.

        * dwarf2read.c (die_type): Replace current_gdbarch by objfile arch.
	(read_tag_pointer_type): Likewise.
        (read_base_type): Likewise.
        (new_symbol): Likewise.

	* coffread.c (decode_type): Add OBJFILE argument.  Update callers.
	(decode_base_type, decode_function_type): Likewise.
	(coff_read_struct_type, coff_read_enum_type): Likewise.
	(coff_symtab_read): Replace current_gdbarch by objfile arch.
	(decode_base_type): Likewise.
	(coff_read_enum_type): Likewise.
	(coff_read_struct_type): Replace current_objfile by OBJFILE argument.
	(coff_read_enum_type): Likewise.

	* dbxread.c (read_dbx_symtab): Replace current_gdbarch by objfile arch.
	(end_psymtab): Likewise.
	(process_one_symbol): Likewise.

	* mdebugread.c (parse_symbol): Replace current_gdbarch by objfile arch.
	(parse_procedure): Likewise.
	(parse_partial_symbols): Likewise.

	* somread.c (som_symtab_read): Replace current_gdbarch by objfile arch.

	* stabsread.c (define_symbol): Replace current_gdbarch by objfile arch.
	Replace static pcc_promotion_type and pcc_unsigned_promotion_type by
	built-in types.
	(read_range_type): Replace current_gdbarch by objfile arch.  Replace
	static range_index_type by built-in type.
	(read_one_struct_field): Replace current_gdbarch by objfile arch.
	(read_enum_type): Likewise.

	* xcoffread.c (read_xcoff_symtab): Replace current_gdbarch by
	objfile arch.


diff -urNp gdb-orig/gdb/coffread.c gdb-head/gdb/coffread.c
--- gdb-orig/gdb/coffread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/coffread.c	2007-12-09 18:42:57.000000000 +0100
@@ -137,19 +137,24 @@ struct coff_symbol
 
 extern void stabsread_clear_cache (void);
 
-static struct type *coff_read_struct_type (int, int, int);
+static struct type *coff_read_struct_type (int, int, int,
+					   struct objfile *);
 
 static struct type *decode_base_type (struct coff_symbol *,
-				      unsigned int, union internal_auxent *);
+				      unsigned int, union internal_auxent *,
+				      struct objfile *);
 
 static struct type *decode_type (struct coff_symbol *, unsigned int,
-				 union internal_auxent *);
+				 union internal_auxent *,
+				 struct objfile *);
 
 static struct type *decode_function_type (struct coff_symbol *,
 					  unsigned int,
-					  union internal_auxent *);
+					  union internal_auxent *,
+					  struct objfile *);
 
-static struct type *coff_read_enum_type (int, int, int);
+static struct type *coff_read_enum_type (int, int, int,
+					 struct objfile *);
 
 static struct symbol *process_coff_symbol (struct coff_symbol *,
 					   union internal_auxent *,
@@ -679,6 +684,7 @@ static void
 coff_symtab_read (long symtab_offset, unsigned int nsyms,
 		  struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct context_stack *new;
   struct coff_symbol coff_symbol;
   struct coff_symbol *cs = &coff_symbol;
@@ -910,8 +916,7 @@ coff_symtab_read (long symtab_offset, un
 		      cs->c_sclass == C_EXT || cs->c_sclass == C_THUMBEXTFUNC
 		      || cs->c_sclass == C_THUMBEXT ?
 		      mst_text : mst_file_text;
-		    tmpaddr = gdbarch_smash_text_address
-				(current_gdbarch, tmpaddr);
+		    tmpaddr = gdbarch_smash_text_address (gdbarch, tmpaddr);
 		  }
 		else if (bfd_section->flags & SEC_ALLOC
 			 && bfd_section->flags & SEC_LOAD)
@@ -932,8 +937,7 @@ coff_symtab_read (long symtab_offset, un
 
 	    msym = record_minimal_symbol (cs, tmpaddr, ms_type, sec, objfile);
 	    if (msym)
-	      gdbarch_coff_make_msymbol_special
-	      (current_gdbarch, cs->c_sclass, msym);
+	      gdbarch_coff_make_msymbol_special (gdbarch, cs->c_sclass, msym);
 
 	    if (SDB_TYPE (cs->c_type))
 	      {
@@ -1503,7 +1507,7 @@ process_coff_symbol (struct coff_symbol 
     {
       SYMBOL_VALUE (sym) += ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
       SYMBOL_TYPE (sym) =
-	lookup_function_type (decode_function_type (cs, cs->c_type, aux));
+	lookup_function_type (decode_function_type (cs, cs->c_type, aux, objfile));
 
       SYMBOL_CLASS (sym) = LOC_BLOCK;
       if (cs->c_sclass == C_STAT || cs->c_sclass == C_THUMBSTAT
@@ -1515,7 +1519,7 @@ process_coff_symbol (struct coff_symbol 
     }
   else
     {
-      SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux);
+      SYMBOL_TYPE (sym) = decode_type (cs, cs->c_type, aux, objfile);
       switch (cs->c_sclass)
 	{
 	case C_NULL:
@@ -1662,7 +1666,7 @@ process_coff_symbol (struct coff_symbol 
 
 static struct type *
 decode_type (struct coff_symbol *cs, unsigned int c_type,
-	     union internal_auxent *aux)
+	     union internal_auxent *aux, struct objfile *objfile)
 {
   struct type *type = 0;
   unsigned int new_c_type;
@@ -1672,12 +1676,12 @@ decode_type (struct coff_symbol *cs, uns
       new_c_type = DECREF (c_type);
       if (ISPTR (c_type))
 	{
-	  type = decode_type (cs, new_c_type, aux);
+	  type = decode_type (cs, new_c_type, aux, objfile);
 	  type = lookup_pointer_type (type);
 	}
       else if (ISFCN (c_type))
 	{
-	  type = decode_type (cs, new_c_type, aux);
+	  type = decode_type (cs, new_c_type, aux, objfile);
 	  type = lookup_function_type (type);
 	}
       else if (ISARY (c_type))
@@ -1699,7 +1703,7 @@ decode_type (struct coff_symbol *cs, uns
 	    *dim = *(dim + 1);
 	  *dim = 0;
 
-	  base_type = decode_type (cs, new_c_type, aux);
+	  base_type = decode_type (cs, new_c_type, aux, objfile);
 	  index_type = builtin_type_int32;
 	  range_type =
 	    create_range_type ((struct type *) NULL, index_type, 0, n - 1);
@@ -1735,7 +1739,7 @@ decode_type (struct coff_symbol *cs, uns
 	}
     }
 
-  return decode_base_type (cs, BTYPE (c_type), aux);
+  return decode_base_type (cs, BTYPE (c_type), aux, objfile);
 }
 
 /* Decode a coff type specifier for function definition;
@@ -1743,59 +1747,60 @@ decode_type (struct coff_symbol *cs, uns
 
 static struct type *
 decode_function_type (struct coff_symbol *cs, unsigned int c_type,
-		      union internal_auxent *aux)
+		      union internal_auxent *aux, struct objfile *objfile)
 {
   if (aux->x_sym.x_tagndx.l == 0)
     cs->c_naux = 0;		/* auxent refers to function, not base type */
 
-  return decode_type (cs, DECREF (c_type), aux);
+  return decode_type (cs, DECREF (c_type), aux, objfile);
 }
 
 /* basic C types */
 
 static struct type *
 decode_base_type (struct coff_symbol *cs, unsigned int c_type,
-		  union internal_auxent *aux)
+		  union internal_auxent *aux, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct type *type;
 
   switch (c_type)
     {
     case T_NULL:
       /* shows up with "void (*foo)();" structure members */
-      return builtin_type (current_gdbarch)->builtin_void;
+      return builtin_type (gdbarch)->builtin_void;
 
 #ifdef T_VOID
     case T_VOID:
       /* Intel 960 COFF has this symbol and meaning.  */
-      return builtin_type (current_gdbarch)->builtin_void;
+      return builtin_type (gdbarch)->builtin_void;
 #endif
 
     case T_CHAR:
-      return builtin_type (current_gdbarch)->builtin_char;
+      return builtin_type (gdbarch)->builtin_char;
 
     case T_SHORT:
-      return builtin_type (current_gdbarch)->builtin_short;
+      return builtin_type (gdbarch)->builtin_short;
 
     case T_INT:
-      return builtin_type (current_gdbarch)->builtin_int;
+      return builtin_type (gdbarch)->builtin_int;
 
     case T_LONG:
       if (cs->c_sclass == C_FIELD
 	  && aux->x_sym.x_misc.x_lnsz.x_size
-	     > gdbarch_long_bit (current_gdbarch))
-	return builtin_type (current_gdbarch)->builtin_long_long;
+	     > gdbarch_long_bit (gdbarch))
+	return builtin_type (gdbarch)->builtin_long_long;
       else
-	return builtin_type (current_gdbarch)->builtin_long;
+	return builtin_type (gdbarch)->builtin_long;
 
     case T_FLOAT:
-      return builtin_type (current_gdbarch)->builtin_float;
+      return builtin_type (gdbarch)->builtin_float;
 
     case T_DOUBLE:
-      return builtin_type (current_gdbarch)->builtin_double;
+      return builtin_type (gdbarch)->builtin_double;
 
     case T_LNGDBL:
-      return builtin_type (current_gdbarch)->builtin_long_double;
+      return builtin_type (gdbarch)->builtin_long_double;
 
     case T_STRUCT:
       if (cs->c_naux != 1)
@@ -1817,7 +1822,8 @@ decode_base_type (struct coff_symbol *cs
 	{
 	  type = coff_read_struct_type (cs->c_symnum,
 					aux->x_sym.x_misc.x_lnsz.x_size,
-				      aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
+					aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
+					objfile);
 	}
       return type;
 
@@ -1840,7 +1846,8 @@ decode_base_type (struct coff_symbol *cs
 	{
 	  type = coff_read_struct_type (cs->c_symnum,
 					aux->x_sym.x_misc.x_lnsz.x_size,
-				      aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
+					aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
+					objfile);
 	}
       TYPE_CODE (type) = TYPE_CODE_UNION;
       return type;
@@ -1864,7 +1871,8 @@ decode_base_type (struct coff_symbol *cs
 	{
 	  type = coff_read_enum_type (cs->c_symnum,
 				      aux->x_sym.x_misc.x_lnsz.x_size,
-				      aux->x_sym.x_fcnary.x_fcn.x_endndx.l);
+				      aux->x_sym.x_fcnary.x_fcn.x_endndx.l,
+				      objfile);
 	}
       return type;
 
@@ -1873,24 +1881,24 @@ decode_base_type (struct coff_symbol *cs
       break;
 
     case T_UCHAR:
-      return builtin_type (current_gdbarch)->builtin_unsigned_char;
+      return builtin_type (gdbarch)->builtin_unsigned_char;
 
     case T_USHORT:
-      return builtin_type (current_gdbarch)->builtin_unsigned_short;
+      return builtin_type (gdbarch)->builtin_unsigned_short;
 
     case T_UINT:
-      return builtin_type (current_gdbarch)->builtin_unsigned_int;
+      return builtin_type (gdbarch)->builtin_unsigned_int;
 
     case T_ULONG:
       if (cs->c_sclass == C_FIELD
 	  && aux->x_sym.x_misc.x_lnsz.x_size
-	     > gdbarch_long_bit (current_gdbarch))
-	return builtin_type (current_gdbarch)->builtin_unsigned_long_long;
+	     > gdbarch_long_bit (gdbarch))
+	return builtin_type (gdbarch)->builtin_unsigned_long_long;
       else
-	return builtin_type (current_gdbarch)->builtin_unsigned_long;
+	return builtin_type (gdbarch)->builtin_unsigned_long;
     }
   complaint (&symfile_complaints, _("Unexpected type for symbol %s"), cs->c_name);
-  return builtin_type (current_gdbarch)->builtin_void;
+  return builtin_type (gdbarch)->builtin_void;
 }
 
 /* This page contains subroutines of read_type.  */
@@ -1899,7 +1907,8 @@ decode_base_type (struct coff_symbol *cs
    object describing the type.  */
 
 static struct type *
-coff_read_struct_type (int index, int length, int lastsym)
+coff_read_struct_type (int index, int length, int lastsym,
+		       struct objfile *objfile)
 {
   struct nextfield
     {
@@ -1928,7 +1937,7 @@ coff_read_struct_type (int index, int le
     {
       read_one_sym (ms, &sub_sym, &sub_aux);
       name = ms->c_name;
-      name = EXTERNAL_NAME (name, current_objfile->obfd);
+      name = EXTERNAL_NAME (name, objfile->obfd);
 
       switch (ms->c_sclass)
 	{
@@ -1942,10 +1951,9 @@ coff_read_struct_type (int index, int le
 
 	  /* Save the data.  */
 	  list->field.name =
-	    obsavestring (name,
-			  strlen (name),
-			  &current_objfile->objfile_obstack);
-	  FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux);
+	    obsavestring (name, strlen (name), &objfile->objfile_obstack);
+	  FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux,
+						  objfile);
 	  FIELD_BITPOS (list->field) = 8 * ms->c_value;
 	  FIELD_BITSIZE (list->field) = 0;
 	  FIELD_STATIC_KIND (list->field) = 0;
@@ -1961,10 +1969,9 @@ coff_read_struct_type (int index, int le
 
 	  /* Save the data.  */
 	  list->field.name =
-	    obsavestring (name,
-			  strlen (name),
-			  &current_objfile->objfile_obstack);
-	  FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux);
+	    obsavestring (name, strlen (name), &objfile->objfile_obstack);
+	  FIELD_TYPE (list->field) = decode_type (ms, ms->c_type, &sub_aux,
+						  objfile);
 	  FIELD_BITPOS (list->field) = ms->c_value;
 	  FIELD_BITSIZE (list->field) = sub_aux.x_sym.x_misc.x_lnsz.x_size;
 	  FIELD_STATIC_KIND (list->field) = 0;
@@ -1995,8 +2002,10 @@ coff_read_struct_type (int index, int le
    Also defines the symbols that represent the values of the type.  */
 
 static struct type *
-coff_read_enum_type (int index, int length, int lastsym)
+coff_read_enum_type (int index, int length, int lastsym,
+		     struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym;
   struct type *type;
   int nsyms = 0;
@@ -2024,19 +2033,17 @@ coff_read_enum_type (int index, int leng
     {
       read_one_sym (ms, &sub_sym, &sub_aux);
       name = ms->c_name;
-      name = EXTERNAL_NAME (name, current_objfile->obfd);
+      name = EXTERNAL_NAME (name, objfile->obfd);
 
       switch (ms->c_sclass)
 	{
 	case C_MOE:
 	  sym = (struct symbol *) obstack_alloc
-	    (&current_objfile->objfile_obstack,
-	     sizeof (struct symbol));
+	    (&objfile->objfile_obstack, sizeof (struct symbol));
 	  memset (sym, 0, sizeof (struct symbol));
 
 	  DEPRECATED_SYMBOL_NAME (sym) =
-	    obsavestring (name, strlen (name),
-			  &current_objfile->objfile_obstack);
+	    obsavestring (name, strlen (name), &objfile->objfile_obstack);
 	  SYMBOL_CLASS (sym) = LOC_CONST;
 	  SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
 	  SYMBOL_VALUE (sym) = ms->c_value;
@@ -2058,7 +2065,7 @@ coff_read_enum_type (int index, int leng
   if (length > 0)
     TYPE_LENGTH (type) = length;
   else /* Assume ints.  */
-    TYPE_LENGTH (type) = gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT;
+    TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
   TYPE_CODE (type) = TYPE_CODE_ENUM;
   TYPE_NFIELDS (type) = nsyms;
   TYPE_FIELDS (type) = (struct field *)
diff -urNp gdb-orig/gdb/dbxread.c gdb-head/gdb/dbxread.c
--- gdb-orig/gdb/dbxread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/dbxread.c	2007-12-09 18:42:57.000000000 +0100
@@ -1174,6 +1174,7 @@ function_outside_compilation_unit_compla
 static void
 read_dbx_symtab (struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch */
   struct internal_nlist nlist;
   CORE_ADDR text_addr;
@@ -1466,7 +1467,7 @@ read_dbx_symtab (struct objfile *objfile
 	       don't relocate it.  */
 
 	    if (nlist.n_value == 0
-		&& gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		&& gdbarch_sofun_address_maybe_missing (gdbarch))
 	      {
 		textlow_not_set = 1;
 		valu = 0;
@@ -1677,9 +1678,9 @@ read_dbx_symtab (struct objfile *objfile
 	  case 'S':
 	    nlist.n_value += ANOFFSET (objfile->section_offsets, data_sect_index);
 
-	    if (gdbarch_static_transform_name_p (current_gdbarch))
+	    if (gdbarch_static_transform_name_p (gdbarch))
 	      namestring = gdbarch_static_transform_name
-			     (current_gdbarch, namestring);
+			     (gdbarch, namestring);
 
 	    add_psymbol_to_list (namestring, p - namestring,
 				 VAR_DOMAIN, LOC_STATIC,
@@ -1832,7 +1833,7 @@ read_dbx_symtab (struct objfile *objfile
 	       value for the bottom of the text seg in those cases. */
 	    if (nlist.n_value == ANOFFSET (objfile->section_offsets, 
 					   SECT_OFF_TEXT (objfile))
-		&& gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		&& gdbarch_sofun_address_maybe_missing (gdbarch))
 	      {
 		CORE_ADDR minsym_valu = 
 		  find_stab_function_addr (namestring, 
@@ -1847,7 +1848,7 @@ read_dbx_symtab (struct objfile *objfile
 		  nlist.n_value = minsym_valu;
 	      }
 	    if (pst && textlow_not_set
-		&& gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		&& gdbarch_sofun_address_maybe_missing (gdbarch))
 	      {
 		pst->textlow = nlist.n_value;
 		textlow_not_set = 0;
@@ -1900,7 +1901,7 @@ read_dbx_symtab (struct objfile *objfile
 	       value for the bottom of the text seg in those cases. */
 	    if (nlist.n_value == ANOFFSET (objfile->section_offsets, 
 					   SECT_OFF_TEXT (objfile))
-		&& gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		&& gdbarch_sofun_address_maybe_missing (gdbarch))
 	      {
 		CORE_ADDR minsym_valu = 
 		  find_stab_function_addr (namestring, 
@@ -1915,7 +1916,7 @@ read_dbx_symtab (struct objfile *objfile
 		  nlist.n_value = minsym_valu;
 	      }
 	    if (pst && textlow_not_set
-		&& gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		&& gdbarch_sofun_address_maybe_missing (gdbarch))
 	      {
 		pst->textlow = nlist.n_value;
 		textlow_not_set = 0;
@@ -2049,7 +2050,7 @@ read_dbx_symtab (struct objfile *objfile
 	     end_psymtab will set pst->texthigh to the proper value, which
 	     is necessary if a module compiled without debugging info
 	     follows this module.  */
-	  if (pst && gdbarch_sofun_address_maybe_missing (current_gdbarch))
+	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
 	  {
 	    end_psymtab (pst, psymtab_include_list, includes_used,
 			 symnum * symbol_size,
@@ -2175,6 +2176,7 @@ end_psymtab (struct partial_symtab *pst,
 {
   int i;
   struct objfile *objfile = pst->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
 
   if (capping_symbol_offset != -1)
     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
@@ -2196,7 +2198,7 @@ end_psymtab (struct partial_symtab *pst,
      last function in the file.  */
 
   if (pst->texthigh == 0 && last_function_name
-      && gdbarch_sofun_address_maybe_missing (current_gdbarch))
+      && gdbarch_sofun_address_maybe_missing (gdbarch))
     {
       char *p;
       int n;
@@ -2227,7 +2229,7 @@ end_psymtab (struct partial_symtab *pst,
       last_function_name = NULL;
     }
 
-  if (!gdbarch_sofun_address_maybe_missing (current_gdbarch))
+  if (!gdbarch_sofun_address_maybe_missing (gdbarch))
     ;
   /* this test will be true if the last .o file is only data */
   else if (textlow_not_set)
@@ -2651,6 +2653,7 @@ process_one_symbol (int type, int desc, 
 		    struct section_offsets *section_offsets,
 		    struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct context_stack *new;
   /* This remembers the address of the start of a function.  It is
      used because in Solaris 2, N_LBRAC, N_RBRAC, and N_SLINE entries
@@ -2741,7 +2744,7 @@ process_one_symbol (int type, int desc, 
 
       /* Relocate for dynamic loading.  */
       valu += ANOFFSET (section_offsets, SECT_OFF_TEXT (objfile));
-      valu = gdbarch_smash_text_address (current_gdbarch, valu);
+      valu = gdbarch_smash_text_address (gdbarch, valu);
       last_function_start = valu;
 
       goto define_a_symbol;
@@ -3081,7 +3084,7 @@ no enclosing block"));
 	      if (type == N_FUN
 		  && valu == ANOFFSET (section_offsets,
 				       SECT_OFF_TEXT (objfile))
-		  && gdbarch_sofun_address_maybe_missing (current_gdbarch))
+		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
 		  CORE_ADDR minsym_valu = 
 		    find_stab_function_addr (name, last_source_file, objfile);
diff -urNp gdb-orig/gdb/dwarf2-frame.c gdb-head/gdb/dwarf2-frame.c
--- gdb-orig/gdb/dwarf2-frame.c	2007-12-09 18:42:50.000000000 +0100
+++ gdb-head/gdb/dwarf2-frame.c	2007-12-09 18:42:57.000000000 +0100
@@ -1408,15 +1408,17 @@ encoding_for_size (unsigned int size)
 }
 
 static unsigned int
-size_of_encoded_value (gdb_byte encoding)
+size_of_encoded_value (struct comp_unit *unit, gdb_byte encoding)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
+
   if (encoding == DW_EH_PE_omit)
     return 0;
 
   switch (encoding & 0x07)
     {
     case DW_EH_PE_absptr:
-      return TYPE_LENGTH (builtin_type_void_data_ptr);
+      return gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
     case DW_EH_PE_udata2:
       return 2;
     case DW_EH_PE_udata4:
@@ -1432,7 +1434,7 @@ static CORE_ADDR
 read_encoded_value (struct comp_unit *unit, gdb_byte encoding,
 		    gdb_byte *buf, unsigned int *bytes_read_ptr)
 {
-  int ptr_len = size_of_encoded_value (DW_EH_PE_absptr);
+  int ptr_len = size_of_encoded_value (unit, DW_EH_PE_absptr);
   ptrdiff_t offset;
   CORE_ADDR base;
 
@@ -1610,6 +1612,7 @@ static gdb_byte *decode_frame_entry (str
 static gdb_byte *
 decode_frame_entry_1 (struct comp_unit *unit, gdb_byte *start, int eh_frame_p)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (unit->objfile);
   gdb_byte *buf, *end;
   LONGEST length;
   unsigned int bytes_read;
@@ -1701,7 +1704,7 @@ decode_frame_entry_1 (struct comp_unit *
       if (augmentation[0] == 'e' && augmentation[1] == 'h')
 	{
 	  /* Skip.  */
-	  buf += TYPE_LENGTH (builtin_type_void_data_ptr);
+	  buf += gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
 	  augmentation += 2;
 	}
 
@@ -1722,7 +1725,7 @@ decode_frame_entry_1 (struct comp_unit *
 	cie->return_address_register = read_unsigned_leb128 (unit->abfd, buf,
 							     &bytes_read);
       cie->return_address_register
-	= dwarf2_frame_adjust_regnum (current_gdbarch,
+	= dwarf2_frame_adjust_regnum (gdbarch,
 				      cie->return_address_register,
 				      eh_frame_p);
 
diff -urNp gdb-orig/gdb/dwarf2loc.c gdb-head/gdb/dwarf2loc.c
--- gdb-orig/gdb/dwarf2loc.c	2007-12-09 18:42:50.000000000 +0100
+++ gdb-head/gdb/dwarf2loc.c	2007-12-09 18:42:57.000000000 +0100
@@ -51,10 +51,11 @@ static gdb_byte *
 find_location_expression (struct dwarf2_loclist_baton *baton,
 			  size_t *locexpr_length, CORE_ADDR pc)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (baton->objfile);
   CORE_ADDR low, high;
   gdb_byte *loc_ptr, *buf_end;
   int length;
-  unsigned int addr_size = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+  unsigned int addr_size = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
   CORE_ADDR base_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1));
   /* Adjust base_address for relocatable objects.  */
   CORE_ADDR base_offset = ANOFFSET (baton->objfile->section_offsets,
@@ -115,11 +116,12 @@ static CORE_ADDR
 dwarf_expr_read_reg (void *baton, int dwarf_regnum)
 {
   struct dwarf_expr_baton *debaton = (struct dwarf_expr_baton *) baton;
+  struct gdbarch *gdbarch = get_frame_arch (debaton->frame);
   CORE_ADDR result;
   int regnum;
 
-  regnum = gdbarch_dwarf2_reg_to_regnum (current_gdbarch, dwarf_regnum);
-  result = address_from_register (builtin_type_void_data_ptr,
+  regnum = gdbarch_dwarf2_reg_to_regnum (gdbarch, dwarf_regnum);
+  result = address_from_register (builtin_type (gdbarch)->builtin_data_ptr,
 				  regnum, debaton->frame);
   return result;
 }
@@ -319,8 +321,10 @@ needs_frame_tls_address (void *baton, CO
    requires a frame to evaluate.  */
 
 static int
-dwarf2_loc_desc_needs_frame (gdb_byte *data, unsigned short size)
+dwarf2_loc_desc_needs_frame (struct objfile *objfile,
+			     gdb_byte *data, unsigned short size)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct needs_frame_baton baton;
   struct dwarf_expr_context *ctx;
   int in_reg;
@@ -328,7 +332,7 @@ dwarf2_loc_desc_needs_frame (gdb_byte *d
   baton.needs_frame = 0;
 
   ctx = new_dwarf_expr_context ();
-  ctx->addr_size = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+  ctx->addr_size = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
   ctx->baton = &baton;
   ctx->read_reg = needs_frame_read_reg;
   ctx->read_mem = needs_frame_read_mem;
@@ -441,7 +445,8 @@ static int
 locexpr_read_needs_frame (struct symbol *symbol)
 {
   struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
-  return dwarf2_loc_desc_needs_frame (dlbaton->data, dlbaton->size);
+  return dwarf2_loc_desc_needs_frame (dlbaton->objfile,
+				      dlbaton->data, dlbaton->size);
 }
 
 /* Print a natural-language description of SYMBOL to STREAM.  */
@@ -450,17 +455,18 @@ locexpr_describe_location (struct symbol
 {
   /* FIXME: be more extensive.  */
   struct dwarf2_locexpr_baton *dlbaton = SYMBOL_LOCATION_BATON (symbol);
-  int addr_size = gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT;
+  struct gdbarch *gdbarch = get_objfile_arch (dlbaton->objfile);
+  int addr_size = gdbarch_addr_bit (gdbarch) / TARGET_CHAR_BIT;
 
   if (dlbaton->size == 1
       && dlbaton->data[0] >= DW_OP_reg0
       && dlbaton->data[0] <= DW_OP_reg31)
     {
       int regno = gdbarch_dwarf2_reg_to_regnum
-		    (current_gdbarch, dlbaton->data[0] - DW_OP_reg0);
+		    (gdbarch, dlbaton->data[0] - DW_OP_reg0);
       fprintf_filtered (stream,
 			"a variable in register %s",
-			gdbarch_register_name (current_gdbarch, regno));
+			gdbarch_register_name (gdbarch, regno));
       return 1;
     }
 
diff -urNp gdb-orig/gdb/dwarf2read.c gdb-head/gdb/dwarf2read.c
--- gdb-orig/gdb/dwarf2read.c	2007-12-08 17:16:24.000000000 +0100
+++ gdb-head/gdb/dwarf2read.c	2007-12-09 18:42:57.000000000 +0100
@@ -4640,6 +4640,7 @@ namespace_name (struct die_info *die, in
 static void
 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
   struct comp_unit_head *cu_header = &cu->header;
   struct type *type;
   struct attribute *attr_byte_size;
@@ -4670,12 +4671,12 @@ read_tag_pointer_type (struct die_info *
      length accordingly.  */
   if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none)
     {
-      if (gdbarch_address_class_type_flags_p (current_gdbarch))
+      if (gdbarch_address_class_type_flags_p (gdbarch))
 	{
 	  int type_flags;
 
 	  type_flags = gdbarch_address_class_type_flags
-			 (current_gdbarch, byte_size, addr_class);
+			 (gdbarch, byte_size, addr_class);
 	  gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0);
 	  type = make_type_with_address_space (type, type_flags);
 	}
@@ -5012,6 +5013,7 @@ read_base_type (struct die_info *die, st
 static void
 read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
   struct type *base_type;
   struct type *range_type;
   struct attribute *attr;
@@ -5029,7 +5031,7 @@ read_subrange_type (struct die_info *die
       complaint (&symfile_complaints,
                 _("DW_AT_type missing from DW_TAG_subrange_type"));
       base_type
-	= init_type (TYPE_CODE_INT, gdbarch_addr_bit (current_gdbarch) / 8,
+	= init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8,
 		     0, NULL, cu->objfile);
     }
 
@@ -7197,6 +7199,7 @@ static struct symbol *
 new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->objfile;
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym = NULL;
   char *name;
   struct attribute *attr = NULL;
@@ -7281,7 +7284,7 @@ new_symbol (struct die_info *die, struct
 	     to something sensible.  */
 	  if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID)
 	    SYMBOL_TYPE (sym)
-	      = builtin_type (current_gdbarch)->nodebug_data_symbol;
+	      = builtin_type (gdbarch)->nodebug_data_symbol;
 
 	  attr = dwarf2_attr (die, DW_AT_const_value, cu);
 	  if (attr)
@@ -7582,6 +7585,7 @@ dwarf2_const_value_data (struct attribut
 static struct type *
 die_type (struct die_info *die, struct dwarf2_cu *cu)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (cu->objfile);
   struct type *type;
   struct attribute *type_attr;
   struct die_info *type_die;
@@ -7590,7 +7594,7 @@ die_type (struct die_info *die, struct d
   if (!type_attr)
     {
       /* A missing DW_AT_type represents a void type.  */
-      return builtin_type (current_gdbarch)->builtin_void;
+      return builtin_type (gdbarch)->builtin_void;
     }
   else
     type_die = follow_die_ref (die, type_attr, cu);
diff -urNp gdb-orig/gdb/elfread.c gdb-head/gdb/elfread.c
--- gdb-orig/gdb/elfread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/elfread.c	2007-12-09 18:42:57.000000000 +0100
@@ -165,8 +165,10 @@ record_minimal_symbol (char *name, CORE_
 		       enum minimal_symbol_type ms_type,
 		       asection *bfd_section, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
   if (ms_type == mst_text || ms_type == mst_file_text)
-    address = gdbarch_smash_text_address (current_gdbarch, address);
+    address = gdbarch_smash_text_address (gdbarch, address);
 
   return prim_record_minimal_symbol_and_info
     (name, address, ms_type, NULL, bfd_section->index, bfd_section, objfile);
@@ -205,6 +207,7 @@ static void
 elf_symtab_read (struct objfile *objfile, int type,
 		 long number_of_symbols, asymbol **symbol_table)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   long storage_needed;
   asymbol *sym;
   long i;
@@ -512,7 +515,7 @@ elf_symtab_read (struct objfile *objfile
 	    }
 	  if (msym != NULL)
 	    msym->filename = filesymname;
-	  gdbarch_elf_make_msymbol_special (current_gdbarch, sym, msym);
+	  gdbarch_elf_make_msymbol_special (gdbarch, sym, msym);
 	}
     }
 }
diff -urNp gdb-orig/gdb/Makefile.in gdb-head/gdb/Makefile.in
--- gdb-orig/gdb/Makefile.in	2007-12-08 17:16:24.000000000 +0100
+++ gdb-head/gdb/Makefile.in	2007-12-09 18:42:57.000000000 +0100
@@ -2526,7 +2526,7 @@ objfiles.o: objfiles.c $(defs_h) $(bfd_h
 	$(objfiles_h) $(gdb_stabs_h) $(target_h) $(bcache_h) $(mdebugread_h) \
 	$(gdb_assert_h) $(gdb_stat_h) $(gdb_obstack_h) $(gdb_string_h) \
 	$(hashtab_h) $(breakpoint_h) $(block_h) $(dictionary_h) $(source_h) \
-	$(parser_defs_h) $(expression_h) $(addrmap_h)
+	$(parser_defs_h) $(expression_h) $(addrmap_h) $(arch_utils_h)
 observer.o: observer.c $(defs_h) $(observer_h) $(command_h) $(gdbcmd_h) \
 	$(observer_inc)
 obsd-tdep.o: obsd-tdep.c $(defs_h) $(frame_h) $(symtab_h) $(obsd_tdep_h)
diff -urNp gdb-orig/gdb/mdebugread.c gdb-head/gdb/mdebugread.c
--- gdb-orig/gdb/mdebugread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/mdebugread.c	2007-12-09 18:42:57.000000000 +0100
@@ -559,6 +559,7 @@ static int
 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	      struct section_offsets *section_offsets, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   char *name;
@@ -653,7 +654,7 @@ parse_symbol (SYMR *sh, union aux_ext *a
       /* Type could be missing if file is compiled without debugging info.  */
       if (SC_IS_UNDEF (sh->sc)
 	  || sh->sc == scNil || sh->index == indexNil)
-	SYMBOL_TYPE (s) = builtin_type (current_gdbarch)->nodebug_data_symbol;
+	SYMBOL_TYPE (s) = builtin_type (gdbarch)->nodebug_data_symbol;
       else
 	SYMBOL_TYPE (s) = parse_type (cur_fd, ax, sh->index, 0, bigend, name);
       /* Value of a data symbol is its memory address */
@@ -1039,8 +1040,7 @@ parse_symbol (SYMR *sh, union aux_ext *a
 	       that too.  */
 	    if (TYPE_LENGTH (t) == TYPE_NFIELDS (t)
 		|| TYPE_LENGTH (t) == 0)
-	      TYPE_LENGTH (t) = 
-		gdbarch_int_bit (current_gdbarch) / HOST_CHAR_BIT;
+	      TYPE_LENGTH (t) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
 	    for (ext_tsym = ext_sh + external_sym_size;
 		 ;
 		 ext_tsym += external_sym_size)
@@ -1825,6 +1825,7 @@ static void
 parse_procedure (PDR *pr, struct symtab *search_symtab,
 		 struct partial_symtab *pst)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (pst->objfile);
   struct symbol *s, *i;
   struct block *b;
   struct mdebug_extra_func_info *e;
@@ -1962,7 +1963,7 @@ parse_procedure (PDR *pr, struct symtab 
   if (processing_gcc_compilation == 0
       && found_ecoff_debugging_info == 0
       && TYPE_CODE (TYPE_TARGET_TYPE (SYMBOL_TYPE (s))) == TYPE_CODE_VOID)
-    SYMBOL_TYPE (s) = builtin_type (current_gdbarch)->nodebug_text_symbol;
+    SYMBOL_TYPE (s) = builtin_type (gdbarch)->nodebug_text_symbol;
 }
 
 /* Parse the external symbol ES. Just call parse_symbol() after
@@ -2226,6 +2227,7 @@ record_minimal_symbol (const char *name,
 static void
 parse_partial_symbols (struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
@@ -2849,8 +2851,7 @@ parse_partial_symbols (struct objfile *o
 			 don't relocate it.  */
 
 		      if (sh.value == 0
-			  && gdbarch_sofun_address_maybe_missing
-			      (current_gdbarch))
+			  && gdbarch_sofun_address_maybe_missing (gdbarch))
 			{
 			  textlow_not_set = 1;
 			  valu = 0;
@@ -2999,9 +3000,9 @@ parse_partial_symbols (struct objfile *o
 		      case 'S':
 			sh.value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
 
-			if (gdbarch_static_transform_name_p (current_gdbarch))
+			if (gdbarch_static_transform_name_p (gdbarch))
 			  namestring = gdbarch_static_transform_name
-					 (current_gdbarch, namestring);
+					 (gdbarch, namestring);
 
 			add_psymbol_to_list (namestring, p - namestring,
 					     VAR_DOMAIN, LOC_STATIC,
@@ -3230,8 +3231,7 @@ parse_partial_symbols (struct objfile *o
 		       necessary if a module compiled without
 		       debugging info follows this module.  */
 		    if (pst
-			&& gdbarch_sofun_address_maybe_missing
-			     (current_gdbarch))
+			&& gdbarch_sofun_address_maybe_missing (gdbarch))
 		      {
 			pst = (struct partial_symtab *) 0;
 			includes_used = 0;
diff -urNp gdb-orig/gdb/objfiles.c gdb-head/gdb/objfiles.c
--- gdb-orig/gdb/objfiles.c	2007-12-08 17:16:24.000000000 +0100
+++ gdb-head/gdb/objfiles.c	2007-12-09 18:42:57.000000000 +0100
@@ -48,6 +48,7 @@
 #include "dictionary.h"
 #include "source.h"
 #include "addrmap.h"
+#include "arch-utils.h"
 
 /* Prototypes for local functions */
 
@@ -187,6 +188,9 @@ allocate_objfile (bfd *abfd, int flags)
     }
   if (abfd != NULL)
     {
+      /* Look up the gdbarch associated with the BFD.  */
+      objfile->gdbarch = gdbarch_from_bfd (abfd);
+
       objfile->name = xstrdup (bfd_get_filename (abfd));
       objfile->mtime = bfd_get_mtime (abfd);
 
@@ -234,6 +238,13 @@ allocate_objfile (bfd *abfd, int flags)
   return (objfile);
 }
 
+/* Retrieve the gdbarch associated with OBJFILE.  */
+struct gdbarch *
+get_objfile_arch (struct objfile *objfile)
+{
+  return objfile->gdbarch;
+}
+
 /* Initialize entry point information for this objfile. */
 
 void
diff -urNp gdb-orig/gdb/objfiles.h gdb-head/gdb/objfiles.h
--- gdb-orig/gdb/objfiles.h	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/objfiles.h	2007-12-09 18:42:57.000000000 +0100
@@ -229,6 +229,10 @@ struct objfile
 
     bfd *obfd;
 
+    /* The gdbarch associated with the BFD.  */
+
+    struct gdbarch *gdbarch;
+
     /* The modification timestamp of the object file, as of the last time
        we read its symbols.  */
 
@@ -470,6 +474,8 @@ extern struct objfile *object_files;
 
 extern struct objfile *allocate_objfile (bfd *, int);
 
+extern struct gdbarch *get_objfile_arch (struct objfile *);
+
 extern void init_entry_point_info (struct objfile *);
 
 extern CORE_ADDR entry_point_address (void);
diff -urNp gdb-orig/gdb/somread.c gdb-head/gdb/somread.c
--- gdb-orig/gdb/somread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/somread.c	2007-12-09 18:42:57.000000000 +0100
@@ -58,6 +58,7 @@ static void
 som_symtab_read (bfd *abfd, struct objfile *objfile,
 		 struct section_offsets *section_offsets)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   unsigned int number_of_symbols;
   int val, dynamic;
   char *stringtab;
@@ -132,7 +133,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_text;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 	    case ST_ENTRY:
@@ -146,7 +147,7 @@ som_symtab_read (bfd *abfd, struct objfi
 		ms_type = mst_text;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 	    case ST_STUB:
@@ -154,7 +155,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_solib_trampoline;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 	    case ST_DATA:
@@ -183,7 +184,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_file_text;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 
 	    check_strange_names:
 	      /* Utah GCC 2.5, FSF GCC 2.6 and later generate correct local
@@ -215,7 +216,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_file_text;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 	    case ST_ENTRY:
@@ -227,7 +228,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_file_text;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 	    case ST_STUB:
@@ -235,7 +236,7 @@ som_symtab_read (bfd *abfd, struct objfi
 	      ms_type = mst_solib_trampoline;
 	      bufp->symbol_value += text_offset;
 	      bufp->symbol_value = gdbarch_smash_text_address
-				     (current_gdbarch, bufp->symbol_value);
+				     (gdbarch, bufp->symbol_value);
 	      break;
 
 
diff -urNp gdb-orig/gdb/stabsread.c gdb-head/gdb/stabsread.c
--- gdb-orig/gdb/stabsread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/stabsread.c	2007-12-09 18:48:27.000000000 +0100
@@ -582,6 +582,7 @@ struct symbol *
 define_symbol (CORE_ADDR valu, char *string, int desc, int type,
 	       struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol *sym;
   char *p = (char *) find_name_end (string);
   int deftype;
@@ -666,7 +667,7 @@ define_symbol (CORE_ADDR valu, char *str
 
 	case 'X':
 	  /* SunPRO (3.0 at least) static variable encoding.  */
-	  if (gdbarch_static_transform_name_p (current_gdbarch))
+	  if (gdbarch_static_transform_name_p (gdbarch))
 	    goto normal;
 	  /* ... fall through ... */
 
@@ -731,7 +732,7 @@ define_symbol (CORE_ADDR valu, char *str
 	       target arithmetic to get the value.  real.c in GCC
 	       probably has the necessary code.  */
 
-	    dbl_type = builtin_type (current_gdbarch)->builtin_double;
+	    dbl_type = builtin_type (gdbarch)->builtin_double;
 	    dbl_valu =
 	      obstack_alloc (&objfile->objfile_obstack,
 			     TYPE_LENGTH (dbl_type));
@@ -751,7 +752,7 @@ define_symbol (CORE_ADDR valu, char *str
 	       types; other languages probably should have at least
 	       unsigned as well as signed constants.  */
 
-	    SYMBOL_TYPE (sym) = builtin_type (current_gdbarch)->builtin_long;
+	    SYMBOL_TYPE (sym) = builtin_type (gdbarch)->builtin_long;
 	    SYMBOL_VALUE (sym) = atoi (p);
 	    SYMBOL_CLASS (sym) = LOC_CONST;
 	  }
@@ -859,10 +860,10 @@ define_symbol (CORE_ADDR valu, char *str
 	         be promoted to the width of the calling conventions, with
 	         a type which references itself. This type is turned into
 	         a TYPE_CODE_VOID type by read_type, and we have to turn
-	         it back into builtin_type_int here.
-	         FIXME: Do we need a new builtin_type_promoted_int_arg ?  */
+	         it back into builtin_int here.
+	         FIXME: Do we need a new builtin_promoted_int_arg ?  */
 	      if (TYPE_CODE (ptype) == TYPE_CODE_VOID)
-		ptype = builtin_type_int;
+		ptype = builtin_type (gdbarch)->builtin_int;
 	      TYPE_FIELD_TYPE (ftype, nparams) = ptype;
 	      TYPE_FIELD_ARTIFICIAL (ftype, nparams++) = 0;
 	    }
@@ -931,7 +932,7 @@ define_symbol (CORE_ADDR valu, char *str
       SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
       add_symbol_to_list (sym, &local_symbols);
 
-      if (gdbarch_byte_order (current_gdbarch) != BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
 	{
 	  /* On little-endian machines, this crud is never necessary,
 	     and, if the extra bytes contain garbage, is harmful.  */
@@ -940,38 +941,21 @@ define_symbol (CORE_ADDR valu, char *str
 
       /* If it's gcc-compiled, if it says `short', believe it.  */
       if (processing_gcc_compilation
-	  || gdbarch_believe_pcc_promotion (current_gdbarch))
+	  || gdbarch_believe_pcc_promotion (gdbarch))
 	break;
 
-      if (!gdbarch_believe_pcc_promotion (current_gdbarch))
+      if (!gdbarch_believe_pcc_promotion (gdbarch))
 	{
-	  /* This is the signed type which arguments get promoted to.  */
-	  static struct type *pcc_promotion_type;
-	  /* This is the unsigned type which arguments get promoted to.  */
-	  static struct type *pcc_unsigned_promotion_type;
-
-	  /* Call it "int" because this is mainly C lossage.  */
-	  if (pcc_promotion_type == NULL)
-	    pcc_promotion_type =
-	      init_type (TYPE_CODE_INT, 
-			 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
-			 0, "int", NULL);
-
-	  if (pcc_unsigned_promotion_type == NULL)
-	    pcc_unsigned_promotion_type =
-	      init_type (TYPE_CODE_INT, 
-			 gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
-			 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
-
 	  /* If PCC says a parameter is a short or a char, it is
 	     really an int.  */
-	  if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
+	  if (TYPE_LENGTH (SYMBOL_TYPE (sym))
+	      < gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT
 	      && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
 	    {
 	      SYMBOL_TYPE (sym) =
 		TYPE_UNSIGNED (SYMBOL_TYPE (sym))
-		? pcc_unsigned_promotion_type
-		: pcc_promotion_type;
+		? builtin_type (gdbarch)->builtin_unsigned_int
+		: builtin_type (gdbarch)->builtin_int;
 	    }
 	  break;
 	}
@@ -1046,8 +1030,7 @@ define_symbol (CORE_ADDR valu, char *str
 
 	  if (local_symbols
 	      && local_symbols->nsyms > 0
-	      && gdbarch_stabs_argument_has_addr (current_gdbarch,
-						  SYMBOL_TYPE (sym)))
+	      && gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym)))
 	    {
 	      struct symbol *prev_sym;
 	      prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
@@ -1076,8 +1059,8 @@ define_symbol (CORE_ADDR valu, char *str
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
-      if (gdbarch_static_transform_name_p (current_gdbarch)
-	  && gdbarch_static_transform_name (current_gdbarch,
+      if (gdbarch_static_transform_name_p (gdbarch)
+	  && gdbarch_static_transform_name (gdbarch,
 					    DEPRECATED_SYMBOL_NAME (sym))
 	     != DEPRECATED_SYMBOL_NAME (sym))
 	{
@@ -1086,7 +1069,7 @@ define_symbol (CORE_ADDR valu, char *str
 	  if (msym != NULL)
 	    {
 	      DEPRECATED_SYMBOL_NAME (sym) = gdbarch_static_transform_name
-					       (current_gdbarch,	
+					       (gdbarch,	
 						DEPRECATED_SYMBOL_NAME (sym));
 	      SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
 	    }
@@ -1259,8 +1242,8 @@ define_symbol (CORE_ADDR valu, char *str
       SYMBOL_TYPE (sym) = read_type (&p, objfile);
       SYMBOL_CLASS (sym) = LOC_STATIC;
       SYMBOL_VALUE_ADDRESS (sym) = valu;
-      if (gdbarch_static_transform_name_p (current_gdbarch)
-	  && gdbarch_static_transform_name (current_gdbarch,
+      if (gdbarch_static_transform_name_p (gdbarch)
+	  && gdbarch_static_transform_name (gdbarch,
 					    DEPRECATED_SYMBOL_NAME (sym))
 	     != DEPRECATED_SYMBOL_NAME (sym))
 	{
@@ -1269,7 +1252,7 @@ define_symbol (CORE_ADDR valu, char *str
 	  if (msym != NULL)
 	    {
 	      DEPRECATED_SYMBOL_NAME (sym) = gdbarch_static_transform_name
-					       (current_gdbarch,	
+					       (gdbarch,	
 						DEPRECATED_SYMBOL_NAME (sym));
 	      SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
 	    }
@@ -1331,7 +1314,7 @@ define_symbol (CORE_ADDR valu, char *str
      of by value, i.e. they will pass the address of a structure (in a
      register or on the stack) instead of the structure itself.  */
 
-  if (gdbarch_stabs_argument_has_addr (current_gdbarch, SYMBOL_TYPE (sym))
+  if (gdbarch_stabs_argument_has_addr (gdbarch, SYMBOL_TYPE (sym))
       && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
     {
       /* We have to convert LOC_REGPARM to LOC_REGPARM_ADDR (for
@@ -2717,6 +2700,8 @@ static void
 read_one_struct_field (struct field_info *fip, char **pp, char *p,
 		       struct type *type, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+
   fip->list->field.name =
     obsavestring (*pp, p - *pp, &objfile->objfile_obstack);
   *pp = p + 1;
@@ -2821,7 +2806,7 @@ read_one_struct_field (struct field_info
 	   == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
 	   || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
 	       && FIELD_BITSIZE (fip->list->field)
-		  == gdbarch_int_bit (current_gdbarch))
+		  == gdbarch_int_bit (gdbarch))
 	  )
 	  &&
 	  FIELD_BITPOS (fip->list->field) % 8 == 0)
@@ -3445,6 +3430,7 @@ static struct type *
 read_enum_type (char **pp, struct type *type,
 		struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   char *p;
   char *name;
   long n;
@@ -3514,7 +3500,7 @@ read_enum_type (char **pp, struct type *
 
   /* Now fill in the fields of the type-structure.  */
 
-  TYPE_LENGTH (type) = gdbarch_int_bit (current_gdbarch) / HOST_CHAR_BIT;
+  TYPE_LENGTH (type) = gdbarch_int_bit (gdbarch) / HOST_CHAR_BIT;
   TYPE_CODE (type) = TYPE_CODE_ENUM;
   TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
   if (unsigned_enum)
@@ -3849,6 +3835,7 @@ static struct type *
 read_range_type (char **pp, int typenums[2], int type_size,
                  struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
@@ -3974,7 +3961,7 @@ read_range_type (char **pp, int typenums
 	  /* We don't know its size.  It is unsigned int or unsigned
 	     long.  GCC 2.3.3 uses this for long long too, but that is
 	     just a GDB 3.5 compatibility hack.  */
-	  bits = gdbarch_int_bit (current_gdbarch);
+	  bits = gdbarch_int_bit (gdbarch);
 	}
 
       return init_type (TYPE_CODE_INT, bits / TARGET_CHAR_BIT,
@@ -4020,7 +4007,7 @@ read_range_type (char **pp, int typenums
   else if (n3 == 0 && n2 < 0
 	   && (self_subrange
 	       || n2 == -gdbarch_long_long_bit
-			  (current_gdbarch) / TARGET_CHAR_BIT))
+			  (gdbarch) / TARGET_CHAR_BIT))
     return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
   else if (n2 == -n3 - 1)
     {
@@ -4037,7 +4024,7 @@ read_range_type (char **pp, int typenums
 handle_true_range:
 
   if (self_subrange)
-    index_type = builtin_type_int;
+    index_type = builtin_type (gdbarch)->builtin_int;
   else
     index_type = *dbx_lookup_type (rangenums);
   if (index_type == NULL)
@@ -4045,16 +4032,10 @@ handle_true_range:
       /* Does this actually ever happen?  Is that why we are worrying
          about dealing with it rather than just calling error_type?  */
 
-      static struct type *range_type_index;
-
       complaint (&symfile_complaints,
 		 _("base type %d of range type is not defined"), rangenums[1]);
-      if (range_type_index == NULL)
-	range_type_index =
-	  init_type (TYPE_CODE_INT, 
-		     gdbarch_int_bit (current_gdbarch) / TARGET_CHAR_BIT,
-		     0, "range type index type", NULL);
-      index_type = range_type_index;
+
+      index_type = builtin_type (gdbarch)->builtin_int;
     }
 
   result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
diff -urNp gdb-orig/gdb/xcoffread.c gdb-head/gdb/xcoffread.c
--- gdb-orig/gdb/xcoffread.c	2007-12-08 17:15:03.000000000 +0100
+++ gdb-head/gdb/xcoffread.c	2007-12-09 18:42:57.000000000 +0100
@@ -1435,6 +1435,7 @@ read_xcoff_symtab (struct partial_symtab
 static struct symbol *
 process_xcoff_symbol (struct coff_symbol *cs, struct objfile *objfile)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct symbol onesymbol;
   struct symbol *sym = &onesymbol;
   struct symbol *sym2 = NULL;
@@ -1474,7 +1475,7 @@ process_xcoff_symbol (struct coff_symbol
          patch_block_stabs (), unless the file was compiled without -g.  */
 
       DEPRECATED_SYMBOL_NAME (sym) = SYMNAME_ALLOC (name, symname_alloced);
-      SYMBOL_TYPE (sym) = builtin_type (current_gdbarch)->nodebug_text_symbol;
+      SYMBOL_TYPE (sym) = builtin_type (gdbarch)->nodebug_text_symbol;
 
       SYMBOL_CLASS (sym) = LOC_BLOCK;
       SYMBOL_DUP (sym, sym2);
@@ -1487,7 +1488,7 @@ process_xcoff_symbol (struct coff_symbol
   else
     {
       /* In case we can't figure out the type, provide default. */
-      SYMBOL_TYPE (sym) = builtin_type (current_gdbarch)->nodebug_data_symbol;
+      SYMBOL_TYPE (sym) = builtin_type (gdbarch)->nodebug_data_symbol;
 
       switch (cs->c_sclass)
 	{
@@ -2582,9 +2583,9 @@ scan_xcoff_symtab (struct objfile *objfi
 	      case 'S':
 		symbol.n_value += ANOFFSET (objfile->section_offsets, SECT_OFF_DATA (objfile));
 
-		if (gdbarch_static_transform_name_p (current_gdbarch))
+		if (gdbarch_static_transform_name_p (gdbarch))
 		  namestring = gdbarch_static_transform_name
-				 (current_gdbarch, namestring);
+				 (gdbarch, namestring);
 
 		add_psymbol_to_list (namestring, p - namestring,
 				     VAR_DOMAIN, LOC_STATIC,
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gdb-patches mailing list