2 * Copyright 2015-present Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <folly/portability/Config.h>
19 #ifdef FOLLY_USE_SYMBOLIZER
20 #include <folly/Singleton.h>
21 #include <folly/experimental/symbolizer/Symbolizer.h> // @manual
27 std::string stackTraceGetter() {
28 // Get and symbolize stack trace
29 constexpr size_t kMaxStackTraceDepth = 100;
30 symbolizer::FrameArray<kMaxStackTraceDepth> addresses;
32 if (!getStackTraceSafe(addresses)) {
35 constexpr size_t kDefaultCapacity = 500;
36 symbolizer::ElfCache elfCache(kDefaultCapacity);
38 symbolizer::Symbolizer symbolizer(&elfCache);
39 symbolizer.symbolize(addresses);
41 symbolizer::StringSymbolizePrinter printer;
42 printer.println(addresses);
47 struct SetStackTraceGetter {
48 SetStackTraceGetter() {
49 SingletonVault::stackTraceGetter().store(stackTraceGetter);
54 // OS X doesn't support constructor priorities.
55 SetStackTraceGetter setStackTraceGetter;
57 SetStackTraceGetter __attribute__((__init_priority__(101))) setStackTraceGetter;