1
0
Fork 0

Replace linear time ThreadGetId(hActiveThread) with constant time GetDebugData()->dwThreadId

This commit is contained in:
torusrxxx 2025-12-04 12:03:10 +08:00
parent 3b8c001d6e
commit 088b088a86
No known key found for this signature in database
GPG Key ID: A795C73A0F1CFADD
7 changed files with 10 additions and 10 deletions

View File

@ -233,7 +233,7 @@ static void HandleZydisOperand(const Zydis & zydis, int opindex, DISASM_ARGTYPE*
const auto & mem = op.mem;
if(mem.segment == ArchValue(ZYDIS_REGISTER_FS, ZYDIS_REGISTER_GS))
{
*value += ThreadGetLocalBase(ThreadGetId(hActiveThread));
*value += ThreadGetLocalBase(GetDebugData()->dwThreadId);
}
*memorySize = op.size / 8;
if(*memorySize <= memoryContentSize && DbgMemIsValidReadPtr(*value))
@ -264,7 +264,7 @@ void TraceRecordManager::TraceExecuteRecord(const Zydis & newInstruction)
duint oldMemory[memoryArrayCount];
unsigned char newMemoryArrayCount = 0;
DbgGetRegDumpEx((REGDUMP_AVX512*)&newContext.registers, sizeof(REGDUMP)); //TODO: Migrate
newThreadId = ThreadGetId(hActiveThread);
newThreadId = GetDebugData()->dwThreadId;
// Don't try to resolve memory values for invalid/lea/nop instructions
if(newInstruction.Success() && !newInstruction.IsNop() && newInstruction.GetId() != ZYDIS_MNEMONIC_LEA)
{

View File

@ -728,7 +728,7 @@ extern "C" DLL_EXPORT bool _dbg_getregdump(REGDUMP_AVX512* regdump)
TranslateTitanContextToRegContext(titcontext, titcontext_AVX512, regdump->regcontext);
auto threadId = ThreadGetId(hActiveThread);
auto threadId = GetDebugData()->dwThreadId;
regdump->lastError = ThreadGetLastError(threadId);
regdump->lastStatus = ThreadGetLastStatus(threadId);
@ -1528,7 +1528,7 @@ extern "C" DLL_EXPORT duint _dbg_sendmessage(DBGMSG type, void* param1, void* pa
case DBG_GET_THREAD_ID:
{
return duint(ThreadGetId(hActiveThread));
return duint(GetDebugData()->dwThreadId);
}
break;

View File

@ -421,7 +421,7 @@ bool cbDebugPause(int argc, char* argv[])
//WORKAROUND: If a program is stuck in NtUserGetMessage (GetMessage was called), this
//will send a WM_NULL to stop the waiting. This only works if the message is not filtered.
//OllyDbg also does this in a similar way.
PostThreadMessageA(ThreadGetId(hActiveThread), WM_NULL, 0, 0);
PostThreadMessageA(GetDebugData()->dwThreadId, WM_NULL, 0, 0);
if(ResumeThread(hActiveThread) == -1)
{
dputs(QT_TRANSLATE_NOOP("DBG", "Error resuming thread"));

View File

@ -58,7 +58,7 @@ bool cbDebugSwitchthread(int argc, char* argv[])
return false;
}
//switch thread
if(ThreadGetId(hActiveThread) != threadid)
if(GetDebugData()->dwThreadId != threadid)
{
hActiveThread = ThreadGetHandle((DWORD)threadid);
HistoryClear();

View File

@ -283,7 +283,7 @@ void cbDebuggerPaused()
static DWORD PrevThreadId = 0;
if(PrevThreadId == 0)
PrevThreadId = fdProcessInfo->dwThreadId; // Initialize to Main Thread
DWORD currentThreadId = ThreadGetId(hActiveThread);
DWORD currentThreadId = GetDebugData()->dwThreadId;
if(currentThreadId != PrevThreadId && PrevThreadId != 0)
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Thread switched from %X to %X !\n"), PrevThreadId, currentThreadId);
@ -501,7 +501,7 @@ static void DebugUpdateTitle(duint disasm_addr, bool analyzeThreadSwitch)
else
_snprintf_s(modtext, _TRUNCATE, GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "Module: %s - ")), modname);
char threadswitch[256] = "";
DWORD currentThreadId = ThreadGetId(hActiveThread);
DWORD currentThreadId = GetDebugData()->dwThreadId;
if(analyzeThreadSwitch)
{
static DWORD PrevThreadId = 0;

View File

@ -150,7 +150,7 @@ static void HandleZydisOperand(Zydis & zydis, int opindex, DISASM_ARG* arg, bool
if(mem.segment == ArchValue(ZYDIS_REGISTER_FS, ZYDIS_REGISTER_GS))
{
arg->segment = ArchValue(SEG_FS, SEG_GS);
value += ThreadGetLocalBase(ThreadGetId(hActiveThread));
value += ThreadGetLocalBase(GetDebugData()->dwThreadId);
}
else
{

View File

@ -174,7 +174,7 @@ namespace Exprfunc
duint tid()
{
return duint(ThreadGetId(hActiveThread));
return duint(GetDebugData()->dwThreadId);
}
duint kusd()