Hacker News new | ask | show | jobs
by lultimouomo 3884 days ago
On Unix segfaults by default don't generate stack traces. This makes it work on linux, don't know about OSX (put it in your main module):

  import etc.linux.memoryerror;
  
  shared static this() {
   	static if (is(typeof(registerMemoryErrorHandler)))
   		registerMemoryErrorHandler();
  }
1 comments

The handler works in a real ubuntu VM but not in docker (the image is probably missing glibc https://github.com/D-Programming-Language/druntime/blob/mast... so that explains "static if" in your snippet)

to be honest, it's better than nothing but still kinda difficult to work with:

  etc.linux.memoryerror.NullPointerError@src/etc/linux/memoryerror.d(325)
  ----------------
  ??:? void etc.linux.memoryerror.sigsegvUserspaceProcess(void*) [0x439045]
  ??:? void etc.linux.memoryerror.sigsegvDataHandler() [0x438f92]
  ??:? _Dmain [0x435c17]
  ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x4376da]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x437630]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x437696]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x437630]
  ??:? _d_run_main [0x43758d]
  ??:? main [0x436075]
  ??:? __libc_start_main [0xb0fa1ec4]
Are you using the new version and compiling with -g there? Those addresses should be translateable into line numbers.

You can also do it manually btw with `addr2line -e your_executable 0x435c17` and the sort.

Thanks, I tried again and it seems to be working:

  $ dmd -g main.d && ./main
  etc.linux.memoryerror.NullPointerError@src/etc/linux/memoryerror.d(325)
  ----------------
  ??:? void etc.linux.memoryerror.sigsegvUserspaceProcess(void*) [0x423321]
  ??:? void etc.linux.memoryerror.sigsegvDataHandler() [0x42326e]
  main.d:12 _Dmain [0x4204e5]
  ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x421b8a]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x421ae0]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x421b46]
  ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x421ae0]
  ??:? _d_run_main [0x421a3d]
  ??:? main [0x420597]
  ??:? __libc_start_main [0xdb825ec4]
this is linux, I use mac as development machine, what can I do for mac? is there a error handler for mac too?