Add VS trace function

VS OutputDebugString doesn't support %hh* %ll*, so let vsnprint handle it then write a simple string to debug console.
The purpose of this is that its faster than writing logs to a file. (Only when debugging with VS tho).

This can be enabled by defining preprocessor: VS_TRACE_DEBUG
This commit is contained in:
Nemirtingas 2019-07-14 22:53:43 +02:00
parent 0677b8e2ff
commit ba23e904ad
2 changed files with 41 additions and 0 deletions

View file

@ -18,6 +18,42 @@
#include "base.h"
#ifdef STEAM_WIN32
#ifndef EMU_RELEASE_BUILD
#ifdef VS_TRACE_DEBUG
#include <cstdio>
// Visual Studio doesn't seem to support hh* or ll* in OutputDebugString
// So process it before sending it to debug console
bool _trace(const char* format, ...)
{
constexpr const int len = 1024; // Initial buffer size, hope it is big enought, we will exapnd it if not.
int res;
char *buffer = new char[len];
va_list argptr;
va_start(argptr, format);
res = vsnprintf(buffer, len, format, argptr);
va_end(argptr);
if (res >= len)
{
delete[]buffer;
// Now we are sure we have enought free space to contain the string
buffer = new char[++res];
va_start(argptr, format);
vsnprintf(buffer, res, format, argptr);
va_end(argptr);
}
OutputDebugString(buffer);
delete[]buffer;
return true;
}
#endif // VS_TRACE_DEBUG
#endif // EMU_RELEASE_BUILD
#include <windows.h>
#include <direct.h>

View file

@ -44,7 +44,12 @@
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
#define PATH_SEPARATOR "\\"
#ifndef EMU_RELEASE_BUILD
#ifdef VS_TRACE_DEBUG
bool _trace(const char* format, ...);
#define PRINT_DEBUG(FMT, ...) _trace(FMT, ##__VA_ARGS__)
#else // VS_TRACE_DEBUG
#define PRINT_DEBUG(a, ...) do {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t); WSASetLastError(0);} while (0)
#endif // VS_TRACE_DEBUG
#endif
#else
#include <arpa/inet.h>