Skip to content

Commit 620fa50

Browse files
committed
DBG: fixed some stuff with the CriticalSectionLocker
1 parent d89228b commit 620fa50

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

x64_dbg_dbg/console.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "console.h"
2+
#include "threading.h"
3+
4+
static char msg[66000] = "";
25

36
void dputs(const char* text)
47
{
@@ -7,9 +10,9 @@ void dputs(const char* text)
710

811
void dprintf(const char* format, ...)
912
{
13+
CriticalSectionLocker locker(LockDprintf);
1014
va_list args;
1115
va_start(args, format);
12-
Memory<char*> msg(66000);
13-
vsnprintf(msg, msg.size(), format, args);
16+
vsnprintf(msg, sizeof(msg), format, args);
1417
GuiAddLogMessage(msg);
1518
}

x64_dbg_dbg/threading.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ bool waitislocked(WAIT_ID id)
2828
return waitarray[id];
2929
}
3030

31-
static CRITICAL_SECTION locks[LockLast] = {};
32-
static bool bInitDone = false;
31+
CRITICAL_SECTION CriticalSectionLocker::locks[LockLast] = {};
32+
bool CriticalSectionLocker::bInitDone = false;
3333

34-
static void CriticalSectionInitializeLocks()
34+
void CriticalSectionLocker::Initialize()
3535
{
3636
if(bInitDone)
3737
return;
@@ -40,18 +40,21 @@ static void CriticalSectionInitializeLocks()
4040
bInitDone = true;
4141
}
4242

43-
void CriticalSectionDeleteLocks()
43+
void CriticalSectionLocker::Deinitialize()
4444
{
4545
if(!bInitDone)
4646
return;
4747
for(int i = 0; i < LockLast; i++)
48+
{
49+
EnterCriticalSection(&locks[i]); //obtain ownership
4850
DeleteCriticalSection(&locks[i]);
51+
}
4952
bInitDone = false;
5053
}
5154

5255
CriticalSectionLocker::CriticalSectionLocker(CriticalSectionLock lock)
5356
{
54-
CriticalSectionInitializeLocks(); //initialize critical sections
57+
Initialize(); //initialize critical sections
5558
gLock = lock;
5659

5760
EnterCriticalSection(&locks[gLock]);

x64_dbg_dbg/threading.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,24 @@ enum CriticalSectionLock
3131
LockBreakpoints,
3232
LockPatches,
3333
LockThreads,
34+
LockDprintf,
3435
LockLast
3536
};
3637

37-
void CriticalSectionDeleteLocks();
38-
3938
class CriticalSectionLocker
4039
{
4140
public:
41+
static void Deinitialize();
4242
CriticalSectionLocker(CriticalSectionLock lock);
4343
~CriticalSectionLocker();
4444
void unlock();
4545
void relock();
4646

4747
private:
48+
static void Initialize();
49+
static bool bInitDone;
50+
static CRITICAL_SECTION locks[LockLast];
51+
4852
CriticalSectionLock gLock;
4953
bool Locked;
5054
};

x64_dbg_dbg/x64_dbg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
312312
}
313313
else
314314
DeleteFileA(alloctrace);
315-
CriticalSectionDeleteLocks();
315+
CriticalSectionLocker::Deinitialize();
316316
}
317317

318318
extern "C" DLL_EXPORT bool _dbg_dbgcmddirectexec(const char* cmd)

0 commit comments

Comments
 (0)