diff options
author | Simon Farre <simon.farre.cx@gmail.com> | 2025-03-03 18:53:12 +0100 |
---|---|---|
committer | Simon Farre <simon.farre.cx@gmail.com> | 2025-03-03 18:53:12 +0100 |
commit | 58539c5f76d4afa25d1b775b29fa00acdb2de578 (patch) | |
tree | e7721c21ed24724d6c2451aeae1ed16fd09f80e8 /gdb | |
parent | f96ad03c0e6c2440f30d9fe7e1215ff0c2a61f2a (diff) | |
download | binutils-58539c5f76d4afa25d1b775b29fa00acdb2de578.zip binutils-58539c5f76d4afa25d1b775b29fa00acdb2de578.tar.gz binutils-58539c5f76d4afa25d1b775b29fa00acdb2de578.tar.bz2 |
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 <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/python/py-breakpoint.c | 25 |
1 files changed, 22 insertions, 3 deletions
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 <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); |