DBG: add ModEnum to remove various bottlenecks with module loading
This commit is contained in:
parent
25e0a1071d
commit
838b03e9d9
|
@ -352,7 +352,7 @@ static duint _membpsize(duint addr)
|
|||
static bool _modrelocationsfromaddr(duint addr, ListOf(DBGRELOCATIONINFO) relocations)
|
||||
{
|
||||
std::vector<MODRELOCATIONINFO> infos;
|
||||
if(!ModRelocationsFromAddr(addr, &infos))
|
||||
if(!ModRelocationsFromAddr(addr, infos))
|
||||
return false;
|
||||
|
||||
BridgeList<MODRELOCATIONINFO>::CopyData(relocations, infos);
|
||||
|
@ -362,7 +362,7 @@ static bool _modrelocationsfromaddr(duint addr, ListOf(DBGRELOCATIONINFO) reloca
|
|||
static bool _modrelocationsinrange(duint addr, duint size, ListOf(DBGRELOCATIONINFO) relocations)
|
||||
{
|
||||
std::vector<MODRELOCATIONINFO> infos;
|
||||
if(!ModRelocationsInRange(addr, size, &infos))
|
||||
if(!ModRelocationsInRange(addr, size, infos))
|
||||
return false;
|
||||
|
||||
BridgeList<MODRELOCATIONINFO>::CopyData(relocations, infos);
|
||||
|
|
|
@ -165,11 +165,8 @@ SCRIPT_EXPORT bool Script::Module::GetMainModuleSectionList(ListOf(ModuleSection
|
|||
|
||||
SCRIPT_EXPORT bool Script::Module::GetList(ListOf(ModuleInfo) list)
|
||||
{
|
||||
std::vector<MODINFO> modList;
|
||||
ModGetList(modList);
|
||||
std::vector<ModuleInfo> modScriptList;
|
||||
modScriptList.reserve(modList.size());
|
||||
for(const auto & mod : modList)
|
||||
ModEnum([&modScriptList](const MODINFO & mod)
|
||||
{
|
||||
ModuleInfo scriptMod;
|
||||
scriptMod.base = mod.base;
|
||||
|
@ -180,6 +177,6 @@ SCRIPT_EXPORT bool Script::Module::GetList(ListOf(ModuleInfo) list)
|
|||
strcat_s(scriptMod.name, mod.extension);
|
||||
strcpy_s(scriptMod.path, mod.path);
|
||||
modScriptList.push_back(scriptMod);
|
||||
}
|
||||
});
|
||||
return BridgeList<ModuleInfo>::CopyData(list, modScriptList);
|
||||
}
|
|
@ -95,8 +95,6 @@ bool cbDebugRunToParty(int argc, char* argv[])
|
|||
{
|
||||
HistoryClear();
|
||||
EXCLUSIVE_ACQUIRE(LockRunToUserCode);
|
||||
std::vector<MODINFO> AllModules;
|
||||
ModGetList(AllModules);
|
||||
if(!RunToUserCodeBreakpoints.empty())
|
||||
{
|
||||
dputs(QT_TRANSLATE_NOOP("DBG", "Run to party is busy.\n"));
|
||||
|
@ -105,7 +103,7 @@ bool cbDebugRunToParty(int argc, char* argv[])
|
|||
if(IsArgumentsLessThan(argc, 2))
|
||||
return false;
|
||||
int party = atoi(argv[1]); // party is a signed integer
|
||||
for(auto i : AllModules)
|
||||
ModEnum([party](const MODINFO & i)
|
||||
{
|
||||
if(i.party == party)
|
||||
{
|
||||
|
@ -120,7 +118,7 @@ bool cbDebugRunToParty(int argc, char* argv[])
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return cbDebugRunInternal(1, argv);
|
||||
}
|
||||
|
||||
|
|
|
@ -499,10 +499,18 @@ void ModGetList(std::vector<MODINFO> & list)
|
|||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
list.clear();
|
||||
list.reserve(modinfo.size());
|
||||
for(const auto & mod : modinfo)
|
||||
list.push_back(mod.second);
|
||||
}
|
||||
|
||||
void ModEnum(const std::function<void(const MODINFO &)> & cbEnum)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
for(const auto & mod : modinfo)
|
||||
cbEnum(mod.second);
|
||||
}
|
||||
|
||||
bool ModAddImportToModule(duint Base, const MODIMPORTINFO & importInfo)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
@ -558,7 +566,7 @@ void ModSetParty(duint Address, int Party)
|
|||
module->party = Party;
|
||||
}
|
||||
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO>* Relocations)
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
||||
|
@ -567,9 +575,7 @@ bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO>* Reloc
|
|||
if(!module || module->relocations.empty())
|
||||
return false;
|
||||
|
||||
// Copy vector <-> set
|
||||
Relocations->resize(module->relocations.size());
|
||||
*Relocations = module->relocations;
|
||||
Relocations = module->relocations;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -601,7 +607,7 @@ bool ModRelocationAtAddr(duint Address, MODRELOCATIONINFO* Relocation)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO>* Relocations)
|
||||
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO> & Relocations)
|
||||
{
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
||||
|
@ -621,13 +627,13 @@ bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONI
|
|||
if(ub != module->relocations.begin())
|
||||
ub--;
|
||||
|
||||
Relocations->clear();
|
||||
Relocations.clear();
|
||||
while(ub != module->relocations.end() && ub->rva < rva + Size)
|
||||
{
|
||||
if(ub->rva >= rva)
|
||||
Relocations->push_back(*ub);
|
||||
Relocations.push_back(*ub);
|
||||
ub++;
|
||||
}
|
||||
|
||||
return !Relocations->empty();
|
||||
return !Relocations.empty();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define _MODULE_H
|
||||
|
||||
#include "_global.h"
|
||||
#include <functional>
|
||||
|
||||
struct MODSECTIONINFO
|
||||
{
|
||||
|
@ -73,12 +74,19 @@ bool ModImportsFromAddr(duint Address, std::vector<MODIMPORTINFO>* Imports);
|
|||
duint ModEntryFromAddr(duint Address);
|
||||
int ModPathFromAddr(duint Address, char* Path, int Size);
|
||||
int ModPathFromName(const char* Module, char* Path, int Size);
|
||||
void ModGetList(std::vector<MODINFO> & list);
|
||||
|
||||
/// <summary>
|
||||
/// Enumerate all loaded modules with a function.
|
||||
/// A shared lock on the modules is held until this function returns.
|
||||
/// </summary>
|
||||
/// <param name="cbEnum">Enumeration function.</param>
|
||||
void ModEnum(const std::function<void(const MODINFO &)> & cbEnum);
|
||||
|
||||
int ModGetParty(duint Address);
|
||||
void ModSetParty(duint Address, int Party);
|
||||
bool ModAddImportToModule(duint Base, const MODIMPORTINFO & importInfo);
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO>* Relocations);
|
||||
bool ModRelocationsFromAddr(duint Address, std::vector<MODRELOCATIONINFO> & Relocations);
|
||||
bool ModRelocationAtAddr(duint Address, MODRELOCATIONINFO* Relocation);
|
||||
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO>* Relocations);
|
||||
bool ModRelocationsInRange(duint Address, duint Size, std::vector<MODRELOCATIONINFO> & Relocations);
|
||||
|
||||
#endif // _MODULE_H
|
||||
|
|
|
@ -120,8 +120,23 @@ int RefFind(duint Address, duint Size, CBREF Callback, void* UserData, bool Sile
|
|||
else if(type == ALL_MODULES) // Search in all Modules
|
||||
{
|
||||
bool initCallBack = true;
|
||||
std::vector<MODINFO> modList;
|
||||
ModGetList(modList);
|
||||
|
||||
struct RefModInfo
|
||||
{
|
||||
duint base;
|
||||
duint size;
|
||||
char name[MAX_MODULE_SIZE];
|
||||
};
|
||||
std::vector<RefModInfo> modList;
|
||||
ModEnum([&modList](const MODINFO & mod)
|
||||
{
|
||||
RefModInfo info;
|
||||
info.base = mod.base;
|
||||
info.size = mod.size;
|
||||
strncpy_s(info.name, mod.name, _TRUNCATE);
|
||||
strncat_s(info.name, mod.extension, _TRUNCATE);
|
||||
modList.push_back(info);
|
||||
});
|
||||
|
||||
if(!modList.size())
|
||||
{
|
||||
|
@ -157,9 +172,6 @@ int RefFind(duint Address, duint Size, CBREF Callback, void* UserData, bool Sile
|
|||
|
||||
int totalPercent = (int)floor(fTotalPercent * 100.f);
|
||||
|
||||
char tst[256];
|
||||
strcpy_s(tst, modList[i].name);
|
||||
|
||||
GuiReferenceSetCurrentTaskProgress(percent, modList[i].name);
|
||||
GuiReferenceSetProgress(totalPercent);
|
||||
}, disasmText);
|
||||
|
|
|
@ -109,16 +109,14 @@ void SymEnumFromCache(duint Base, CBSYMBOLENUM EnumCallback, void* UserData)
|
|||
|
||||
bool SymGetModuleList(std::vector<SYMBOLMODULEINFO>* List)
|
||||
{
|
||||
std::vector<MODINFO> modList;
|
||||
ModGetList(modList);
|
||||
for(auto & mod : modList)
|
||||
ModEnum([List](const MODINFO & mod)
|
||||
{
|
||||
SYMBOLMODULEINFO curMod;
|
||||
curMod.base = mod.base;
|
||||
strcpy_s(curMod.name, mod.name);
|
||||
strcat_s(curMod.name, mod.extension);
|
||||
List->push_back(curMod);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue