DBG: fixed some handle leaks with CreateThread

DBG: fixed a bug in valtostring (thanks to a friend for reporting!)
DBG: reset script when the target is closed (thanks to a friend for reporting!)
DBG: removed annoying result of the 'mov' instruction (thanks to a friend for reporting!)
DBG: error when your target is already running and you try to run a script
This commit is contained in:
Mr. eXoDia 2014-04-22 01:39:09 +02:00
parent 3324a3567a
commit 8e0e02bc2e
6 changed files with 31 additions and 16 deletions

View File

@ -14,6 +14,7 @@
#include "symbolinfo.h"
#include "thread.h"
#include "disasm_fast.h"
#include "simplescript.h"
#include "BeaEngine\BeaEngine.h"
#include "DeviceNameResolver\DeviceNameResolver.h"
@ -1012,16 +1013,13 @@ CMDRESULT cbDebugInit(int argc, char* argv[])
//initialize
wait(WAITID_STOP); //wait for the debugger to stop
waitclear(); //clear waiting flags NOTE: thread-unsafe
if(!CreateThread(0, 0, threadDebugLoop, init, 0, 0))
{
dputs("failed creating debug thread!");
return STATUS_ERROR;
}
CloseHandle(CreateThread(0, 0, threadDebugLoop, init, 0, 0));
return STATUS_CONTINUE;
}
CMDRESULT cbStopDebug(int argc, char* argv[])
{
scriptreset(); //reset the currently-loaded script
StopDebug();
unlock(WAITID_RUN);
wait(WAITID_STOP);
@ -1833,7 +1831,7 @@ CMDRESULT cbStartScylla(int argc, char* argv[])
return STATUS_ERROR;
}
bScyllaLoaded=true;
CreateThread(0, 0, scyllaThread, 0, 0, 0);
CloseHandle(CreateThread(0, 0, scyllaThread, 0, 0, 0));
return STATUS_CONTINUE;
}
@ -1952,7 +1950,7 @@ CMDRESULT cbDebugAttach(int argc, char* argv[])
return STATUS_ERROR;
}
CloseHandle(hProcess);
CreateThread(0, 0, threadAttachLoop, (void*)pid, 0, 0);
CloseHandle(CreateThread(0, 0, threadAttachLoop, (void*)pid, 0, 0));
return STATUS_CONTINUE;
}

View File

@ -151,7 +151,6 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
}
varnew(argv[1], set_value, VAR_USER);
}
cbBadCmd(1, &argv[1]);
return STATUS_CONTINUE;
}

View File

@ -11,8 +11,8 @@ static std::vector<LINEMAPENTRY> linemap;
static std::vector<SCRIPTBP> scriptbplist;
static std::vector<int> scriptstack;
static int scriptIp=0;
static bool bAbort=false;
static bool bIsRunning=false;
static bool volatile bAbort=false;
static bool volatile bIsRunning=false;
static SCRIPTBRANCHTYPE scriptgetbranchtype(const char* text)
{
@ -449,7 +449,7 @@ void scriptload(const char* filename)
{
static char filename_[MAX_PATH]="";
strcpy(filename_, filename);
CreateThread(0, 0, scriptLoadThread, filename_, 0, 0);
CloseHandle(CreateThread(0, 0, scriptLoadThread, filename_, 0, 0));
}
void scriptunload()
@ -462,10 +462,15 @@ void scriptunload()
void scriptrun(int destline)
{
if(!waitislocked(WAITID_RUN))
{
GuiScriptError(0, "Debugger must be paused to run a script!");
return;
}
if(bIsRunning) //already running
return;
bIsRunning=true;
CreateThread(0, 0, scriptRunThread, (void*)(uint)destline, 0, 0);
CloseHandle(CreateThread(0, 0, scriptRunThread, (void*)(uint)destline, 0, 0));
}
DWORD WINAPI scriptStepThread(void* param)
@ -484,7 +489,7 @@ DWORD WINAPI scriptStepThread(void* param)
void scriptstep()
{
CreateThread(0, 0, scriptStepThread, 0, 0, 0);
CloseHandle(CreateThread(0, 0, scriptStepThread, 0, 0, 0));
}
bool scriptbptoggle(int line)
@ -543,6 +548,8 @@ void scriptabort()
{
if(bIsRunning)
bAbort=true;
else //reset the script
scriptsetip(0);
}
SCRIPTLINETYPE scriptgetlinetype(int line)
@ -560,6 +567,17 @@ void scriptsetip(int line)
GuiScriptSetIp(scriptIp);
}
void scriptreset()
{
while(bIsRunning)
{
bAbort=true;
Sleep(1);
}
Sleep(10);
scriptsetip(0);
}
CMDRESULT cbScriptLoad(int argc, char* argv[])
{
if(argc<2)

View File

@ -54,6 +54,7 @@ bool scriptcmdexec(const char* command);
void scriptabort();
SCRIPTLINETYPE scriptgetlinetype(int line);
void scriptsetip(int line);
void scriptreset();
//script commands
CMDRESULT cbScriptLoad(int argc, char* argv[]);

View File

@ -1409,8 +1409,7 @@ bool valtostring(const char* string, uint* value, bool silent)
read_size=new_size;
}
uint temp;
//TODO: check this
if(!valfromstring(newstring+add, &temp, silent, true))
if(!valfromstring(newstring+add, &temp, silent, false))
{
efree(newstring, "valfromstring::newstring");
return false;

View File

@ -199,7 +199,7 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
return "Could not allocate message stack!";
varinit();
registercommands();
CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0);
CloseHandle(CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0));
char plugindir[deflen]="";
strcpy(plugindir, dir);
PathAppendA(plugindir, "plugins");