mirror of
https://github.com/ModOrganizer2/mob.git
synced 2026-07-27 14:07:05 -07:00
fixed terminate handler never being called
ripped error message from uibase
This commit is contained in:
+4
-4
@@ -280,10 +280,10 @@ parsed_option parse_option(const std::string& s)
|
||||
"bad option {}, must be [task:]section/key=value", s);
|
||||
}
|
||||
|
||||
std::string task = trim_copy(m[1]);
|
||||
std::string section = trim_copy(m[2]);
|
||||
std::string key = trim_copy(m[3]);
|
||||
std::string value = trim_copy(m[4]);
|
||||
std::string task = trim_copy(m[1].str());
|
||||
std::string section = trim_copy(m[2].str());
|
||||
std::string key = trim_copy(m[3].str());
|
||||
std::string value = trim_copy(m[4].str());
|
||||
|
||||
return {task, section, key, value};
|
||||
}
|
||||
|
||||
+27
-3
@@ -112,10 +112,34 @@ std::string prefix(context::reason r)
|
||||
return std::string(total, ' ');
|
||||
}
|
||||
|
||||
std::string error_message(DWORD e)
|
||||
std::string error_message(DWORD id)
|
||||
{
|
||||
return std::error_code(
|
||||
static_cast<int>(e), std::system_category()).message();
|
||||
wchar_t* message = nullptr;
|
||||
|
||||
const auto ret = FormatMessageW(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
id,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPWSTR>(&message),
|
||||
0, NULL);
|
||||
|
||||
std::wstring s;
|
||||
|
||||
std::wostringstream oss;
|
||||
oss << L"0x" << std::hex << id;
|
||||
|
||||
if (ret == 0 || !message) {
|
||||
s = oss.str();
|
||||
} else {
|
||||
s = trim_copy(message) + L" (" + oss.str() + L")";
|
||||
}
|
||||
|
||||
LocalFree(message);
|
||||
|
||||
return utf16_to_utf8(s);
|
||||
}
|
||||
|
||||
std::string timestamp()
|
||||
|
||||
+42
-6
@@ -24,13 +24,15 @@ static unsigned char sym_buffer[sizeof(SYMBOL_INFOW) + max_name_length];
|
||||
static SYMBOL_INFOW* sym = (SYMBOL_INFOW*)sym_buffer;
|
||||
static wchar_t exception_message[exception_message_length + 1] = {};
|
||||
|
||||
static LPTOP_LEVEL_EXCEPTION_FILTER g_previous_handler = nullptr;
|
||||
|
||||
void dump_stacktrace(const wchar_t* what)
|
||||
{
|
||||
std::scoped_lock lock(g_output_mutex);
|
||||
|
||||
std::wcerr
|
||||
<< L"\n\n*****************************\n"
|
||||
<< "\n\nmob has crashed\n"
|
||||
<< L"*****************************\n\n"
|
||||
<< what << L"\n\n";
|
||||
|
||||
|
||||
@@ -43,7 +45,7 @@ void dump_stacktrace(const wchar_t* what)
|
||||
SymInitializeW(process, NULL, TRUE);
|
||||
|
||||
const std::size_t frame_count = CaptureStackBackTrace(
|
||||
3, max_frames, frame_addresses, nullptr);
|
||||
0, max_frames, frame_addresses, nullptr);
|
||||
|
||||
for (std::size_t i=0; i<frame_count; ++i)
|
||||
{
|
||||
@@ -144,8 +146,15 @@ const wchar_t* error_code_name(DWORD code)
|
||||
default: return L"unknown exception" ;
|
||||
}
|
||||
}
|
||||
|
||||
LONG WINAPI unhandled_exception_handler(LPEXCEPTION_POINTERS ep) noexcept
|
||||
{
|
||||
if (ep->ExceptionRecord->ExceptionCode == 0xE06D7363)
|
||||
{
|
||||
if (g_previous_handler)
|
||||
return g_previous_handler(ep);;
|
||||
}
|
||||
|
||||
wchar_t* p = exception_message;
|
||||
std::size_t remaining = exception_message_length;
|
||||
|
||||
@@ -172,8 +181,10 @@ LONG WINAPI unhandled_exception_handler(LPEXCEPTION_POINTERS ep) noexcept
|
||||
|
||||
void set_thread_exception_handlers()
|
||||
{
|
||||
g_previous_handler = SetUnhandledExceptionFilter(
|
||||
mob::unhandled_exception_handler);
|
||||
|
||||
std::set_terminate(mob::terminate_handler);
|
||||
SetUnhandledExceptionFilter(mob::unhandled_exception_handler);
|
||||
}
|
||||
|
||||
|
||||
@@ -343,7 +354,8 @@ std::vector<std::string> split(const std::string& s, const std::string& seps)
|
||||
return v;
|
||||
}
|
||||
|
||||
void trim(std::string& s, const std::string& what)
|
||||
template <class C>
|
||||
void trim_impl(std::basic_string<C>& s, std::basic_string_view<C> what)
|
||||
{
|
||||
while (!s.empty())
|
||||
{
|
||||
@@ -356,13 +368,37 @@ void trim(std::string& s, const std::string& what)
|
||||
}
|
||||
}
|
||||
|
||||
std::string trim_copy(const std::string& s, const std::string& what)
|
||||
template <class C>
|
||||
std::basic_string<C> trim_copy_impl(
|
||||
std::basic_string_view<C> s, std::basic_string_view<C> what)
|
||||
{
|
||||
std::string c = s;
|
||||
std::basic_string<C> c(s);
|
||||
trim(c, what);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
void trim(std::string& s, std::string_view what)
|
||||
{
|
||||
trim_impl(s, what);
|
||||
}
|
||||
|
||||
void trim(std::wstring& s, std::wstring_view what)
|
||||
{
|
||||
trim_impl(s, what);
|
||||
}
|
||||
|
||||
std::string trim_copy(std::string_view s, std::string_view what)
|
||||
{
|
||||
return trim_copy_impl(s, what);
|
||||
}
|
||||
|
||||
std::wstring trim_copy(std::wstring_view s, std::wstring_view what)
|
||||
{
|
||||
return trim_copy_impl(s, what);
|
||||
}
|
||||
|
||||
|
||||
std::string pad_right(std::string s, std::size_t n, char c)
|
||||
{
|
||||
if (s.size() < n)
|
||||
|
||||
+5
-2
@@ -237,8 +237,11 @@ std::vector<std::string> split(const std::string& s, const std::string& sep);
|
||||
std::string pad_right(std::string s, std::size_t n, char c=' ');
|
||||
std::string pad_left(std::string s, std::size_t n, char c=' ');
|
||||
|
||||
void trim(std::string& s, const std::string& what=" \t\r\n");
|
||||
std::string trim_copy(const std::string& s, const std::string& what=" \t\r\n");
|
||||
void trim(std::string& s, std::string_view what=" \t\r\n");
|
||||
void trim(std::wstring& s, std::wstring_view what=L" \t\r\n");
|
||||
|
||||
std::string trim_copy(std::string_view s, std::string_view what=" \t\r\n");
|
||||
std::wstring trim_copy(std::wstring_view s, std::wstring_view what=L" \t\r\n");
|
||||
|
||||
std::wstring utf8_to_utf16(std::string_view s);
|
||||
std::string utf16_to_utf8(std::wstring_view ws);
|
||||
|
||||
Reference in New Issue
Block a user