Blame SOURCES/gdb-rhbz1105165-ibm-tdb-support-system-z-5of9.patch

7b26da
From 098dbe61246fd65ea5e3825d77afb31d52c43153 Mon Sep 17 00:00:00 2001
7b26da
From: Andreas Arnez <arnez@linux.vnet.ibm.com>
7b26da
Date: Fri, 12 Dec 2014 14:14:20 +0100
7b26da
Subject: [PATCH 7/9] gdbserver: Prevent stale/random values in register cache
7b26da
7b26da
When fetch_inferior_registers does not update all registers, this
7b26da
patch assures that no stale register values remain in the register
7b26da
cache.  On Linux platforms using the regsets interface, when one of
7b26da
the ptrace calls used for fetching the register values returns an
7b26da
error, this patch also avoids copying the random data returned from
7b26da
ptrace into the register cache.  All unfetched registers are marked
7b26da
"unavailable" instead.
7b26da
7b26da
gdb/gdbserver/ChangeLog:
7b26da
7b26da
	* linux-low.c (regsets_fetch_inferior_registers): Do not invoke
7b26da
	the regset's store function when ptrace returned an error.
7b26da
	* regcache.c (get_thread_regcache): Invalidate register cache
7b26da
	before fetching inferior's registers.
7b26da
---
7b26da
 gdb/gdbserver/ChangeLog   |  7 +++++++
7b26da
 gdb/gdbserver/linux-low.c | 11 ++++++-----
7b26da
 gdb/gdbserver/regcache.c  |  3 +++
7b26da
 3 files changed, 16 insertions(+), 5 deletions(-)
7b26da
7b26da
Index: gdb-7.6.1/gdb/gdbserver/linux-low.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/gdbserver/linux-low.c
7b26da
+++ gdb-7.6.1/gdb/gdbserver/linux-low.c
7b26da
@@ -4080,8 +4080,6 @@ regsets_fetch_inferior_registers (struct
7b26da
 	      /* If we get EIO on a regset, do not try it again for
7b26da
 		 this process.  */
7b26da
 	      disabled_regsets[regset - target_regsets] = 1;
7b26da
-	      free (buf);
7b26da
-	      continue;
7b26da
 	    }
7b26da
 	  else
7b26da
 	    {
7b26da
@@ -4091,9 +4089,12 @@ regsets_fetch_inferior_registers (struct
7b26da
 	      perror (s);
7b26da
 	    }
7b26da
 	}
7b26da
-      else if (regset->type == GENERAL_REGS)
7b26da
-	saw_general_regs = 1;
7b26da
-      regset->store_function (regcache, buf);
7b26da
+      else
7b26da
+	{
7b26da
+	  if (regset->type == GENERAL_REGS)
7b26da
+	    saw_general_regs = 1;
7b26da
+	  regset->store_function (regcache, buf);
7b26da
+	}
7b26da
       regset ++;
7b26da
       free (buf);
7b26da
     }
7b26da
Index: gdb-7.6.1/gdb/gdbserver/regcache.c
7b26da
===================================================================
7b26da
--- gdb-7.6.1.orig/gdb/gdbserver/regcache.c
7b26da
+++ gdb-7.6.1/gdb/gdbserver/regcache.c
7b26da
@@ -47,6 +47,9 @@ get_thread_regcache (struct thread_info
7b26da
       struct thread_info *saved_inferior = current_inferior;
7b26da
 
7b26da
       current_inferior = thread;
7b26da
+      /* Invalidate all registers, to prevent stale left-overs.  */
7b26da
+      memset (regcache->register_status, REG_UNAVAILABLE,
7b26da
+	      num_registers);
7b26da
       fetch_inferior_registers (regcache, -1);
7b26da
       current_inferior = saved_inferior;
7b26da
       regcache->registers_valid = 1;