[v2,4/5] Make gdb.PendingFrame.read_register handle "user" registers

Message ID 20161102152332.29708966@pinnacle.lan
State New, archived
Headers

Commit Message

Kevin Buettner Nov. 2, 2016, 10:23 p.m. UTC
  [ FYI, Pedro has already OK'd this one.  It's unchanged from the version
  in the earlier series, but is included here for completeness. ]

The C function, pending_framepy_read_register(), which implements
the python interface gdb.PendingFrame.read_register does not handle
the so called "user" registers like "pc".  An assertion error is
triggered due to the user registers having numbers larger than or
equal to gdbarch_num_regs(gdbarch).

With the VALUE_FRAME_ID tweak in place, the call to
get_frame_register_value() can simply be replaced by a call to
value_of_register(), which handles both real registers as well as the
user registers.

gdb/ChangeLog:
    
    	* python/py-unwind.c (pending_framepy_read_register): Use
    	value_of_register() instead of get_frame_register_value().
---
 gdb/python/py-unwind.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

Kevin Buettner Nov. 16, 2016, 7:08 p.m. UTC | #1
On Wed, 2 Nov 2016 15:23:32 -0700
Kevin Buettner <kevin@buettner.to> wrote:

> [ FYI, Pedro has already OK'd this one.  It's unchanged from the version
>   in the earlier series, but is included here for completeness. ]
> 
> The C function, pending_framepy_read_register(), which implements
> the python interface gdb.PendingFrame.read_register does not handle
> the so called "user" registers like "pc".  An assertion error is
> triggered due to the user registers having numbers larger than or
> equal to gdbarch_num_regs(gdbarch).
> 
> With the VALUE_FRAME_ID tweak in place, the call to
> get_frame_register_value() can simply be replaced by a call to
> value_of_register(), which handles both real registers as well as the
> user registers.
> 
> gdb/ChangeLog:
>     
>     	* python/py-unwind.c (pending_framepy_read_register): Use
>     	value_of_register() instead of get_frame_register_value().

I've pushed this change.

Kevin
  

Patch

diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index cc685ae..6740034 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -412,7 +412,12 @@  pending_framepy_read_register (PyObject *self, PyObject *args)
 
   TRY
     {
-      val = get_frame_register_value (pending_frame->frame_info, regnum);
+      /* Fetch the value associated with a register, whether it's
+	 a real register or a so called "user" register, like "pc",
+	 which maps to a real register.  In the past,
+	 get_frame_register_value() was used here, which did not
+	 handle the user register case.  */
+      val = value_of_register (regnum, pending_frame->frame_info);
       if (val == NULL)
         PyErr_Format (PyExc_ValueError,
                       "Cannot read register %d from frame.",