diff --git a/include/validator.hpp b/include/validator.hpp index 3f037df..9099772 100644 --- a/include/validator.hpp +++ b/include/validator.hpp @@ -55,6 +55,9 @@ class Validator std::optional demangle(const char* mangled); std::optional get_symbol(std::string_view name); + bool check_thrown_functions(std::string_view func_name); + std::vector find_thrown_functions(); + enum class CorrelateError { NoTypeinfoForFunction, // Validator has no typeinfo for this function diff --git a/src/main.cpp b/src/main.cpp index b45daec..e578515 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -42,7 +42,7 @@ enum class main_error : uint8_t */ struct arg_value_s { - std::string_view file_name; + std::string file_name; std::optional flag; }; @@ -128,6 +128,11 @@ int main(int argc, char* argv[]) return EXIT_FAILURE; } + for (const auto& f : val.find_thrown_functions()) { + std::println("throws: {}", + val.demangle(f.name.c_str()).value_or(f.name)); + } + // we print it but we canremove this for (const auto& m : res.value()) { auto dn = val.demangle(m.thrown.name.c_str()).value_or(m.thrown.name); diff --git a/src/validator.cpp b/src/validator.cpp index 5fbe381..590d6d2 100644 --- a/src/validator.cpp +++ b/src/validator.cpp @@ -198,4 +198,32 @@ Validator::Result Validator::analyze_exceptions(std::string_view func_name) cons return result; } +bool Validator::check_thrown_functions(std::string_view func_name) +{ + auto thrown_opt = find_typeinfo(func_name); + return thrown_opt.has_value() && !thrown_opt->empty(); +} + +std::vector Validator::find_thrown_functions() +{ + std::vector out; + + for (const auto& s : m_sym) { + // Only consider real functions + if (GELF_ST_TYPE(s.info) != STT_FUNC) { + continue; + } + // skip undefined / external stubs if you want + if (s.shndx == SHN_UNDEF) { + continue; + } + + if (check_thrown_functions(s.name)) { + out.push_back(s); + } + } + + return out; +} + } // namespace safe