fall back to .debug_info scan in fatal signal handler
[folly.git] / folly / experimental / symbolizer / Symbolizer.h
index d8060330fb9559f27640adf893507fb2661ab8f0..bd93c121f42195fe62aa2057991cd951797a3659 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2015 Facebook, Inc.
+ * Copyright 2016 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@
  * limitations under the License.
  */
 
-#ifndef FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_
-#define FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_
+#pragma once
 
 #include <array>
 #include <cstdint>
@@ -42,7 +41,10 @@ class Symbolizer;
 struct SymbolizedFrame {
   SymbolizedFrame() { }
 
-  void set(const std::shared_ptr<ElfFile>& file, uintptr_t address);
+  void set(const std::shared_ptr<ElfFile>& file,
+           uintptr_t address,
+           Dwarf::LocationInfoMode mode);
+
   void clear() { *this = SymbolizedFrame(); }
 
   bool found = false;
@@ -55,6 +57,7 @@ struct SymbolizedFrame {
   fbstring demangledName() const {
     return name ? demangle(name) : fbstring();
   }
+
  private:
   std::shared_ptr<ElfFile> file_;
 };
@@ -108,7 +111,14 @@ inline bool getStackTraceSafe(FrameArray<N>& fa) {
 
 class Symbolizer {
  public:
-  explicit Symbolizer(ElfCacheBase* cache = nullptr);
+  static constexpr Dwarf::LocationInfoMode kDefaultLocationInfoMode =
+      Dwarf::LocationInfoMode::FAST;
+
+  explicit Symbolizer(Dwarf::LocationInfoMode mode = kDefaultLocationInfoMode)
+    : Symbolizer(nullptr, mode) {}
+
+  explicit Symbolizer(ElfCacheBase* cache,
+                      Dwarf::LocationInfoMode mode = kDefaultLocationInfoMode);
 
   /**
    * Symbolize given addresses.
@@ -131,11 +141,12 @@ class Symbolizer {
   }
 
  private:
-  ElfCacheBase* const cache_ = nullptr;
+  ElfCacheBase* const cache_;
+  const Dwarf::LocationInfoMode mode_;
 };
 
 /**
- * Format one address in the way it's usually printer by SymbolizePrinter.
+ * Format one address in the way it's usually printed by SymbolizePrinter.
  * Async-signal-safe.
  */
 class AddressFormatter {
@@ -204,6 +215,9 @@ class SymbolizePrinter {
 
     // Colorize output only if output is printed to a TTY (ANSI escape code)
     COLOR_IF_TTY = 1 << 3,
+
+    // Skip frame address information
+    NO_FRAME_ADDRESS = 1 << 4,
   };
 
   // NOTE: enum values used as indexes in kColorMap.
@@ -295,5 +309,3 @@ class StringSymbolizePrinter : public SymbolizePrinter {
 
 }  // namespace symbolizer
 }  // namespace folly
-
-#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_SYMBOLIZER_H_ */