Skip to content

Commit

Permalink
DBG: (hopefully) fixed issue #249 (force refresh memory map every sec…
Browse files Browse the repository at this point in the history
…ond)
  • Loading branch information
mrexodia committed Nov 20, 2015
1 parent bac2859 commit 5e9a330
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 33 deletions.
1 change: 0 additions & 1 deletion src/dbg/_dbgfunctions.cpp
Expand Up @@ -166,7 +166,6 @@ bool _getprocesslist(DBGPROCESSINFO** entries, int* count)

static void _memupdatemap()
{
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();
}
Expand Down
29 changes: 3 additions & 26 deletions src/dbg/debugger.cpp
Expand Up @@ -35,7 +35,6 @@ static bool bSkipExceptions = false;
static bool bBreakOnNextDll = false;
static int ecount = 0;
static std::vector<ExceptionRange> ignoredExceptionRange;
static SIZE_T cachePrivateUsage = 0;
static HANDLE hEvent = 0;
static HANDLE hProcess = 0;
static HANDLE hMemMapThread = 0;
Expand Down Expand Up @@ -64,13 +63,8 @@ static DWORD WINAPI memMapThread(void* ptr)
}
if(bStopMemMapThread)
break;
const SIZE_T PrivateUsage = dbggetprivateusage(fdProcessInfo->hProcess);
if(cachePrivateUsage != PrivateUsage && !dbgisrunning()) //update the memory map when the memory usage changed
{
cachePrivateUsage = PrivateUsage;
MemUpdateMap();
GuiUpdateMemoryView();
}
MemUpdateMap();
GuiUpdateMemoryView();
Sleep(1000);
}
return 0;
Expand Down Expand Up @@ -115,17 +109,6 @@ void dbgstop()
WaitForThreadTermination(hTimeWastedCounterThread);
}

SIZE_T dbggetprivateusage(HANDLE hProcess, bool update)
{
PROCESS_MEMORY_COUNTERS_EX memoryCounters;
memoryCounters.cb = sizeof(PROCESS_MEMORY_COUNTERS_EX);
if(!GetProcessMemoryInfo(fdProcessInfo->hProcess, (PPROCESS_MEMORY_COUNTERS)&memoryCounters, sizeof(PROCESS_MEMORY_COUNTERS_EX)))
return 0;
if(update)
cachePrivateUsage = memoryCounters.PrivateUsage;
return memoryCounters.PrivateUsage;
}

duint dbgdebuggedbase()
{
return pDebuggedBase;
Expand Down Expand Up @@ -642,7 +625,6 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
dprintf("Process Started: " fhex " %s\n", base, DebugFileName);

//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down Expand Up @@ -764,7 +746,6 @@ static void cbCreateThread(CREATE_THREAD_DEBUG_INFO* CreateThread)
if(settingboolget("Events", "ThreadStart"))
{
//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
//update GUI
GuiSetDebugState(paused);
Expand Down Expand Up @@ -856,7 +837,6 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
ModLoad((duint)base, modInfo.ImageSize, modInfo.ImageName);

//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down Expand Up @@ -984,7 +964,6 @@ static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll)
ModUnload((duint)base);

//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();
}
Expand Down Expand Up @@ -1057,7 +1036,7 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
dputs("paused!");
SetNextDbgContinueStatus(DBG_CONTINUE);
GuiSetDebugState(paused);
dbggetprivateusage(fdProcessInfo->hProcess, true);
//update memory map
MemUpdateMap();
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), true);
//lock
Expand Down Expand Up @@ -1174,7 +1153,6 @@ DWORD WINAPI threadDebugLoop(void* lpParameter)
varset("$hp", (duint)fdProcessInfo->hProcess, true);
varset("$pid", fdProcessInfo->dwProcessId, true);
ecount = 0;
cachePrivateUsage = 0;
//NOTE: set custom handlers
SetCustomHandler(UE_CH_CREATEPROCESS, (void*)cbCreateProcess);
SetCustomHandler(UE_CH_EXITPROCESS, (void*)cbExitProcess);
Expand Down Expand Up @@ -1438,7 +1416,6 @@ DWORD WINAPI threadAttachLoop(void* lpParameter)
bFileIsDll = IsFileDLL(szFileName, 0);
GuiAddRecentFile(szFileName);
ecount = 0;
cachePrivateUsage = 0;
//NOTE: set custom handlers
SetCustomHandler(UE_CH_CREATEPROCESS, (void*)cbCreateProcess);
SetCustomHandler(UE_CH_EXITPROCESS, (void*)cbExitProcess);
Expand Down
1 change: 0 additions & 1 deletion src/dbg/debugger.h
Expand Up @@ -61,7 +61,6 @@ typedef struct _THREADNAME_INFO
#pragma pack(pop)

//functions
SIZE_T dbggetprivateusage(HANDLE hProcess, bool update = false);
void dbginit();
void dbgstop();
duint dbgdebuggedbase();
Expand Down
4 changes: 0 additions & 4 deletions src/dbg/debugger_commands.cpp
Expand Up @@ -799,7 +799,6 @@ CMDRESULT cbDebugAlloc(int argc, char* argv[])
if(mem)
varset("$lastalloc", mem, true);
//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down Expand Up @@ -828,7 +827,6 @@ CMDRESULT cbDebugFree(int argc, char* argv[])
if(!ok)
dputs("VirtualFreeEx failed");
//update memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down Expand Up @@ -1869,7 +1867,6 @@ CMDRESULT cbDebugSetPageRights(int argc, char* argv[])
}

//update the memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down Expand Up @@ -2074,7 +2071,6 @@ CMDRESULT cbDebugSetCmdline(int argc, char* argv[])
}

//update the memory map
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();

Expand Down
1 change: 0 additions & 1 deletion src/dbg/instruction.cpp
Expand Up @@ -2225,7 +2225,6 @@ CMDRESULT cbInstrMeminfo(int argc, char* argv[])
}
else if (argv[1][0] == 'r')
{
dbggetprivateusage(fdProcessInfo->hProcess, true);
MemUpdateMap();
GuiUpdateMemoryView();
dputs("memory map updated!");
Expand Down

2 comments on commit 5e9a330

@Nukem9
Copy link
Member

@Nukem9 Nukem9 commented on 5e9a330 Nov 20, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to assume you meant #429. https://xkcd.com/745/ 👍

@mrexodia
Copy link
Member Author

@mrexodia mrexodia commented on 5e9a330 Nov 20, 2015 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.