Fix SignalHandlerTest with ASAN
[folly.git] / folly / experimental / symbolizer / Elf.h
index 48b5f8fb03d56d5ba0311376cf094ae3d21c231c..a4f5afd22553ca9045c2571bf5ff98b07dcdaf6e 100644 (file)
 #include <link.h> // For ElfW()
 
 #include <cstdio>
+#include <initializer_list>
 #include <stdexcept>
 #include <system_error>
 
 #include <folly/Conv.h>
 #include <folly/Likely.h>
 #include <folly/Range.h>
-#include <folly/SafeAssert.h>
+#include <folly/lang/SafeAssert.h>
 
 namespace folly {
 namespace symbolizer {
@@ -122,6 +123,14 @@ class ElfFile {
   template <class Fn>
   const char* iterateStrings(const ElfShdr& stringTable, Fn fn) const;
 
+  /**
+   * Iterate over program headers as long as fn(section) returns false.
+   * Returns a pointer to the current ("found") section when fn returned
+   * true, or nullptr if fn returned false for all sections.
+   */
+  template <class Fn>
+  const ElfPhdr* iterateProgramHeaders(Fn fn) const;
+
   /**
    * Iterate over all sections for as long as fn(section) returns false.
    * Returns a pointer to the current ("found") section when fn returned
@@ -131,12 +140,21 @@ class ElfFile {
   const ElfShdr* iterateSections(Fn fn) const;
 
   /**
-   * Iterate over all sections with a given type.  Similar to
+   * Iterate over all sections with a given type. Similar to
    * iterateSections(), but filtered only for sections with the given type.
    */
   template <class Fn>
   const ElfShdr* iterateSectionsWithType(uint32_t type, Fn fn) const;
 
+  /**
+   * Iterate over all sections with a given types. Similar to
+   * iterateSectionWithTypes(), but filtered on multiple types.
+   */
+  template <class Fn>
+  const ElfShdr* iterateSectionsWithTypes(
+      std::initializer_list<uint32_t> types,
+      Fn fn) const;
+
   /**
    * Iterate over all symbols witin a given section.
    *
@@ -148,6 +166,11 @@ class ElfFile {
   template <class Fn>
   const ElfSym*
   iterateSymbolsWithType(const ElfShdr& section, uint32_t type, Fn fn) const;
+  template <class Fn>
+  const ElfSym* iterateSymbolsWithTypes(
+      const ElfShdr& section,
+      std::initializer_list<uint32_t> types,
+      Fn fn) const;
 
   /**
    * Find symbol definition by address.