public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/28404] New: Verify bsearch precondition in find_pc_section
@ 2021-10-01  9:25 vries at gcc dot gnu.org
  2021-10-01 15:10 ` [Bug gdb/28404] " vries at gcc dot gnu.org
  2021-10-01 15:13 ` vries at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-01  9:25 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28404

            Bug ID: 28404
           Summary: Verify bsearch precondition in find_pc_section
           Product: gdb
           Version: HEAD
            Status: NEW
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: vries at gcc dot gnu.org
  Target Milestone: ---

While debugging some problem I came across a bsearch in find_pc_section, which
relies on the sections array being in ascending sorted order.

Visual inspection revealed that the precondition was not met.

It would probably be good to write an assert checking the precondition, and use
it to see if indeed it triggers.

Perhaps even add a verify_bsearch to gdbsupport that can be dropped in place to
check the precondition.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/28404] Verify bsearch precondition in find_pc_section
  2021-10-01  9:25 [Bug gdb/28404] New: Verify bsearch precondition in find_pc_section vries at gcc dot gnu.org
@ 2021-10-01 15:10 ` vries at gcc dot gnu.org
  2021-10-01 15:13 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-01 15:10 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28404

--- Comment #1 from Tom de Vries <vries at gcc dot gnu.org> ---
I wrote this:
...
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index b65fa8820ca..cc9a47eaad8 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -1227,6 +1227,19 @@ find_pc_section (CORE_ADDR pc)
       return NULL;
     }

+  {
+    struct obj_section *prev_elem = nullptr;
+    struct obj_section *elem = nullptr;
+    for (int i = 0; i < pspace_info->num_sections; (prev_elem = elem), ++i)

+      {
+       elem = pspace_info->sections[i];
+       gdb_assert (elem->addr () <= elem->endaddr ());
+       if (prev_elem == nullptr)
+         continue;
+       gdb_assert (prev_elem->endaddr () <= elem->addr ());
+      }
+  }re--
+
   sp = (struct obj_section **) bsearch (&pc,
                                        pspace_info->sections,
                                        pspace_info->num_sections,
... 

And tested using target board unix/-fPIE/-pie.  No regression.

So, I guess I was looking at the consequences of the patch series I was playing
around with.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug gdb/28404] Verify bsearch precondition in find_pc_section
  2021-10-01  9:25 [Bug gdb/28404] New: Verify bsearch precondition in find_pc_section vries at gcc dot gnu.org
  2021-10-01 15:10 ` [Bug gdb/28404] " vries at gcc dot gnu.org
@ 2021-10-01 15:13 ` vries at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: vries at gcc dot gnu.org @ 2021-10-01 15:13 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=28404

Tom de Vries <vries at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WORKSFORME
             Status|NEW                         |RESOLVED

--- Comment #2 from Tom de Vries <vries at gcc dot gnu.org> ---
(In reply to Tom de Vries from comment #0)
> Perhaps even add a verify_bsearch to gdbsupport that can be dropped in place
> to check the precondition.

That doesn't seem to be possible, since the check that we're trying to do uses
a different compare function (elem vs elem) than bsearch does (key vs elem).

Adding this code as a regular check seems somewhat expensive.  So I'm leaving
things as they are for now.

Marking this fixed-worksforme.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2021-10-01 15:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01  9:25 [Bug gdb/28404] New: Verify bsearch precondition in find_pc_section vries at gcc dot gnu.org
2021-10-01 15:10 ` [Bug gdb/28404] " vries at gcc dot gnu.org
2021-10-01 15:13 ` vries at gcc dot gnu.org

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