1
0
Fork 0

DBG+GUI+PROJECT: JIT Debugging now actually works (before it would hang in WaitForMultipleObjects) + added JIT restore option + updated help

This commit is contained in:
Mr. eXoDia 2014-08-05 07:39:15 +02:00
parent bd7803b3b5
commit 091af5d362
9 changed files with 98 additions and 60 deletions

View File

@ -19,6 +19,8 @@ html,body {
debugger to a running process.</P>
<P><U>arguments</U><BR>&nbsp; arg1: Process Identifier
(PID) of the running process.</P>
<P>[arg2]: Handle to an Event Object to signal (this
is for internal use only).</P>
<P><U>result</U> <BR>This command will give control back to the user&nbsp;after
the&nbsp;system breakpoint&nbsp;is reached. It will
set&nbsp;<U>$pid</U>&nbsp;and&nbsp;<U>$hp/$hProcess</U>&nbsp;variables.

View File

@ -56,9 +56,8 @@ html,body {
target=_blank>tr4ceflow</A>
</DIV></LI></UL>
<P><STRONG>Special Thanks</STRONG><BR>acidflash, cyberbob, Teddy Rogers, <A
href="http://forum.exetools.com/" target=_blank>EXETools community</A>, <A
href="https://forum.tuts4you.com/" target=_blank>Tuts4You community</A>
, <b>TEAM DVT</b>, DMichael, Artic, Nukem,
href="http://forum.exetools.com/" target=_blank>EXETools community</A>, <A href="http://forum.tuts4you.com" target=_blank>Tuts4You
community</A>, <b>TEAM DVT</b>, DMichael, Artic, Nukem,
ahmadmansoor </P>
<P><STRONG>Developers</STRONG>
@ -74,4 +73,4 @@ Sigma </DIV>
<LI>
<DIV><A href="http://blog.tr4ceflow.com/"
target=_blank>tr4ceflow</A>
&nbsp; </DIV></LI></UL></head>
&nbsp; </DIV></LI></UL></body></HTML>

View File

@ -129,7 +129,7 @@ BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, du
BRIDGE_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value)
{
if(!section || !key || !value)
if(!section)
return false;
if(!WritePrivateProfileStringA(section, key, value, szIniFile))
return false;

View File

@ -26,6 +26,7 @@ static int ecount = 0;
static std::vector<ExceptionRange> ignoredExceptionRange;
static std::map<unsigned int, const char*> exceptionNames;
static SIZE_T cachePrivateUsage = 0;
static HANDLE hEvent = 0;
//Superglobal variables
char szFileName[MAX_PATH] = "";
@ -166,6 +167,11 @@ bool dbgisdll()
return bFileIsDll;
}
void dbgsetattachevent(HANDLE handle)
{
hEvent = handle;
}
void dbgsetskipexceptions(bool skip)
{
bSkipExceptions = skip;
@ -1396,6 +1402,11 @@ bool cbDeleteAllHardwareBreakpoints(const BREAKPOINT* bp)
static void cbAttachDebugger()
{
if(hEvent) //Signal the AeDebug event
{
SetEvent(hEvent);
hEvent = 0;
}
varset("$hp", (uint)fdProcessInfo->hProcess, true);
varset("$pid", fdProcessInfo->dwProcessId, true);
}

View File

@ -6,7 +6,7 @@
#include "command.h"
#include "breakpoint.h"
#define ATTACH_CMD_LINE "\" -a %ld"
#define ATTACH_CMD_LINE "\" -a %ld -e %ld"
#define JIT_ENTRY_DEF_SIZE (MAX_PATH + sizeof(ATTACH_CMD_LINE) + 2)
//structures
@ -41,6 +41,7 @@ void dbgdisablebpx();
void dbgenablebpx();
bool dbgisrunning();
bool dbgisdll();
void dbgsetattachevent(HANDLE handle);
void DebugUpdateGui(uint disasm_addr, bool stack);
void dbgsetskipexceptions(bool skip);
void dbgsetstepping(bool stepping);

View File

@ -849,10 +849,14 @@ CMDRESULT cbDebugAttach(int argc, char* argv[])
return STATUS_ERROR;
}
uint pid = 0;
if(!valfromstring(argv[1], &pid))
{
dprintf("invalid expression \"%s\"!\n", argv[1]);
if(!valfromstring(argv[1], &pid, false))
return STATUS_ERROR;
if(argc > 2)
{
uint eventHandle = 0;
if(!valfromstring(argv[2], &eventHandle, false))
return STATUS_ERROR;
dbgsetattachevent((HANDLE)eventHandle);
}
if(DbgIsDebugging())
DbgCmdExecDirect("stop");
@ -1387,10 +1391,19 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
{
arch actual_arch;
char* jit_debugger_cmd;
char oldjit[MAX_SETTING_SIZE] = "";
if(argc < 2)
{
char path[JIT_ENTRY_DEF_SIZE];
dbggetdefjit(path);
char* get_entry = NULL;
if(!dbggetjit(& get_entry, notfound, & actual_arch))
{
dprintf("Error getting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
strcpy_s(oldjit, get_entry);
efree(get_entry);
jit_debugger_cmd = path;
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
@ -1398,14 +1411,31 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
if(_stricmp(oldjit, path))
BridgeSettingSet("JIT", "Old", oldjit);
}
else if(argc == 2)
{
jit_debugger_cmd = argv[1];
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
if(!_strcmpi(argv[1], "restore"))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
jit_debugger_cmd = oldjit;
if(!BridgeSettingGet("JIT", "Old", jit_debugger_cmd))
return STATUS_CONTINUE; //nothing to restore
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
BridgeSettingSet("JIT", 0, 0);
}
else
{
jit_debugger_cmd = argv[1];
if(!dbgsetjit(jit_debugger_cmd, notfound, & actual_arch))
{
dprintf("Error setting JIT %s\n", (actual_arch == x64) ? "x64" : "x32");
return STATUS_ERROR;
}
}
}
else if(argc == 3)
@ -1441,7 +1471,7 @@ CMDRESULT cbDebugSetJIT(int argc, char* argv[])
return STATUS_ERROR;
}
dprintf(" New JIT %s: %s\n", (actual_arch == x64) ? "x64" : "x32", jit_debugger_cmd);
dprintf("New JIT %s: %s\n", (actual_arch == x64) ? "x64" : "x32", jit_debugger_cmd);
return STATUS_CONTINUE;
}

View File

@ -283,20 +283,15 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
str += "\"";
DbgCmdExec(str.c_str());
}
else if(argc > 2)
else if(argc == 5) //4 arguments (JIT)
{
if(_strcmpi(argv[1], "-a") == 0)
if(_strcmpi(argv[1], "-a") == 0 && !_stricmp(argv[3], "-e"))
{
#define ATTACH_CMD_JIT_STRING "attach ."
char* attachcmd = (char*)(char*)emalloc(sizeof(ATTACH_CMD_JIT_STRING) + strlen(argv[2]) + 1, "_dbg_dbginit:attachcmd");
if(attachcmd != NULL)
{
strcpy(attachcmd, ATTACH_CMD_JIT_STRING);
strcat(attachcmd, argv[2]);
DbgCmdExec(attachcmd);
efree(attachcmd);
}
std::string str = "attach .";
str += argv[2];
str += ", .";
str += argv[4];
DbgCmdExec(str.c_str());
}
}
commandlinefree(argc, argv);

View File

@ -159,10 +159,7 @@ void SettingsDialog::LoadSettings()
ui->chkOnlyCipAutoComments->setChecked(settings.disasmOnlyCipAutoComments);
//Misc tab
GetSettingBool("Misc", "SetJIT", &settings.eventSetJIT);
ui->chkSetJIT->setCheckState(bool2check(settings.eventSetJIT));
if(DbgFunctions()->GetJit != NULL)
if(DbgFunctions()->GetJit)
{
char jit_entry[MAX_SETTING_SIZE] = "";
char jit_def_entry[MAX_SETTING_SIZE] = "";
@ -179,9 +176,8 @@ void SettingsDialog::LoadSettings()
settings.eventSetJIT = true;
else
settings.eventSetJIT = false;
ui->editJIT->setText(jit_entry);
ui->editJIT->setCursorPosition(0);
ui->chkSetJIT->setCheckState(bool2check(settings.eventSetJIT));
}
}
@ -225,7 +221,13 @@ void SettingsDialog::SaveSettings()
BridgeSettingSetUint("Disassembler", "OnlyCipAutoComments", settings.disasmOnlyCipAutoComments);
//Misc tab
BridgeSettingSetUint("Misc", "SetJIT", settings.eventSetJIT);
if(DbgFunctions()->GetJit)
{
if(settings.eventSetJIT)
DbgCmdExecDirect("setjit");
else
DbgCmdExecDirect("setjit restore");
}
Config()->load();
DbgSettingsUpdated();
@ -321,12 +323,10 @@ void SettingsDialog::on_chkAttachBreakpoint_stateChanged(int arg1)
void SettingsDialog::on_chkSetJIT_stateChanged(int arg1)
{
/*
if(arg1==Qt::Unchecked)
settings.eventSetJIT=false;
if(arg1 == Qt::Unchecked)
settings.eventSetJIT = false;
else
settings.eventSetJIT=true;
*/
settings.eventSetJIT = true;
}

View File

@ -39,7 +39,7 @@
<bool>true</bool>
</property>
<property name="currentIndex">
<number>4</number>
<number>0</number>
</property>
<widget class="QWidget" name="tabEvents">
<attribute name="title">
@ -469,39 +469,39 @@
<rect>
<x>10</x>
<y>10</y>
<width>151</width>
<width>281</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Set Just In Time Debugger</string>
<string>Set x64_dbg as Just In Time Debugger</string>
</property>
</widget>
<widget class="QLabel" name="label">
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>21</width>
<height>16</height>
<width>281</width>
<height>22</height>
</rect>
</property>
<property name="text">
<string>JIT:</string>
</property>
</widget>
<widget class="QLineEdit" name="editJIT">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>251</width>
<height>20</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>JIT:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editJIT">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>