COMMUNITY

`CallStack.callStack()` always empty on cpp?

If I write a small program like this and compile it with cpp:

class Main {
  static public function main(): Void {
    trace('${haxe.CallStack.callstack()}');
  }
}

…then on cpp it always produces an empty array ([]). This is making it rather hard to debug things. Is there any compiler setting I need to enable to make this work? I’ve tried it with --debug both on and off.

This is with Haxe 4.1.3 on Debian Linux.

There is an hxcpp-debugger, if you can’t get your print debugging to work. https://github.com/HaxeFoundation/hxcpp-debugger. It has a command-line interface as well as IDE support.

Sadly, the debugger won’t help here — I need to capture the stack trace in logs.

I should add that I’m not getting stack traces when throwing an uncaught exception or when catching a haxe.Exception and looking a the stack field, either.

Ah — sorted! Turns out that adding --debug renames the output executable, so my build tool was picking up the old, non-debug version… oops.

Unfortunately I need stack traces in production builds, where running --debug isn’t an option. Is there any way to get them without --debug?

You can try to play with those defines:
HXCPP_STACK_TRACE Have valid function-level stack traces, even in release mode.
HXCPP_STACK_LINE Include line information in stack traces, even in release mode.

There are more in the manual, maybe you will find something suitable for your needs: