[binutils-gdb] gdb: change find_pcs_for_symtab_line() to return entries instead of PCs
Jan Vrany
jv@sourceware.org
Thu Oct 23 19:41:08 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1fc36f02cd627894f0726e1801cc148ab3952e93
commit 1fc36f02cd627894f0726e1801cc148ab3952e93
Author: Jan Vrany <jan.vrany@labware.com>
Date: Thu Oct 23 20:39:44 2025 +0100
gdb: change find_pcs_for_symtab_line() to return entries instead of PCs
This commit changes find_pcs_for_symtab_line() to return complete
linetable entries instead of just PCs. This is a preparation for adding
more attributes to gdb.LinetableEntry objects.
I also renamed the function to find_linetable_entries_for_symtab_line()
to better reflect what it does.
Approved-By: Tom Tromey <tom@tromey.com>
Diff:
---
gdb/linespec.c | 11 ++++++-----
gdb/python/py-linetable.c | 23 ++++++++++++++---------
gdb/symtab.c | 11 +++++------
gdb/symtab.h | 2 +-
4 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/gdb/linespec.c b/gdb/linespec.c
index 459f1371de2..b7ddd166c8a 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -3958,23 +3958,24 @@ decode_digits_ordinary (struct linespec_state *self,
std::vector<symtab_and_line> sals;
for (const auto &elt : ls->file_symtabs)
{
- std::vector<CORE_ADDR> pcs;
+ std::vector<const linetable_entry *> pcs;
/* The logic above should ensure this. */
gdb_assert (elt != NULL);
- program_space *pspace = elt->compunit ()->objfile ()->pspace ();
+ objfile *objfile = elt->compunit ()->objfile ();
+ program_space *pspace = objfile->pspace ();
set_current_program_space (pspace);
- pcs = find_pcs_for_symtab_line (elt, line, best_entry);
- for (CORE_ADDR pc : pcs)
+ pcs = find_linetable_entries_for_symtab_line (elt, line, best_entry);
+ for (auto linetable_entry : pcs)
{
symtab_and_line sal;
sal.pspace = pspace;
sal.symtab = elt;
sal.line = line;
sal.explicit_line = true;
- sal.pc = pc;
+ sal.pc = linetable_entry->pc (objfile);
sals.push_back (std::move (sal));
}
}
diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c
index f575305ed94..663260056d8 100644
--- a/gdb/python/py-linetable.c
+++ b/gdb/python/py-linetable.c
@@ -117,22 +117,25 @@ build_linetable_entry (int line, CORE_ADDR address)
address. */
static PyObject *
-build_line_table_tuple_from_pcs (int line, const std::vector<CORE_ADDR> &pcs)
+build_line_table_tuple_from_entries
+ (const struct objfile *objfile,
+ const std::vector<const linetable_entry *> &entries)
{
int i;
- if (pcs.size () < 1)
+ if (entries.size () < 1)
Py_RETURN_NONE;
- gdbpy_ref<> tuple (PyTuple_New (pcs.size ()));
+ gdbpy_ref<> tuple (PyTuple_New (entries.size ()));
if (tuple == NULL)
return NULL;
- for (i = 0; i < pcs.size (); ++i)
+ for (i = 0; i < entries.size (); ++i)
{
- CORE_ADDR pc = pcs[i];
- gdbpy_ref<> obj (build_linetable_entry (line, pc));
+ auto entry = entries[i];
+ gdbpy_ref<> obj (build_linetable_entry
+ (entry->line, entry->pc (objfile)));
if (obj == NULL)
return NULL;
@@ -153,7 +156,7 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
struct symtab *symtab;
gdb_py_longest py_line;
const linetable_entry *best_entry = nullptr;
- std::vector<CORE_ADDR> pcs;
+ std::vector<const linetable_entry*> entries;
LTPY_REQUIRE_VALID (self, symtab);
@@ -162,14 +165,16 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args)
try
{
- pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry);
+ entries = find_linetable_entries_for_symtab_line (symtab, py_line,
+ &best_entry);
}
catch (const gdb_exception &except)
{
return gdbpy_handle_gdb_exception (nullptr, except);
}
- return build_line_table_tuple_from_pcs (py_line, pcs);
+ struct objfile *objfile = symtab->compunit ()->objfile ();
+ return build_line_table_tuple_from_entries (objfile, entries);
}
/* Implementation of gdb.LineTable.has_line (self, line) -> Boolean.
diff --git a/gdb/symtab.c b/gdb/symtab.c
index e65744bea23..2b54d245b86 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -3343,13 +3343,12 @@ done:
exactly match LINE. Returns an empty vector if there are no exact
matches, but updates BEST_ITEM in this case. */
-std::vector<CORE_ADDR>
-find_pcs_for_symtab_line (struct symtab *symtab, int line,
- const linetable_entry **best_item)
+std::vector<const linetable_entry *>
+find_linetable_entries_for_symtab_line (struct symtab *symtab, int line,
+ const linetable_entry **best_item)
{
int start = 0;
- std::vector<CORE_ADDR> result;
- struct objfile *objfile = symtab->compunit ()->objfile ();
+ std::vector<const linetable_entry *> result;
/* First, collect all the PCs that are at this line. */
while (1)
@@ -3373,7 +3372,7 @@ find_pcs_for_symtab_line (struct symtab *symtab, int line,
break;
}
- result.push_back (symtab->linetable ()->item[idx].pc (objfile));
+ result.push_back (&symtab->linetable ()->item[idx]);
start = idx + 1;
}
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 6049d60a5dc..985843f76b6 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -2802,7 +2802,7 @@ bool compare_glob_filenames_for_search (const char *filename,
void iterate_over_symtabs (program_space *pspace, const char *name,
gdb::function_view<bool (symtab *)> callback);
-std::vector<CORE_ADDR> find_pcs_for_symtab_line
+std::vector<const linetable_entry *> find_linetable_entries_for_symtab_line
(struct symtab *symtab, int line, const linetable_entry **best_entry);
/* Prototype for callbacks for LA_ITERATE_OVER_SYMBOLS. The callback
More information about the Gdb-cvs
mailing list