From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v3 2/5] [gdb] Add section_addrmap
Date: Mon, 21 Sep 2026 22:55:54 +0200 [thread overview]
Message-ID: <20260921205557.2706300-3-tdevries@suse.de> (raw)
In-Reply-To: <20260921205557.2706300-1-tdevries@suse.de>
Add a function section_addrmap that returns an addrmap that maps addresses to
sections, mapping the same way as find_pc_section does.
---
gdb/objfiles.c | 27 +++++++++++++++++++++++++++
gdb/objfiles.h | 6 ++++++
2 files changed, 33 insertions(+)
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 453397c4f43..2b03f424756 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -984,6 +984,33 @@ find_pc_section (CORE_ADDR pc)
return NULL;
}
+/* See objfiles.h. */
+
+std::unique_ptr<addrmap_mutable>
+section_addrmap ()
+{
+ std::unique_ptr<addrmap_mutable> res (new addrmap_mutable ());
+
+ /* Insert mapped overlay sections first. */
+ if (overlay_debugging)
+ for (objfile &objfile : current_program_space->objfiles ())
+ for (obj_section &osect : objfile.sections ())
+ if (section_is_mapped (&osect))
+ res->set_empty (osect.addr (), osect.endaddr () - 1, &osect);
+
+ update_section_map (current_program_space);
+
+ struct objfile_pspace_info *pspace_info
+ = get_objfile_pspace_data (current_program_space);
+
+ for (int i = 0; i < pspace_info->num_sections; ++i)
+ {
+ obj_section *s = pspace_info->sections[i];
+ res->set_empty (s->addr (), s->endaddr () - 1, s);
+ }
+
+ return res;
+}
/* Return non-zero if PC is in a section called NAME. */
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index fa265f83b79..b193aec3be7 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -38,6 +38,7 @@
struct htab;
struct objfile_data;
struct partial_symbol;
+struct addrmap_mutable;
/* This structure maintains information on a per-objfile basis about the
"entry point" of the objfile, and the scope within which the entry point
@@ -956,6 +957,11 @@ extern void objfile_purge_solibs (program_space *pspace);
extern struct obj_section *find_pc_section (CORE_ADDR pc);
+/* Returns an addrmap mapping addresses to sections, similar to how
+ find_pc_section maps. */
+
+extern std::unique_ptr<addrmap_mutable> section_addrmap ();
+
/* Return true if PC is in a section called NAME. */
extern bool pc_in_section (CORE_ADDR, const char *);
--
2.51.0
next prev parent reply other threads:[~2026-09-21 20:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 20:55 [PATCH v3 0/5] [gdb/tui] Some section hole handling fixes Tom de Vries
2026-09-21 20:55 ` [PATCH v3 1/5] [gdb] Factor out update_section_map Tom de Vries
2026-09-21 20:55 ` Tom de Vries [this message]
2026-09-21 20:55 ` [PATCH v3 3/5] [gdb] Extend addrmap::find with low/high results Tom de Vries
2026-09-21 20:55 ` [PATCH v3 4/5] [gdb] Handle sections when disassembling Tom de Vries
2026-09-21 20:55 ` [PATCH v3 5/5] [gdb] Don't stop disassembly at section hole Tom de Vries
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=20260921205557.2706300-3-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