This is the mail archive of the gdb-patches@sources.redhat.com 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]

[patch:rfc] Invalidate ``current_gdbarch'' when createing a new


Hello,

The attached follows up the threads:

[rfc] Swap out current when creating a new architecture
http://sources.redhat.com/ml/gdb-patches/2001-09/msg00342.html
http://sources.redhat.com/ml/gdb-patches/2001-10/msg00001.html
and

[rfc] Sort architectures M.R.U.; Was: swap out current when ...
http://sources.redhat.com/ml/gdb-patches/2002-04/msg00609.html

The original description is appended.

With the attached patch (and the two just posted fixes) applied, I was 
able to rebuild and start all the GDB targets.

Hopefully this can go in towards the end of the week.

enjoy,
Andrew


> The attached changes the run-time environment within which a new 
> architectures are created.  Briefly the simplified sequence:
> 
> - call XXX_gdbarch_init()
> - swap out old architecture
> - install new architecture
> 
> is changed to:
> 
> - swap out old architecture
> - call XX_gdbarch_init()
> - install new architecture
> 
> This has the effect of making current_gdbarch invalid for the lifetime 
> of the XXX_gdbarch_init() call.
> 
> The motivation behind this change is to stop XXXX_gdbarch_init() 
> functions refering (unintentionally I suspect) to the previous 
> architecture.  I think it is proving effective since it has so far 
> flushed out two bugs.
> 
> I can think of one additional tweek: add a ``gdb_assert (gdbarch != 
> NULL)'' to each architecture method.  Without it a XXX_gdbarch_init() 
> function that tries to use current_gdbarch will dump core :-/
> 
> thoughts?
> Andrew

2002-04-20  Andrew Cagney  <ac131313@redhat.com>

	* gdbarch.sh (gdbarch_update_p): Swap out the old architecture
	before probing for a new one.  Detect errorenous gdbarch_init
	functions.
	* gdbarch.c: Regenerate.

Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.128
diff -u -r1.128 gdbarch.sh
--- gdbarch.sh	20 Apr 2002 17:41:18 -0000	1.128
+++ gdbarch.sh	21 Apr 2002 03:33:30 -0000
@@ -2057,6 +2057,7 @@
 gdbarch_update_p (struct gdbarch_info info)
 {
   struct gdbarch *new_gdbarch;
+  struct gdbarch *old_gdbarch;
   struct gdbarch_registration *rego;
 
   /* Fill in missing parts of the INFO struct using a number of
@@ -2125,30 +2126,40 @@
       return 0;
     }
 
+  /* Swap the data belonging to the old target out.  This stops the
+     ->init() function trying to refer to the previous architecture.  */
+  swapout_gdbarch_swap (current_gdbarch);
+  init_gdbarch_swap (current_gdbarch);
+  old_gdbarch = current_gdbarch;
+  current_gdbarch = NULL;
+
   /* Ask the target for a replacement architecture. */
   new_gdbarch = rego->init (info, rego->arches);
 
-  /* Did the target like it?  No. Reject the change. */
+  /* Did the target like it?  No. Reject the change and revert to the
+     old architecture.  */
   if (new_gdbarch == NULL)
     {
       if (gdbarch_debug)
 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update: Target rejected architecture\\n");
+      swapin_gdbarch_swap (old_gdbarch);
+      current_gdbarch = old_gdbarch;
       return 0;
     }
 
-  /* Did the architecture change?  No. Do nothing. */
-  if (current_gdbarch == new_gdbarch)
+  /* Did the architecture change?  No.  Oops, put the old architecture
+     back.  */
+  if (old_gdbarch == new_gdbarch)
     {
       if (gdbarch_debug)
 	fprintf_unfiltered (gdb_stdlog, "gdbarch_update: Architecture 0x%08lx (%s) unchanged\\n",
 			    (long) new_gdbarch,
 			    new_gdbarch->bfd_arch_info->printable_name);
+      swapin_gdbarch_swap (old_gdbarch);
+      current_gdbarch = old_gdbarch;
       return 1;
     }
 
-  /* Swap all data belonging to the old target out */
-  swapout_gdbarch_swap (current_gdbarch);
-
   /* Is this a pre-existing architecture?  Yes. Move it to the front
      of the list of architectures (keeping the list sorted Most
      Recently Used) and then copy it in.  */
@@ -2205,14 +2216,10 @@
   new_gdbarch->dump_tdep = rego->dump_tdep;
   verify_gdbarch (new_gdbarch);
 
-  /* Initialize the per-architecture memory (swap) areas.
-     CURRENT_GDBARCH must be update before these modules are
-     called. */
-  init_gdbarch_swap (new_gdbarch);
-  
-  /* Initialize the per-architecture data-pointer of all parties that
-     registered an interest in this architecture.  CURRENT_GDBARCH
-     must be updated before these modules are called. */
+  /* Initialize the per-architecture data-pointers and swap areas for
+     all parties that registered an interest in this architecture.
+     CURRENT_GDBARCH must be updated before these modules are called.
+     The swap area's will have already been initialized to zero.  */
   init_gdbarch_data (new_gdbarch);
   architecture_changed_event ();
 

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