Skip to content

Commit

Permalink
Reformat sources
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoAnomaly committed Mar 15, 2018
1 parent a598ee0 commit d253625
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 68 deletions.
5 changes: 4 additions & 1 deletion src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ root = true
# 4 space indentation
[*.{cpp,h,hpp}]
indent_style = space
indent_size = 4
indent_size = 4

# newline ending every file
insert_final_newline = true
14 changes: 7 additions & 7 deletions src/xrCore/Threading/ScopeLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
#include "Threading/Lock.hpp"
#include "xrDebug.h"

class ScopeLock: Noncopyable
class ScopeLock : Noncopyable
{
public:
ScopeLock(Lock* SyncObject);
ScopeLock(Lock *SyncObject);
~ScopeLock();

private:
Lock * m_SyncObject;
Lock *syncObject;
};

ScopeLock::ScopeLock(Lock* SyncObject): m_SyncObject(SyncObject)
ScopeLock::ScopeLock(Lock *SyncObject) : syncObject(SyncObject)
{
VERIFY(m_SyncObject);
VERIFY(syncObject);

m_SyncObject->Enter();
syncObject->Enter();
}

ScopeLock::~ScopeLock()
{
m_SyncObject->Leave();
syncObject->Leave();
}
74 changes: 37 additions & 37 deletions src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ xrDebug::DialogHandler xrDebug::OnDialog = nullptr;
string_path xrDebug::BugReportFile;
bool xrDebug::ErrorAfterDialog = false;

bool xrDebug::m_SymEngineInitialized = false;
Lock xrDebug::m_DbgHelpLock;
bool xrDebug::symEngineInitialized = false;
Lock xrDebug::dbgHelpLock;

void xrDebug::SetBugReportFile(const char* fileName) { strcpy_s(BugReportFile, fileName); }
void xrDebug::SetBugReportFile(const char *fileName) { strcpy_s(BugReportFile, fileName); }

bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string& frameStr)
bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string &frameStr)
{
BOOL result = StackWalk(MACHINE_TYPE, GetCurrentProcess(), GetCurrentThread(), stackFrame, threadCtx, nullptr,
SymFunctionTableAccess, SymGetModuleBase, nullptr);
Expand Down Expand Up @@ -140,7 +140,7 @@ bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCt
/// Source info
///
DWORD dwLineOffset;
IMAGEHLP_LINE sourceInfo = { 0 };
IMAGEHLP_LINE sourceInfo = {};
sourceInfo.SizeOfStruct = sizeof(sourceInfo);

result = SymGetLineFromAddr(GetCurrentProcess(), stackFrame->AddrPC.Offset, &dwLineOffset, &sourceInfo);
Expand All @@ -164,36 +164,36 @@ bool xrDebug::GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCt

bool xrDebug::InitializeSymbolEngine()
{
if (!m_SymEngineInitialized)
if (!symEngineInitialized)
{
DWORD dwOptions = SymGetOptions();
SymSetOptions(dwOptions | SYMOPT_DEFERRED_LOADS | SYMOPT_LOAD_LINES | SYMOPT_UNDNAME);

if (SymInitialize(GetCurrentProcess(), nullptr, TRUE))
{
m_SymEngineInitialized = true;
symEngineInitialized = true;
}
}

return m_SymEngineInitialized;
return symEngineInitialized;
}

void xrDebug::DeinitializeSymbolEngine(void)
{
if (m_SymEngineInitialized)
if (symEngineInitialized)
{
SymCleanup(GetCurrentProcess());

m_SymEngineInitialized = false;
symEngineInitialized = false;
}
}

xr_vector<xr_string> xrDebug::BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesCount)
{
ScopeLock Lock(&m_DbgHelpLock);
ScopeLock Lock(&dbgHelpLock);

SStringVec traceResult;
STACKFRAME stackFrame = { 0 };
STACKFRAME stackFrame = {};
xr_string frameStr;

if (!InitializeSymbolEngine())
Expand Down Expand Up @@ -234,28 +234,28 @@ xr_vector<xr_string> xrDebug::BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesC

SStringVec xrDebug::BuildStackTrace(u16 maxFramesCount)
{
CONTEXT currentThreadCtx = { 0 };
CONTEXT currentThreadCtx = {};

RtlCaptureContext(&currentThreadCtx); /// GetThreadContext cann't be used on the current thread
currentThreadCtx.ContextFlags = CONTEXT_FULL;

return BuildStackTrace(&currentThreadCtx, maxFramesCount);
}

void xrDebug::LogStackTrace(const char* header)
void xrDebug::LogStackTrace(const char *header)
{
SStringVec stackTrace = BuildStackTrace();
Msg("%s", header);
for(const auto& frame : stackTrace)
for (const auto &frame : stackTrace)
{
Msg("%s", frame.c_str());
}
}

void xrDebug::GatherInfo(char* assertionInfo, const ErrorLocation& loc, const char* expr, const char* desc,
const char* arg1, const char* arg2)
void xrDebug::GatherInfo(char *assertionInfo, const ErrorLocation &loc, const char *expr, const char *desc,
const char *arg1, const char *arg2)
{
char* buffer = assertionInfo;
char *buffer = assertionInfo;
if (!expr)
expr = "<no expression>";
bool extendedDesc = desc && strchr(desc, '\n');
Expand Down Expand Up @@ -317,7 +317,7 @@ void xrDebug::GatherInfo(char* assertionInfo, const ErrorLocation& loc, const ch
os_clipboard::copy_to_clipboard(assertionInfo);
}

void xrDebug::Fatal(const ErrorLocation& loc, const char* format, ...)
void xrDebug::Fatal(const ErrorLocation &loc, const char *format, ...)
{
string1024 desc;
va_list args;
Expand All @@ -328,14 +328,14 @@ void xrDebug::Fatal(const ErrorLocation& loc, const char* format, ...)
Fail(ignoreAlways, loc, nullptr, "fatal error", desc);
}

void xrDebug::Fail(
bool& ignoreAlways, const ErrorLocation& loc, const char* expr, long hresult, const char* arg1, const char* arg2)
void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr, long hresult, const char *arg1,
const char *arg2)
{
Fail(ignoreAlways, loc, expr, xrDebug::ErrorToString(hresult), arg1, arg2);
}

void xrDebug::Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* expr, const char* desc, const char* arg1,
const char* arg2)
void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr, const char *desc, const char *arg1,
const char *arg2)
{
#ifdef PROFILE_CRITICAL_SECTIONS
static Lock lock(MUTEX_PROFILE_ID(xrDebug::Backend));
Expand Down Expand Up @@ -393,13 +393,13 @@ void xrDebug::Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* exp
lock.Leave();
}

void xrDebug::Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* expr, const std::string& desc,
const char* arg1, const char* arg2)
void xrDebug::Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr, const std::string &desc,
const char *arg1, const char *arg2)
{
Fail(ignoreAlways, loc, expr, desc.c_str(), arg1, arg2);
}

void xrDebug::DoExit(const std::string& message)
void xrDebug::DoExit(const std::string &message)
{
FlushLog();
MessageBox(NULL, message.c_str(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
Expand All @@ -408,7 +408,7 @@ void xrDebug::DoExit(const std::string& message)

LPCSTR xrDebug::ErrorToString(long code)
{
const char* result = nullptr;
const char *result = nullptr;
static string1024 descStorage;
DXGetErrorDescription(code, descStorage, sizeof(descStorage));
if (!result)
Expand Down Expand Up @@ -476,7 +476,7 @@ void WINAPI xrDebug::PreErrorHandler(INT_PTR)
BT_SaveSnapshot(nullptr);
}

void xrDebug::SetupExceptionHandler(const bool& dedicated)
void xrDebug::SetupExceptionHandler(const bool &dedicated)
{
// disable 'appname has stopped working' popup dialog
UINT prevMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
Expand Down Expand Up @@ -516,7 +516,7 @@ void xrDebug::SetupExceptionHandler(const bool& dedicated)
#endif // USE_BUG_TRAP

#ifdef USE_OWN_MINI_DUMP
void xrDebug::SaveMiniDump(EXCEPTION_POINTERS* exPtrs)
void xrDebug::SaveMiniDump(EXCEPTION_POINTERS *exPtrs)
{
string64 dateStr;
timestamp(dateStr);
Expand All @@ -537,23 +537,23 @@ void xrDebug::SaveMiniDump(EXCEPTION_POINTERS* exPtrs)
}
#endif

void xrDebug::FormatLastError(char* buffer, const size_t& bufferSize)
void xrDebug::FormatLastError(char *buffer, const size_t &bufferSize)
{
int lastErr = GetLastError();
if (lastErr == ERROR_SUCCESS)
{
*buffer = 0;
return;
}
void* msg = nullptr;
void *msg = nullptr;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, nullptr, lastErr,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&msg, 0, nullptr);
// XXX nitrocaster: check buffer overflow
sprintf(buffer, "[error][%8d]: %s", lastErr, (char*)msg);
LocalFree(msg);
}

LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS* exPtrs)
LONG WINAPI xrDebug::UnhandledFilter(EXCEPTION_POINTERS *exPtrs)
{
string256 errMsg;
FormatLastError(errMsg, sizeof(errMsg));
Expand Down Expand Up @@ -628,14 +628,14 @@ void _terminate()
}
#endif // USE_BUG_TRAP

static void handler_base(const char* reason)
static void handler_base(const char *reason)
{
bool ignoreAlways = false;
xrDebug::Fail(ignoreAlways, DEBUG_INFO, nullptr, reason, nullptr, nullptr);
}

static void invalid_parameter_handler(
const wchar_t* expression, const wchar_t* function, const wchar_t* file, unsigned int line, uintptr_t reserved)
static void invalid_parameter_handler(const wchar_t *expression, const wchar_t *function, const wchar_t *file,
unsigned int line, uintptr_t reserved)
{
bool ignoreAlways = false;
string4096 mbExpression;
Expand All @@ -657,7 +657,7 @@ static void invalid_parameter_handler(
line = __LINE__;
xr_strcpy(mbFile, __FILE__);
}
xrDebug::Fail(ignoreAlways, { mbFile, int(line), mbFunction }, mbExpression, "invalid parameter");
xrDebug::Fail(ignoreAlways, {mbFile, int(line), mbFunction}, mbExpression, "invalid parameter");
}

static void pure_call_handler() { handler_base("pure virtual function call"); }
Expand Down Expand Up @@ -692,7 +692,7 @@ void xrDebug::OnThreadSpawn()
#endif
}

void xrDebug::Initialize(const bool& dedicated)
void xrDebug::Initialize(const bool &dedicated)
{
*BugReportFile = 0;
OnThreadSpawn();
Expand Down
46 changes: 23 additions & 23 deletions src/xrCore/xrDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ class ErrorLocation
int Line = -1;
const char* Function = nullptr;

ErrorLocation(const char* file, int line, const char* function)
ErrorLocation(const char* file, int line, const char *function)
{
File = file;
Line = line;
Function = function;
}

ErrorLocation& operator=(const ErrorLocation& rhs)
ErrorLocation& operator=(const ErrorLocation &rhs)
{
File = rhs.File;
Line = rhs.Line;
Expand All @@ -40,7 +40,7 @@ class XRCORE_API xrDebug
using OutOfMemoryCallbackFunc = void(*)();
using CrashHandler = void(*)();
using DialogHandler = void(*)(bool);
using UnhandledExceptionFilter = LONG(WINAPI*)(EXCEPTION_POINTERS* exPtrs);
using UnhandledExceptionFilter = LONG(WINAPI*)(EXCEPTION_POINTERS *exPtrs);

private:
static const u16 MaxFramesCountDefault = 512;
Expand All @@ -64,41 +64,41 @@ class XRCORE_API xrDebug
static DialogHandler GetDialogHandler() { return OnDialog; }
static void SetDialogHandler(DialogHandler handler) { OnDialog = handler; }
static const char* ErrorToString(long code);
static void SetBugReportFile(const char* fileName);
static void GatherInfo(char* assertionInfo, const ErrorLocation& loc, const char* expr, const char* desc,
const char* arg1 = nullptr, const char* arg2 = nullptr);
static void Fatal(const ErrorLocation& loc, const char* format, ...);
static void Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* expr, long hresult,
const char* arg1 = nullptr, const char* arg2 = nullptr);
static void Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* expr,
const char* desc = "assertion failed", const char* arg1 = nullptr, const char* arg2 = nullptr);
static void Fail(bool& ignoreAlways, const ErrorLocation& loc, const char* expr, const std::string& desc,
const char* arg1 = nullptr, const char* arg2 = nullptr);
static void DoExit(const std::string& message);
static void SetBugReportFile(const char *fileName);
static void GatherInfo(char *assertionInfo, const ErrorLocation &loc, const char *expr, const char *desc,
const char *arg1 = nullptr, const char *arg2 = nullptr);
static void Fatal(const ErrorLocation &loc, const char *format, ...);
static void Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr, long hresult,
const char *arg1 = nullptr, const char *arg2 = nullptr);
static void Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr,
const char *desc = "assertion failed", const char *arg1 = nullptr, const char *arg2 = nullptr);
static void Fail(bool &ignoreAlways, const ErrorLocation &loc, const char *expr, const std::string &desc,
const char *arg1 = nullptr, const char *arg2 = nullptr);
static void DoExit(const std::string &message);

static void LogStackTrace(const char* header);
static void LogStackTrace(const char *header);
static xr_vector<xr_string> BuildStackTrace(u16 maxFramesCount = MaxFramesCountDefault);
private:
static void FormatLastError(char* buffer, const size_t& bufferSize);
static void SetupExceptionHandler(const bool& dedicated);
static LONG WINAPI UnhandledFilter(EXCEPTION_POINTERS* exPtrs);
static void FormatLastError(char *buffer, const size_t &bufferSize);
static void SetupExceptionHandler(const bool &dedicated);
static LONG WINAPI UnhandledFilter(EXCEPTION_POINTERS *exPtrs);
static void WINAPI PreErrorHandler(INT_PTR);
static void SaveMiniDump(EXCEPTION_POINTERS* exPtrs);
static void SaveMiniDump(EXCEPTION_POINTERS *exPtrs);

///
/// Next members relates to stack tracing
///
static bool m_SymEngineInitialized;
static Lock m_DbgHelpLock;
static bool symEngineInitialized;
static Lock dbgHelpLock;

static xr_vector<xr_string> BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesCount);
static bool GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string& frameStr);
static bool GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string &frameStr);
static bool InitializeSymbolEngine();
static void DeinitializeSymbolEngine(void);
};

// for debug purposes only
inline std::string make_string(const char* format, ...)
inline std::string make_string(const char *format, ...)
{
va_list args;
va_start(args, format);
Expand Down

0 comments on commit d253625

Please sign in to comment.