mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 04:52:59 +01:00
Implement a safer version of GetCrashInfoFromException (#3652)
* Implement a safer version of GetCrashInfoFromException `abi::__cxa_current_exception_type()` can return `null`, handle this properly * Update src/stacktraces.cpp Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> * Update src/stacktraces.cpp Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com> Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
This commit is contained in:
parent
4414b5c3c7
commit
bd5c047e28
@ -690,32 +690,34 @@ crash_info GetCrashInfoFromException(const std::exception_ptr& e)
|
||||
std::string type;
|
||||
std::string what;
|
||||
|
||||
auto getExceptionType = [&]() -> std::string {
|
||||
auto type = abi::__cxa_current_exception_type();
|
||||
if (type && (strlen(type->name()) > 0)) {
|
||||
return DemangleSymbol(type->name());
|
||||
}
|
||||
return "<unknown>";
|
||||
};
|
||||
|
||||
try {
|
||||
// rethrow and catch the exception as there is no other way to reliably cast to the real type (not possible with RTTI)
|
||||
std::rethrow_exception(e);
|
||||
} catch (const std::exception& e) {
|
||||
type = abi::__cxa_current_exception_type()->name();
|
||||
type = getExceptionType();
|
||||
what = GetExceptionWhat(e);
|
||||
} catch (const std::string& e) {
|
||||
type = abi::__cxa_current_exception_type()->name();
|
||||
type = getExceptionType();
|
||||
what = GetExceptionWhat(e);
|
||||
} catch (const char* e) {
|
||||
type = abi::__cxa_current_exception_type()->name();
|
||||
type = getExceptionType();
|
||||
what = GetExceptionWhat(e);
|
||||
} catch (int e) {
|
||||
type = abi::__cxa_current_exception_type()->name();
|
||||
type = getExceptionType();
|
||||
what = GetExceptionWhat(e);
|
||||
} catch (...) {
|
||||
type = abi::__cxa_current_exception_type()->name();
|
||||
type = getExceptionType();
|
||||
what = "<unknown>";
|
||||
}
|
||||
|
||||
if (type.empty()) {
|
||||
type = "<unknown>";
|
||||
} else {
|
||||
type = DemangleSymbol(type);
|
||||
}
|
||||
|
||||
ci.crashDescription += strprintf("type=%s, what=\"%s\"", type, what);
|
||||
|
||||
auto stackframes = GetExceptionStacktrace(e);
|
||||
|
Loading…
Reference in New Issue
Block a user