1
0
Fork 0

DBG: some fixes in addrinfo

This commit is contained in:
Mr. eXoDia 2014-06-20 00:09:09 +02:00
parent 8ba093b0ba
commit b587c30aeb
4 changed files with 27 additions and 10 deletions

View File

@ -21,26 +21,30 @@ static char alloctrace[MAX_PATH]="";
void* emalloc(size_t size, const char* reason)
{
unsigned char* a=new (std::nothrow)unsigned char[size+0x1000];
unsigned char* a=new (std::nothrow)unsigned char[size];
if(!a)
{
MessageBoxA(0, "Could not allocate memory", "Error", MB_ICONERROR);
ExitProcess(1);
}
memset(a, 0, size+0x1000);
memset(a, 0, size);
emalloc_count++;
/*
FILE* file=fopen(alloctrace, "a+");
fprintf(file, "DBG%.5d:alloc:"fhex":%s:"fhex"\n", emalloc_count, a, reason, size);
fclose(file);
*/
return a;
}
void efree(void* ptr, const char* reason)
{
emalloc_count--;
/*
FILE* file=fopen(alloctrace, "a+");
fprintf(file, "DBG%.5d:efree:"fhex":%s\n", emalloc_count, ptr, reason);
fclose(file);
*/
delete[] (unsigned char*)ptr;
}

View File

@ -16,19 +16,26 @@ static LoopsInfo loops;
//database functions
void dbsave()
{
dprintf("saving database...");
DWORD ticks=GetTickCount();
JSON root=json_object();
commentcachesave(root);
json_dump_file(root, dbpath, JSON_INDENT(4)|JSON_SORT_KEYS);
if(json_object_size(root))
json_dump_file(root, dbpath, JSON_INDENT(4));
json_decref(root); //free root
dprintf("%ums\n", GetTickCount()-ticks);
}
void dbload()
{
dprintf("loading database...");
DWORD ticks=GetTickCount();
JSON root=json_load_file(dbpath, 0, 0);
if(!root)
return;
commentcacheload(root);
json_decref(root); //free root
dprintf("%ums\n", GetTickCount()-ticks);
}
void dbupdate()
@ -37,6 +44,12 @@ void dbupdate()
dbload(); //load database to cache (and update the module bases + VAs)
}
void dbclose()
{
dbsave();
CommentsInfo().swap(comments);
}
///module functions
bool modload(uint base, uint size, const char* fullpath)
{
@ -73,7 +86,6 @@ bool modload(uint base, uint size, const char* fullpath)
bool modunload(uint base)
{
dbupdate();
int total=modinfo.size();
for(int i=0; i<total; i++)
{
@ -81,6 +93,7 @@ bool modunload(uint base)
{
modinfo.erase(modinfo.begin()+i);
symupdatemodulelist();
dbupdate();
return true;
}
}

View File

@ -68,6 +68,7 @@ typedef std::vector<LOOPSINFO> LoopsInfo;
void dbsave();
void dbload();
void dbupdate();
void dbclose();
bool modload(uint base, uint size, const char* fullpath);
bool modunload(uint base);

View File

@ -1007,7 +1007,7 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
//message the user/do final stuff
RemoveAllBreakPoints(UE_OPTION_REMOVEALL); //remove all breakpoints
//cleanup
dbsave();
dbclose();
modclear();
threadclear();
GuiSetDebugState(stopped);
@ -1821,14 +1821,13 @@ CMDRESULT cbDebugMemset(int argc, char* argv[])
CMDRESULT cbBenchmark(int argc, char* argv[])
{
uint addr=GetContextData(UE_CIP);
uint addr=memfindbaseaddr(fdProcessInfo->hProcess, GetContextData(UE_CIP), 0);
DWORD ticks=GetTickCount();
char comment[MAX_COMMENT_SIZE]="";
for(uint i=addr; i<addr+100000; i++)
for(uint i=addr; i<addr+1000000; i++)
{
DbgGetCommentAt(i, comment);
commentset(i, "test", false);
}
//DbgGetCommentAt(addr+1493, comment);
dprintf("%ums\n", GetTickCount()-ticks);
return STATUS_CONTINUE;
}
@ -1955,7 +1954,7 @@ static DWORD WINAPI threadAttachLoop(void* lpParameter)
plugincbcall(CB_STOPDEBUG, &stopInfo);
//message the user/do final stuff
RemoveAllBreakPoints(UE_OPTION_REMOVEALL); //remove all breakpoints
dbsave();
dbclose();
modclear();
GuiSetDebugState(stopped);
dputs("debugging stopped!");