Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/validator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class Validator
std::optional<std::string> demangle(const char* mangled);
std::optional<symbol_s> get_symbol(std::string_view name);

bool check_thrown_functions(std::string_view func_name);
std::vector<symbol_s> find_thrown_functions();

enum class CorrelateError
{
NoTypeinfoForFunction, // Validator has no typeinfo for this function
Expand Down
7 changes: 6 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string_view> flag;
};

Expand Down Expand Up @@ -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);
Expand Down
28 changes: 28 additions & 0 deletions src/validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<symbol_s> Validator::find_thrown_functions()
{
std::vector<symbol_s> 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