]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: change find_pcs_for_symtab_line() to return entries instead of PCs
authorJan Vrany <jan.vrany@labware.com>
Thu, 23 Oct 2025 19:39:44 +0000 (20:39 +0100)
committerJan Vrany <jan.vrany@labware.com>
Thu, 23 Oct 2025 19:39:44 +0000 (20:39 +0100)
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>
gdb/linespec.c
gdb/python/py-linetable.c
gdb/symtab.c
gdb/symtab.h

index 459f1371de2537a00141dbcb475102625560fb3f..b7ddd166c8ac3255bcce301982665ca1179774ce 100644 (file)
@@ -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));
        }
     }
index f575305ed946d04fead9e9a0f4b4f51a57a81c23..663260056d8bcfc620f5983e288aa4fec201e222 100644 (file)
@@ -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.
index e65744bea23356312b57cb0abca198deebc74208..2b54d245b86a5ec7342926029ab5351426cb33e2 100644 (file)
@@ -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;
     }
 
index 6049d60a5dc1add9aa94b4638583e6227d48537f..985843f76b650643d54347b64e357c20ed50555a 100644 (file)
@@ -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