Move some ppc macros to nat/ppc-linux.h
[deliverable/binutils-gdb.git] / gdb / gdbserver / regcache.c
index 916a47994a48ed590c73e9ef1a574edf60edf160..8d7957b30e9f450414ef6e4713cf6eac6813495d 100644 (file)
@@ -1,5 +1,5 @@
 /* Register support routines for the remote server for GDB.
-   Copyright (C) 2001-2014 Free Software Foundation, Inc.
+   Copyright (C) 2001-2015 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -41,8 +41,7 @@ get_thread_regcache (struct thread_info *thread, int fetch)
     {
       struct process_info *proc = get_thread_process (thread);
 
-      if (proc->tdesc == NULL)
-       fatal ("no target description");
+      gdb_assert (proc->tdesc != NULL);
 
       regcache = new_register_cache (proc->tdesc);
       set_inferior_regcache_data (thread, regcache);
@@ -50,17 +49,28 @@ get_thread_regcache (struct thread_info *thread, int fetch)
 
   if (fetch && regcache->registers_valid == 0)
     {
-      struct thread_info *saved_inferior = current_inferior;
+      struct thread_info *saved_thread = current_thread;
 
-      current_inferior = thread;
+      current_thread = thread;
+      /* Invalidate all registers, to prevent stale left-overs.  */
+      memset (regcache->register_status, REG_UNAVAILABLE,
+             regcache->tdesc->num_registers);
       fetch_inferior_registers (regcache, -1);
-      current_inferior = saved_inferior;
+      current_thread = saved_thread;
       regcache->registers_valid = 1;
     }
 
   return regcache;
 }
 
+/* See common/common-regcache.h.  */
+
+struct regcache *
+get_thread_regcache_for_ptid (ptid_t ptid)
+{
+  return get_thread_regcache (find_thread_ptid (ptid), 1);
+}
+
 void
 regcache_invalidate_thread (struct thread_info *thread)
 {
@@ -73,11 +83,11 @@ regcache_invalidate_thread (struct thread_info *thread)
 
   if (regcache->registers_valid)
     {
-      struct thread_info *saved_inferior = current_inferior;
+      struct thread_info *saved_thread = current_thread;
 
-      current_inferior = thread;
+      current_thread = thread;
       store_inferior_registers (regcache, -1);
-      current_inferior = saved_inferior;
+      current_thread = saved_thread;
     }
 
   regcache->registers_valid = 0;
@@ -101,7 +111,7 @@ void
 regcache_invalidate (void)
 {
   /* Only update the threads of the current process.  */
-  int pid = ptid_get_pid (current_inferior->entry.id);
+  int pid = ptid_get_pid (current_thread->entry.id);
 
   find_inferior (&all_threads, regcache_invalidate_one, &pid);
 }
@@ -126,7 +136,7 @@ init_register_cache (struct regcache *regcache,
       regcache->register_status = xcalloc (1, tdesc->num_registers);
       gdb_assert (REG_UNAVAILABLE == 0);
 #else
-      fatal ("init_register_cache: can't allocate memory from the heap");
+      gdb_assert_not_reached ("can't allocate memory from the heap");
 #endif
     }
   else
@@ -239,8 +249,8 @@ find_register_by_name (const struct target_desc *tdesc, const char *name)
   for (i = 0; i < tdesc->num_registers; i++)
     if (strcmp (name, tdesc->reg_defs[i].name) == 0)
       return &tdesc->reg_defs[i];
-  fatal ("Unknown register %s requested", name);
-  return 0;
+  internal_error (__FILE__, __LINE__, "Unknown register %s requested",
+                 name);
 }
 
 int
@@ -251,8 +261,8 @@ find_regno (const struct target_desc *tdesc, const char *name)
   for (i = 0; i < tdesc->num_registers; i++)
     if (strcmp (name, tdesc->reg_defs[i].name) == 0)
       return i;
-  fatal ("Unknown register %s requested", name);
-  return -1;
+  internal_error (__FILE__, __LINE__, "Unknown register %s requested",
+                 name);
 }
 
 struct reg *
This page took 0.025095 seconds and 4 git commands to generate.