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:
parent
3324a3567a
commit
8e0e02bc2e
|
@ -14,6 +14,7 @@
|
||||||
#include "symbolinfo.h"
|
#include "symbolinfo.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "disasm_fast.h"
|
#include "disasm_fast.h"
|
||||||
|
#include "simplescript.h"
|
||||||
|
|
||||||
#include "BeaEngine\BeaEngine.h"
|
#include "BeaEngine\BeaEngine.h"
|
||||||
#include "DeviceNameResolver\DeviceNameResolver.h"
|
#include "DeviceNameResolver\DeviceNameResolver.h"
|
||||||
|
@ -1012,16 +1013,13 @@ CMDRESULT cbDebugInit(int argc, char* argv[])
|
||||||
//initialize
|
//initialize
|
||||||
wait(WAITID_STOP); //wait for the debugger to stop
|
wait(WAITID_STOP); //wait for the debugger to stop
|
||||||
waitclear(); //clear waiting flags NOTE: thread-unsafe
|
waitclear(); //clear waiting flags NOTE: thread-unsafe
|
||||||
if(!CreateThread(0, 0, threadDebugLoop, init, 0, 0))
|
CloseHandle(CreateThread(0, 0, threadDebugLoop, init, 0, 0));
|
||||||
{
|
|
||||||
dputs("failed creating debug thread!");
|
|
||||||
return STATUS_ERROR;
|
|
||||||
}
|
|
||||||
return STATUS_CONTINUE;
|
return STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
CMDRESULT cbStopDebug(int argc, char* argv[])
|
CMDRESULT cbStopDebug(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
scriptreset(); //reset the currently-loaded script
|
||||||
StopDebug();
|
StopDebug();
|
||||||
unlock(WAITID_RUN);
|
unlock(WAITID_RUN);
|
||||||
wait(WAITID_STOP);
|
wait(WAITID_STOP);
|
||||||
|
@ -1833,7 +1831,7 @@ CMDRESULT cbStartScylla(int argc, char* argv[])
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
bScyllaLoaded=true;
|
bScyllaLoaded=true;
|
||||||
CreateThread(0, 0, scyllaThread, 0, 0, 0);
|
CloseHandle(CreateThread(0, 0, scyllaThread, 0, 0, 0));
|
||||||
return STATUS_CONTINUE;
|
return STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1952,7 +1950,7 @@ CMDRESULT cbDebugAttach(int argc, char* argv[])
|
||||||
return STATUS_ERROR;
|
return STATUS_ERROR;
|
||||||
}
|
}
|
||||||
CloseHandle(hProcess);
|
CloseHandle(hProcess);
|
||||||
CreateThread(0, 0, threadAttachLoop, (void*)pid, 0, 0);
|
CloseHandle(CreateThread(0, 0, threadAttachLoop, (void*)pid, 0, 0));
|
||||||
return STATUS_CONTINUE;
|
return STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,6 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
|
||||||
}
|
}
|
||||||
varnew(argv[1], set_value, VAR_USER);
|
varnew(argv[1], set_value, VAR_USER);
|
||||||
}
|
}
|
||||||
cbBadCmd(1, &argv[1]);
|
|
||||||
return STATUS_CONTINUE;
|
return STATUS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,8 @@ static std::vector<LINEMAPENTRY> linemap;
|
||||||
static std::vector<SCRIPTBP> scriptbplist;
|
static std::vector<SCRIPTBP> scriptbplist;
|
||||||
static std::vector<int> scriptstack;
|
static std::vector<int> scriptstack;
|
||||||
static int scriptIp=0;
|
static int scriptIp=0;
|
||||||
static bool bAbort=false;
|
static bool volatile bAbort=false;
|
||||||
static bool bIsRunning=false;
|
static bool volatile bIsRunning=false;
|
||||||
|
|
||||||
static SCRIPTBRANCHTYPE scriptgetbranchtype(const char* text)
|
static SCRIPTBRANCHTYPE scriptgetbranchtype(const char* text)
|
||||||
{
|
{
|
||||||
|
@ -449,7 +449,7 @@ void scriptload(const char* filename)
|
||||||
{
|
{
|
||||||
static char filename_[MAX_PATH]="";
|
static char filename_[MAX_PATH]="";
|
||||||
strcpy(filename_, filename);
|
strcpy(filename_, filename);
|
||||||
CreateThread(0, 0, scriptLoadThread, filename_, 0, 0);
|
CloseHandle(CreateThread(0, 0, scriptLoadThread, filename_, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void scriptunload()
|
void scriptunload()
|
||||||
|
@ -462,10 +462,15 @@ void scriptunload()
|
||||||
|
|
||||||
void scriptrun(int destline)
|
void scriptrun(int destline)
|
||||||
{
|
{
|
||||||
|
if(!waitislocked(WAITID_RUN))
|
||||||
|
{
|
||||||
|
GuiScriptError(0, "Debugger must be paused to run a script!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(bIsRunning) //already running
|
if(bIsRunning) //already running
|
||||||
return;
|
return;
|
||||||
bIsRunning=true;
|
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)
|
DWORD WINAPI scriptStepThread(void* param)
|
||||||
|
@ -484,7 +489,7 @@ DWORD WINAPI scriptStepThread(void* param)
|
||||||
|
|
||||||
void scriptstep()
|
void scriptstep()
|
||||||
{
|
{
|
||||||
CreateThread(0, 0, scriptStepThread, 0, 0, 0);
|
CloseHandle(CreateThread(0, 0, scriptStepThread, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool scriptbptoggle(int line)
|
bool scriptbptoggle(int line)
|
||||||
|
@ -543,6 +548,8 @@ void scriptabort()
|
||||||
{
|
{
|
||||||
if(bIsRunning)
|
if(bIsRunning)
|
||||||
bAbort=true;
|
bAbort=true;
|
||||||
|
else //reset the script
|
||||||
|
scriptsetip(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SCRIPTLINETYPE scriptgetlinetype(int line)
|
SCRIPTLINETYPE scriptgetlinetype(int line)
|
||||||
|
@ -560,6 +567,17 @@ void scriptsetip(int line)
|
||||||
GuiScriptSetIp(scriptIp);
|
GuiScriptSetIp(scriptIp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void scriptreset()
|
||||||
|
{
|
||||||
|
while(bIsRunning)
|
||||||
|
{
|
||||||
|
bAbort=true;
|
||||||
|
Sleep(1);
|
||||||
|
}
|
||||||
|
Sleep(10);
|
||||||
|
scriptsetip(0);
|
||||||
|
}
|
||||||
|
|
||||||
CMDRESULT cbScriptLoad(int argc, char* argv[])
|
CMDRESULT cbScriptLoad(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if(argc<2)
|
if(argc<2)
|
||||||
|
|
|
@ -54,6 +54,7 @@ bool scriptcmdexec(const char* command);
|
||||||
void scriptabort();
|
void scriptabort();
|
||||||
SCRIPTLINETYPE scriptgetlinetype(int line);
|
SCRIPTLINETYPE scriptgetlinetype(int line);
|
||||||
void scriptsetip(int line);
|
void scriptsetip(int line);
|
||||||
|
void scriptreset();
|
||||||
|
|
||||||
//script commands
|
//script commands
|
||||||
CMDRESULT cbScriptLoad(int argc, char* argv[]);
|
CMDRESULT cbScriptLoad(int argc, char* argv[]);
|
||||||
|
|
|
@ -1409,8 +1409,7 @@ bool valtostring(const char* string, uint* value, bool silent)
|
||||||
read_size=new_size;
|
read_size=new_size;
|
||||||
}
|
}
|
||||||
uint temp;
|
uint temp;
|
||||||
//TODO: check this
|
if(!valfromstring(newstring+add, &temp, silent, false))
|
||||||
if(!valfromstring(newstring+add, &temp, silent, true))
|
|
||||||
{
|
{
|
||||||
efree(newstring, "valfromstring::newstring");
|
efree(newstring, "valfromstring::newstring");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -199,7 +199,7 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
|
||||||
return "Could not allocate message stack!";
|
return "Could not allocate message stack!";
|
||||||
varinit();
|
varinit();
|
||||||
registercommands();
|
registercommands();
|
||||||
CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0);
|
CloseHandle(CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0));
|
||||||
char plugindir[deflen]="";
|
char plugindir[deflen]="";
|
||||||
strcpy(plugindir, dir);
|
strcpy(plugindir, dir);
|
||||||
PathAppendA(plugindir, "plugins");
|
PathAppendA(plugindir, "plugins");
|
||||||
|
|
Loading…
Reference in New Issue