Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfc] Introduce "target_gdbarch" variable
@ 2008-08-13 19:53 Ulrich Weigand
  2008-08-18 11:34 ` Joel Brobecker
  2008-08-26 17:33 ` Ulrich Weigand
  0 siblings, 2 replies; 5+ messages in thread
From: Ulrich Weigand @ 2008-08-13 19:53 UTC (permalink / raw)
  To: gdb-patches

Hello,

while moving away from current_gdbarch and towards a per-thread /
per-frame / per-objfile architecture, I noticed a couple of places
where we currently use current_gdbarch that simply do not make sense
in a per-thread / per-frame / per-objfile context.

For example, the remote target uses "current_gdbarch" to store
basic information about the target connection (layout of various
packets etc).  Also, the shared library layer uses "current_gdbarch"
to store the master solib_ops structure.

These seem to me to be overall properties of the current target.
One way to move forward would be to introduce a new global variable
"target_gdbarch" that is defined as the architecture associated with
the current target.  It is defined once when the target is opened,
and stays the same as long as the connection is in place.

The idea is that this variable would stay even as other uses of
current_gdbarch are being eliminated in favor of per-thread etc.
architectures.  Now, why not simply leave those uses of current_gdbarch
as they are while eliminating the other?  Some reasons:

- Giving these uses a different name makes it more obvious that the
  remaining uses of current_gdbarch should be eliminated while these
  can stay.

- Separating the two makes it easier to "switch" current_gdbarch
  between multiple values as an intermediate step towards a multi-
  architecture debugger.  (Conceptually, current_gdbarch should be
  considered more or less equivalent to "architecture of the 
  current frame" in this scenario.)

- Even today, there are places that temporarily switch current_gdbarch,
  e.g. in gdbarch_find_by_info -- this has caused problems with the
  patch to retrieve shared libraries from the remote target that I'm
  posting as a separate message.

Tested on powerpc-linux and powerpc64-linux with no regressions.

Does this seem reasonable?

Bye,
Ulrich


ChangeLog:

	* gdbarch.sh (target_gdbarch): New global variable.
	(deprecated_current_gdbarch_select_hack): Set it.
	* gdbarch.c, gdbarch.h: Regenerate.

	* remote.c (struct packet_reg): Use target_gdbarch instead
	of current_gdbarch.
	(get_remote_arch_state, packet_reg_from_regnum,
	packet_reg_from_pnum, remote_check_symbols, remote_wait,
	remote_address_masked, remote_insert_breakpoint,
	remote_insert_hw_breakpoint, remote_read_description): Likewise.

	* solib.c (solib_open, solib_map_sections, solib_read_symbols,
	solib_add, info_sharedlibrary_command, solib_address, 
	solib_create_inferior_hook, in_solib_dynsym_resolve_code,
	solib_global_lookup): Likewise.
	* solib-frv.c (enable_break2, frv_relocate_main_executable): Likewise.
	* solib-irix.c (irix_current_sos, irix_open_symbol_file_object):
	Likewise.
	* solib-svr4.c (exec_entry_point, enable_break, svr4_free_so,
	set_solib_svr4_fetch_link_map_offsets, svr4_fetch_link_map_offsets):
	Likewise.


diff -urNp gdb-orig/gdb/gdbarch.c gdb-head/gdb/gdbarch.c
--- gdb-orig/gdb/gdbarch.c	2008-08-12 19:13:15.000000000 +0200
+++ gdb-head/gdb/gdbarch.c	2008-08-13 18:05:32.204548167 +0200
@@ -376,6 +376,7 @@ struct gdbarch startup_gdbarch =
 };
 
 struct gdbarch *current_gdbarch = &startup_gdbarch;
+struct gdbarch *target_gdbarch = &startup_gdbarch;
 
 /* Create a new ``struct gdbarch'' based on information provided by
    ``struct gdbarch_info''. */
@@ -3665,6 +3666,7 @@ deprecated_current_gdbarch_select_hack (
   gdb_assert (current_gdbarch != NULL);
   gdb_assert (new_gdbarch->initialized_p);
   current_gdbarch = new_gdbarch;
+  target_gdbarch = new_gdbarch;
   observer_notify_architecture_changed (new_gdbarch);
   reinit_frame_cache ();
 }
diff -urNp gdb-orig/gdb/gdbarch.h gdb-head/gdb/gdbarch.h
--- gdb-orig/gdb/gdbarch.h	2008-08-12 19:13:15.000000000 +0200
+++ gdb-head/gdb/gdbarch.h	2008-08-13 17:56:36.681153229 +0200
@@ -54,6 +54,7 @@ struct displaced_step_closure;
 struct core_regset_section;
 
 extern struct gdbarch *current_gdbarch;
+extern struct gdbarch *target_gdbarch;
 
 
 /* The following are pre-initialized by GDBARCH. */
diff -urNp gdb-orig/gdb/gdbarch.sh gdb-head/gdb/gdbarch.sh
--- gdb-orig/gdb/gdbarch.sh	2008-08-12 19:13:15.000000000 +0200
+++ gdb-head/gdb/gdbarch.sh	2008-08-13 17:57:19.513522561 +0200
@@ -822,6 +822,7 @@ struct displaced_step_closure;
 struct core_regset_section;
 
 extern struct gdbarch *current_gdbarch;
+extern struct gdbarch *target_gdbarch;
 EOF
 
 # function typedef's
@@ -1280,6 +1281,7 @@ cat <<EOF
 };
 
 struct gdbarch *current_gdbarch = &startup_gdbarch;
+struct gdbarch *target_gdbarch = &startup_gdbarch;
 EOF
 
 # Create a new gdbarch struct
@@ -2021,6 +2023,7 @@ deprecated_current_gdbarch_select_hack (
   gdb_assert (current_gdbarch != NULL);
   gdb_assert (new_gdbarch->initialized_p);
   current_gdbarch = new_gdbarch;
+  target_gdbarch = new_gdbarch;
   observer_notify_architecture_changed (new_gdbarch);
   reinit_frame_cache ();
 }
diff -urNp gdb-orig/gdb/remote.c gdb-head/gdb/remote.c
--- gdb-orig/gdb/remote.c	2008-08-12 19:13:15.000000000 +0200
+++ gdb-head/gdb/remote.c	2008-08-13 17:58:58.833295385 +0200
@@ -301,9 +301,9 @@ struct packet_reg
   long regnum; /* GDB's internal register number.  */
   LONGEST pnum; /* Remote protocol register number.  */
   int in_g_packet; /* Always part of G packet.  */
-  /* long size in bytes;  == register_size (current_gdbarch, regnum);
+  /* long size in bytes;  == register_size (target_gdbarch, regnum);
      at present.  */
-  /* char *name; == gdbarch_register_name (current_gdbarch, regnum);
+  /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
      at present.  */
 };
 
@@ -336,7 +336,7 @@ static struct gdbarch_data *remote_gdbar
 static struct remote_arch_state *
 get_remote_arch_state (void)
 {
-  return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
+  return gdbarch_data (target_gdbarch, remote_gdbarch_data_handle);
 }
 
 /* Fetch the global remote target state.  */
@@ -472,7 +472,7 @@ get_remote_packet_size (void)
 static struct packet_reg *
 packet_reg_from_regnum (struct remote_arch_state *rsa, long regnum)
 {
-  if (regnum < 0 && regnum >= gdbarch_num_regs (current_gdbarch))
+  if (regnum < 0 && regnum >= gdbarch_num_regs (target_gdbarch))
     return NULL;
   else
     {
@@ -486,7 +486,7 @@ static struct packet_reg *
 packet_reg_from_pnum (struct remote_arch_state *rsa, LONGEST pnum)
 {
   int i;
-  for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+  for (i = 0; i < gdbarch_num_regs (target_gdbarch); i++)
     {
       struct packet_reg *r = &rsa->regs[i];
       if (r->pnum == pnum)
@@ -2427,7 +2427,7 @@ remote_check_symbols (struct objfile *ob
 
 	  /* If this is a function address, return the start of code
 	     instead of any data function descriptor.  */
-	  sym_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							 sym_addr,
 							 &current_target);
 
@@ -3615,10 +3615,10 @@ Packet: '%s'\n"),
 			     phex_nz (pnum, 0), p, buf);
 
 		    fieldsize = hex2bin (p, regs,
-					 register_size (current_gdbarch,
+					 register_size (target_gdbarch,
 							reg->regnum));
 		    p += 2 * fieldsize;
-		    if (fieldsize < register_size (current_gdbarch,
+		    if (fieldsize < register_size (target_gdbarch,
 						   reg->regnum))
 		      warning (_("Remote reply is too short: %s"), buf);
 		    regcache_raw_supply (get_current_regcache (),
@@ -4132,7 +4132,7 @@ remote_address_masked (CORE_ADDR addr)
   int address_size = remote_address_size;
   /* If "remoteaddresssize" was not set, default to target address size.  */
   if (!address_size)
-    address_size = gdbarch_addr_bit (current_gdbarch);
+    address_size = gdbarch_addr_bit (target_gdbarch);
 
   if (address_size > 0
       && address_size < (sizeof (ULONGEST) * 8))
@@ -5400,8 +5400,7 @@ remote_insert_breakpoint (struct bp_targ
       char *p;
       int bpsize;
 
-      gdbarch_breakpoint_from_pc
-	(current_gdbarch, &addr, &bpsize);
+      gdbarch_breakpoint_from_pc (target_gdbarch, &addr, &bpsize);
 
       rs = get_remote_state ();
       p = rs->buf;
@@ -5603,7 +5602,7 @@ remote_insert_hw_breakpoint (struct bp_t
      instruction, even though we aren't inserting one ourselves.  */
 
   gdbarch_breakpoint_from_pc
-    (current_gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
+    (target_gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
 
   if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
     return -1;
@@ -6532,7 +6531,7 @@ static const struct target_desc *
 remote_read_description (struct target_ops *target)
 {
   struct remote_g_packet_data *data
-    = gdbarch_data (current_gdbarch, remote_g_packet_data_handle);
+    = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
 
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
diff -urNp gdb-orig/gdb/solib.c gdb-head/gdb/solib.c
--- gdb-orig/gdb/solib.c	2008-07-12 22:00:20.000000000 +0200
+++ gdb-head/gdb/solib.c	2008-08-13 17:59:32.303545384 +0200
@@ -142,7 +142,7 @@ The search path for loading non-absolute
 int
 solib_open (char *in_pathname, char **found_pathname)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   int found_file = -1;
   char *temp_pathname = NULL;
   char *p = in_pathname;
@@ -321,7 +321,7 @@ solib_map_sections (void *arg)
 
   for (p = so->sections; p < so->sections_end; p++)
     {
-      struct target_so_ops *ops = solib_ops (current_gdbarch);
+      struct target_so_ops *ops = solib_ops (target_gdbarch);
 
       /* Relocate the section binding addresses as recorded in the shared
          object's file by the base address to which the object was actually
@@ -369,7 +369,7 @@ solib_map_sections (void *arg)
 void
 free_so (struct so_list *so)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   char *bfd_filename = 0;
 
   if (so->sections)
@@ -490,7 +490,7 @@ solib_read_symbols (struct so_list *so, 
 static void
 update_solib_list (int from_tty, struct target_ops *target)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   struct so_list *inferior = ops->current_sos();
   struct so_list *gdb, **gdb_link;
 
@@ -705,7 +705,7 @@ solib_add (char *pattern, int from_tty, 
 
     if (loaded_any_symbols)
       {
-	struct target_so_ops *ops = solib_ops (current_gdbarch);
+	struct target_so_ops *ops = solib_ops (target_gdbarch);
 
 	/* Getting new symbols may change our opinion about what is
 	   frameless.  */
@@ -741,7 +741,7 @@ info_sharedlibrary_command (char *ignore
   int addr_width;
 
   /* "0x", a little whitespace, and two hex digits per byte of pointers.  */
-  addr_width = 4 + (gdbarch_ptr_bit (current_gdbarch) / 4);
+  addr_width = 4 + (gdbarch_ptr_bit (target_gdbarch) / 4);
 
   update_solib_list (from_tty, 0);
 
@@ -824,7 +824,7 @@ solib_address (CORE_ADDR address)
 void
 clear_solib (void)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
 
   /* This function is expected to handle ELF shared libraries.  It is
      also used on Solaris, which can run either ELF or a.out binaries
@@ -880,7 +880,7 @@ clear_solib (void)
 void
 solib_create_inferior_hook (void)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   ops->solib_create_inferior_hook();
 }
 
@@ -903,7 +903,7 @@ solib_create_inferior_hook (void)
 int
 in_solib_dynsym_resolve_code (CORE_ADDR pc)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   return ops->in_dynsym_resolve_code (pc);
 }
 
@@ -973,7 +973,7 @@ solib_global_lookup (const struct objfil
 		     const char *linkage_name,
 		     const domain_enum domain)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
 
   if (ops->lookup_lib_global_symbol != NULL)
     return ops->lookup_lib_global_symbol (objfile, name, linkage_name, domain);
diff -urNp gdb-orig/gdb/solib-frv.c gdb-head/gdb/solib-frv.c
--- gdb-orig/gdb/solib-frv.c	2008-05-09 21:16:06.000000000 +0200
+++ gdb-head/gdb/solib-frv.c	2008-08-13 18:01:01.502307758 +0200
@@ -687,7 +687,7 @@ enable_break2 (void)
 	  return 0;
 	}
 
-      status = frv_fdpic_loadmap_addresses (current_gdbarch,
+      status = frv_fdpic_loadmap_addresses (target_gdbarch,
                                             &interp_loadmap_addr, 0);
       if (status < 0)
 	{
@@ -876,7 +876,7 @@ frv_relocate_main_executable (void)
   int changed;
   struct obj_section *osect;
 
-  status = frv_fdpic_loadmap_addresses (current_gdbarch, 0, &exec_addr);
+  status = frv_fdpic_loadmap_addresses (target_gdbarch, 0, &exec_addr);
 
   if (status < 0)
     {
diff -urNp gdb-orig/gdb/solib-irix.c gdb-head/gdb/solib-irix.c
--- gdb-orig/gdb/solib-irix.c	2008-01-29 22:11:24.000000000 +0100
+++ gdb-head/gdb/solib-irix.c	2008-08-13 18:01:21.184542307 +0200
@@ -505,9 +505,9 @@ irix_current_sos (void)
 
   read_memory (debug_base,
 	       addr_buf,
-	       gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT);
+	       gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT);
   lma = extract_mips_address (addr_buf,
-			      gdbarch_addr_bit (current_gdbarch)
+			      gdbarch_addr_bit (target_gdbarch)
 				/ TARGET_CHAR_BIT);
 
   while (lma)
@@ -611,9 +611,9 @@ irix_open_symbol_file_object (void *from
   /* First link map member should be the executable.  */
   read_memory (debug_base,
 	       addr_buf,
-	       gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT);
+	       gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT);
   lma = extract_mips_address (addr_buf,
-			      gdbarch_addr_bit (current_gdbarch)
+			      gdbarch_addr_bit (target_gdbarch)
 				/ TARGET_CHAR_BIT);
   if (lma == 0)
     return 0;			/* failed somehow...  */
diff -urNp gdb-orig/gdb/solib-svr4.c gdb-head/gdb/solib-svr4.c
--- gdb-orig/gdb/solib-svr4.c	2008-08-05 22:16:26.000000000 +0200
+++ gdb-head/gdb/solib-svr4.c	2008-08-13 17:56:36.822133011 +0200
@@ -909,7 +909,7 @@ exec_entry_point (struct bfd *abfd, stru
      gdbarch_convert_from_func_ptr_addr().  The method
      gdbarch_convert_from_func_ptr_addr() is the merely the identify
      function for targets which don't use function descriptors.  */
-  return gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+  return gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 					     bfd_get_start_address (abfd),
 					     targ);
 }
@@ -987,7 +987,7 @@ enable_break (void)
       struct obj_section *os;
 
       sym_addr = gdbarch_addr_bits_remove
-	(current_gdbarch, gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	(target_gdbarch, gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							      sym_addr,
 							      &current_target));
 
@@ -1149,7 +1149,7 @@ enable_break (void)
 	/* Convert 'sym_addr' from a function pointer to an address.
 	   Because we pass tmp_bfd_target instead of the current
 	   target, this will always produce an unrelocated value.  */
-	sym_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 						       sym_addr,
 						       tmp_bfd_target);
 
@@ -1455,12 +1455,12 @@ svr4_free_so (struct so_list *so)
 static CORE_ADDR
 svr4_truncate_ptr (CORE_ADDR addr)
 {
-  if (gdbarch_ptr_bit (current_gdbarch) == sizeof (CORE_ADDR) * 8)
+  if (gdbarch_ptr_bit (target_gdbarch) == sizeof (CORE_ADDR) * 8)
     /* We don't need to truncate anything, and the bit twiddling below
        will fail due to overflow problems.  */
     return addr;
   else
-    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (current_gdbarch)) - 1);
+    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (target_gdbarch)) - 1);
 }
 
 
@@ -1518,7 +1518,7 @@ set_solib_svr4_fetch_link_map_offsets (s
 static struct link_map_offsets *
 svr4_fetch_link_map_offsets (void)
 {
-  struct solib_svr4_ops *ops = gdbarch_data (current_gdbarch, solib_svr4_data);
+  struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
 
   gdb_assert (ops->fetch_link_map_offsets);
   return ops->fetch_link_map_offsets ();
@@ -1529,7 +1529,7 @@ svr4_fetch_link_map_offsets (void)
 static int
 svr4_have_link_map_offsets (void)
 {
-  struct solib_svr4_ops *ops = gdbarch_data (current_gdbarch, solib_svr4_data);
+  struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
   return (ops->fetch_link_map_offsets != NULL);
 }
 \f
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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

* Re: [rfc] Introduce "target_gdbarch" variable
  2008-08-13 19:53 [rfc] Introduce "target_gdbarch" variable Ulrich Weigand
@ 2008-08-18 11:34 ` Joel Brobecker
  2008-08-18 13:59   ` Ulrich Weigand
  2008-08-26 17:33 ` Ulrich Weigand
  1 sibling, 1 reply; 5+ messages in thread
From: Joel Brobecker @ 2008-08-18 11:34 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

Just my 2 cents...

> The idea is that this variable would stay even as other uses of
> current_gdbarch are being eliminated in favor of per-thread etc.
> architectures.

I am wondering why these ones are OK to stay, or perhaps you were
thinking of a short-to-medium term situation. Otherwise, isn't this
global going to be a problem with true multi-arch? Another situation
where this might be a problem is when the debugger is debugging more
than one process from different architectures (Stan's project).

> - Giving these uses a different name makes it more obvious that the
>   remaining uses of current_gdbarch should be eliminated while these
>   can stay.

That's a good reason. In fact, I started with something similar when
I first worked on the project of getting rid of the "current_language"
global (which I haven't forgotten about!)

> Does this seem reasonable?

It seems reasonable to me, modulo the part where I don't understand
why the current globals used in target-remote/solib are OK to stay.

-- 
Joel


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

* Re: [rfc] Introduce "target_gdbarch" variable
  2008-08-18 11:34 ` Joel Brobecker
@ 2008-08-18 13:59   ` Ulrich Weigand
  2008-08-18 14:11     ` Joel Brobecker
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2008-08-18 13:59 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches

Joel Brobecker wrote:

> Just my 2 cents...

Thanks for looking at this!

> > The idea is that this variable would stay even as other uses of
> > current_gdbarch are being eliminated in favor of per-thread etc.
> > architectures.
> 
> I am wondering why these ones are OK to stay, or perhaps you were
> thinking of a short-to-medium term situation. Otherwise, isn't this
> global going to be a problem with true multi-arch? Another situation
> where this might be a problem is when the debugger is debugging more
> than one process from different architectures (Stan's project).

The idea was that target_gdbarch is the architecture assoicated with
the connection to one target.  As we currently support only one target
at a time, using a global for that should be fine.  As soon as we start
supporting multiple target connections at the same time, we'd need 
multiple instances of this as well.  At this point, it would probably
make sense to make this a member of "struct target".

> > Does this seem reasonable?
> 
> It seems reasonable to me, modulo the part where I don't understand
> why the current globals used in target-remote/solib are OK to stay.

"remote" uses gdbarch to store properties of the connection to its
targets.  For example, the layout of the "g" packet is stored there.
Even in a scenario where we have per-thread / per-frame architectures,
those properties will still stay invariant for one target.

Similarly, "solib" stores the overall method to use to search for
shared libraries as gdbarch properties.  Again, this is a global
property of a certain target, even though the inferior may have
some threads / frames that use a different architecture.

It may be that at some point, this will need to be fundamentally
changed anyway, e.g. because the association of one single solib
method to one target may no longer be sufficient.  At this point,
those properties might have to be moved out of gdbarch completely.

But even so, I think moving them to target_gdbarch (even if in the
long run this turns out to be just a temporary solution) would be
helpful in the short run, as it allows adding per-frame architecture
support without major up-front changes to the solib code ...

Bye,
Ulrich

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


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

* Re: [rfc] Introduce "target_gdbarch" variable
  2008-08-18 13:59   ` Ulrich Weigand
@ 2008-08-18 14:11     ` Joel Brobecker
  0 siblings, 0 replies; 5+ messages in thread
From: Joel Brobecker @ 2008-08-18 14:11 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

> "remote" uses gdbarch to store properties of the connection to its
> targets.  For example, the layout of the "g" packet is stored there.
> Even in a scenario where we have per-thread / per-frame architectures,
> those properties will still stay invariant for one target.
[...]
> It may be that at some point, this will need to be fundamentally
> changed anyway, e.g. because the association of one single solib
> method to one target may no longer be sufficient.  At this point,
> those properties might have to be moved out of gdbarch completely.

I was thinking exactly this as I was reading your explaination!
As struct target seems indeed the way to go, eventually.

> But even so, I think moving them to target_gdbarch (even if in the
> long run this turns out to be just a temporary solution) would be
> helpful in the short run, as it allows adding per-frame architecture
> support without major up-front changes to the solib code ...

I agree it's helpful, and the cost of having to another global doesn't
seem very high (at least at first sight! I won't be surprised if we
run into trouble later because of some little detail we forgot, but
I'm sure we can deal with them when they arise). I know others such
as Daniel know this code a lot better than I do, though. It'd be nice
if they could comment as well, but no objection from me.

-- 
Joel


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

* Re: [rfc] Introduce "target_gdbarch" variable
  2008-08-13 19:53 [rfc] Introduce "target_gdbarch" variable Ulrich Weigand
  2008-08-18 11:34 ` Joel Brobecker
@ 2008-08-26 17:33 ` Ulrich Weigand
  1 sibling, 0 replies; 5+ messages in thread
From: Ulrich Weigand @ 2008-08-26 17:33 UTC (permalink / raw)
  To: gdb-patches


> while moving away from current_gdbarch and towards a per-thread /
> per-frame / per-objfile architecture, I noticed a couple of places
> where we currently use current_gdbarch that simply do not make sense
> in a per-thread / per-frame / per-objfile context.
> 
> For example, the remote target uses "current_gdbarch" to store
> basic information about the target connection (layout of various
> packets etc).  Also, the shared library layer uses "current_gdbarch"
> to store the master solib_ops structure.

I've now checked in the version below, which adds some more places
that should be using a per-target architecture which I missed before.
These include addition solib and remote uses, and a number of places
where the per-target architecture is explicitly addressed.

Re-tested on powerpc-linux, powerpc64-linux, and spu-elf, and by
running a --enable-targets=all compile.

Bye,
Ulrich

ChangeLog:

	* gdbarch.sh (target_gdbarch): New global variable.
	(deprecated_current_gdbarch_select_hack): Set it.
	* gdbarch.c, gdbarch.h: Regenerate.

	* arch-utils.c (gdbarch_update_p): Use target_gdbarch instead
	of current_gdbarch.
	* target-descriptions.c (target_find_description): Likewise.
	* arm-tdep.c (arm_update_current_architecture): Likewise.
	(show_fp_model, arm_show_abi, arm_show_fallback_mode, 
	arm_show_force_mode): Likewise.
	* mips-tdep.c (show_mask_address, show_mipsfpu_command,
	show_mips_abi): Likewise.
	* mep-tdep.c (me_module_register_set, current_me_module): Likewise.

	* target.c (target_translate_tls_address): Use target_gdbarch
	instead of current_gdbarch.
	* remote.c (struct packet_reg): Likewise.
	(get_remote_arch_state, packet_reg_from_regnum,
	packet_reg_from_pnum, remote_check_symbols, remote_wait,
	remote_address_masked, remote_insert_breakpoint,
	remote_insert_hw_breakpoint, remote_read_description): Likewise.
	* remote-m32r-sdi.c (m32r_resume, m32r_wait): Likewise.
	* remote-mips.c (mips_open, mips_common_breakpoint): Likewise.
	* cris-tdep.c (cris_can_use_hardware_watchpoint): Likewise.

	* solib.c (solib_open, solib_map_sections, solib_read_symbols,
	solib_add, info_sharedlibrary_command, solib_address, 
	solib_create_inferior_hook, in_solib_dynsym_resolve_code,
	solib_global_lookup): Likewise.
	* solib-frv.c (enable_break2, frv_relocate_main_executable): Likewise.
	* solib-irix.c (irix_current_sos, irix_open_symbol_file_object):
	Likewise.
	* solib-sunos.c (sunos_solib_create_inferior_hook): Likewise.
	* solib-svr4.c (exec_entry_point, enable_break, svr4_free_so,
	set_solib_svr4_fetch_link_map_offsets, svr4_fetch_link_map_offsets):
	Likewise.
	* nto-tdep.c (nto_find_and_open_solib, nto_init_solib_absolute_prefix,
	nto_truncate_ptr): Likewise.
	* mips-linux-tdep.c (mips_linux_in_dynsym_stub): Likewise.


diff -urNp gdb-orig/gdb/arch-utils.c gdb-head/gdb/arch-utils.c
--- gdb-orig/gdb/arch-utils.c	2008-08-22 03:25:26.000000000 +0200
+++ gdb-head/gdb/arch-utils.c	2008-08-26 00:41:54.000000000 +0200
@@ -491,7 +491,7 @@ gdbarch_update_p (struct gdbarch_info in
 
   /* If it is the same old architecture, accept the request (but don't
      swap anything).  */
-  if (new_gdbarch == current_gdbarch)
+  if (new_gdbarch == target_gdbarch)
     {
       if (gdbarch_debug)
 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update_p: "
diff -urNp gdb-orig/gdb/arm-tdep.c gdb-head/gdb/arm-tdep.c
--- gdb-orig/gdb/arm-tdep.c	2008-08-26 00:05:35.000000000 +0200
+++ gdb-head/gdb/arm-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -2704,7 +2704,7 @@ arm_update_current_architecture (void)
   struct gdbarch_info info;
 
   /* If the current architecture is not ARM, we have nothing to do.  */
-  if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_arm)
+  if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_arm)
     return;
 
   /* Update the architecture.  */
@@ -2738,10 +2738,10 @@ static void
 show_fp_model (struct ui_file *file, int from_tty,
 	       struct cmd_list_element *c, const char *value)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   if (arm_fp_model == ARM_FLOAT_AUTO
-      && gdbarch_bfd_arch_info (current_gdbarch)->arch == bfd_arch_arm)
+      && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
     fprintf_filtered (file, _("\
 The current ARM floating point model is \"auto\" (currently \"%s\").\n"),
 		      fp_model_strings[tdep->fp_model]);
@@ -2775,10 +2775,10 @@ static void
 arm_show_abi (struct ui_file *file, int from_tty,
 	     struct cmd_list_element *c, const char *value)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   if (arm_abi_global == ARM_ABI_AUTO
-      && gdbarch_bfd_arch_info (current_gdbarch)->arch == bfd_arch_arm)
+      && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_arm)
     fprintf_filtered (file, _("\
 The current ARM ABI is \"auto\" (currently \"%s\").\n"),
 		      arm_abi_strings[tdep->arm_abi]);
@@ -2791,7 +2791,7 @@ static void
 arm_show_fallback_mode (struct ui_file *file, int from_tty,
 			struct cmd_list_element *c, const char *value)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   fprintf_filtered (file, _("\
 The current execution mode assumed (when symbols are unavailable) is \"%s\".\n"),
@@ -2802,7 +2802,7 @@ static void
 arm_show_force_mode (struct ui_file *file, int from_tty,
 		     struct cmd_list_element *c, const char *value)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   fprintf_filtered (file, _("\
 The current execution mode assumed (even when symbols are available) is \"%s\".\n"),
diff -urNp gdb-orig/gdb/cris-tdep.c gdb-head/gdb/cris-tdep.c
--- gdb-orig/gdb/cris-tdep.c	2008-08-26 00:05:35.000000000 +0200
+++ gdb-head/gdb/cris-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -498,7 +498,7 @@ crisv32_single_step_through_delay (struc
 int
 cris_can_use_hardware_watchpoint (int type, int count, int other)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   /* No bookkeeping is done here; it is handled by the remote debug agent.  */
 
diff -urNp gdb-orig/gdb/gdbarch.c gdb-head/gdb/gdbarch.c
--- gdb-orig/gdb/gdbarch.c	2008-08-25 22:55:59.000000000 +0200
+++ gdb-head/gdb/gdbarch.c	2008-08-26 00:41:54.000000000 +0200
@@ -377,6 +377,7 @@ struct gdbarch startup_gdbarch =
 };
 
 struct gdbarch *current_gdbarch = &startup_gdbarch;
+struct gdbarch *target_gdbarch = &startup_gdbarch;
 
 /* Create a new ``struct gdbarch'' based on information provided by
    ``struct gdbarch_info''. */
@@ -3666,6 +3667,7 @@ deprecated_current_gdbarch_select_hack (
   gdb_assert (current_gdbarch != NULL);
   gdb_assert (new_gdbarch->initialized_p);
   current_gdbarch = new_gdbarch;
+  target_gdbarch = new_gdbarch;
   observer_notify_architecture_changed (new_gdbarch);
   registers_changed ();
 }
diff -urNp gdb-orig/gdb/gdbarch.h gdb-head/gdb/gdbarch.h
--- gdb-orig/gdb/gdbarch.h	2008-08-22 03:25:27.000000000 +0200
+++ gdb-head/gdb/gdbarch.h	2008-08-26 00:41:54.000000000 +0200
@@ -54,6 +54,7 @@ struct displaced_step_closure;
 struct core_regset_section;
 
 extern struct gdbarch *current_gdbarch;
+extern struct gdbarch *target_gdbarch;
 
 
 /* The following are pre-initialized by GDBARCH. */
diff -urNp gdb-orig/gdb/gdbarch.sh gdb-head/gdb/gdbarch.sh
--- gdb-orig/gdb/gdbarch.sh	2008-08-25 22:55:59.000000000 +0200
+++ gdb-head/gdb/gdbarch.sh	2008-08-26 00:41:54.000000000 +0200
@@ -822,6 +822,7 @@ struct displaced_step_closure;
 struct core_regset_section;
 
 extern struct gdbarch *current_gdbarch;
+extern struct gdbarch *target_gdbarch;
 EOF
 
 # function typedef's
@@ -1281,6 +1282,7 @@ cat <<EOF
 };
 
 struct gdbarch *current_gdbarch = &startup_gdbarch;
+struct gdbarch *target_gdbarch = &startup_gdbarch;
 EOF
 
 # Create a new gdbarch struct
@@ -2022,6 +2024,7 @@ deprecated_current_gdbarch_select_hack (
   gdb_assert (current_gdbarch != NULL);
   gdb_assert (new_gdbarch->initialized_p);
   current_gdbarch = new_gdbarch;
+  target_gdbarch = new_gdbarch;
   observer_notify_architecture_changed (new_gdbarch);
   registers_changed ();
 }
diff -urNp gdb-orig/gdb/mep-tdep.c gdb-head/gdb/mep-tdep.c
--- gdb-orig/gdb/mep-tdep.c	2008-08-26 00:05:35.000000000 +0200
+++ gdb-head/gdb/mep-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -264,7 +264,7 @@ me_module_register_set (CONFIG_ATTR me_m
        mask contains any of the me_module's coprocessor ISAs,
        specifically excluding the generic coprocessor register sets.  */
 
-  CGEN_CPU_DESC desc = gdbarch_tdep (current_gdbarch)->cpu_desc;
+  CGEN_CPU_DESC desc = gdbarch_tdep (target_gdbarch)->cpu_desc;
   const CGEN_HW_ENTRY *hw;
 
   if (me_module == CONFIG_NONE)
@@ -855,7 +855,7 @@ current_me_module ()
       return regval;
     }
   else
-    return gdbarch_tdep (current_gdbarch)->me_module;
+    return gdbarch_tdep (target_gdbarch)->me_module;
 }
 
 
diff -urNp gdb-orig/gdb/mips-linux-tdep.c gdb-head/gdb/mips-linux-tdep.c
--- gdb-orig/gdb/mips-linux-tdep.c	2008-08-26 00:04:20.000000000 +0200
+++ gdb-head/gdb/mips-linux-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -603,7 +603,7 @@ mips_linux_in_dynsym_stub (CORE_ADDR pc,
 {
   unsigned char buf[28], *p;
   ULONGEST insn, insn1;
-  int n64 = (mips_abi (current_gdbarch) == MIPS_ABI_N64);
+  int n64 = (mips_abi (target_gdbarch) == MIPS_ABI_N64);
 
   read_memory (pc - 12, buf, 28);
 
diff -urNp gdb-orig/gdb/mips-tdep.c gdb-head/gdb/mips-tdep.c
--- gdb-orig/gdb/mips-tdep.c	2008-08-26 00:05:35.000000000 +0200
+++ gdb-head/gdb/mips-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -778,7 +778,7 @@ static void
 show_mask_address (struct ui_file *file, int from_tty,
 		   struct cmd_list_element *c, const char *value)
 {
-  struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
+  struct gdbarch_tdep *tdep = gdbarch_tdep (target_gdbarch);
 
   deprecated_show_value_hack (file, from_tty, c, value);
   switch (mask_address_var)
@@ -4788,7 +4788,7 @@ show_mipsfpu_command (char *args, int fr
 {
   char *fpu;
 
-  if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
+  if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
     {
       printf_unfiltered
 	("The MIPS floating-point coprocessor is unknown "
@@ -4796,7 +4796,7 @@ show_mipsfpu_command (char *args, int fr
       return;
     }
 
-  switch (MIPS_FPU_TYPE (current_gdbarch))
+  switch (MIPS_FPU_TYPE (target_gdbarch))
     {
     case MIPS_FPU_SINGLE:
       fpu = "single-precision";
@@ -5958,7 +5958,7 @@ show_mips_abi (struct ui_file *file,
 	       struct cmd_list_element *ignored_cmd,
 	       const char *ignored_value)
 {
-  if (gdbarch_bfd_arch_info (current_gdbarch)->arch != bfd_arch_mips)
+  if (gdbarch_bfd_arch_info (target_gdbarch)->arch != bfd_arch_mips)
     fprintf_filtered
       (file, 
        "The MIPS ABI is unknown because the current architecture "
@@ -5966,7 +5966,7 @@ show_mips_abi (struct ui_file *file,
   else
     {
       enum mips_abi global_abi = global_mips_abi ();
-      enum mips_abi actual_abi = mips_abi (current_gdbarch);
+      enum mips_abi actual_abi = mips_abi (target_gdbarch);
       const char *actual_abi_str = mips_abi_strings[actual_abi];
 
       if (global_abi == MIPS_ABI_UNKNOWN)
diff -urNp gdb-orig/gdb/nto-tdep.c gdb-head/gdb/nto-tdep.c
--- gdb-orig/gdb/nto-tdep.c	2008-08-26 00:04:20.000000000 +0200
+++ gdb-head/gdb/nto-tdep.c	2008-08-26 00:44:45.000000000 +0200
@@ -107,14 +107,14 @@ nto_find_and_open_solib (char *solib, un
 #define PATH_FMT "%s/lib:%s/usr/lib:%s/usr/photon/lib:%s/usr/photon/dll:%s/lib/dll"
 
   nto_root = nto_target ();
-  if (strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name, "i386") == 0)
+  if (strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name, "i386") == 0)
     {
       arch = "x86";
       endian = "";
     }
-  else if (strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name,
+  else if (strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name,
 		   "rs6000") == 0
-	   || strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name,
+	   || strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name,
 		   "powerpc") == 0)
     {
       arch = "ppc";
@@ -122,8 +122,8 @@ nto_find_and_open_solib (char *solib, un
     }
   else
     {
-      arch = gdbarch_bfd_arch_info (current_gdbarch)->arch_name;
-      endian = gdbarch_byte_order (current_gdbarch)
+      arch = gdbarch_bfd_arch_info (target_gdbarch)->arch_name;
+      endian = gdbarch_byte_order (target_gdbarch)
 	       == BFD_ENDIAN_BIG ? "be" : "le";
     }
 
@@ -169,14 +169,14 @@ nto_init_solib_absolute_prefix (void)
   const char *arch;
 
   nto_root = nto_target ();
-  if (strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name, "i386") == 0)
+  if (strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name, "i386") == 0)
     {
       arch = "x86";
       endian = "";
     }
-  else if (strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name,
+  else if (strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name,
 		   "rs6000") == 0
-	   || strcmp (gdbarch_bfd_arch_info (current_gdbarch)->arch_name,
+	   || strcmp (gdbarch_bfd_arch_info (target_gdbarch)->arch_name,
 		   "powerpc") == 0)
     {
       arch = "ppc";
@@ -184,8 +184,8 @@ nto_init_solib_absolute_prefix (void)
     }
   else
     {
-      arch = gdbarch_bfd_arch_info (current_gdbarch)->arch_name;
-      endian = gdbarch_byte_order (current_gdbarch)
+      arch = gdbarch_bfd_arch_info (target_gdbarch)->arch_name;
+      endian = gdbarch_byte_order (target_gdbarch)
 	       == BFD_ENDIAN_BIG ? "be" : "le";
     }
 
@@ -291,12 +291,12 @@ LM_ADDR (struct so_list *so)
 static CORE_ADDR
 nto_truncate_ptr (CORE_ADDR addr)
 {
-  if (gdbarch_ptr_bit (current_gdbarch) == sizeof (CORE_ADDR) * 8)
+  if (gdbarch_ptr_bit (target_gdbarch) == sizeof (CORE_ADDR) * 8)
     /* We don't need to truncate anything, and the bit twiddling below
        will fail due to overflow problems.  */
     return addr;
   else
-    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (current_gdbarch)) - 1);
+    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (target_gdbarch)) - 1);
 }
 
 Elf_Internal_Phdr *
diff -urNp gdb-orig/gdb/remote.c gdb-head/gdb/remote.c
--- gdb-orig/gdb/remote.c	2008-08-22 03:25:28.000000000 +0200
+++ gdb-head/gdb/remote.c	2008-08-26 00:41:54.000000000 +0200
@@ -274,9 +274,9 @@ struct packet_reg
   long regnum; /* GDB's internal register number.  */
   LONGEST pnum; /* Remote protocol register number.  */
   int in_g_packet; /* Always part of G packet.  */
-  /* long size in bytes;  == register_size (current_gdbarch, regnum);
+  /* long size in bytes;  == register_size (target_gdbarch, regnum);
      at present.  */
-  /* char *name; == gdbarch_register_name (current_gdbarch, regnum);
+  /* char *name; == gdbarch_register_name (target_gdbarch, regnum);
      at present.  */
 };
 
@@ -309,7 +309,7 @@ static struct gdbarch_data *remote_gdbar
 static struct remote_arch_state *
 get_remote_arch_state (void)
 {
-  return gdbarch_data (current_gdbarch, remote_gdbarch_data_handle);
+  return gdbarch_data (target_gdbarch, remote_gdbarch_data_handle);
 }
 
 /* Fetch the global remote target state.  */
@@ -445,7 +445,7 @@ get_remote_packet_size (void)
 static struct packet_reg *
 packet_reg_from_regnum (struct remote_arch_state *rsa, long regnum)
 {
-  if (regnum < 0 && regnum >= gdbarch_num_regs (current_gdbarch))
+  if (regnum < 0 && regnum >= gdbarch_num_regs (target_gdbarch))
     return NULL;
   else
     {
@@ -459,7 +459,7 @@ static struct packet_reg *
 packet_reg_from_pnum (struct remote_arch_state *rsa, LONGEST pnum)
 {
   int i;
-  for (i = 0; i < gdbarch_num_regs (current_gdbarch); i++)
+  for (i = 0; i < gdbarch_num_regs (target_gdbarch); i++)
     {
       struct packet_reg *r = &rsa->regs[i];
       if (r->pnum == pnum)
@@ -2400,7 +2400,7 @@ remote_check_symbols (struct objfile *ob
 
 	  /* If this is a function address, return the start of code
 	     instead of any data function descriptor.  */
-	  sym_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	  sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							 sym_addr,
 							 &current_target);
 
@@ -3588,10 +3588,10 @@ Packet: '%s'\n"),
 			     phex_nz (pnum, 0), p, buf);
 
 		    fieldsize = hex2bin (p, regs,
-					 register_size (current_gdbarch,
+					 register_size (target_gdbarch,
 							reg->regnum));
 		    p += 2 * fieldsize;
-		    if (fieldsize < register_size (current_gdbarch,
+		    if (fieldsize < register_size (target_gdbarch,
 						   reg->regnum))
 		      warning (_("Remote reply is too short: %s"), buf);
 		    regcache_raw_supply (get_current_regcache (),
@@ -4105,7 +4105,7 @@ remote_address_masked (CORE_ADDR addr)
   int address_size = remote_address_size;
   /* If "remoteaddresssize" was not set, default to target address size.  */
   if (!address_size)
-    address_size = gdbarch_addr_bit (current_gdbarch);
+    address_size = gdbarch_addr_bit (target_gdbarch);
 
   if (address_size > 0
       && address_size < (sizeof (ULONGEST) * 8))
@@ -5373,8 +5373,7 @@ remote_insert_breakpoint (struct bp_targ
       char *p;
       int bpsize;
 
-      gdbarch_breakpoint_from_pc
-	(current_gdbarch, &addr, &bpsize);
+      gdbarch_breakpoint_from_pc (target_gdbarch, &addr, &bpsize);
 
       rs = get_remote_state ();
       p = rs->buf;
@@ -5576,7 +5575,7 @@ remote_insert_hw_breakpoint (struct bp_t
      instruction, even though we aren't inserting one ourselves.  */
 
   gdbarch_breakpoint_from_pc
-    (current_gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
+    (target_gdbarch, &bp_tgt->placed_address, &bp_tgt->placed_size);
 
   if (remote_protocol_packets[PACKET_Z1].support == PACKET_DISABLE)
     return -1;
@@ -6505,7 +6504,7 @@ static const struct target_desc *
 remote_read_description (struct target_ops *target)
 {
   struct remote_g_packet_data *data
-    = gdbarch_data (current_gdbarch, remote_g_packet_data_handle);
+    = gdbarch_data (target_gdbarch, remote_g_packet_data_handle);
 
   if (!VEC_empty (remote_g_packet_guess_s, data->guesses))
     {
diff -urNp gdb-orig/gdb/remote-m32r-sdi.c gdb-head/gdb/remote-m32r-sdi.c
--- gdb-orig/gdb/remote-m32r-sdi.c	2008-08-22 03:25:28.000000000 +0200
+++ gdb-head/gdb/remote-m32r-sdi.c	2008-08-26 00:43:10.000000000 +0200
@@ -481,7 +481,7 @@ m32r_resume (ptid_t ptid, int step, enum
       else
 	{
 	  buf[0] = SDI_WRITE_MEMORY;
-	  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	  if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	    store_long_parameter (buf + 1, pc_addr);
 	  else
 	    store_long_parameter (buf + 1, pc_addr - 1);
@@ -521,7 +521,7 @@ m32r_resume (ptid_t ptid, int step, enum
 	continue;
 
       /* Set PBP. */
-      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	send_three_arg_cmd (SDI_WRITE_MEMORY, 0xffff8000 + 4 * i, 4,
 			    0x00000006);
       else
@@ -548,7 +548,7 @@ m32r_resume (ptid_t ptid, int step, enum
       store_long_parameter (buf + 5, 4);
       if ((bp_addr & 2) == 0 && bp_addr != (pc_addr & 0xfffffffc))
 	{
-	  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	  if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	    {
 	      buf[9] = dbt_bp_entry[0];
 	      buf[10] = dbt_bp_entry[1];
@@ -565,7 +565,7 @@ m32r_resume (ptid_t ptid, int step, enum
 	}
       else
 	{
-	  if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	  if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	    {
 	      if ((bp_addr & 2) == 0)
 		{
@@ -612,7 +612,7 @@ m32r_resume (ptid_t ptid, int step, enum
 	continue;
 
       /* DBC register */
-      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	{
 	  switch (ab_type[i])
 	    {
@@ -754,7 +754,7 @@ m32r_wait (ptid_t ptid, struct target_wa
   if (last_pc_addr != 0xffffffff)
     {
       buf[0] = SDI_WRITE_MEMORY;
-      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 	store_long_parameter (buf + 1, last_pc_addr);
       else
 	store_long_parameter (buf + 1, last_pc_addr - 1);
@@ -783,7 +783,7 @@ m32r_wait (ptid_t ptid, struct target_wa
 	     address, we have to take care of it later. */
 	  if ((pc_addr & 0x2) != 0)
 	    {
-	      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 		{
 		  if ((bp_data[i][2] & 0x80) != 0)
 		    {
@@ -845,7 +845,7 @@ m32r_wait (ptid_t ptid, struct target_wa
 	  c = serial_readchar (sdi_desc, SDI_TIMEOUT);
 	  if (c != '-' && recv_data (buf, 4) != -1)
 	    {
-	      if (gdbarch_byte_order (current_gdbarch) == BFD_ENDIAN_BIG)
+	      if (gdbarch_byte_order (target_gdbarch) == BFD_ENDIAN_BIG)
 		{
 		  if ((buf[3] & 0x1) == 0x1)
 		    hit_watchpoint_addr = ab_address[i];
diff -urNp gdb-orig/gdb/remote-mips.c gdb-head/gdb/remote-mips.c
--- gdb-orig/gdb/remote-mips.c	2008-07-19 17:23:19.000000000 +0200
+++ gdb-head/gdb/remote-mips.c	2008-08-26 00:42:36.000000000 +0200
@@ -1593,10 +1593,10 @@ static void
 mips_open (char *name, int from_tty)
 {
   const char *monitor_prompt = NULL;
-  if (gdbarch_bfd_arch_info (current_gdbarch) != NULL
-      && gdbarch_bfd_arch_info (current_gdbarch)->arch == bfd_arch_mips)
+  if (gdbarch_bfd_arch_info (target_gdbarch) != NULL
+      && gdbarch_bfd_arch_info (target_gdbarch)->arch == bfd_arch_mips)
     {
-    switch (gdbarch_bfd_arch_info (current_gdbarch)->mach)
+    switch (gdbarch_bfd_arch_info (target_gdbarch)->mach)
       {
       case bfd_mach_mips4100:
       case bfd_mach_mips4300:
@@ -2417,7 +2417,7 @@ mips_common_breakpoint (int set, CORE_AD
   int rpid, rerrflg, rresponse, rlen;
   int nfields;
 
-  addr = gdbarch_addr_bits_remove (current_gdbarch, addr);
+  addr = gdbarch_addr_bits_remove (target_gdbarch, addr);
 
   if (mips_monitor == MON_LSI)
     {
diff -urNp gdb-orig/gdb/solib.c gdb-head/gdb/solib.c
--- gdb-orig/gdb/solib.c	2008-07-19 17:23:19.000000000 +0200
+++ gdb-head/gdb/solib.c	2008-08-26 00:41:54.000000000 +0200
@@ -142,7 +142,7 @@ The search path for loading non-absolute
 int
 solib_open (char *in_pathname, char **found_pathname)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   int found_file = -1;
   char *temp_pathname = NULL;
   char *p = in_pathname;
@@ -321,7 +321,7 @@ solib_map_sections (void *arg)
 
   for (p = so->sections; p < so->sections_end; p++)
     {
-      struct target_so_ops *ops = solib_ops (current_gdbarch);
+      struct target_so_ops *ops = solib_ops (target_gdbarch);
 
       /* Relocate the section binding addresses as recorded in the shared
          object's file by the base address to which the object was actually
@@ -369,7 +369,7 @@ solib_map_sections (void *arg)
 void
 free_so (struct so_list *so)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   char *bfd_filename = 0;
 
   if (so->sections)
@@ -490,7 +490,7 @@ solib_read_symbols (struct so_list *so, 
 static void
 update_solib_list (int from_tty, struct target_ops *target)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   struct so_list *inferior = ops->current_sos();
   struct so_list *gdb, **gdb_link;
 
@@ -705,7 +705,7 @@ solib_add (char *pattern, int from_tty, 
 
     if (loaded_any_symbols)
       {
-	struct target_so_ops *ops = solib_ops (current_gdbarch);
+	struct target_so_ops *ops = solib_ops (target_gdbarch);
 
 	/* Getting new symbols may change our opinion about what is
 	   frameless.  */
@@ -741,7 +741,7 @@ info_sharedlibrary_command (char *ignore
   int addr_width;
 
   /* "0x", a little whitespace, and two hex digits per byte of pointers.  */
-  addr_width = 4 + (gdbarch_ptr_bit (current_gdbarch) / 4);
+  addr_width = 4 + (gdbarch_ptr_bit (target_gdbarch) / 4);
 
   update_solib_list (from_tty, 0);
 
@@ -824,7 +824,7 @@ solib_address (CORE_ADDR address)
 void
 clear_solib (void)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
 
   /* This function is expected to handle ELF shared libraries.  It is
      also used on Solaris, which can run either ELF or a.out binaries
@@ -880,7 +880,7 @@ clear_solib (void)
 void
 solib_create_inferior_hook (void)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   ops->solib_create_inferior_hook();
 }
 
@@ -903,7 +903,7 @@ solib_create_inferior_hook (void)
 int
 in_solib_dynsym_resolve_code (CORE_ADDR pc)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
   return ops->in_dynsym_resolve_code (pc);
 }
 
@@ -973,7 +973,7 @@ solib_global_lookup (const struct objfil
 		     const char *linkage_name,
 		     const domain_enum domain)
 {
-  struct target_so_ops *ops = solib_ops (current_gdbarch);
+  struct target_so_ops *ops = solib_ops (target_gdbarch);
 
   if (ops->lookup_lib_global_symbol != NULL)
     return ops->lookup_lib_global_symbol (objfile, name, linkage_name, domain);
diff -urNp gdb-orig/gdb/solib-frv.c gdb-head/gdb/solib-frv.c
--- gdb-orig/gdb/solib-frv.c	2008-08-22 03:25:29.000000000 +0200
+++ gdb-head/gdb/solib-frv.c	2008-08-26 00:41:54.000000000 +0200
@@ -687,7 +687,7 @@ enable_break2 (void)
 	  return 0;
 	}
 
-      status = frv_fdpic_loadmap_addresses (current_gdbarch,
+      status = frv_fdpic_loadmap_addresses (target_gdbarch,
                                             &interp_loadmap_addr, 0);
       if (status < 0)
 	{
@@ -876,7 +876,7 @@ frv_relocate_main_executable (void)
   int changed;
   struct obj_section *osect;
 
-  status = frv_fdpic_loadmap_addresses (current_gdbarch, 0, &exec_addr);
+  status = frv_fdpic_loadmap_addresses (target_gdbarch, 0, &exec_addr);
 
   if (status < 0)
     {
diff -urNp gdb-orig/gdb/solib-irix.c gdb-head/gdb/solib-irix.c
--- gdb-orig/gdb/solib-irix.c	2008-05-25 18:19:40.000000000 +0200
+++ gdb-head/gdb/solib-irix.c	2008-08-26 00:41:54.000000000 +0200
@@ -505,9 +505,9 @@ irix_current_sos (void)
 
   read_memory (debug_base,
 	       addr_buf,
-	       gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT);
+	       gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT);
   lma = extract_mips_address (addr_buf,
-			      gdbarch_addr_bit (current_gdbarch)
+			      gdbarch_addr_bit (target_gdbarch)
 				/ TARGET_CHAR_BIT);
 
   while (lma)
@@ -611,9 +611,9 @@ irix_open_symbol_file_object (void *from
   /* First link map member should be the executable.  */
   read_memory (debug_base,
 	       addr_buf,
-	       gdbarch_addr_bit (current_gdbarch) / TARGET_CHAR_BIT);
+	       gdbarch_addr_bit (target_gdbarch) / TARGET_CHAR_BIT);
   lma = extract_mips_address (addr_buf,
-			      gdbarch_addr_bit (current_gdbarch)
+			      gdbarch_addr_bit (target_gdbarch)
 				/ TARGET_CHAR_BIT);
   if (lma == 0)
     return 0;			/* failed somehow...  */
diff -urNp gdb-orig/gdb/solib-sunos.c gdb-head/gdb/solib-sunos.c
--- gdb-orig/gdb/solib-sunos.c	2008-08-22 03:25:29.000000000 +0200
+++ gdb-head/gdb/solib-sunos.c	2008-08-26 00:44:10.000000000 +0200
@@ -780,9 +780,9 @@ sunos_solib_create_inferior_hook (void)
      the GDB software break point list.  Thus we have to adjust the
      PC here.  */
 
-  if (gdbarch_decr_pc_after_break (current_gdbarch))
+  if (gdbarch_decr_pc_after_break (target_gdbarch))
     {
-      stop_pc -= gdbarch_decr_pc_after_break (current_gdbarch);
+      stop_pc -= gdbarch_decr_pc_after_break (target_gdbarch);
       write_pc (stop_pc);
     }
 
diff -urNp gdb-orig/gdb/solib-svr4.c gdb-head/gdb/solib-svr4.c
--- gdb-orig/gdb/solib-svr4.c	2008-08-22 03:25:29.000000000 +0200
+++ gdb-head/gdb/solib-svr4.c	2008-08-26 00:41:54.000000000 +0200
@@ -909,7 +909,7 @@ exec_entry_point (struct bfd *abfd, stru
      gdbarch_convert_from_func_ptr_addr().  The method
      gdbarch_convert_from_func_ptr_addr() is the merely the identify
      function for targets which don't use function descriptors.  */
-  return gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+  return gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 					     bfd_get_start_address (abfd),
 					     targ);
 }
@@ -987,7 +987,7 @@ enable_break (void)
       struct obj_section *os;
 
       sym_addr = gdbarch_addr_bits_remove
-	(current_gdbarch, gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	(target_gdbarch, gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 							      sym_addr,
 							      &current_target));
 
@@ -1149,7 +1149,7 @@ enable_break (void)
 	/* Convert 'sym_addr' from a function pointer to an address.
 	   Because we pass tmp_bfd_target instead of the current
 	   target, this will always produce an unrelocated value.  */
-	sym_addr = gdbarch_convert_from_func_ptr_addr (current_gdbarch,
+	sym_addr = gdbarch_convert_from_func_ptr_addr (target_gdbarch,
 						       sym_addr,
 						       tmp_bfd_target);
 
@@ -1455,12 +1455,12 @@ svr4_free_so (struct so_list *so)
 static CORE_ADDR
 svr4_truncate_ptr (CORE_ADDR addr)
 {
-  if (gdbarch_ptr_bit (current_gdbarch) == sizeof (CORE_ADDR) * 8)
+  if (gdbarch_ptr_bit (target_gdbarch) == sizeof (CORE_ADDR) * 8)
     /* We don't need to truncate anything, and the bit twiddling below
        will fail due to overflow problems.  */
     return addr;
   else
-    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (current_gdbarch)) - 1);
+    return addr & (((CORE_ADDR) 1 << gdbarch_ptr_bit (target_gdbarch)) - 1);
 }
 
 
@@ -1518,7 +1518,7 @@ set_solib_svr4_fetch_link_map_offsets (s
 static struct link_map_offsets *
 svr4_fetch_link_map_offsets (void)
 {
-  struct solib_svr4_ops *ops = gdbarch_data (current_gdbarch, solib_svr4_data);
+  struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
 
   gdb_assert (ops->fetch_link_map_offsets);
   return ops->fetch_link_map_offsets ();
@@ -1529,7 +1529,7 @@ svr4_fetch_link_map_offsets (void)
 static int
 svr4_have_link_map_offsets (void)
 {
-  struct solib_svr4_ops *ops = gdbarch_data (current_gdbarch, solib_svr4_data);
+  struct solib_svr4_ops *ops = gdbarch_data (target_gdbarch, solib_svr4_data);
   return (ops->fetch_link_map_offsets != NULL);
 }
 \f
diff -urNp gdb-orig/gdb/target.c gdb-head/gdb/target.c
--- gdb-orig/gdb/target.c	2008-08-22 03:25:29.000000000 +0200
+++ gdb-head/gdb/target.c	2008-08-26 00:41:54.000000000 +0200
@@ -826,7 +826,7 @@ target_translate_tls_address (struct obj
   volatile CORE_ADDR addr = 0;
 
   if (target_get_thread_local_address_p ()
-      && gdbarch_fetch_tls_load_module_address_p (current_gdbarch))
+      && gdbarch_fetch_tls_load_module_address_p (target_gdbarch))
     {
       ptid_t ptid = inferior_ptid;
       volatile struct gdb_exception ex;
@@ -836,7 +836,7 @@ target_translate_tls_address (struct obj
 	  CORE_ADDR lm_addr;
 	  
 	  /* Fetch the load module address for this objfile.  */
-	  lm_addr = gdbarch_fetch_tls_load_module_address (current_gdbarch,
+	  lm_addr = gdbarch_fetch_tls_load_module_address (target_gdbarch,
 	                                                   objfile);
 	  /* If it's 0, throw the appropriate exception.  */
 	  if (lm_addr == 0)
diff -urNp gdb-orig/gdb/target-descriptions.c gdb-head/gdb/target-descriptions.c
--- gdb-orig/gdb/target-descriptions.c	2008-08-25 22:55:59.000000000 +0200
+++ gdb-head/gdb/target-descriptions.c	2008-08-26 00:41:54.000000000 +0200
@@ -183,7 +183,7 @@ target_find_description (void)
   /* The current architecture should not have any target description
      specified.  It should have been cleared, e.g. when we
      disconnected from the previous target.  */
-  gdb_assert (gdbarch_target_desc (current_gdbarch) == NULL);
+  gdb_assert (gdbarch_target_desc (target_gdbarch) == NULL);
 
   /* First try to fetch an XML description from the user-specified
      file.  */
@@ -216,7 +216,7 @@ target_find_description (void)
 	{
 	  struct tdesc_arch_data *data;
 
-	  data = gdbarch_data (current_gdbarch, tdesc_data);
+	  data = gdbarch_data (target_gdbarch, tdesc_data);
 	  if (tdesc_has_registers (current_target_desc)
 	      && data->registers == NULL)
 	    warning (_("Target-supplied registers are not supported "

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


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

end of thread, other threads:[~2008-08-26 17:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-13 19:53 [rfc] Introduce "target_gdbarch" variable Ulrich Weigand
2008-08-18 11:34 ` Joel Brobecker
2008-08-18 13:59   ` Ulrich Weigand
2008-08-18 14:11     ` Joel Brobecker
2008-08-26 17:33 ` Ulrich Weigand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox