void show_stackframe() {
std::cout << "Show stack frame function from Abseil." << std::endl;
void *trace[100];
int i, trace_size = 0;
trace_size = absl::GetStackTrace(trace, 100, 0);
printf("[bt] Execution path: %d\n", trace_size);
for (i=0; i<trace_size; ++i)
{
printf("[bt] %s\n", (char*)trace[i]);
}
}
I was using this function get stacktrace at a certain point in a large code base. I know for a fact that the point at which I am trying to get stacktrace at is at 10 function calls deep(Previously I caused a segmentation fault at this point and I looked the stack trace using GDB.) However I am getting no stack-trace back at all. I.e. the trace_size that Abseil is returning back is 0. Why is this not working?
Is it because the point at which I am trying to obtain a stack-trace is inside a thread? Does this not work in a multithreaded environment?
absl::GetStackTrace only return the code address(program counter), it's not the function name, so you cannot do printf("%s") stuff as if it's a string. To convert code address to function name, you need something like Symbolize, code from https://clickhouse.com/codebrowser/ClickHouse/contrib/abseil-cpp/absl/debugging/symbolize_elf.inc.html#_ZN4absl12lts_202111029SymbolizeEPKvPci: