Add a multi-type version of iterateSymbolsWithType
[folly.git] / folly / experimental / symbolizer / Elf-inl.h
index bd9b0a4029252332494027a9e7d147f3334d9640..3e2f4dcf3ba70a9f2d306c0d8e2e2dcb4b87b8f3 100644 (file)
@@ -97,5 +97,18 @@ const ElfSym* ElfFile::iterateSymbolsWithType(
   });
 }
 
+template <class Fn>
+const ElfSym* ElfFile::iterateSymbolsWithTypes(
+    const ElfShdr& section,
+    std::initializer_list<uint32_t> types,
+    Fn fn) const {
+  // N.B. st_info has the same representation on 32- and 64-bit platforms
+  return iterateSymbols(section, [&](const ElfSym& sym) -> bool {
+    auto const elfType = ELF32_ST_TYPE(sym.st_info);
+    auto const it = std::find(types.begin(), types.end(), elfType);
+    return it != types.end() && fn(sym);
+  });
+}
+
 } // namespace symbolizer
 } // namespace folly