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


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

[rfc] Introduce "target_gdbarch" variable


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);
 }
 
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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