fall back to .debug_info scan in fatal signal handler
[folly.git] / folly / experimental / symbolizer / Dwarf.h
index 87f9b175b20bcb7e06681708d0e31fd20f1da99d..192d0c0339fbbedb3a73c9be0e9e8c6085904a5d 100644 (file)
@@ -16,8 +16,7 @@
 
 // DWARF record parser
 
-#ifndef FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_
-#define FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_
+#pragma once
 
 #include <boost/variant.hpp>
 
@@ -101,22 +100,40 @@ class Dwarf {
     folly::StringPiece file_;
   };
 
-  struct LocationInfo {
-    LocationInfo() : hasMainFile(false), hasFileAndLine(false), line(0) { }
+  enum class LocationInfoMode {
+    // Don't resolve location info.
+    DISABLED,
+    // Perform CU lookup using .debug_aranges (might be incomplete).
+    FAST,
+    // Scan all CU in .debug_info (slow!) on .debug_aranges lookup failure.
+    FULL,
+  };
 
-    bool hasMainFile;
+  struct LocationInfo {
+    bool hasMainFile = false;
     Path mainFile;
 
-    bool hasFileAndLine;
+    bool hasFileAndLine = false;
     Path file;
-    uint64_t line;
+    uint64_t line = 0;
   };
 
-  /** Find the file and line number information corresponding to address */
-  bool findAddress(uintptr_t address, LocationInfo& info) const;
+  /**
+   * Find the file and line number information corresponding to address.
+   */
+  bool findAddress(uintptr_t address,
+                   LocationInfo& info,
+                   LocationInfoMode mode) const;
 
  private:
+  static bool findDebugInfoOffset(uintptr_t address,
+                                  StringPiece aranges,
+                                  uint64_t& offset);
+
   void init();
+  bool findLocation(uintptr_t address,
+                    StringPiece& infoEntry,
+                    LocationInfo& info) const;
 
   const ElfFile* elf_;
 
@@ -270,5 +287,3 @@ inline std::ostream& operator<<(std::ostream& out, const Dwarf::Path& path) {
 
 }  // namespace symbolizer
 }  // namespace folly
-
-#endif /* FOLLY_EXPERIMENTAL_SYMBOLIZER_DWARF_H_ */