Add file and line info to backtraces under Linux#1354
Add file and line info to backtraces under Linux#1354MartinNowak merged 3 commits intodlang:masterfrom
Conversation
|
That would be important, stack traces must not use the GC. |
I think the order should be It would be great to abbreviate the demangled names somehow (@ibuclaw any idea?), but it's not part of this PR. |
src/rt/backtrace/dwarf.d
Outdated
There was a problem hiding this comment.
char[1024] symbolBuffer = void
|
Great! This is a step in the right direction.
@MartinNowak, to abbreviate the demangled names we can use:
And omit:
With my and your proposed changes it should look something like this: std.format.FormatException@/home/administrator/Projects/d-devel/phobos/std/format.d(487): Orphan format specifier: %s
----------------
/home/administrator/Projects/d-devel/phobos/std/exception.d:589 enforceEx!(std.format.FormatException, bool)(..) [0x432c37]
/home/administrator/Projects/d-devel/phobos/std/format.d:487 formattedWrite!(std.array.Appender!(immutable(char)[]), char)(..) [0x430089]
/home/administrator/Projects/d-devel/phobos/std/format.d:6548 format!(char)(..) [0x42faf3]
foo/bar.d:9 f1!(main.main().__lambda1(int))(..) [0x42fa92]
foo/bar.d:19 f2!(main.main().__lambda1(int))(..) [0x4382bc]
foo/bar.d:13 f1!(main.main().__lambda1(int))(..) [0x42faa4]
foo/bar.d:19 f2!(main.main().__lambda1(int))(..) [0x4382bc]
foo/bar.d:13 f1!(main.main().__lambda1(int))(..) [0x42faa4]
main.d:10 _Dmain [0x42fa65]Additionally, we can pretty print the backtrace by:
For example: in package main (./):
at main:10 _Dmain(..) [0x42fa65]
in package foo (./foo):
at bar:13 f1!(..)(..) [0x42faa4] instanciated with: (main().__lambda1(int))
at bar:19 f2!(..)(..) [0x4382bc] instanciated with: (main().__lambda1(int))
at bar:13 f1!(..)(..) [0x42faa4] instanciated with: (main().__lambda1(int))
at bar:19 f2!(..)(..) [0x4382bc] instanciated with: (main().__lambda1(int))
at bar:9 f1!(..)(..) [0x42fa92] instanciated with: (main().__lambda1(int))
in package std (/home/administrator/Projects/d-devel/phobos/std):
at format:6548: format!(..)(..) [0x42faf3] instanciated with: (char)
at format:487: formattedWrite!(..)(..) [0x430089] instanciated with: (std.array.Appender!(immutable(char)[]), char)
at exception:6548: enforceEx!(..)(..) [0x432c37] instanciated with: (std.format.FormatException, bool)
-------------------
std.format.FormatException@/usr/include/dmd/phobos/std/format.d(487): Orphan format specifier: %sI want to work on this (and this is totally outside the scope of this PR), but I won't be able to probably until mid-September. Should I add myself to the trello card? |
|
updated
|
|
I wanted to abbreviate function names but I don't know of a way to do it easily. |
That one is a false friend. What you want is to hightlight the filename and line number to quickly open that in your editor, e.g. |
|
Grouping by package sounds nice but might not work well in callback heavy code. |
Omit the return type and attributes from the demangle would be a start. Can core.demangle even do that? Not sure about abbreviating templates, but it sounds like could turn into an art form. |
So be it, but the ideas above already look great, and it's also a useful functionality to have for core.demangle. |
|
@yazd, do you need help with the tests or anything else? |
|
I am good. But I do wonder if I should version out all of the code for the other OS'es. |
Might want to put a |
|
Adding |
Ah right, forgot about that detail ;-). |
|
I have added a test and I needed to use sed to make the diff not depend on the addresses (is there a problem with depending on sed?). The test works on 64-bit, but not on 32-bit as there seems to be a bug in resolving addresses under 32-bit. I will download a 32-bit distro and test under a VM tomorrow night. |
Just as a side note, you can overload opApply for different delegates or templatize the function and let the compiler infer @nogc and nothrow.
You can simply do |
|
All green. Let me squash the commits once the review is done. |
We already rely on |
src/core/runtime.d
Outdated
There was a problem hiding this comment.
No need to make FIRSTFRAME a template parameter, simply traceHandlerOpApplyImpl!(true)(callstack[FIRSTFRAME .. min(FIRSTFRAME, numframes)], dg); should work as well.
src/rt/backtrace/dwarf.d
Outdated
There was a problem hiding this comment.
This could probably use the return value of snprintf instead of searching for the null terminator?
|
Updates:
|
|
And always enabled using |
|
Please do not merge. I have found a bug in resolving the addresses. |
OK, the rest LGTM. |
|
Fixed bug + all green. |
|
Anything left to address? |
|
Sorry for the delay, been busy with the betas. |
|
No problem. Take your time. |
|
It's a lot nicer than what we have currently but it's still far from a readable stracktrace. |
|
Works nicely. |
Add file and line info to backtraces under Linux
|
Oh, of course we should mention that in the changelog, see #1387. |
fixup #1354 - add changelog entry for backtraces
|
Thanks for the review. I will work on adding FreeBSD support in the next few days. |
Nice, let me know if you need help. |
|
I've just pushed a FreeBSD follow up PR: #1399. |
Add file and line info to backtraces under Linux
Add file and line info to backtraces under Linux
This work provides file and line info by reading the DWARF debug section
.debug_lineand resolving the stacktrace addresses.Example stacktrace output on exception when program is compiled with
-g:vs
-L--export-dynamiclinker option is still needed to provide the function names. Otherwise only file and line number are shown.TODOs:
@complexmath, I added your name in authors field as I copied some code from rt/runtime.d.
@MartinNowak, you were interested in this.
Please review freely and if you see any possible enhancements, I will work on them.
Edit: updated output from stacktrace to (file:line function [addr])