#include <iostream>
#define BOOST_STACKTRACE_USE_ADDR2LINE
#include <boost/stacktrace.hpp>
void my_func_2(void) {
std::cout << boost::stacktrace::stacktrace() << std::endl;
}
void my_func_1(double f) {
(void)f;
my_func_2();
}
void my_func_1(int i) {
(void)i;
my_func_2();
}
int main(int argc, char **argv) {
long long unsigned int n;
if (argc > 1) {
n = strtoul(argv[1], NULL, 0);
} else {
n = 1;
}
for (long long unsigned int i = 0; i < n; ++i) {
my_func_1(1); // line 28
my_func_1(2.0); // line 29
}
}
# g++ backtrace.cpp -ldl
# ./a.out
0# my_func_2() in ./a.out
1# my_func_1(int) in ./a.out
2# main in ./a.out
3# __libc_start_main in /usr/lib64/libc.so.6
4# _start in ./a.out
0# my_func_2() in ./a.out
1# my_func_1(double) in ./a.out
2# main in ./a.out
3# __libc_start_main in /usr/lib64/libc.so.6
4# _start in ./a.out