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_STEPPED, //PLUG_CB_STEPPED
CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG) CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG)
CB_DETACH //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG) CB_DETACH //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
}; };
//typedefs //typedefs

View File

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

View File

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

View File

@ -22,6 +22,17 @@ static VAR* varfind(const char* name, VAR** link)
return 0; 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() void varinit()
{ {
vars=(VAR*)emalloc(sizeof(VAR), "varinit:vars"); 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)); memset(var, 0, sizeof(VAR));
var->name=name; var->name=name;
var->type=type; 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) if(!nonext)
{ {
VAR* cur=vars; VAR* cur=vars;
@ -119,11 +134,15 @@ bool varget(const char* name, uint* value, int* size, VAR_TYPE* type)
return false; return false;
if(type) if(type)
*type=found->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; return true;
} }
bool varset(const char* name, uint value, bool setreadonly) bool varset(const char* name, VAR_VALUE* value, bool setreadonly)
{ {
char newname[deflen]="$"; char newname[deflen]="$";
int add=0; int add=0;
@ -135,23 +154,45 @@ bool varset(const char* name, uint value, bool setreadonly)
return false; return false;
if(!setreadonly and (found->type==VAR_READONLY or found->type==VAR_HIDDEN)) if(!setreadonly and (found->type==VAR_READONLY or found->type==VAR_HIDDEN))
return false; return false;
found->value.value=value; varsetvalue(found, value);
return true; 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"); VAR_VALUE varvalue;
if(*name_!='$') 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='$'; *name_='$';
strcpy(name+1, name_); strcpy(name_+1, name);
} }
else else
strcpy(name, name_); strcpy(name_, name);
VAR* prev=0; VAR* prev=0;
VAR* found=varfind(name, &prev); VAR* found=varfind(name_, &prev);
efree(name, "vardel:name"); efree(name_, "vardel:name");
if(!found) if(!found)
return false; return false;
VAR_TYPE type=found->type; VAR_TYPE type=found->type;
@ -159,6 +200,11 @@ bool vardel(const char* name_, bool delsystem)
return false; return false;
if(type==VAR_HIDDEN) if(type==VAR_HIDDEN)
return false; 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"); efree(found->name, "vardel:found->name");
if(found==vars) if(found==vars)
{ {

View File

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

View File

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