1
0
Fork 0

GUI: fixed a bug in the exception catcher

DBG: started with multi-type variables
This commit is contained in:
mr.exodia 2014-03-26 22:52:41 +01:00
parent a1cb43657a
commit ffce59a2b6
6 changed files with 76 additions and 32 deletions

View File

@ -138,7 +138,6 @@ enum CBTYPE
CB_STEPPED, //PLUG_CB_STEPPED
CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG)
CB_DETACH //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
};
//typedefs

View File

@ -944,8 +944,8 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
threadclear();
GuiSetDebugState(stopped);
dputs("debugging stopped!");
varset("$hp", 0, true);
varset("$pid", 0, true);
varset("$hp", (uint)0, true);
varset("$pid", (uint)0, true);
unlock(WAITID_STOP); //we are done
return 0;
}
@ -1708,7 +1708,7 @@ CMDRESULT cbDebugFree(int argc, char* argv[])
return STATUS_ERROR;
}
if(addr==lastalloc)
varset("$lastalloc", 0, true);
varset("$lastalloc", (uint)0, true);
bool ok=VirtualFreeEx(fdProcessInfo->hProcess, (void*)addr, 0, MEM_RELEASE);
if(!ok)
dputs("VirtualFreeEx failed");
@ -1923,8 +1923,8 @@ static DWORD WINAPI threadAttachLoop(void* lpParameter)
modclear();
GuiSetDebugState(stopped);
dputs("debugging stopped!");
varset("$hp", 0, true);
varset("$pid", 0, true);
varset("$hp", (uint)0, true);
varset("$pid", (uint)0, true);
unlock(WAITID_STOP);
waitclear();
return 0;

View File

@ -177,7 +177,7 @@ CMDRESULT cbInstrVarList(int argc, char* argv[])
for(int i=0; i<len; i++)
if(name[i]==1)
name[i]='/';
uint value=(uint)cur->value.value;
uint value=(uint)cur->value.u.value;
if(cur->type!=VAR_HIDDEN)
{
if(filter)

View File

@ -22,6 +22,17 @@ static VAR* varfind(const char* name, VAR** link)
return 0;
}
static void varsetvalue(VAR* var, VAR_VALUE* value)
{
switch(var->value.type)
{
case VAR_STRING:
delete [] var->value.u.data;
break;
}
memcpy(&var->value, value, sizeof(VAR_VALUE));
}
void varinit()
{
vars=(VAR*)emalloc(sizeof(VAR), "varinit:vars");
@ -94,7 +105,11 @@ bool varnew(const char* name_, uint value, VAR_TYPE type)
memset(var, 0, sizeof(VAR));
var->name=name;
var->type=type;
var->value.value=value;
VAR_VALUE varvalue;
varvalue.size=sizeof(uint);
varvalue.type=VAR_UINT;
varvalue.u.value=value;
varsetvalue(var, &varvalue);
if(!nonext)
{
VAR* cur=vars;
@ -119,11 +134,15 @@ bool varget(const char* name, uint* value, int* size, VAR_TYPE* type)
return false;
if(type)
*type=found->type;
*value=found->value.value;
if(found->value.type!=VAR_UINT)
return false;
if(size)
*size=found->value.size;
*value=found->value.u.value;
return true;
}
bool varset(const char* name, uint value, bool setreadonly)
bool varset(const char* name, VAR_VALUE* value, bool setreadonly)
{
char newname[deflen]="$";
int add=0;
@ -135,23 +154,45 @@ bool varset(const char* name, uint value, bool setreadonly)
return false;
if(!setreadonly and (found->type==VAR_READONLY or found->type==VAR_HIDDEN))
return false;
found->value.value=value;
varsetvalue(found, value);
return true;
}
bool vardel(const char* name_, bool delsystem)
bool varset(const char* name, uint value, bool setreadonly)
{
char* name=(char*)emalloc(strlen(name_)+2, "vardel:name");
if(*name_!='$')
VAR_VALUE varvalue;
varvalue.size=sizeof(uint);
varvalue.type=VAR_UINT;
varvalue.u.value=value;
varset(name, &varvalue, setreadonly);
return true;
}
bool varset(const char* name, char* data, bool setreadonly)
{
VAR_VALUE varvalue;
int size=strlen(data);
varvalue.size=size;
varvalue.type=VAR_STRING;
varvalue.u.data=new std::vector<unsigned char>;
varvalue.u.data->resize(size);
memcpy(&varvalue.u.data->front(), data, size);
return true;
}
bool vardel(const char* name, bool delsystem)
{
char* name_=(char*)emalloc(strlen(name)+2, "vardel:name");
if(*name!='$')
{
*name='$';
strcpy(name+1, name_);
*name_='$';
strcpy(name_+1, name);
}
else
strcpy(name, name_);
strcpy(name_, name);
VAR* prev=0;
VAR* found=varfind(name, &prev);
efree(name, "vardel:name");
VAR* found=varfind(name_, &prev);
efree(name_, "vardel:name");
if(!found)
return false;
VAR_TYPE type=found->type;
@ -159,6 +200,11 @@ bool vardel(const char* name_, bool delsystem)
return false;
if(type==VAR_HIDDEN)
return false;
VAR_VALUE varvalue;
varvalue.size=sizeof(uint);
varvalue.type=VAR_UINT;
varvalue.u.value=0;
varsetvalue(found, &varvalue);
efree(found->name, "vardel:found->name");
if(found==vars)
{

View File

@ -16,13 +16,18 @@ enum VAR_TYPE
enum VAR_VALUE_TYPE
{
VAR_INT=1
VAR_UINT,
VAR_STRING,
};
//structures
struct VAR_VALUE
{
union
{
uint value;
std::vector<unsigned char>* data;
} u;
VAR_VALUE_TYPE type;
int size;
};
@ -41,7 +46,9 @@ void varfree();
VAR* vargetptr();
bool varnew(const char* name, uint value, VAR_TYPE type);
bool varget(const char* name, uint* value, int* size, VAR_TYPE* type);
bool varset(const char* name, VAR_VALUE* value, bool setreadonly);
bool varset(const char* name, uint value, bool setreadonly);
bool vardel(const char* name_, bool delsystem);
bool varset(const char* name, char* data, bool setreadonly);
bool vardel(const char* name, bool delsystem);
#endif // _VARIABLE_H

View File

@ -17,19 +17,11 @@ bool MyApplication::notify(QObject* receiver, QEvent* event)
}
catch (const std::exception& ex)
{
QMessageBox msg(QMessageBox::Critical, "Fatal GUI Exception!", QString(ex.what()));
msg.setWindowIcon(QIcon(":/icons/images/compile-error.png"));
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
msg.exec();
ExitProcess(1);
GuiAddLogMessage(QString().sprintf("Fatal GUI Exception: %s!\n", ex.what()).toUtf8().constData());
}
catch (...)
{
QMessageBox msg(QMessageBox::Critical, "Fatal GUI Exception!", "(...)");
msg.setWindowIcon(QIcon(":/icons/images/compile-error.png"));
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
msg.exec();
ExitProcess(1);
GuiAddLogMessage("Fatal GUI Exception: (...)!\n");
}
return done;
}