]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb] Make addrmap_mutable::set_empty return bool
authorTom de Vries <tdevries@suse.de>
Sat, 23 Aug 2025 04:11:41 +0000 (06:11 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 23 Aug 2025 04:11:41 +0000 (06:11 +0200)
Function addrmap_mutable::set_empty has the follow behavior (shortened
comment):
...
/* In the mutable address map MAP, associate the addresses from START
   to END_INCLUSIVE that are currently associated with NULL with OBJ
   instead.  Addresses mapped to an object other than NULL are left
   unchanged.  */
  void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
  void *obj);
...

Change the return type to bool, and return true if the full range
[START, END_INCLUSIVE] is mapped to OBJ.

Tested on x86_64-linux.

Approved-By: Simon Marchi <simon.marchi@efficios.com>
gdb/addrmap.c
gdb/addrmap.h

index 45493509f21b2d1d82210572c3db4dca746c5cc4..2b333a1fd700cf536dd8c4afbe13261bfd1a40c2 100644 (file)
@@ -201,10 +201,11 @@ xfree_wrapper (splay_tree_key key)
   xfree ((void *) key);
 }
 
-void
+bool
 addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
                            void *obj)
 {
+  bool full_range = true;
   splay_tree_node n, next;
   void *prior_value;
 
@@ -234,7 +235,12 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
        n && addrmap_node_key (n) <= end_inclusive;
        n = splay_tree_successor (addrmap_node_key (n)))
     {
-      if (! addrmap_node_value (n))
+      if (addrmap_node_value (n))
+       {
+         /* Already mapped.  */
+         full_range = false;
+       }
+      else
        addrmap_node_set_value (n, obj);
     }
 
@@ -254,6 +260,8 @@ addrmap_mutable::set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
       else
        prior_value = addrmap_node_value (n);
     }
+
+  return full_range;
 }
 
 
@@ -433,7 +441,9 @@ test_addrmap ()
   check_addrmap_find (map, array, 0, 19, nullptr);
 
   /* Insert address range into mutable addrmap.  */
-  map.set_empty (core_addr (&array[10]), core_addr (&array[12]), val1);
+  bool full_range_p
+    = map.set_empty (core_addr (&array[10]), core_addr (&array[12]), val1);
+  SELF_CHECK (full_range_p);
   check_addrmap_find (map, array, 0, 9, nullptr);
   check_addrmap_find (map, array, 10, 12, val1);
   check_addrmap_find (map, array, 13, 19, nullptr);
@@ -469,7 +479,9 @@ test_addrmap ()
   check_addrmap_find (*map2, array, 14, 19, nullptr);
 
   /* Insert partially overlapping address range into mutable addrmap.  */
-  map.set_empty (core_addr (&array[11]), core_addr (&array[13]), val2);
+  full_range_p
+    = map.set_empty (core_addr (&array[11]), core_addr (&array[13]), val2);
+  SELF_CHECK (!full_range_p);
   check_addrmap_find (map, array, 0, 9, nullptr);
   check_addrmap_find (map, array, 10, 12, val1);
   check_addrmap_find (map, array, 13, 13, val2);
index 179e1f866683c4a4bf33484f25bf2b6d0112d032..398bdd84215c572d4c561aa706503a4edb463b11 100644 (file)
@@ -152,7 +152,7 @@ public:
   /* In the mutable address map MAP, associate the addresses from START
      to END_INCLUSIVE that are currently associated with NULL with OBJ
      instead.  Addresses mapped to an object other than NULL are left
-     unchanged.
+     unchanged.  Return true if the full range is mapped to OBJ.
 
      As the name suggests, END_INCLUSIVE is also mapped to OBJ.  This
      convention is unusual, but it allows callers to accurately specify
@@ -186,7 +186,7 @@ public:
      semantics than to provide an interface which allows it to be
      implemented efficiently, but doesn't reveal too much of the
      representation.  */
-  void set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
+  bool set_empty (CORE_ADDR start, CORE_ADDR end_inclusive,
                  void *obj);
 
   /* Clear this addrmap.  */