'Abseil's GetStackTrace function returns back nothing

    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?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source