Skip to content

Commit

Permalink
Adds a synchronization to the stack tracing methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoAnomaly committed Mar 15, 2018
1 parent b7a8955 commit a598ee0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/xrCore/Threading/ScopeLock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "Common/Noncopyable.hpp"
#include "Threading/Lock.hpp"
#include "xrDebug.h"

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

private:
Lock * m_SyncObject;
};

ScopeLock::ScopeLock(Lock* SyncObject): m_SyncObject(SyncObject)

This comment has been minimized.

Copy link
@Xottab-DUTY

Xottab-DUTY Mar 15, 2018

Member

Why not to implement it right in the class declaration?)

{
VERIFY(m_SyncObject);

m_SyncObject->Enter();
}

ScopeLock::~ScopeLock()
{
m_SyncObject->Leave();
}
1 change: 1 addition & 0 deletions src/xrCore/xrCore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@
<ClInclude Include="SubAlloc.hpp" />
<ClInclude Include="Text\MbHelpers.h" />
<ClInclude Include="Threading\Event.hpp" />
<ClInclude Include="Threading\ScopeLock.h" />
<ClInclude Include="Threading\ThreadPool.hpp" />
<ClInclude Include="Threading\Lock.hpp" />
<ClInclude Include="vector.h" />
Expand Down
3 changes: 3 additions & 0 deletions src/xrCore/xrCore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,9 @@
<ClInclude Include="xrMemory.h">
<Filter>Memory</Filter>
</ClInclude>
<ClInclude Include="Threading\ScopeLock.h">
<Filter>Threading</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="xrCore.rc">
Expand Down
7 changes: 6 additions & 1 deletion src/xrCore/xrDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "xrDebug.h"
#include "os_clipboard.h"
#include "Debug/dxerr.h"
#include "xrCore/Threading/Lock.hpp"
#include "Threading/ScopeLock.h"

#pragma warning(push)
#pragma warning(disable : 4091) // 'typedef ': ignored on left of '' when no variable is declared
#include "Debug/MiniDump.h"
Expand Down Expand Up @@ -76,7 +77,9 @@ xrDebug::CrashHandler xrDebug::OnCrash = nullptr;
xrDebug::DialogHandler xrDebug::OnDialog = nullptr;
string_path xrDebug::BugReportFile;
bool xrDebug::ErrorAfterDialog = false;

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

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

Expand Down Expand Up @@ -187,6 +190,8 @@ void xrDebug::DeinitializeSymbolEngine(void)

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

SStringVec traceResult;
STACKFRAME stackFrame = { 0 };
xr_string frameStr;
Expand Down
6 changes: 3 additions & 3 deletions src/xrCore/xrDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "xrCore/_types.h"
#include "xrCommon/xr_string.h"
#include "xrCommon/xr_vector.h"
#include "Threading/Lock.hpp"

#include <string>

#pragma warning(push)
Expand Down Expand Up @@ -74,9 +76,6 @@ class XRCORE_API xrDebug
const char* arg1 = nullptr, const char* arg2 = nullptr);
static void DoExit(const std::string& message);

///
/// Note: DbgHelp is singlethreaded, so you must synchronize calls to these functions
///
static void LogStackTrace(const char* header);
static xr_vector<xr_string> BuildStackTrace(u16 maxFramesCount = MaxFramesCountDefault);
private:
Expand All @@ -90,6 +89,7 @@ class XRCORE_API xrDebug
/// Next members relates to stack tracing
///
static bool m_SymEngineInitialized;
static Lock m_DbgHelpLock;

static xr_vector<xr_string> BuildStackTrace(PCONTEXT threadCtx, u16 maxFramesCount);
static bool GetNextStackFrameString(LPSTACKFRAME stackFrame, PCONTEXT threadCtx, xr_string& frameStr);
Expand Down

0 comments on commit a598ee0

Please sign in to comment.