public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Change register_changed_p returns bool
@ 2017-11-03  8:56 Yao Qi
  2017-11-03  8:56 ` [PATCH 2/2] Change value_contents_eq return bool Yao Qi
  2017-11-24 10:49 ` [PATCH 1/2] Change register_changed_p returns bool Yao Qi
  0 siblings, 2 replies; 3+ messages in thread
From: Yao Qi @ 2017-11-03  8:56 UTC (permalink / raw)
  To: gdb-patches

register_changed_p actually returns bool, but return type is still int.
This patch changes the return type to bool.  The caller of
register_changed_p also checked whether the return value can be negative,
which is not needed now.  Such check was added in fb40c2090 in 2000,
at that moment, register_changed_p returns -1 when
read_relative_register_raw_bytes fails.  I can tell from its name that
it reads register contents, but we don't have this function called inside
register_changed_p, and the regcache is read-only.

gdb:

2017-11-01  Yao Qi  <yao.qi@linaro.org>

	* mi/mi-main.c (mi_cmd_data_list_changed_registers): Remove
	local 'changed'.  Remove error.
	(register_changed_p): Change return type to bool.
---
 gdb/mi/mi-main.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 480d2fd..42df94e 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -95,8 +95,8 @@ static void mi_execute_cli_command (const char *cmd, int args_p,
 				    const char *args);
 static void mi_execute_async_cli_command (const char *cli_command,
 					  char **argv, int argc);
-static int register_changed_p (int regnum, struct regcache *,
-			       struct regcache *);
+static bool register_changed_p (int regnum, regcache *,
+				regcache *);
 static void output_register (struct frame_info *, int regnum, int format,
 			     int skip_unavailable);
 
@@ -988,7 +988,7 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
   struct ui_out *uiout = current_uiout;
   std::unique_ptr<struct regcache> prev_regs;
   struct gdbarch *gdbarch;
-  int regnum, numregs, changed;
+  int regnum, numregs;
   int i;
 
   /* The last time we visited this function, the current frame's
@@ -1021,12 +1021,9 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
 	  if (gdbarch_register_name (gdbarch, regnum) == NULL
 	      || *(gdbarch_register_name (gdbarch, regnum)) == '\0')
 	    continue;
-	  changed = register_changed_p (regnum, prev_regs.get (),
-					this_regs.get ());
-	  if (changed < 0)
-	    error (_("-data-list-changed-registers: "
-		     "Unable to read register contents."));
-	  else if (changed)
+
+	  if (register_changed_p (regnum, prev_regs.get (),
+				  this_regs.get ()))
 	    uiout->field_int (NULL, regnum);
 	}
     }
@@ -1041,12 +1038,8 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
 	  && gdbarch_register_name (gdbarch, regnum) != NULL
 	  && *gdbarch_register_name (gdbarch, regnum) != '\000')
 	{
-	  changed = register_changed_p (regnum, prev_regs.get (),
-					this_regs.get ());
-	  if (changed < 0)
-	    error (_("-data-list-changed-registers: "
-		     "Unable to read register contents."));
-	  else if (changed)
+	  if (register_changed_p (regnum, prev_regs.get (),
+				  this_regs.get ()))
 	    uiout->field_int (NULL, regnum);
 	}
       else
@@ -1054,18 +1047,17 @@ mi_cmd_data_list_changed_registers (const char *command, char **argv, int argc)
     }
 }
 
-static int
+static bool
 register_changed_p (int regnum, struct regcache *prev_regs,
 		    struct regcache *this_regs)
 {
   struct gdbarch *gdbarch = this_regs->arch ();
   struct value *prev_value, *this_value;
-  int ret;
 
   /* First time through or after gdbarch change consider all registers
      as changed.  */
   if (!prev_regs || prev_regs->arch () != gdbarch)
-    return 1;
+    return true;
 
   /* Get register contents and compare.  */
   prev_value = prev_regs->cooked_read_value (regnum);
@@ -1073,8 +1065,8 @@ register_changed_p (int regnum, struct regcache *prev_regs,
   gdb_assert (prev_value != NULL);
   gdb_assert (this_value != NULL);
 
-  ret = value_contents_eq (prev_value, 0, this_value, 0,
-			   register_size (gdbarch, regnum)) == 0;
+  auto ret = value_contents_eq (prev_value, 0, this_value, 0,
+				register_size (gdbarch, regnum)) == 0;
 
   release_value (prev_value);
   release_value (this_value);
-- 
1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Change value_contents_eq return bool
  2017-11-03  8:56 [PATCH 1/2] Change register_changed_p returns bool Yao Qi
@ 2017-11-03  8:56 ` Yao Qi
  2017-11-24 10:49 ` [PATCH 1/2] Change register_changed_p returns bool Yao Qi
  1 sibling, 0 replies; 3+ messages in thread
From: Yao Qi @ 2017-11-03  8:56 UTC (permalink / raw)
  To: gdb-patches

This patch changes value_contents_eq return type from int to bool.

gdb:

2017-11-01  Yao Qi  <yao.qi@linaro.org>

	* mi/mi-main.c (register_changed_p): Update.
	* value.c (value_contents_bits_eq): Change return type.
	(value_contents_eq): Likewise.
	* value.h: Update comments.
---
 gdb/mi/mi-main.c |  4 ++--
 gdb/value.c      | 10 +++++-----
 gdb/value.h      | 24 ++++++++++++------------
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c
index 42df94e..8f9b7e4 100644
--- a/gdb/mi/mi-main.c
+++ b/gdb/mi/mi-main.c
@@ -1065,8 +1065,8 @@ register_changed_p (int regnum, struct regcache *prev_regs,
   gdb_assert (prev_value != NULL);
   gdb_assert (this_value != NULL);
 
-  auto ret = value_contents_eq (prev_value, 0, this_value, 0,
-				register_size (gdbarch, regnum)) == 0;
+  auto ret = !value_contents_eq (prev_value, 0, this_value, 0,
+				 register_size (gdbarch, regnum));
 
   release_value (prev_value);
   release_value (this_value);
diff --git a/gdb/value.c b/gdb/value.c
index 7d0966c..f3b0288 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -810,7 +810,7 @@ find_first_range_overlap_and_match (struct ranges_and_idx *rp1,
    with LENGTH bits of VAL2's contents starting at OFFSET2 bits.
    Return true if the available bits match.  */
 
-static int
+static bool
 value_contents_bits_eq (const struct value *val1, int offset1,
 			const struct value *val2, int offset2,
 			int length)
@@ -849,7 +849,7 @@ value_contents_bits_eq (const struct value *val1, int offset1,
 	  if (!find_first_range_overlap_and_match (&rp1[i], &rp2[i],
 						   offset1, offset2, length,
 						   &l_tmp, &h_tmp))
-	    return 0;
+	    return false;
 
 	  /* We're interested in the lowest/first range found.  */
 	  if (i == 0 || l_tmp < l)
@@ -862,17 +862,17 @@ value_contents_bits_eq (const struct value *val1, int offset1,
       /* Compare the available/valid contents.  */
       if (memcmp_with_bit_offsets (val1->contents, offset1,
 				   val2->contents, offset2, l) != 0)
-	return 0;
+	return false;
 
       length -= h;
       offset1 += h;
       offset2 += h;
     }
 
-  return 1;
+  return true;
 }
 
-int
+bool
 value_contents_eq (const struct value *val1, LONGEST offset1,
 		   const struct value *val2, LONGEST offset2,
 		   LONGEST length)
diff --git a/gdb/value.h b/gdb/value.h
index cfc8cae..8f8f960 100644
--- a/gdb/value.h
+++ b/gdb/value.h
@@ -550,12 +550,12 @@ extern void mark_value_bits_unavailable (struct value *value,
 
    then:
 
-     value_contents_eq(val, 0, val, 8, 6) => 1
-     value_contents_eq(val, 0, val, 4, 4) => 0
-     value_contents_eq(val, 0, val, 8, 8) => 0
-     value_contents_eq(val, 4, val, 12, 2) => 1
-     value_contents_eq(val, 4, val, 12, 4) => 0
-     value_contents_eq(val, 3, val, 4, 4) => 0
+     value_contents_eq(val, 0, val, 8, 6) => true
+     value_contents_eq(val, 0, val, 4, 4) => false
+     value_contents_eq(val, 0, val, 8, 8) => false
+     value_contents_eq(val, 4, val, 12, 2) => true
+     value_contents_eq(val, 4, val, 12, 4) => true
+     value_contents_eq(val, 3, val, 4, 4) => true
 
    If 'x's represent an unavailable byte, 'o' represents an optimized
    out byte, in a value with length 8:
@@ -565,9 +565,9 @@ extern void mark_value_bits_unavailable (struct value *value,
 
    then:
 
-     value_contents_eq(val, 0, val, 2, 2) => 1
-     value_contents_eq(val, 4, val, 6, 2) => 1
-     value_contents_eq(val, 0, val, 4, 4) => 0
+     value_contents_eq(val, 0, val, 2, 2) => true
+     value_contents_eq(val, 4, val, 6, 2) => true
+     value_contents_eq(val, 0, val, 4, 4) => true
 
    We only know whether a value chunk is unavailable or optimized out
    if we've tried to read it.  As this routine is used by printing
@@ -575,9 +575,9 @@ extern void mark_value_bits_unavailable (struct value *value,
    after the inferior is gone, it works with const values.  Therefore,
    this routine must not be called with lazy values.  */
 
-extern int value_contents_eq (const struct value *val1, LONGEST offset1,
-			      const struct value *val2, LONGEST offset2,
-			      LONGEST length);
+extern bool value_contents_eq (const struct value *val1, LONGEST offset1,
+			       const struct value *val2, LONGEST offset2,
+			       LONGEST length);
 
 /* Read LENGTH addressable memory units starting at MEMADDR into BUFFER,
    which is (or will be copied to) VAL's contents buffer offset by
-- 
1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Change register_changed_p returns bool
  2017-11-03  8:56 [PATCH 1/2] Change register_changed_p returns bool Yao Qi
  2017-11-03  8:56 ` [PATCH 2/2] Change value_contents_eq return bool Yao Qi
@ 2017-11-24 10:49 ` Yao Qi
  1 sibling, 0 replies; 3+ messages in thread
From: Yao Qi @ 2017-11-24 10:49 UTC (permalink / raw)
  To: gdb-patches

Yao Qi <qiyaoltc@gmail.com> writes:

> 2017-11-01  Yao Qi  <yao.qi@linaro.org>
>
> 	* mi/mi-main.c (mi_cmd_data_list_changed_registers): Remove
> 	local 'changed'.  Remove error.
> 	(register_changed_p): Change return type to bool.

I pushed patch 1/2 and 2/2 in.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-11-24 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-03  8:56 [PATCH 1/2] Change register_changed_p returns bool Yao Qi
2017-11-03  8:56 ` [PATCH 2/2] Change value_contents_eq return bool Yao Qi
2017-11-24 10:49 ` [PATCH 1/2] Change register_changed_p returns bool Yao Qi

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).