Printing C++ stack traces

How do we get C++ to print stack traces? I’m getting the following error from ProcessGroupNCCL.cpp

vector::_M_range_check: __n (which is 1044) >= this->size() (which is 0)

Doing TORCH_SHOW_CPP_STACKTRACES=1 doesn’t help print the stack trace.

You can use the built-in GNU backtrace mechanism:

export TORCH_SHOW_CPP_STACKTRACES=1
export TORCH_CPP_DEBUG=1

I still don’t get anything. Particularly, this is the error.

[ProcessGroupNCCL.cpp:2092] Process group watchdog thread terminated with exception: vector::_M_range_check: __n (which is 1049) >= this->size() (which is 0)

The code only prints what() on the exception. And no stack trace gets printed, just the error message.