]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[gdb/breakpoints] Stabilize info breakpoints output
authorTom de Vries <tdevries@suse.de>
Mon, 26 May 2025 13:15:31 +0000 (15:15 +0200)
committerTom de Vries <tdevries@suse.de>
Mon, 26 May 2025 13:15:31 +0000 (15:15 +0200)
With test-case gdb.multi/pending-bp-del-inferior.exp, occasionally I run into:
...
(gdb) info breakpoints^M
Num     Type           Disp Enb Address    What^M
3       dprintf        keep y   <MULTIPLE> ^M
        printf "in foo"^M
3.1                         y   0x004004dc in foo at $c:21 inf 2^M
3.2                         y   0x004004dc in foo at $c:21 inf 1^M
(gdb) FAIL: $exp: bp_pending=false: info breakpoints before inferior removal
...

The FAIL happens because the test-case expects:
- breakpoint location 3.1 to be in inferior 1, and
- breakpoint location 3.2 to be in inferior 2
but it's the other way around.

I managed to reproduce this with a trigger patch in
compare_symbols from gdb/linespec.c:
...
   uia = (uintptr_t) a.symbol->symtab ()->compunit ()->objfile ()->pspace ();
   uib = (uintptr_t) b.symbol->symtab ()->compunit ()->objfile ()->pspace ();

-  if (uia < uib)
+  if (uia > uib)
     return true;
-  if (uia > uib)
+  if (uia < uib)
     return false;
...

The order enforced by compare_symbols shows up in the "info breakpoints"
output because breakpoint::add_location doesn't enforce an ordering for equal
addresses:
...
  auto ub = std::upper_bound (m_locations.begin (), m_locations.end (),
      loc,
      [] (const bp_location &left,
  const bp_location &right)
{ return left.address < right.address; });
   m_locations.insert (ub, loc);
...

Fix this by using new function bp_location_is_less_than
(forwarding to bp_location_ptr_is_less_than) in breakpoint::add_location.

Tested on x86_64-linux.

Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
Approved-By: Andrew Burgess <aburgess@redhat.com>
PR gdb/32202
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32202

gdb/breakpoint.c

index bbafa096309c472fa1dd686f4a643ced87c80ded..abae16fe23f5d37563df78e0913561e1d904fb5c 100644 (file)
@@ -11254,6 +11254,15 @@ bp_location_ptr_is_less_than (const bp_location *a, const bp_location *b)
   return a < b;
 }
 
+/* A comparison function for bp_locations A and B being interfaced to
+   std::sort, for instance to sort an std::vector<bp_location>.  */
+
+static bool
+bp_location_is_less_than (const bp_location &a, const bp_location &b)
+{
+  return bp_location_ptr_is_less_than (&a, &b);
+}
+
 /* Set bp_locations_placed_address_before_address_max and
    bp_locations_shadow_len_after_address_max according to the current
    content of the bp_locations array.  */
@@ -11907,9 +11916,7 @@ breakpoint::add_location (bp_location &loc)
 
   auto ub = std::upper_bound (m_locations.begin (), m_locations.end (),
                              loc,
-                             [] (const bp_location &left,
-                                 const bp_location &right)
-                               { return left.address < right.address; });
+                             bp_location_is_less_than);
   m_locations.insert (ub, loc);
 }