From: Tom de Vries Date: Mon, 26 May 2025 13:15:31 +0000 (+0200) Subject: [gdb/breakpoints] Stabilize info breakpoints output X-Git-Tag: binutils-2_45~494 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=6b4f72a01e60c854654a46f4faa555e258fa98b0;p=thirdparty%2Fbinutils-gdb.git [gdb/breakpoints] Stabilize info breakpoints output 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 ^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 Approved-By: Andrew Burgess PR gdb/32202 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32202 --- diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index bbafa096309..abae16fe23f 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -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. */ + +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); }