[v1,gdb/python] Bploc should try to return full path
Checks
Context |
Check |
Description |
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_build--master-arm |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_gdb_check--master-arm |
success
|
Test passed
|
Commit Message
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.
---
gdb/python/py-breakpoint.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
Simon Farre <simon.farre.cx@gmail.com> writes:
> 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.
I think some of this code is showing its pre-C++ origins, but I wonder
if you'd be better using symtab_to_fullname() instead of accessing
symtab::fullname() directly?
It's not entirely clear, but I think, this will always return
non-nullptr, and will have set symtab::fullname() if needed.
Thanks,
Andrew
@@ -1643,9 +1643,10 @@ 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);
+ const char *full = self->bp_loc->symtab->fullname ();
+ gdbpy_ref<> filename = full != nullptr
+ ? host_string_to_python_string (full)
+ : host_string_to_python_string (self->bp_loc->symtab->filename);
if (filename == nullptr)
return nullptr;
auto line = gdb_py_object_from_ulongest (self->bp_loc->line_number);