Added more robust debugger logging to the Windows backend, PROPERLY this time.

This commit is contained in:
Pietro Gagliardi 2015-06-09 12:38:06 -04:00
parent daa9a42e46
commit a105522e0a
3 changed files with 59 additions and 13 deletions

View File

@ -15,6 +15,7 @@ osCFILES = \
windows/group.c \
windows/init.c \
windows/label.c \
windows/logging.c \
windows/main.c \
windows/menu.c \
windows/parent.c \

58
redo/windows/logging.c Normal file
View File

@ -0,0 +1,58 @@
// 9 june 2015
#include "uipriv_windows.h"
// We can't use the private heap for these functions, since they are allowed to be run before uiInit() or after uiUninit().
static void nomemlog(void)
{
OutputDebugStringW(L"[libui] memory exhausted logging message");
DebugBreak();
abort(); // just in case
}
void uiLog(const char *format, ...)
{
va_list ap;
va_start(ap, format);
uiLogv(format, ap);
va_end(ap);
}
void uiLogv(const char *format, va_list ap)
{
va_list ap2;
int n;
char *buf;
va_copy(ap2, ap);
n = _vscprintf(format, ap2);
va_end(ap2);
// "[libui] message\0" == (8 + n + 1)
buf = (char *) malloc((8 + n + 1)
if (buf == NULL)
nomemlog();
buf[0] = '[';
buf[1] = 'l';
buf[2] = 'i';
buf[3] = 'b';
buf[4] = 'u';
buf[5] = 'i';
buf[6] = ']';
buf[7] = ' ';
vsnprintf_s(buf + 8, n + 1, n, format, ap);
// breaking the rules: we can't reliably tell that the encoding of debugging messages is UTF-8 like we could with everything else :/
OutputDebugStringA(buf);
free(buf);
}
void complain(const char *format, ...)
{
va_list ap;
va_start(ap, format);
uiLogv(format, av);
va_end(ap);
DebugBreak();
abort(); // just in case
}

View File

@ -34,19 +34,6 @@ int windowClassOf(HWND hwnd, ...)
return -1;
}
void complain(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
fprintf(stderr, "[libui] ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
va_end(ap);
DebugBreak();
abort(); // just in case
}
// wrapper around MapWindowRect() that handles the complex error handling
void mapWindowRect(HWND from, HWND to, RECT *r)
{