]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: add value::allocate_register
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 1 Dec 2023 16:27:26 +0000 (11:27 -0500)
committerSimon Marchi <simon.marchi@efficios.com>
Thu, 14 Dec 2023 16:04:49 +0000 (16:04 +0000)
Add value::allocate_register, to facilitate allocating a value
representing a register in a given frame (or rather, in the given
frame's previous frame).  It will be used in a subsequent patch.  I
changed one relatively obvious spot that could use it, to at least
exercise the code path.

Change-Id: Icd4960f5e471a74b657bb3596c88d89679ef3772
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
gdb/regcache.c
gdb/value.c
gdb/value.h

index 19ba353a335ce3ae9f0412458d134d5f6fbc58a8..9b3fd4f060c7ad48832a069108ff102d576fdb1c 100644 (file)
@@ -775,11 +775,8 @@ readable_regcache::cooked_read_value (int regnum)
       || (m_has_pseudo && m_register_status[regnum] != REG_UNKNOWN)
       || !gdbarch_pseudo_register_read_value_p (m_descr->gdbarch))
     {
-      struct value *result;
-
-      result = value::allocate (register_type (m_descr->gdbarch, regnum));
-      result->set_lval (lval_register);
-      VALUE_REGNUM (result) = regnum;
+      value *result = value::allocate_register
+       (get_next_frame_sentinel_okay (get_current_frame ()), regnum);
 
       /* It is more efficient in general to do this delegation in this
         direction than in the other one, even though the value-based
index e9308b04f933214b539178cfb9bc529f2a8839c1..5e48a4c86487c0d87cb7c6426908d5486bdc2f68 100644 (file)
@@ -959,6 +959,21 @@ value::allocate (struct type *type)
   return allocate (type, true);
 }
 
+/* See value.h  */
+
+struct value *
+value::allocate_register (frame_info_ptr next_frame, int regnum)
+{
+  value *result
+    = value::allocate (register_type (frame_unwind_arch (next_frame), regnum));
+
+  result->set_lval (lval_register);
+  VALUE_REGNUM (result) = regnum;
+  VALUE_NEXT_FRAME_ID (result) = get_frame_id (next_frame);
+
+  return result;
+}
+
 /* Allocate a  value  that has the correct length
    for COUNT repetitions of type TYPE.  */
 
index 3f9b35b589bd0b690a51d2fb2b142162efa8304d..2f3b41e26ea44aadfca13a1566c074755f9c1cb4 100644 (file)
@@ -159,6 +159,13 @@ public:
   /* Allocate a value and its contents for type TYPE.  */
   static struct value *allocate (struct type *type);
 
+  /* Allocate a non-lazy value representing register RENUM in the frame previous
+     to NEXT_FRAME.  The type of the value is found using `register_type`.
+
+     The caller is responsible for filling the value's contents.  */
+  static struct value *allocate_register (frame_info_ptr next_frame,
+                                         int regnum);
+
   /* Create a computed lvalue, with type TYPE, function pointers
      FUNCS, and closure CLOSURE.  */
   static struct value *allocate_computed (struct type *type,