folly::symbolizer::SafeStackTracePrinter

Use this class to print a stack trace from a signal handler, or other place where you shouldn't allocate memory on the heap, and fsync()ing your file descriptor is more important than performance.

Synopsis

Declared in <folly/debugging/symbolizer/Symbolizer.h>

class SafeStackTracePrinter;

Description

Make sure to create one of these on startup, not in the signal handler, as the constructor allocates on the heap, whereas the other methods don't. Best practice is to just leak this object, rather than worry about destruction order.

These methods aren't thread safe, so if you could have signals on multiple threads at the same time, you need to do your own locking to ensure you don't call these methods from multiple threads. They are signal safe, however.

Member Functions

NameDescription
SafeStackTracePrinter [constructor]Construct a printer that writes to the given file descriptor.
~SafeStackTracePrinter [destructor] [virtual]Virtual destructor.
flush Flush printer_, also fsync, in case we're about to crash again.
print Print a string to the underlying printer.
printStackTrace Only allocates on the stack and is signal-safe but not thread-safe. Don't call printStackTrace() on the same StackTracePrinter object from multiple threads at the same time.

Protected Member Functions

NameDescription
printSymbolizedStackTrace [virtual]Symbolize the captured frames and print them.
printUnsymbolizedStackTrace Print the captured frames without symbolizing them.