rocksdb/port
Peter Dillinger e17f31057b Support stack traces with gdb (and debugger invocation) (#11150)
Summary:
LIB_MODE=shared is much more efficient for building all the unit tests but comes with the downside of ugly stack traces, generally missing name demangling and source line info. Searching the internet suggests the reliable way to get stack traces with dynamic loading is with gdb.

This change automatically tries to use gdb to get a stack trace if built with LIB_MODE=shared, and only on Linux because that's where we have the capability to attach to the proper thread. (We could revise the exact conditions in the future.) If there's a failure invoking gdb, it falls back on the old method. Obscure details of making the output reasonable / pretty are in the source code comments.

Based on this, it was easy to make it so that running a test command with ROCKSDB_DEBUG=1 would invoke gdb whenever the stack trace handler was invoked, so I included that.

Intended follow-up: make LIB_MODE=shared the new default `make` build config

Pull Request resolved: https://github.com/facebook/rocksdb/pull/11150

Test Plan:
manual, mostly by injecting an "assert(false)" into a unit test and trying different build modes etc.

Although gdb is slower to start showing stack trace output, it seems overall faster in many if not most cases, presumably because it doesn't reload the symbol table for each stack entry. At least with parallel test runs, having many tests dumping stacks with the old method can take so long it appears to hang the test run.

Reviewed By: cbi42

Differential Revision: D42894064

Pulled By: pdillinger

fbshipit-source-id: 608143309d8c69c40049c9a4abcde4f22e87b4d8
2023-02-03 13:21:03 -08:00
..
win clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
jemalloc_helper.h
lang.h clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
likely.h clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
malloc.h
mmap.cc
mmap.h Fix include of windows.h in mmap.h (#10885) 2022-10-26 18:07:57 -07:00
port.h
port_dirent.h clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
port_example.h
port_posix.cc clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
port_posix.h support loongarch64 for rocksdb (#10036) 2023-01-13 08:42:44 -08:00
README
stack_trace.cc Support stack traces with gdb (and debugger invocation) (#11150) 2023-02-03 13:21:03 -08:00
stack_trace.h
sys_time.h clang format files under port/ (#10849) 2022-10-24 16:56:01 -07:00
util_logger.h
xpress.h

This directory contains interfaces and implementations that isolate the
rest of the package from platform details.

Code in the rest of the package includes "port.h" from this directory.
"port.h" in turn includes a platform specific "port_<platform>.h" file
that provides the platform specific implementation.

See port_posix.h for an example of what must be provided in a platform
specific header file.