|
10 | 10 | */ |
11 | 11 | #include <expected> |
12 | 12 | #include <filesystem> |
| 13 | +#include <iostream> |
13 | 14 | #include <print> |
14 | 15 | #include <span> |
15 | 16 | #include <string> |
16 | 17 | #include <string_view> |
17 | 18 | #include <tuple> |
18 | | -#include <vector> |
19 | 19 | #include <unordered_set> |
20 | | -#include <iostream> |
21 | | -#include <string> |
| 20 | +#include <vector> |
22 | 21 |
|
23 | 22 | #include "abi_parse.hpp" |
24 | 23 | #include "elf_parser.hpp" |
@@ -122,24 +121,42 @@ int main(int argc, char* argv[]) |
122 | 121 | // Load LSDA catch table into Validator |
123 | 122 | val.load_lsda(lsda); |
124 | 123 |
|
125 | | - auto res = val.analyze_exceptions("_Z3fooi"); |
126 | | - if (!res.has_value()) { |
127 | | - std::print("analyze_exceptions failed\n"); |
128 | | - return EXIT_FAILURE; |
129 | | - } |
130 | | - |
131 | | - for (const auto& f : val.find_thrown_functions()) { |
132 | | - std::println("throws: {}", |
133 | | - val.demangle(f.name.c_str()).value_or(f.name)); |
| 124 | + std::println("======================================="); |
| 125 | + std::println("Function that can throw: "); |
| 126 | + std::println("======================================="); |
| 127 | + std::vector<symbol_s> callsite_function = val.find_thrown_functions(); |
| 128 | + for (const auto& func : callsite_function) { |
| 129 | + std::println(" {}", |
| 130 | + val.demangle(func.name.c_str()).value_or(func.name)); |
134 | 131 | } |
135 | 132 |
|
| 133 | + std::println("======================================="); |
| 134 | + std::println("Catch Sites: "); |
| 135 | + std::println("======================================="); |
136 | 136 | // we print it but we canremove this |
137 | | - for (const auto& m : res.value()) { |
138 | | - auto dn = val.demangle(m.thrown.name.c_str()).value_or(m.thrown.name); |
139 | | - std::print("Thrown: {}\n", dn); |
140 | | - for (auto* h : m.handlers) { |
141 | | - std::print(" caught by {} type_index={}\n", h->scope_id, h->type_index); |
| 137 | + for (const auto& func : callsite_function) { |
| 138 | + std::println("Function: {}", func.name); |
| 139 | + |
| 140 | + auto caught_throws = val.analyze_exceptions(func.name); |
| 141 | + if (!caught_throws.has_value()) { |
| 142 | + std::print("analyze_exceptions failed\n"); |
| 143 | + return EXIT_FAILURE; |
| 144 | + } |
| 145 | + |
| 146 | + for (auto& caught_throw : caught_throws.value()) { |
| 147 | + symbol_s caught_throw_obj = caught_throw.thrown; |
| 148 | + std::string caught_throw_name |
| 149 | + = val.demangle(caught_throw_obj.name.c_str()) |
| 150 | + .value_or(caught_throw_obj.name); |
| 151 | + std::println("\tThrows: {}", caught_throw_name); |
| 152 | + auto callsite_handlers = caught_throw.handlers; |
| 153 | + for (auto& handler : callsite_handlers) { |
| 154 | + std::print("\t\t* caught by {}\n\t\t* type_index={}\n", |
| 155 | + handler->scope_id, |
| 156 | + handler->type_index); |
| 157 | + } |
142 | 158 | } |
| 159 | + std::println("---------------------------------------"); |
143 | 160 | } |
144 | 161 |
|
145 | 162 | return 0; |
|
0 commit comments