Thread overview
Stack trace linux/windows why the difference
Jul 21, 2014
Trass3r
Jul 22, 2014
deadalnix
July 21, 2014
Hello !

When getting runtime errors the stack trace on terminal is a lot confuse and hard to work with simple tools like scite text editor, also there is a difference between windows/linux, windows get a bit better/clean stack trace and includes line numbers, where is this info generated to try improve it ?

Chhers !

=========windows
D:\tutorial>dmd -gs -gc testStackTrace.d

D:\tutorial>testStackTrace.exe
finally: func2
object.Exception@testStackTrace.d(12): on func2
----------------
0x004020E4 in void testStackTrace.func2() at D:\tutorial\testStackTrace.d(12)
0x0040210C in void testStackTrace.func3() at D:\tutorial\testStackTrace.d(18)
0x00402118 in _Dmain at D:\tutorial\testStackTrace.d(22)
0x00403188 in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().void __lambda1()
0x0040315B in void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()
0x00403074 in _d_run_main
0x00402A98 in main
0x00419C91 in mainCRTStartup
0x7598A55E in BaseThreadInitThunk
0x77E48F03 in RtlInitializeExceptionChain
0x77E48ED9 in RtlInitializeExceptionChain
=========
=========linux
$:~/dev/d/tutorial$ dmd -gs -gc testStackTrace.d
$:~/dev/d/tutorial$ ./testStackTrace
finally: func2
object.Exception@testStackTrace.d(12): on func2
----------------
./testStackTrace(void testStackTrace.func3()+0x9) [0x434ef1]
./testStackTrace(_Dmain+0x9) [0x434f01]
./testStackTrace(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f) [0x438a4f]
./testStackTrace(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x4389a2]
./testStackTrace(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x30) [0x438a08]
./testStackTrace(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x4389a2]
./testStackTrace(_d_run_main+0x193) [0x438923]
./testStackTrace(main+0x25) [0x435acd]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed) [0x7f9227bfe76d]
=========

=========testStackTrace.d
import std.stdio;

void func1()
{
	//int x, z = 2/x;
}

void func2()
{
	try { func1(); }
	catch(Exception e) { writeln("catch %s", e.msg);}
	finally {writeln("finally: func2"); throw new Exception("on func2");}
}

void func3()
{
	func2();
}

void main()
{
	func3();
}
=========
July 21, 2014
After writing this post I found the place and the why:
- druntime/src/core/runtime.d
- Window implementation has extra code that search for more info to display
- Linux only make calls to execinfo functions and dump what it gets

On linux more work should be done to get line infos, I'm investigating how to get then.

Cheers !
July 21, 2014
> On linux more work should be done to get line infos, I'm investigating how to get then.
>
> Cheers !

That's the spirit!
July 22, 2014
On Monday, 21 July 2014 at 21:06:54 UTC, Domingo Alvarez Duarte
wrote:
> After writing this post I found the place and the why:
> - druntime/src/core/runtime.d
> - Window implementation has extra code that search for more info to display
> - Linux only make calls to execinfo functions and dump what it gets
>
> On linux more work should be done to get line infos, I'm investigating how to get then.
>
> Cheers !

Worth looking at:
https://github.com/bombela/backward-cpp
July 22, 2014
On Tuesday, 22 July 2014 at 00:00:11 UTC, deadalnix wrote:
> Worth looking at:
> https://github.com/bombela/backward-cpp

Thanks for the link !

I also found this one interesting http://blog.bigpixel.ro/2010/09/stack-unwinding-stack-trace-with-gcc/ .

Cheers !

July 22, 2014
On 7/21/14, 2:06 PM, Domingo Alvarez Duarte wrote:
> On linux more work should be done to get line infos, I'm investigating
> how to get then.

That would be awesome! -- Andrei
July 22, 2014
Trying to implement something on druntime.d I can see that what's availlable there is the bare minimum we can not include anything from phobos.

And when thre is a need to find/search on strings it's done by libc raw functions.

So we have some nice facilities on phobos but can not use.

Life would not be easier if some basic high level functions move to runtime ?

July 23, 2014
Today I found that the Tango library have code that scand the executable to find function lines, but I could not get it to show all functions yet.

Maybe the author of it "Fawzi Mohamed" are still around here and can explain/fix that implementation.