I want to print a stacktrace from my C++/CUDA code. The code I have is:
#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>
#include <iostream>
#include <string>
void nested_n(int depth){
if(depth<20){
nested_n(depth+1);
} else {
std::cout << boost::stacktrace::stacktrace() << std::endl;
}
}
void nested3(){ nested_n(0); }
void nested2(){ nested3(); }
void nested1(){ nested2(); }
int main(){
nested1();
return 0;
}
When I compile this with clang using
clang++ -g main.cpp -lboost_stacktrace_basic -ldl
I get a nice stacktrace:
0# basic_stacktrace at /usr/include/boost/stacktrace/stacktrace.hpp:128
1# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
2# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
3# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
4# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
5# nested_n(int) at /home/rick/projects/facebook/cuda_assertion_stack/main.cpp:9
...
But, when I compile with NVCC using
nvcc -g main.cpp -lboost_stacktrace_basic -ldl
I get an un-nice stacktrace:
0# 0x0000561CD50E6EB6 in ./a.out
1# 0x0000561CD50E6E75 in ./a.out
2# 0x0000561CD50E6E75 in ./a.out
3# 0x0000561CD50E6E75 in ./a.out
4# 0x0000561CD50E6E75 in ./a.out
5# 0x0000561CD50E6E75 in ./a.out
...
How can I get a nice stacktrace from NVCC?
(I'm on Cuda compilation tools, release 11.2, V11.2.152
with gcc (Ubuntu 10.3.0-1ubuntu1) 10.3.0
as a host compiler running on Ubuntu 21.04 with Boost 1.74.)