ianlancetaylor / libbacktrace

A C library that may be linked into a C/C++ program to produce symbolic backtraces
Other
971 stars 228 forks source link

libbacktrace giving only relative path, even when absolute path is available in DWARF information #97

Closed the-shank closed 1 year ago

the-shank commented 1 year ago

Thanks for the wonderful library!

I am facing an issue wherein libbacktrace is providing only relative paths, despite absolute paths being available in the dwarf information:

For example, here is the relevant section from llvm-dwarfdump output for a particular binary that I built locally. image

And here is the backtrace produced using backtrace_full: image

Is there a way to have libbacktrace provide absolute filenames?

ianlancetaylor commented 1 year ago

libbacktrace doesn't look at DW_AT_decl_file. It gets the file name from the line header. I'm not sure off-hand how to see that information using llvm-dwarfdump. With readelf you can see it using readelf --debug=line. Look for the "File Name Table".

the-shank commented 1 year ago

Thanks for the quick response: This is the file name table I am gettting using readelf --debug=line <binary> image

Does this in any way convey that the paths in the backtrace (using libbacktrace) would be relative?

Edit: I think the dir corresponding to the dir number is what would be prepended to the filename. image

It might be too basic a question, but what step would I have to take during compilation so that the dir does not become relative? If you can point me in the correct direction, it would be a great help. Thanks.

ianlancetaylor commented 1 year ago

I would guess that you are executing something like $CC src/core/fxfont.cpp and that is probably where the directory entry is coming from. You could try using an absolute path there.

In any case this doesn't seem like a bug in libbacktrace, so closing.