Windows: log more descriptive errors

This commit is contained in:
Megamouse 2023-03-04 11:05:32 +01:00
parent 8409979dc5
commit 92ae57c9ee
8 changed files with 28 additions and 10 deletions

View file

@ -1783,7 +1783,7 @@ const std::string& fs::get_config_dir()
if (GetEnvironmentVariable(L"RPCS3_CONFIG_DIR", buf, size) - 1 >= size - 1 &&
GetModuleFileName(nullptr, buf, size) - 1 >= size - 1)
{
MessageBoxA(nullptr, fmt::format("GetModuleFileName() failed: error %u.", GetLastError()).c_str(), "fs::get_config_dir()", MB_ICONERROR);
MessageBoxA(nullptr, fmt::format("GetModuleFileName() failed: error: %s", fmt::win_error{GetLastError(), nullptr}).c_str(), "fs::get_config_dir()", MB_ICONERROR);
return dir; // empty
}
@ -1868,7 +1868,7 @@ const std::string& fs::get_temp_dir()
wchar_t buf[MAX_PATH + 2]{};
if (GetTempPathW(MAX_PATH + 1, buf) - 1 > MAX_PATH)
{
MessageBoxA(nullptr, fmt::format("GetTempPath() failed: error %u.", GetLastError()).c_str(), "fs::get_temp_dir()", MB_ICONERROR);
MessageBoxA(nullptr, fmt::format("GetTempPath() failed: error: %s", fmt::win_error{GetLastError(), nullptr}).c_str(), "fs::get_temp_dir()", MB_ICONERROR);
return dir; // empty
}

View file

@ -79,6 +79,17 @@ std::string fmt::win_error_to_string(unsigned long error, void* module_handle)
return message;
}
std::string fmt::win_error_to_string(const fmt::win_error& error)
{
return fmt::win_error_to_string(error.error, error.module_handle);
}
template <>
void fmt_class_string<fmt::win_error>::format(std::string& out, u64 arg)
{
fmt::append(out, "%s", fmt::win_error_to_string(get_object(arg)));
}
#endif
template <>

View file

@ -10,8 +10,15 @@ namespace fmt
static std::string format(const CharT(&)[N], const Args&...);
#ifdef _WIN32
struct win_error
{
unsigned long error{};
void* module_handle{};
};
// Get a string for a windows error (DWORD). Optionally a module HANDLE can be passed.
std::string win_error_to_string(unsigned long error, void* module_handle = nullptr);
std::string win_error_to_string(const win_error& error);
#endif
}

View file

@ -2710,7 +2710,7 @@ void thread_ctrl::detect_cpu_layout()
if (!GetLogicalProcessorInformationEx(relationship,
reinterpret_cast<SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *>(buffer.data()), &buffer_size))
{
sig_log.error("GetLogicalProcessorInformationEx failed (size=%u, error=%u)", buffer_size, GetLastError());
sig_log.error("GetLogicalProcessorInformationEx failed (size=%u, error=%s)", buffer_size, fmt::win_error{GetLastError(), nullptr});
}
else
{
@ -2957,7 +2957,7 @@ void thread_ctrl::set_native_priority(int priority)
if (!SetThreadPriority(_this_thread, native_priority))
{
sig_log.error("SetThreadPriority() failed: 0x%x", GetLastError());
sig_log.error("SetThreadPriority() failed: %s", fmt::win_error{GetLastError(), nullptr});
}
#else
int policy;
@ -3009,7 +3009,7 @@ void thread_ctrl::set_thread_affinity_mask(u64 mask)
HANDLE _this_thread = GetCurrentThread();
if (!SetThreadAffinityMask(_this_thread, !mask ? process_affinity_mask : mask))
{
sig_log.error("Failed to set thread affinity 0x%x: error 0x%x.", mask, GetLastError());
sig_log.error("Failed to set thread affinity 0x%x: error: %s", mask, fmt::win_error{GetLastError(), nullptr});
}
#elif __APPLE__
// Supports only one core