Commit 2b99b21b authored by Kenny Yu's avatar Kenny Yu Committed by Facebook GitHub Bot

add symbolizer::getStackTrace to replace detail::getSingletonStackTrace

Summary:
Currently, `getSingletonStackTrace` is in the logically private `detail`
namespace. This adds `symbolizer::getStackTrace` to replace `detail::getSingletonStackTrace`,
and this new location mirrors the existing `symbolizer::getAsyncStackTrace`.

The changes will be done in multiple parts:
- Add the new version
- Modify all internal callers to use the new version
- Delete the old version

Reviewed By: yfeldblum

Differential Revision: D33783972

fbshipit-source-id: 137a1d654aea5a451bb90ca12e1916f91589b0df
parent c24b947e
...@@ -400,6 +400,33 @@ void SafeStackTracePrinter::printStackTrace(bool symbolize) { ...@@ -400,6 +400,33 @@ void SafeStackTracePrinter::printStackTrace(bool symbolize) {
} }
} }
std::string getStackTraceStr() {
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
// Get and symbolize stack trace
constexpr size_t kMaxStackTraceDepth = 100;
FrameArray<kMaxStackTraceDepth> addresses;
if (!getStackTrace(addresses)) {
return "";
} else {
symbolizer::ElfCache elfCache;
symbolizer::Symbolizer symbolizer(&elfCache);
symbolizer.symbolize(addresses);
symbolizer::StringSymbolizePrinter printer;
printer.println(addresses);
return printer.str();
}
#else
return "";
#endif // FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
}
std::string getAsyncStackTraceStr() { std::string getAsyncStackTraceStr() {
#if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF #if FOLLY_HAVE_ELF && FOLLY_HAVE_DWARF
......
...@@ -243,6 +243,15 @@ class SafeStackTracePrinter { ...@@ -243,6 +243,15 @@ class SafeStackTracePrinter {
std::unique_ptr<FrameArray<kMaxStackTraceDepth>> addresses_; std::unique_ptr<FrameArray<kMaxStackTraceDepth>> addresses_;
}; };
/**
* Gets the stack trace for the current thread and returns a string
* representation. Convenience function meant for debugging and logging.
* Empty string indicates stack trace functionality is not available.
*
* NOT async-signal-safe.
*/
std::string getStackTraceStr();
/** /**
* Gets the async stack trace for the current thread and returns a string * Gets the async stack trace for the current thread and returns a string
* representation. Convenience function meant for debugging and logging. * representation. Convenience function meant for debugging and logging.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment