From: Jan Vrany <jan.vrany@labware.com>
To: gdb-patches@sourceware.org
Cc: Jan Vrany <jan.vrany@labware.com>
Subject: [RFC v5 01/18] gdb: introduce expand_symtabs_maybe_overlapping
Date: Mon, 23 Jun 2025 17:09:56 +0100 [thread overview]
Message-ID: <20250623161013.650814-2-jan.vrany@labware.com> (raw)
In-Reply-To: <20250623161013.650814-1-jan.vrany@labware.com>
This commit introduces expand_symtabs_maybe_overlapping, a new "quick
symbol function". This will be used later by Python API to create new
compunits to ensure to-be-created compunit does not overlap with
existing one.
For DWARF2 base index functions, all compunits are expanded
unconditionally since there seem to be no way to extract unexpanded
compunit's conservative address range.
---
gdb/dwarf2/cooked-index.h | 11 +++++++++++
gdb/dwarf2/read.c | 11 +++++++++++
gdb/dwarf2/read.h | 3 +++
gdb/objfiles.h | 3 +++
gdb/psymtab.c | 21 +++++++++++++++++++++
gdb/psymtab.h | 3 +++
gdb/quick-symbol.h | 5 +++++
gdb/symfile-debug.c | 16 ++++++++++++++++
gdbsupport/range.h | 35 +++++++++++++++++++++++++++++++++++
9 files changed, 108 insertions(+)
create mode 100644 gdbsupport/range.h
diff --git a/gdb/dwarf2/cooked-index.h b/gdb/dwarf2/cooked-index.h
index 43b27232aec..894f2078e9f 100644
--- a/gdb/dwarf2/cooked-index.h
+++ b/gdb/dwarf2/cooked-index.h
@@ -237,6 +237,17 @@ struct cooked_index_functions : public dwarf2_base_index_functions
dwarf2_base_index_functions::expand_all_symtabs (objfile);
}
+ /* Cooked index's version of expand_symtabs_maybe_overlapping. See its
+ definition in the definition of quick_symbol_functions in symfile.h. */
+
+ void expand_symtabs_maybe_overlapping (struct objfile *objfile,
+ CORE_ADDR start, CORE_ADDR end) override
+ {
+ wait (objfile, true);
+ dwarf2_base_index_functions::expand_symtabs_maybe_overlapping
+ (objfile, start, end);
+ }
+
bool expand_symtabs_matching
(struct objfile *objfile,
expand_symtabs_file_matcher file_matcher,
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 2f27b7cff4c..3270ce55c56 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -1926,6 +1926,17 @@ dwarf2_base_index_functions::expand_all_symtabs (struct objfile *objfile)
}
}
+/* DWARF2 index's version of expand_symtabs_maybe_overlapping. See its definition
+ in the definition of quick_symbol_functions in symfile.h. */
+
+void
+dwarf2_base_index_functions::expand_symtabs_maybe_overlapping
+ (struct objfile *objfile, CORE_ADDR start, CORE_ADDR end)
+{
+ /* Simply expand all symtabs. I do not know how to extract (if at all
+ possible) conservative address range from dwarf2_per_cu_data. */
+ expand_all_symtabs (objfile);
+}
/* See read.h. */
bool
diff --git a/gdb/dwarf2/read.h b/gdb/dwarf2/read.h
index a5cfb3144f7..da55f993123 100644
--- a/gdb/dwarf2/read.h
+++ b/gdb/dwarf2/read.h
@@ -1192,6 +1192,9 @@ struct dwarf2_base_index_functions : public quick_symbol_functions
void expand_all_symtabs (struct objfile *objfile) override;
+ virtual void expand_symtabs_maybe_overlapping (struct objfile *objfile,
+ CORE_ADDR start, CORE_ADDR end) override;
+
struct compunit_symtab *find_pc_sect_compunit_symtab
(struct objfile *objfile, bound_minimal_symbol msymbol,
CORE_ADDR pc, struct obj_section *section, int warn_if_readin)
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 4a3475862a9..0206b49e00c 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -597,6 +597,9 @@ struct objfile : intrusive_list_node<objfile>
code, e.g., DW_TAG_type_unit for dwarf debug info. */
void expand_symtabs_with_fullname (const char *fullname);
+ /* See quick_symbol_functions. */
+ void expand_symtabs_maybe_overlapping (CORE_ADDR start, CORE_ADDR end);
+
/* See quick_symbol_functions. */
bool expand_symtabs_matching
(expand_symtabs_file_matcher file_matcher,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 986ef44f6c7..d40afd5877f 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -36,6 +36,7 @@
#include <algorithm>
#include <set>
#include "gdbsupport/buildargv.h"
+#include "gdbsupport/range.h"
static const struct partial_symbol *lookup_partial_symbol
(struct objfile *, struct partial_symtab *, const lookup_name_info &,
@@ -731,6 +732,26 @@ psymbol_functions::expand_all_symtabs (struct objfile *objfile)
psymtab_to_symtab (objfile, psymtab);
}
+/* Psymtab version of expand_symtabs_maybe_overlapping. See its definition in
+ the definition of quick_symbol_functions in symfile.h. */
+
+void
+psymbol_functions::expand_symtabs_maybe_overlapping
+ (struct objfile *objfile, CORE_ADDR start, CORE_ADDR end)
+{
+ for (partial_symtab *psymtab : partial_symbols (objfile))
+ {
+ if (psymtab->text_low_valid && psymtab->text_high_valid)
+ {
+ CORE_ADDR text_low = psymtab->text_low (objfile);
+ CORE_ADDR text_high = psymtab->text_high (objfile);
+
+ if (ranges_overlap (start, end, text_low, text_high))
+ psymtab_to_symtab (objfile, psymtab);
+ }
+ }
+}
+
/* Psymtab version of map_symbol_filenames. See its definition in
the definition of quick_symbol_functions in symfile.h. */
diff --git a/gdb/psymtab.h b/gdb/psymtab.h
index ad0b2ff4234..8a8ea738bbd 100644
--- a/gdb/psymtab.h
+++ b/gdb/psymtab.h
@@ -626,6 +626,9 @@ struct psymbol_functions : public quick_symbol_functions
void expand_all_symtabs (struct objfile *objfile) override;
+ virtual void expand_symtabs_maybe_overlapping (struct objfile *objfile,
+ CORE_ADDR start, CORE_ADDR end) override;
+
bool expand_symtabs_matching
(struct objfile *objfile,
expand_symtabs_file_matcher file_matcher,
diff --git a/gdb/quick-symbol.h b/gdb/quick-symbol.h
index 9db1f1860cb..899f2f22239 100644
--- a/gdb/quick-symbol.h
+++ b/gdb/quick-symbol.h
@@ -130,6 +130,11 @@ struct quick_symbol_functions
/* Read all symbol tables associated with OBJFILE. */
virtual void expand_all_symtabs (struct objfile *objfile) = 0;
+ /* Read all symbol tables associated with OBJFILE which may overlap
+ with range [START, END). */
+ virtual void expand_symtabs_maybe_overlapping (struct objfile *objfile,
+ CORE_ADDR start, CORE_ADDR end) = 0;
+
/* Expand all symbol tables in OBJFILE matching some criteria.
If LANG_MATCHER returns false, expansion of the symbol table may be
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 9c5ce85d26e..900d1bf90e2 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -343,6 +343,22 @@ objfile::expand_all_symtabs ()
iter->expand_all_symtabs (this);
}
+/* See objfiles.h. */
+
+void
+objfile::expand_symtabs_maybe_overlapping (CORE_ADDR start, CORE_ADDR end)
+{
+ if (debug_symfile)
+ gdb_printf (gdb_stdlog,
+ "qf->expand_symtabs_maybe_overlapping (%s, %s, %s)\n",
+ objfile_debug_name (this),
+ hex_string (start),
+ hex_string (end));
+
+ for (const auto &iter : qf)
+ iter->expand_symtabs_maybe_overlapping (this, start, end);
+}
+
void
objfile::expand_symtabs_with_fullname (const char *fullname)
{
diff --git a/gdbsupport/range.h b/gdbsupport/range.h
new file mode 100644
index 00000000000..b665943cfd3
--- /dev/null
+++ b/gdbsupport/range.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 2025-2025 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef GDBSUPPORT_RANGE_H
+#define GDBSUPPORT_RANGE_H
+
+/* Return true if given ranges [AL, AH) and [BL, BH) overlap. Return false
+ otherwise. */
+
+template <typename T>
+bool ranges_overlap (T al, T ah, T bl, T bh)
+{
+ static_assert (std::is_integral<T>::value, "Integral type required");
+
+ gdb_assert (al <= ah);
+ gdb_assert (bl <= bh);
+
+ return !(ah <= bl || bh <= al);
+}
+
+#endif /* GDBSUPPORT_RANGE_H */
--
2.47.2
next prev parent reply other threads:[~2025-06-23 16:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 16:09 [RFC v5 00/19] Add Python "JIT" API Jan Vrany
2025-06-23 16:09 ` Jan Vrany [this message]
2025-06-24 15:22 ` [RFC v5 01/18] gdb: introduce expand_symtabs_maybe_overlapping Tom Tromey
2025-06-26 15:05 ` Jan Vraný
2025-06-23 16:09 ` [RFC v5 02/18] gdb: introduce compunit_symtab::maybe_contains Jan Vrany
2025-06-23 16:09 ` [RFC v5 03/18] gdb: update is_addr_in_objfile to support "dynamic" objfiles Jan Vrany
2025-06-23 16:09 ` [RFC v5 04/18] gdb: introduce new function create_function_type Jan Vrany
2025-06-24 15:29 ` Tom Tromey
2025-06-26 11:12 ` Jan Vraný
2025-06-27 14:21 ` Tom Tromey
2025-06-27 14:30 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 05/18] gdb/python: add function () method to gdb.Type object Jan Vrany
2025-06-24 16:11 ` Tom Tromey
2025-06-26 11:13 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 06/18] gdb: use std::vector<> to hold on blocks in struct blockvector Jan Vrany
2025-06-23 16:10 ` [RFC v5 07/18] gdb/python: add gdb.Compunit Jan Vrany
2025-06-23 16:10 ` [RFC v5 08/18] gdb/python: allow instantiation of gdb.Objfile from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 09/18] gdb/python: add unlink () method to gdb.Objfile object Jan Vrany
2025-06-23 16:10 ` [RFC v5 10/18] gdb/python: allow instantiation of gdb.Compunit from Python Jan Vrany
2025-06-23 16:10 ` [RFC v5 11/18] gdb/python: allow instantiation of gdb.Symtab " Jan Vrany
2025-06-23 16:10 ` [RFC v5 12/18] gdb/python: allow instantiation of gdb.Block " Jan Vrany
2025-06-23 16:10 ` [RFC v5 13/18] gdb/python: allow instantiation of gdb.Symbol " Jan Vrany
2025-06-23 16:10 ` [RFC v5 14/18] gdb/python: add add_symbol () method to gdb.Block Jan Vrany
2025-08-29 14:10 ` Andrew Burgess
2025-08-29 14:14 ` Andrew Burgess
2025-06-23 16:10 ` [RFC v5 15/18] gdb/python: add more attributes to gdb.LinetableEntry objects Jan Vrany
2025-08-29 14:00 ` Andrew Burgess
2025-09-02 11:03 ` Jan Vraný
2025-06-23 16:10 ` [RFC v5 16/18] gdb/python: allow instantiation of gdb.LineTableEntry objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 17/18] gdb/python: allow instantiation of gdb.LineTable objects Jan Vrany
2025-06-23 16:10 ` [RFC v5 18/18] gdb/python: add section in documentation on implementing JIT interface Jan Vrany
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=20250623161013.650814-2-jan.vrany@labware.com \
--to=jan.vrany@labware.com \
--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