digitalmars.D.announce - line numbers for linux exception traces
- Adam D. Ruppe (59/59) Aug 05 2015 If you just download this little file:
- Adam D. Ruppe (6/6) Aug 05 2015 Oh also a note about addr2line's output on my computer at least:
- Martin Nowak (5/11) Aug 05 2015 There already is http://code.dlang.org/packages/backtrace-d.
- Colin (4/7) Aug 06 2015 This is v nice - thanks!
- Martin Nowak (4/6) Aug 07 2015 It's not too complex to implement in the *runtime*. The code already
- Martin Nowak (3/4) Aug 07 2015 Here is that card in our backlog btw.
- Martin Nowak (3/5) Aug 07 2015 I also opened an ER to collect some ideas for nicer backtraces.
If you just download this little file: http://arsdnet.net/dcode/linetrace.d and add it to your build, when compiling in debug mode, it will translate the addresses into line numbers (by simply piping out to addr2line on the command line) No modification to your program is required. before: dmd yourapp.d -g object.Exception x.d(4): test ---------------- ./x(_Dmain+0xb) [0x808276b] ./x(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x12) [0x809215a] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80920d0] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x809211f] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80920d0] ./x(_d_run_main+0x166) [0x8092066] ./x(main+0x14) [0x8085b9c] /lib/libc.so.6(__libc_start_main+0xf3) [0xf7321773] after: dmd yourapp.d linetrace.d -g object.Exception x.d(4): test ---------------- ./x(void x.t()+0x3e) [/home/me/test/x.d:5] ./x(_Dmain+0xb) [/home/me/test/x.d:11] ./x(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x12) [0x80b993a] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80b98b0] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x27) [0x80b98ff] ./x(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x18) [0x80b98b0] ./x(_d_run_main+0x166) [0x80b9846] ./x(main+0x14) [0x80ac71c] /lib/libc.so.6(__libc_start_main+0xf3) [0xf7318773] Notice the line numbers on the first two lines. I also added a -version=hide_names that will cut out the function names (and the druntime lines) with the logic being that the line number in your own code is probably the most relevant part to you anyway and you don't need any distractiions: dmd yourapp.d linetrace.d -g -version=hide_names object.Exception x.d(4): test ---------------- /home/me/test/x.d:5 /home/me/test/x.d:11 My code isn't too complex: it wraps the default handler then manipulates the string using plain phobos techniques. Inefficient surely, but since the program is probably dying anyway when this is called, I don't mind it. addr2line does need to be available on the system for this to work though. If it isn't, the old address behavior should still work. I suspect this will also work on other posix systems but I haven't tried. But the simple code there ought to be easy enough for you to customize to your liking too.
Aug 05 2015
Oh also a note about addr2line's output on my computer at least: it prints the line of the *next* instruction after the function call, which can be a few lines away sometimes. But still, close enough: go to the line it references then look immediately before it and you should see the function call referred to in the stack trace.
Aug 05 2015
On Wednesday, 5 August 2015 at 15:57:46 UTC, Adam D. Ruppe wrote:If you just download this little file: http://arsdnet.net/dcode/linetrace.d and add it to your build, when compiling in debug mode, it will translate the addresses into line numbers (by simply piping out to addr2line on the command line) No modification to your program is required.There already is http://code.dlang.org/packages/backtrace-d. And there exists even an ELF based backtrace, but I'm still waiting for someone to polish it for druntime. https://issues.dlang.org/show_bug.cgi?id=11870
Aug 05 2015
On Wednesday, 5 August 2015 at 15:57:46 UTC, Adam D. Ruppe wrote:If you just download this little file: http://arsdnet.net/dcode/linetrace.d [...]This is v nice - thanks! I wonder how difficult implementing this in the compiler would be? Obviously cant use external tools...
Aug 06 2015
On 08/06/2015 05:32 PM, Colin wrote:I wonder how difficult implementing this in the compiler would be? Obviously cant use external tools...It's not too complex to implement in the *runtime*. The code already exists, someone just needs to remove the phobos dependencies. https://github.com/yazd/elf-d
Aug 07 2015
On 08/07/2015 08:00 PM, Martin Nowak wrote:On 08/06/2015 05:32 PM, Colin wrote:Here is that card in our backlog btw. https://trello.com/c/FbuWfpVE/13-backtraces-with-line-numbers
Aug 07 2015
On 08/06/2015 05:32 PM, Colin wrote:I wonder how difficult implementing this in the compiler would be? Obviously cant use external tools...I also opened an ER to collect some ideas for nicer backtraces. https://issues.dlang.org/show_bug.cgi?id=14885
Aug 07 2015