[idd] debug: full Unicode handling and log as UTF-8

This commit makes `CDebug` use Unicode internally instead of whatever
random code page is in use. It also gets rid of the horrible character
counting and replaces that with `vasprintf` and `vaswprintf` helpers
(partially inspired by Linux) which allocates a buffer.

For HRESULT logging, the error code in both hex and decimal are included.

The output is now guaranteed to be UTF-8.
This commit is contained in:
Quantum
2025-09-14 04:42:21 -04:00
committed by Geoffrey McRae
parent e2bc1856b6
commit daa78bcf47
4 changed files with 203 additions and 122 deletions

View File

@@ -1,4 +1,4 @@
/**
/**
* Looking Glass
* Copyright © 2017-2025 The Looking Glass Authors
* https://looking-glass.io
@@ -27,7 +27,7 @@ class CDebug
{
private:
std::ofstream m_stream;
void Write(const char * line);
void Write(const wchar_t *line);
public:
@@ -44,22 +44,18 @@ class CDebug
LEVEL_MAX
};
void Init(const char * name);
void Log_va(CDebug::Level level, const char* function, int line, const char* fmt, va_list args);
void Log(CDebug::Level level, const char * function, int line, const char * fmt, ...);
void LogHR(CDebug::Level level, HRESULT hr, const char* function, int line, const char* fmt, ...);
void Init(const wchar_t * name);
void Log_va(CDebug::Level level, const char *function, int line, const wchar_t *fmt, va_list args);
void Log(CDebug::Level level, const char *function, int line, const wchar_t *fmt, ...);
void Log_va(CDebug::Level level, const char *function, int line, const char *fmt, va_list args);
void Log(CDebug::Level level, const char *function, int line, const char *fmt, ...);
void LogHR(CDebug::Level level, HRESULT hr, const char *function, int line, const char *fmt, ...);
void LogHR(CDebug::Level level, HRESULT hr, const char *function, int line, const wchar_t *fmt, ...);
private:
const char* m_levelStr[LEVEL_MAX] =
{
" ",
"I",
"W",
"E",
"T",
"!",
"F"
};
void LogStr(CDebug::Level level, const char *function, int line, bool wide, const void *str);
void LogStrHR(CDebug::Level level, HRESULT hr, const char *function, int line, bool wide, const void *str);
static const char *s_levelStr[LEVEL_MAX];
};
extern CDebug g_debug;