From 58539c5f76d4afa25d1b775b29fa00acdb2de578 Mon Sep 17 00:00:00 2001 From: Simon Farre Date: Mon, 3 Mar 2025 18:53:12 +0100 Subject: Bploc should try to return full path 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 --- gdb/python/py-breakpoint.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'gdb') diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 75f50e1..882b825 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -17,6 +17,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#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); -- cgit v1.1