diff --git a/include/private/vkd3d_debug.h b/include/private/vkd3d_debug.h index ebedcb61..5a14678f 100644 --- a/include/private/vkd3d_debug.h +++ b/include/private/vkd3d_debug.h @@ -34,6 +34,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_level level, const char *function, const char *fmt, ...) VKD3D_PRINTF_FUNC(3, 4) DECLSPEC_HIDDEN; const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2) DECLSPEC_HIDDEN; +const char *debugstr_a(const char *str) DECLSPEC_HIDDEN; const char *debugstr_w(const WCHAR *wstr) DECLSPEC_HIDDEN; #define VKD3D_DBG_LOG(level) \ diff --git a/libs/vkd3d-common/debug.c b/libs/vkd3d-common/debug.c index 7c08b5e6..b71e0540 100644 --- a/libs/vkd3d-common/debug.c +++ b/libs/vkd3d-common/debug.c @@ -103,6 +103,66 @@ const char *vkd3d_dbg_sprintf(const char *fmt, ...) return buffer; } +const char *debugstr_a(const char *str) +{ + char *buffer, *ptr; + char c; + + if (!str) + return "(null)"; + + ptr = buffer = get_buffer(); + + *ptr++ = '"'; + while ((c = *str++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 8) + { + int escape_char; + + switch (c) + { + case '"': + case '\\': + case '\n': + case '\r': + case '\t': + escape_char = c; + break; + default: + escape_char = 0; + break; + } + + if (escape_char) + { + *ptr++ = '\\'; + *ptr++ = escape_char; + continue; + } + + if (isprint(c)) + { + *ptr++ = c; + } + else + { + *ptr++ = '\\'; + sprintf(ptr, "%02x", c); + ptr += 2; + } + } + *ptr++ = '"'; + + if (c) + { + *ptr++ = '.'; + *ptr++ = '.'; + *ptr++ = '.'; + } + *ptr = '\0'; + + return buffer; +} + const char *debugstr_w(const WCHAR *wstr) { char *buffer, *ptr;