1
0
Fork 0

DBG: ASync everywhere (totally not going to cause shit in the long run of course...)

This commit is contained in:
mrexodia 2016-07-06 09:28:43 +02:00
parent acf652cbfa
commit 923722cb21
No known key found for this signature in database
GPG Key ID: D72F9A4FAA0073B4
6 changed files with 39 additions and 51 deletions

View File

@ -47,8 +47,7 @@ PLUG_IMPEXP void _plugin_logputs(const char* text)
PLUG_IMPEXP void _plugin_debugpause()
{
GuiSetDebugState(paused);
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
dbgsetskipexceptions(false);

View File

@ -327,21 +327,24 @@ void DebugUpdateGui(duint disasm_addr, bool stack)
GuiUpdateAllViews();
GuiFocusView(GUI_DISASSEMBLY);
}
static DWORD WINAPI _debugUpdateGuiStack(void* disasm_addr)
void DebugUpdateGuiSetState(duint disasm_addr, bool stack, DBGSTATE state = paused)
{
DebugUpdateGui((duint)disasm_addr, true);
return 0;
GuiSetDebugState(state);
DebugUpdateGui(disasm_addr, stack);
}
static DWORD WINAPI _debugUpdateGuiNoStack(void* disasm_addr)
void DebugUpdateGuiSetStateAsync(duint disasm_addr, bool stack, DBGSTATE state)
{
DebugUpdateGui((duint)disasm_addr, false);
return 0;
//correctly orders the GuiSetDebugState DebugUpdateGui to prevent drawing inconsistencies
static TaskThread_<decltype(&DebugUpdateGuiSetState), duint, bool, DBGSTATE> DebugUpdateGuiSetStateTask(&DebugUpdateGuiSetState);
DebugUpdateGuiSetStateTask.WakeUp(disasm_addr, stack, state);
}
void DebugUpdateGuiAsync(duint disasm_addr, bool stack)
{
static TaskThread_<decltype(&DebugUpdateGui), duint, bool> DebugUpdateGuiAsync(&DebugUpdateGui);
DebugUpdateGuiAsync.WakeUp(disasm_addr, stack);
static TaskThread_<decltype(&DebugUpdateGui), duint, bool> DebugUpdateGuiTask(&DebugUpdateGui);
DebugUpdateGuiTask.WakeUp(disasm_addr, stack);
}
void DebugUpdateStack(duint dumpAddr, duint csp, bool forceDump)
@ -492,8 +495,7 @@ void cbPauseBreakpoint()
hActiveThread = ThreadGetHandle(((DEBUG_EVENT*)GetDebugData())->dwThreadId);
auto CIP = GetContextDataEx(hActiveThread, UE_CIP);
DeleteBPX(CIP);
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(CIP, true);
DebugUpdateGuiSetStateAsync(CIP, true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -526,8 +528,7 @@ static void cbGenericBreakpoint(BP_TYPE bptype, void* ExceptionAddress = nullptr
{
SHARED_RELEASE();
dputs("Breakpoint reached not in list!");
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -587,8 +588,7 @@ static void cbGenericBreakpoint(BP_TYPE bptype, void* ExceptionAddress = nullptr
default:
break;
}
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(CIP, true);
DebugUpdateGuiSetStateAsync(CIP, true);
}
// plugin interaction
@ -642,8 +642,7 @@ static void cbGenericBreakpoint(BP_TYPE bptype, void* ExceptionAddress = nullptr
default:
break;
}
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(CIP, true);
DebugUpdateGuiSetStateAsync(CIP, true);
PLUG_CB_PAUSEDEBUG pauseInfo;
pauseInfo.reserved = nullptr;
plugincbcall(CB_PAUSEDEBUG, &pauseInfo);
@ -700,8 +699,7 @@ void cbRunToUserCodeBreakpoint(void* ExceptionAddress)
pauseInfo.reserved = nullptr;
plugincbcall(CB_PAUSEDEBUG, &pauseInfo);
_dbg_dbgtraceexecute(CIP);
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
SetForegroundWindow(GuiGetWindowHandle());
bSkipExceptions = false;
wait(WAITID_RUN);
@ -871,9 +869,8 @@ void cbStep()
{
hActiveThread = ThreadGetHandle(((DEBUG_EVENT*)GetDebugData())->dwThreadId);
isStepping = false;
GuiSetDebugStateAsync(paused);
duint CIP = GetContextDataEx(hActiveThread, UE_CIP);
DebugUpdateGuiAsync(CIP, true);
DebugUpdateGuiSetStateAsync(CIP, true);
// Trace record
_dbg_dbgtraceexecute(CIP);
// Plugin interaction
@ -894,11 +891,10 @@ static void cbRtrFinalStep()
{
dbgcleartracecondition();
hActiveThread = ThreadGetHandle(((DEBUG_EVENT*)GetDebugData())->dwThreadId);
GuiSetDebugStateAsync(paused);
duint CIP = GetContextDataEx(hActiveThread, UE_CIP);
// Trace record
_dbg_dbgtraceexecute(CIP);
DebugUpdateGuiAsync(CIP, true);
DebugUpdateGuiSetStateAsync(CIP, true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1211,8 +1207,7 @@ static void cbCreateThread(CREATE_THREAD_DEBUG_INFO* CreateThread)
//update memory map
MemUpdateMap();
//update GUI
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1248,8 +1243,7 @@ static void cbExitThread(EXIT_THREAD_DEBUG_INFO* ExitThread)
if(settingboolget("Events", "ThreadEnd"))
{
//update GUI
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1266,9 +1260,8 @@ static void cbSystemBreakpoint(void* ExceptionData)
// Update GUI (this should be the first triggered event)
duint cip = GetContextDataEx(hActiveThread, UE_CIP);
GuiSetDebugStateAsync(running);
GuiDumpAt(MemFindBaseAddr(cip, 0, true)); //dump somewhere
DebugUpdateGuiAsync(cip, true);
DebugUpdateGuiSetStateAsync(cip, true, running);
//log message
if(bIsAttached)
@ -1418,8 +1411,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
{
bBreakOnNextDll = false;
//update GUI
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1449,8 +1441,7 @@ static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll)
{
bBreakOnNextDll = false;
//update GUI
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1494,8 +1485,7 @@ static void cbOutputDebugString(OUTPUT_DEBUG_STRING_INFO* DebugString)
if(settingboolget("Events", "DebugStrings"))
{
//update GUI
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1533,10 +1523,9 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
{
dputs("paused!");
SetNextDbgContinueStatus(DBG_CONTINUE);
GuiSetDebugStateAsync(paused);
//update memory map
MemUpdateMap();
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -1589,8 +1578,7 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
SetNextDbgContinueStatus(DBG_CONTINUE);
}
GuiSetDebugStateAsync(paused);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -2190,7 +2178,7 @@ static void debugLoopFunction(void* lpParameter, bool attach)
SetCustomHandler(UE_CH_DEBUGEVENT, (void*)cbDebugEvent);
//inform GUI we started without problems
GuiSetDebugStateAsync(initialized);
GuiSetDebugState(initialized);
GuiAddRecentFile(szFileName);
//set GUI title
@ -2243,7 +2231,7 @@ static void debugLoopFunction(void* lpParameter, bool attach)
ModClear();
ThreadClear();
TraceRecord.clear();
GuiSetDebugStateAsync(stopped);
GuiSetDebugState(stopped);
GuiUpdateAllViews();
dputs("Debugging stopped!");
varset("$hp", (duint)0, true);

View File

@ -68,6 +68,8 @@ bool dbgisrunning();
bool dbgisdll();
void dbgsetattachevent(HANDLE handle);
void DebugUpdateGui(duint disasm_addr, bool stack);
void DebugUpdateGuiAsync(duint disasm_addr, bool stack);
void DebugUpdateGuiSetStateAsync(duint disasm_addr, bool stack, DBGSTATE state = paused);
void DebugUpdateStack(duint dumpAddr, duint csp, bool forceDump = false);
void GuiSetDebugStateAsync(DBGSTATE state);
void dbgsetskipexceptions(bool skip);

View File

@ -1266,7 +1266,7 @@ CMDRESULT cbDebugDisasm(int argc, char* argv[])
{
addr = GetContextDataEx(hActiveThread, UE_CIP);
}
DebugUpdateGui(addr, false);
DebugUpdateGuiAsync(addr, false);
return STATUS_CONTINUE;
}
@ -1754,7 +1754,7 @@ CMDRESULT cbDebugSwitchthread(int argc, char* argv[])
}
//switch thread
hActiveThread = ThreadGetHandle((DWORD)threadid);
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
dputs("Thread switched!");
return STATUS_CONTINUE;
}
@ -2435,8 +2435,7 @@ void cbDebugLoadLibBPX()
MemFreeRemote(ASMAddr);
ThreadResumeAll();
//update GUI
GuiSetDebugState(paused);
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), true);
DebugUpdateGuiSetStateAsync(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
lock(WAITID_RUN);
SetForegroundWindow(GuiGetWindowHandle());
@ -2560,7 +2559,7 @@ CMDRESULT cbDebugSkip(int argc, char* argv[])
disasmfast(cip, &basicinfo);
cip += basicinfo.size;
SetContextDataEx(hActiveThread, UE_CIP, cip);
DebugUpdateGui(cip, false); //update GUI
DebugUpdateGuiAsync(cip, false); //update GUI
return STATUS_CONTINUE;
}

View File

@ -2388,7 +2388,7 @@ CMDRESULT cbInstrVisualize(int argc, char* argv[])
BookmarkSet(jumpback, false);
if(fardest)
BpNew(fardest, true, false, 0, BPHARDWARE, 0, nullptr);
DebugUpdateGui(addr, false);
DebugUpdateGuiAsync(addr, false);
Sleep(300);
//continue algorithm
@ -2435,7 +2435,7 @@ CMDRESULT cbInstrVisualize(int argc, char* argv[])
BpClear();
BookmarkClear();
SetContextDataEx(fdProcessInfo->hThread, UE_CIP, start);
DebugUpdateGui(start, false);
DebugUpdateGuiAsync(start, false);
}
return STATUS_CONTINUE;
}
@ -2691,7 +2691,7 @@ CMDRESULT cbInstrEnableGuiUpdate(int argc, char* argv[])
if(argc > 1 && valfromstring(argv[1], &value) && value == 0)
return STATUS_CONTINUE;
duint cip = GetContextDataEx(hActiveThread, UE_CIP);
DebugUpdateGui(cip, false);
DebugUpdateGuiAsync(cip, false);
return STATUS_CONTINUE;
}

View File

@ -2232,7 +2232,7 @@ bool valtostring(const char* string, duint value, bool silent)
strcpy_s(regName(), len + 1, string);
_strlwr(regName());
if(strstr(regName(), "ip"))
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), false); //update disassembly + register view
DebugUpdateGuiAsync(GetContextDataEx(hActiveThread, UE_CIP), false); //update disassembly + register view
else if(strstr(regName(), "sp")) //update stack
{
duint csp = GetContextDataEx(hActiveThread, UE_CSP);