]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Bploc should try to return full path
authorSimon Farre <simon.farre.cx@gmail.com>
Mon, 3 Mar 2025 17:53:12 +0000 (18:53 +0100)
committerSimon Farre <simon.farre.cx@gmail.com>
Mon, 3 Mar 2025 17:53:12 +0000 (18:53 +0100)
Compilers often emit relative paths in the line number program,
relative to the build directory for that compilation unit (if it's
DWARF>=4 I think).

Therefore use symtab->fullname() when not null as this seemingly
has attempted path normalization for the symtab and only
fall back on symtab->filename which will never be null if that fails.

This has a much better UX. Applications may choose to expose
this name as a clickable link to some file, at which point
a non-normalized and non-absolute path would lead nowhere.

When I wrote this feature the first time, I don't think this
relative-to-cu-scheme was as prevalent in the output of gcc/clang
for DWARF.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/py-breakpoint.c

index 75f50e1f423e613510643b6303c754a8b55b44f5..882b825f6820f21125d4708eaaac871ef1679503 100644 (file)
@@ -17,6 +17,7 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
+#include "source.h"
 #include "value.h"
 #include "python-internal.h"
 #include "python.h"
@@ -1629,6 +1630,26 @@ bplocpy_get_owner (PyObject *py_self, void *closure)
   return (PyObject *) self->owner;
 }
 
+/* Attempt to get fully resolved file path for symtab.  */
+
+static gdbpy_ref<>
+bploc_filepath (struct symtab *bploc_symtab)
+{
+  /* The exception is not ours to handle.  We should always
+     return some string value and filename is never null.  */
+  try
+    {
+      const char *full = symtab_to_fullname (bploc_symtab);
+      if (full)
+       return host_string_to_python_string (full);
+    }
+  catch (const gdb_exception &except)
+    {
+    }
+
+  return host_string_to_python_string (bploc_symtab->filename);
+}
+
 /* Python function to get the source file name path and line number
    where this breakpoint location was set.   */
 
@@ -1643,9 +1664,7 @@ bplocpy_get_source_location (PyObject *py_self, void *closure)
       gdbpy_ref<> tup (PyTuple_New (2));
       if (tup == nullptr)
        return nullptr;
-      /* symtab->filename is never NULL. */
-      gdbpy_ref<> filename
-       = host_string_to_python_string (self->bp_loc->symtab->filename);
+      gdbpy_ref<> filename = bploc_filepath (self->bp_loc->symtab);
       if (filename == nullptr)
        return nullptr;
       auto line = gdb_py_object_from_ulongest (self->bp_loc->line_number);