changing the register cache layout.
	(regcache_invalidate_one): Allow a NULL regcache.
	* linux-x86-low.c (x86_linux_update_xmltarget): Invalidate
	regcaches before changing the register cache layout or the target
	regsets.
+2010-04-12  Pedro Alves  <pedro@codesourcery.com>
+
+       * regcache.c (set_register_cache): Invalidate regcaches before
+       changing the register cache layout.
+       (regcache_invalidate_one): Allow a NULL regcache.
+       * linux-x86-low.c (x86_linux_update_xmltarget): Invalidate
+       regcaches before changing the register cache layout or the target
+       regsets.
+
 2010-04-12  H.J. Lu  <hongjiu.lu@intel.com>
 
        * linux-x86-low.c (x86_linux_update_xmltarget): Avoid unused
 
   if (!current_inferior)
     return;
 
+  /* Before changing the register cache internal layout or the target
+     regsets, flush the contents of the current valid caches back to
+     the threads.  */
+  regcache_invalidate ();
+
   pid = pid_of (get_thread_lwp (current_inferior));
 #ifdef __x86_64__
   if (num_xmm_registers == 8)
 
 
   regcache = (struct regcache *) inferior_regcache_data (thread);
 
+  if (regcache == NULL)
+    return;
+
   if (regcache->registers_valid)
     {
       struct thread_info *saved_inferior = current_inferior;
 {
   int offset, i;
 
+  /* Before changing the register cache internal layout, flush the
+     contents of valid caches back to the threads.  */
+  regcache_invalidate ();
+
   reg_defs = regs;
   num_registers = n;