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