2016-04-21 20:57:36 -05:00
|
|
|
// 25 february 2015
|
2016-04-23 20:38:51 -05:00
|
|
|
#include "uipriv_windows.hpp"
|
2016-04-21 20:57:36 -05:00
|
|
|
|
2016-05-22 17:37:53 -05:00
|
|
|
// LONGTERM disable logging and stopping on no-debug builds
|
2016-04-21 20:57:36 -05:00
|
|
|
|
2016-04-23 21:15:33 -05:00
|
|
|
static void printDebug(const WCHAR *msg)
|
2016-04-21 20:57:36 -05:00
|
|
|
{
|
|
|
|
OutputDebugStringW(msg);
|
|
|
|
}
|
|
|
|
|
2016-04-23 21:15:33 -05:00
|
|
|
HRESULT _logLastError(debugargs, const WCHAR *s)
|
2016-04-21 20:57:36 -05:00
|
|
|
{
|
|
|
|
DWORD le;
|
|
|
|
WCHAR *msg;
|
|
|
|
WCHAR *formatted;
|
|
|
|
BOOL useFormatted;
|
|
|
|
|
|
|
|
le = GetLastError();
|
|
|
|
|
|
|
|
useFormatted = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, le, 0, (LPWSTR) (&formatted), 0, NULL) != 0;
|
|
|
|
if (!useFormatted)
|
|
|
|
formatted = L"\n";
|
2016-05-13 21:05:02 -05:00
|
|
|
msg = strf(L"[libui] %s:%s:%s() %s: GetLastError() == %I32u %s",
|
2016-04-21 20:57:36 -05:00
|
|
|
file, line, func,
|
|
|
|
s, le, formatted);
|
|
|
|
if (useFormatted)
|
|
|
|
LocalFree(formatted); // ignore error
|
2016-05-13 21:05:02 -05:00
|
|
|
printDebug(msg);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(msg);
|
2016-04-21 20:57:36 -05:00
|
|
|
DebugBreak();
|
|
|
|
|
|
|
|
SetLastError(le);
|
|
|
|
// a function does not have to set a last error
|
|
|
|
// if the last error we get is actually 0, then HRESULT_FROM_WIN32(0) will return S_OK (0 cast to an HRESULT, since 0 <= 0), which we don't want
|
|
|
|
// prevent this by returning E_FAIL
|
|
|
|
if (le == 0)
|
|
|
|
return E_FAIL;
|
|
|
|
return HRESULT_FROM_WIN32(le);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT _logHRESULT(debugargs, const WCHAR *s, HRESULT hr)
|
|
|
|
{
|
|
|
|
WCHAR *msg;
|
|
|
|
WCHAR *formatted;
|
|
|
|
BOOL useFormatted;
|
|
|
|
|
|
|
|
useFormatted = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, 0, (LPWSTR) (&formatted), 0, NULL) != 0;
|
|
|
|
if (!useFormatted)
|
|
|
|
formatted = L"\n";
|
2016-05-13 21:05:02 -05:00
|
|
|
msg = strf(L"[libui] %s:%s:%s() %s: HRESULT == 0x%08I32X %s",
|
2016-04-21 20:57:36 -05:00
|
|
|
file, line, func,
|
|
|
|
s, hr, formatted);
|
|
|
|
if (useFormatted)
|
|
|
|
LocalFree(formatted); // ignore error
|
2016-05-13 21:05:02 -05:00
|
|
|
printDebug(msg);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(msg);
|
2016-04-21 20:57:36 -05:00
|
|
|
DebugBreak();
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-04-15 20:46:08 -05:00
|
|
|
void uiprivRealBug(const char *file, const char *line, const char *func, const char *prefix, const char *format, va_list ap)
|
2016-04-21 20:57:36 -05:00
|
|
|
{
|
2016-05-13 21:05:02 -05:00
|
|
|
va_list ap2;
|
|
|
|
char *msg;
|
|
|
|
size_t n;
|
|
|
|
WCHAR *final;
|
2016-04-21 20:57:36 -05:00
|
|
|
|
2016-05-13 21:05:02 -05:00
|
|
|
va_copy(ap2, ap);
|
|
|
|
n = _vscprintf(format, ap2);
|
|
|
|
va_end(ap2);
|
2016-05-13 21:53:56 -05:00
|
|
|
n++; // terminating '\0'
|
2016-04-21 20:57:36 -05:00
|
|
|
|
2018-04-15 17:12:58 -05:00
|
|
|
msg = (char *) uiprivAlloc(n * sizeof (char), "char[]");
|
2016-05-13 21:53:56 -05:00
|
|
|
// includes terminating '\0' according to example in https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx
|
2016-05-13 21:05:02 -05:00
|
|
|
vsprintf_s(msg, n, format, ap);
|
2016-04-21 20:57:36 -05:00
|
|
|
|
2016-05-13 21:05:02 -05:00
|
|
|
final = strf(L"[libui] %hs:%hs:%hs() %hs%hs\n", file, line, func, prefix, msg);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(msg);
|
2016-05-13 21:05:02 -05:00
|
|
|
printDebug(final);
|
2018-04-15 17:12:58 -05:00
|
|
|
uiprivFree(final);
|
2016-04-21 20:57:36 -05:00
|
|
|
|
|
|
|
DebugBreak();
|
|
|
|
}
|