public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 8/9] gdb: remove VALUE_REGNUM, add value::regnum
Date: Thu, 21 Dec 2023 14:16:29 -0500	[thread overview]
Message-ID: <20231221191716.257256-9-simon.marchi@efficios.com> (raw)
In-Reply-To: <20231221191716.257256-1-simon.marchi@efficios.com>

Remove VALUE_REGNUM, replace it with a method on struct value.  Set
`m_location.reg.regnum` directly from value::allocate_register_lazy,
which is fine because allocate_register_lazy is a static creation
function for struct value.

Change-Id: Id632502357da971617d9dce1e2eab9b56dbcf52d
---
 gdb/findvar.c          |  2 +-
 gdb/frame.c            |  7 +++----
 gdb/python/py-unwind.c |  2 +-
 gdb/stack.c            |  3 +--
 gdb/valops.c           | 15 ++++++---------
 gdb/value.c            | 20 ++++++++++----------
 gdb/value.h            |  8 ++++----
 7 files changed, 26 insertions(+), 31 deletions(-)

diff --git a/gdb/findvar.c b/gdb/findvar.c
index ef7129dab331..7c360eb37ff9 100644
--- a/gdb/findvar.c
+++ b/gdb/findvar.c
@@ -785,7 +785,7 @@ read_frame_register_value (value *value)
   gdbarch *gdbarch = frame_unwind_arch (next_frame);
   LONGEST offset = 0;
   LONGEST reg_offset = value->offset ();
-  int regnum = VALUE_REGNUM (value);
+  int regnum = value->regnum ();
   int len = type_length_units (check_typedef (value->type ()));
 
   /* Skip registers wholly inside of REG_OFFSET.  */
diff --git a/gdb/frame.c b/gdb/frame.c
index 5f4c8c621a04..41003cc7771e 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -1196,7 +1196,7 @@ frame_register_unwind (frame_info_ptr next_frame, int regnum,
   *lvalp = value->lval ();
   *addrp = value->address ();
   if (*lvalp == lval_register)
-    *realnump = VALUE_REGNUM (value);
+    *realnump = value->regnum ();
   else
     *realnump = -1;
 
@@ -1304,8 +1304,7 @@ frame_unwind_register_value (frame_info_ptr next_frame, int regnum)
       else
 	{
 	  if (value->lval () == lval_register)
-	    gdb_printf (&debug_file, " register=%d",
-			VALUE_REGNUM (value));
+	    gdb_printf (&debug_file, " register=%d", value->regnum ());
 	  else if (value->lval () == lval_memory)
 	    gdb_printf (&debug_file, " address=%s",
 			paddress (gdbarch,
@@ -1417,7 +1416,7 @@ read_frame_register_unsigned (frame_info_ptr frame, int regnum,
     {
       struct gdbarch *gdbarch = get_frame_arch (frame);
       enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
-      int size = register_size (gdbarch, VALUE_REGNUM (regval));
+      int size = register_size (gdbarch, regval->regnum ());
 
       *val = extract_unsigned_integer (regval->contents ().data (), size,
 				       byte_order);
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 8fed55beadca..f12485c22b77 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -336,7 +336,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw)
       struct value *user_reg_value
 	= value_of_user_reg (regnum, pending_frame->frame_info);
       if (user_reg_value->lval () == lval_register)
-	regnum = VALUE_REGNUM (user_reg_value);
+	regnum = user_reg_value->regnum ();
       if (regnum >= gdbarch_num_cooked_regs (pending_frame->gdbarch))
 	{
 	  PyErr_SetString (PyExc_ValueError, "Bad register");
diff --git a/gdb/stack.c b/gdb/stack.c
index 20bb85efd19e..fad4b62c6f72 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1724,8 +1724,7 @@ info_frame_command_core (frame_info_ptr fi, bool selected_frame_p)
 	    else if (value->lval () == lval_register)
 	      {
 		gdb_printf (" Previous frame's sp in %s\n",
-			    gdbarch_register_name (gdbarch,
-						   VALUE_REGNUM (value)));
+			    gdbarch_register_name (gdbarch, value->regnum ()));
 	      }
 
 	    release_value (value);
diff --git a/gdb/valops.c b/gdb/valops.c
index 5a5b3f14ad44..16cdf1f45530 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -1194,8 +1194,7 @@ value_assign (struct value *toval, struct value *fromval)
     case lval_register:
       {
 	frame_info_ptr next_frame = frame_find_by_id (toval->next_frame_id ());
-
-	int value_reg = VALUE_REGNUM (toval);
+	int value_reg = toval->regnum ();
 
 	if (next_frame == nullptr)
 	  error (_("Value being assigned to is no longer active."));
@@ -1240,15 +1239,13 @@ value_assign (struct value *toval, struct value *fromval)
 	  }
 	else
 	  {
-	    if (gdbarch_convert_register_p (gdbarch, VALUE_REGNUM (toval),
-					    type))
+	    if (gdbarch_convert_register_p (gdbarch, toval->regnum (), type))
 	      {
 		/* If TOVAL is a special machine register requiring
 		   conversion of program values to a special raw
 		   format.  */
-		gdbarch_value_to_register (gdbarch,
-					   get_prev_frame_always (next_frame),
-					   VALUE_REGNUM (toval), type,
+		gdbarch_value_to_register (gdbarch, next_frame,
+					   toval->regnum (), type,
 					   fromval->contents ().data ());
 	      }
 	    else
@@ -1415,8 +1412,8 @@ address_of_variable (struct symbol *var, const struct block *b)
 	frame_info_ptr frame = frame_find_by_id (val->next_frame_id ());
 	gdb_assert (frame != nullptr);
 
-	regname = gdbarch_register_name (get_frame_arch (frame),
-					 VALUE_REGNUM (val));
+	regname
+	  = gdbarch_register_name (get_frame_arch (frame), val->regnum ());
 	gdb_assert (regname != nullptr && *regname != '\0');
 
 	error (_("Address requested for identifier "
diff --git a/gdb/value.c b/gdb/value.c
index a16ba2fb5d6b..a69bc348167a 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -971,7 +971,7 @@ value::allocate_register_lazy (frame_info_ptr next_frame, int regnum,
   value *result = value::allocate_lazy (type);
 
   result->set_lval (lval_register);
-  VALUE_REGNUM (result) = regnum;
+  result->m_location.reg.regnum = regnum;
   result->m_location.reg.next_frame_id = get_frame_id (next_frame);
 
   return result;
@@ -1429,11 +1429,14 @@ value::next_frame_id ()
   return m_location.reg.next_frame_id;
 }
 
-int *
-value::deprecated_regnum_hack ()
+/* See value.h.  */
+
+int
+value::regnum ()
 {
   gdb_assert (m_lval == lval_register);
-  return &m_location.reg.regnum;
+
+  return m_location.reg.regnum;
 }
 
 \f
@@ -3929,8 +3932,6 @@ value::fetch_lazy_memory ()
 void
 value::fetch_lazy_register ()
 {
- 
-  int regnum;
   struct type *type = check_typedef (this->type ());
   struct value *new_val = this;
 
@@ -3946,7 +3947,7 @@ value::fetch_lazy_register ()
       frame_info_ptr next_frame = frame_find_by_id (next_frame_id);
       gdb_assert (next_frame != NULL);
 
-      regnum = VALUE_REGNUM (new_val);
+      int regnum = new_val->regnum ();
 
       /* Convertible register routines are used for multi-register
 	 values and for interpretation in different types
@@ -3990,7 +3991,7 @@ value::fetch_lazy_register ()
     {
       frame_info_ptr frame = frame_find_by_id (this->next_frame_id ());
       frame = get_prev_frame_always (frame);
-      regnum = VALUE_REGNUM (this);
+      int regnum = this->regnum ();
       gdbarch *gdbarch = get_frame_arch (frame);
 
       string_file debug_file;
@@ -4011,8 +4012,7 @@ value::fetch_lazy_register ()
 	  gdb::array_view<const gdb_byte> buf = new_val->contents ();
 
 	  if (new_val->lval () == lval_register)
-	    gdb_printf (&debug_file, " register=%d",
-			VALUE_REGNUM (new_val));
+	    gdb_printf (&debug_file, " register=%d", new_val->regnum ());
 	  else if (new_val->lval () == lval_memory)
 	    gdb_printf (&debug_file, " address=%s",
 			paddress (gdbarch,
diff --git a/gdb/value.h b/gdb/value.h
index c33d2d8f0cd1..f1202007bb4f 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -378,7 +378,10 @@ struct value
      The value must be of lval == lval_register.  */
   frame_id next_frame_id ();
 
-  int *deprecated_regnum_hack ();
+  /* Return this value's register number.
+
+     The value must be of lval == lval_register.  */
+  int regnum ();
 
   /* contents() and contents_raw() both return the address of the gdb
      buffer used to hold a copy of the contents of the lval.
@@ -967,9 +970,6 @@ extern void error_value_optimized_out (void);
 /* Pointer to internal variable.  */
 #define VALUE_INTERNALVAR(val) (*((val)->deprecated_internalvar_hack ()))
 
-/* Register number if the value is from a register.  */
-#define VALUE_REGNUM(val) (*((val)->deprecated_regnum_hack ()))
-
 /* Return value after lval_funcs->coerce_ref (after check_typedef).  Return
    NULL if lval_funcs->coerce_ref is not applicable for whatever reason.  */
 
-- 
2.43.0


  parent reply	other threads:[~2023-12-21 19:19 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-21 19:16 [PATCH 0/9] Some register value cleanups Simon Marchi
2023-12-21 19:16 ` [PATCH 1/9] gdb: don't set frame id after calling cooked_read_value Simon Marchi
2023-12-21 19:16 ` [PATCH 2/9] gdb: pass frame_info_ptr to gdbarch_value_from_register Simon Marchi
2023-12-22 16:40   ` Tom Tromey
2023-12-22 16:53     ` Simon Marchi
2023-12-22 16:56       ` Tom Tromey
2023-12-21 19:16 ` [PATCH 3/9] gdb: pass non-nullptr frame to gdbarch_value_from_register in address_from_register Simon Marchi
2023-12-21 19:16 ` [PATCH 4/9] gdb: add type parameter to value::allocate_register and add value::allocate_register_lazy Simon Marchi
2023-12-21 19:16 ` [PATCH 5/9] gdb: remove read_frame_register_value's frame parameter Simon Marchi
2023-12-21 19:16 ` [PATCH 6/9] gdb: implement address_from_register using value_from_register Simon Marchi
2023-12-21 19:16 ` [PATCH 7/9] gdb: remove VALUE_NEXT_FRAME_ID, add value::next_frame_id Simon Marchi
2023-12-22 16:51   ` Tom Tromey
2023-12-22 16:56     ` Simon Marchi
2023-12-22 17:02       ` Tom Tromey
2023-12-22 17:06         ` Simon Marchi
2023-12-24 15:35           ` Simon Marchi
2023-12-21 19:16 ` Simon Marchi [this message]
2023-12-22 16:52   ` [PATCH 8/9] gdb: remove VALUE_REGNUM, add value::regnum Tom Tromey
2023-12-22 16:57     ` Simon Marchi
2023-12-21 19:16 ` [PATCH 9/9] gdb: make value::allocate_register_lazy store id of next non-inline frame Simon Marchi
2023-12-22 16:53 ` [PATCH 0/9] Some register value cleanups Tom Tromey
2023-12-22 16:58   ` Simon Marchi
2023-12-22 17:02     ` Tom Tromey
2023-12-24 18:28       ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231221191716.257256-9-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).