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

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