Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 5/7] [gdb] Add prev/next params to find_pc_section
Date: Wed,  9 Sep 2026 11:48:47 +0200	[thread overview]
Message-ID: <20260909094849.2745086-6-tdevries@suse.de> (raw)
In-Reply-To: <20260909094849.2745086-1-tdevries@suse.de>

Now that we're using std::lower_bound to find sections in find_pc_section,
extend find_pc_section to return the previous and next section in case it
returns nullptr.
---
 gdb/objfiles.c | 32 ++++++++++++++++++++++++++++++--
 gdb/objfiles.h |  4 +++-
 2 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 066d1af9b9e..3871ef1670f 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -912,14 +912,22 @@ update_section_map (struct program_space *pspace,
   *pmap_size = map_size;
 }
 
-/* Returns a section whose range includes PC or NULL if none found.   */
+/* Returns a section whose range includes PC or nullptr if none found.
+   On returning nullptr, set PREV_PTR and NEXT_PTR to point to the sections
+   before and after PC, if any.  */
 
 struct obj_section *
-find_pc_section (CORE_ADDR pc)
+find_pc_section (CORE_ADDR pc, struct obj_section **prev_ptr,
+		 struct obj_section **next_ptr)
 {
   struct objfile_pspace_info *pspace_info;
   struct obj_section *s;
 
+  if (prev_ptr != nullptr)
+    *prev_ptr = nullptr;
+  if (next_ptr != nullptr)
+    *next_ptr = nullptr;
+
   /* Check for mapped overlay section first.  */
   s = find_pc_mapped_section (pc);
   if (s)
@@ -964,6 +972,26 @@ find_pc_section (CORE_ADDR pc)
       && (*it)->addr () <= pc && pc < (*it)->endaddr ())
     return *it;
 
+  struct obj_section *prev = nullptr, *next = nullptr;
+  auto prev_it = (it == data.cbegin ()
+		  ? data.cend ()
+		  : it - 1);
+  if (prev_it != data.cend ())
+    {
+      prev = *prev_it;
+      gdb_assert (prev->endaddr () <= pc);
+    }
+  if (it != data.cend ())
+    {
+      next = *it;
+      gdb_assert (pc < next->addr ());
+    }
+
+  if (prev_ptr != nullptr)
+    *prev_ptr = prev;
+  if (next_ptr != nullptr)
+    *next_ptr = next;
+
   return NULL;
 }
 
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index fa265f83b79..d23e2b3046e 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -954,7 +954,9 @@ extern void objfile_purge_solibs (program_space *pspace);
 /* Functions for dealing with the minimal symbol table, really a misc
    address<->symbol mapping for things we don't have debug symbols for.  */
 
-extern struct obj_section *find_pc_section (CORE_ADDR pc);
+extern struct obj_section *find_pc_section (CORE_ADDR pc,
+					    struct obj_section **prev = nullptr,
+					    struct obj_section **next = nullptr);
 
 /* Return true if PC is in a section called NAME.  */
 extern bool pc_in_section (CORE_ADDR, const char *);
-- 
2.51.0


  parent reply	other threads:[~2026-09-09  9:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09  9:48 [PATCH v2 0/7] [gdb/tui] Some section hole handling fixes Tom de Vries
2026-09-09  9:48 ` [PATCH v2 1/7] [gdb/tui] Improve tui_disassemble comment Tom de Vries
2026-09-09  9:48 ` [PATCH v2 2/7] [gdb/tui] Fix underflow in tui_find_backward_disassembly_start_address Tom de Vries
2026-09-11 18:12   ` Tom Tromey
2026-09-11 18:14     ` Tom Tromey
2026-09-09  9:48 ` [PATCH v2 3/7] [gdb/tui] Improve section handling " Tom de Vries
2026-09-11 18:26   ` Tom Tromey
2026-09-14  7:31     ` Tom de Vries
2026-09-09  9:48 ` [PATCH v2 4/7] [gdb] replace bsearch with std::lower_bound in find_pc_section Tom de Vries
2026-09-11 18:19   ` Tom Tromey
2026-09-14  7:34     ` Tom de Vries
2026-09-09  9:48 ` Tom de Vries [this message]
2026-09-11 18:40   ` [PATCH v2 5/7] [gdb] Add prev/next params to find_pc_section Tom Tromey
2026-09-09  9:48 ` [PATCH v2 6/7] [gdb/tui] Handle section holes when forward disassembling Tom de Vries
2026-09-11 18:39   ` Tom Tromey
2026-09-09  9:48 ` [PATCH v2 7/7] [gdb/tui] Handle section holes when backward disassembling Tom de Vries
2026-09-11 18:48   ` Tom Tromey
2026-09-11 18:52 ` [PATCH v2 0/7] [gdb/tui] Some section hole handling fixes Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260909094849.2745086-6-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox