1
0
Fork 0

Remove unused DbgHelp loading.

This commit is contained in:
ZehMatt 2017-11-22 13:23:27 +01:00 committed by Duncan Ogilvie
parent bd173bf01e
commit 3a3afa3744
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
8 changed files with 97 additions and 80 deletions

View File

@ -1345,19 +1345,7 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
DbLoad(DbLoadSaveType::DebugData);
bDatabaseLoaded = true;
SafeSymSetOptions(SYMOPT_IGNORE_CVREC | SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_FAVOR_COMPRESSED | SYMOPT_IGNORE_NT_SYMPATH);
GuiSymbolLogClear();
char szServerSearchPath[MAX_PATH * 2] = "";
sprintf_s(szServerSearchPath, "SRV*%s", szSymbolCachePath);
SafeSymInitializeW(fdProcessInfo->hProcess, StringUtils::Utf8ToUtf16(szServerSearchPath).c_str(), false); //initialize symbols
SafeSymRegisterCallbackW64(fdProcessInfo->hProcess, SymRegisterCallbackProc64, 0);
SafeSymLoadModuleExW(fdProcessInfo->hProcess, CreateProcessInfo->hFile, StringUtils::Utf8ToUtf16(DebugFileName).c_str(), 0, (DWORD64)base, 0, 0, 0);
IMAGEHLP_MODULEW64 modInfo;
memset(&modInfo, 0, sizeof(modInfo));
modInfo.SizeOfStruct = sizeof(modInfo);
if(SafeSymGetModuleInfoW64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
ModLoad((duint)base, modInfo.ImageSize, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str());
ModLoad((duint)base, 1, DebugFileName);
char modname[256] = "";
if(ModNameFromAddr((duint)base, modname, true))
@ -1412,28 +1400,29 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
IMAGEHLP_MODULE64 modInfoUtf8;
memset(&modInfoUtf8, 0, sizeof(modInfoUtf8));
modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8);
modInfoUtf8.BaseOfImage = modInfo.BaseOfImage;
modInfoUtf8.ImageSize = modInfo.ImageSize;
modInfoUtf8.TimeDateStamp = modInfo.TimeDateStamp;
modInfoUtf8.CheckSum = modInfo.CheckSum;
modInfoUtf8.NumSyms = modInfo.NumSyms;
modInfoUtf8.SymType = modInfo.SymType;
strncpy_s(modInfoUtf8.ModuleName, StringUtils::Utf16ToUtf8(modInfo.ModuleName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, StringUtils::Utf16ToUtf8(modInfo.LoadedImageName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, StringUtils::Utf16ToUtf8(modInfo.LoadedPdbName).c_str(), _TRUNCATE);
modInfoUtf8.CVSig = modInfo.CVSig;
strncpy_s(modInfoUtf8.CVData, StringUtils::Utf16ToUtf8(modInfo.CVData).c_str(), _TRUNCATE);
modInfoUtf8.PdbSig = modInfo.PdbSig;
modInfoUtf8.PdbSig70 = modInfo.PdbSig70;
modInfoUtf8.PdbAge = modInfo.PdbAge;
modInfoUtf8.PdbUnmatched = modInfo.PdbUnmatched;
modInfoUtf8.DbgUnmatched = modInfo.DbgUnmatched;
modInfoUtf8.LineNumbers = modInfo.LineNumbers;
modInfoUtf8.GlobalSymbols = modInfo.GlobalSymbols;
modInfoUtf8.TypeInfo = modInfo.TypeInfo;
modInfoUtf8.SourceIndexed = modInfo.SourceIndexed;
modInfoUtf8.Publics = modInfo.Publics;
modInfoUtf8.BaseOfImage = (DWORD64)base;
modInfoUtf8.ImageSize = 0;
modInfoUtf8.TimeDateStamp = 0;
modInfoUtf8.CheckSum = 0;
modInfoUtf8.NumSyms = 1;
modInfoUtf8.SymType = SymDia;
strncpy_s(modInfoUtf8.ModuleName, DebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, DebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, "", _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, "", _TRUNCATE);
modInfoUtf8.CVSig = 0;
strncpy_s(modInfoUtf8.CVData, "", _TRUNCATE);
modInfoUtf8.PdbSig = 0;
modInfoUtf8.PdbAge = 0;
modInfoUtf8.PdbUnmatched = FALSE;
modInfoUtf8.DbgUnmatched = FALSE;
modInfoUtf8.LineNumbers = TRUE;
modInfoUtf8.GlobalSymbols = 0;
modInfoUtf8.TypeInfo = TRUE;
modInfoUtf8.SourceIndexed = TRUE;
modInfoUtf8.Publics = TRUE;
callbackInfo.modInfo = &modInfoUtf8;
callbackInfo.DebugFileName = DebugFileName;
callbackInfo.fdProcessInfo = fdProcessInfo;
@ -1638,12 +1627,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
if(!GetFileNameFromHandle(LoadDll->hFile, DLLDebugFileName) && !GetFileNameFromModuleHandle(fdProcessInfo->hProcess, HMODULE(base), DLLDebugFileName))
strcpy_s(DLLDebugFileName, GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "??? (GetFileNameFromHandle failed)")));
SafeSymLoadModuleExW(fdProcessInfo->hProcess, LoadDll->hFile, StringUtils::Utf8ToUtf16(DLLDebugFileName).c_str(), 0, (DWORD64)base, 0, 0, 0);
IMAGEHLP_MODULEW64 modInfo;
memset(&modInfo, 0, sizeof(modInfo));
modInfo.SizeOfStruct = sizeof(modInfo);
if(SafeSymGetModuleInfoW64(fdProcessInfo->hProcess, (DWORD64)base, &modInfo))
ModLoad((duint)base, modInfo.ImageSize, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str());
ModLoad((duint)base, 1, DLLDebugFileName);
// Update memory map
MemUpdateMapAsync();
@ -1711,34 +1695,34 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
dprintf(QT_TRANSLATE_NOOP("DBG", "DLL Loaded: %p %s\n"), base, DLLDebugFileName);
//plugin callback
PLUG_CB_LOADDLL callbackInfo;
callbackInfo.LoadDll = LoadDll;
IMAGEHLP_MODULE64 modInfoUtf8;
memset(&modInfoUtf8, 0, sizeof(modInfoUtf8));
modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8);
modInfoUtf8.BaseOfImage = modInfo.BaseOfImage;
modInfoUtf8.ImageSize = modInfo.ImageSize;
modInfoUtf8.TimeDateStamp = modInfo.TimeDateStamp;
modInfoUtf8.CheckSum = modInfo.CheckSum;
modInfoUtf8.NumSyms = modInfo.NumSyms;
modInfoUtf8.SymType = modInfo.SymType;
strncpy_s(modInfoUtf8.ModuleName, StringUtils::Utf16ToUtf8(modInfo.ModuleName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, StringUtils::Utf16ToUtf8(modInfo.LoadedImageName).c_str(), _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, StringUtils::Utf16ToUtf8(modInfo.LoadedPdbName).c_str(), _TRUNCATE);
modInfoUtf8.CVSig = modInfo.CVSig;
strncpy_s(modInfoUtf8.CVData, StringUtils::Utf16ToUtf8(modInfo.CVData).c_str(), _TRUNCATE);
modInfoUtf8.PdbSig = modInfo.PdbSig;
modInfoUtf8.PdbSig70 = modInfo.PdbSig70;
modInfoUtf8.PdbAge = modInfo.PdbAge;
modInfoUtf8.PdbUnmatched = modInfo.PdbUnmatched;
modInfoUtf8.DbgUnmatched = modInfo.DbgUnmatched;
modInfoUtf8.LineNumbers = modInfo.LineNumbers;
modInfoUtf8.GlobalSymbols = modInfo.GlobalSymbols;
modInfoUtf8.TypeInfo = modInfo.TypeInfo;
modInfoUtf8.SourceIndexed = modInfo.SourceIndexed;
modInfoUtf8.Publics = modInfo.Publics;
modInfoUtf8.BaseOfImage = (DWORD64)base;
modInfoUtf8.ImageSize = 0;
modInfoUtf8.TimeDateStamp = 0;
modInfoUtf8.CheckSum = 0;
modInfoUtf8.NumSyms = 0;
modInfoUtf8.SymType = SymDia;
strncpy_s(modInfoUtf8.ModuleName, DLLDebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, DLLDebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, "", _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, "", _TRUNCATE);
modInfoUtf8.CVSig = 0;
strncpy_s(modInfoUtf8.CVData, "", _TRUNCATE);
modInfoUtf8.PdbSig = 0;
modInfoUtf8.PdbAge = 0;
modInfoUtf8.PdbUnmatched = FALSE;
modInfoUtf8.DbgUnmatched = FALSE;
modInfoUtf8.LineNumbers = 0;
modInfoUtf8.GlobalSymbols = TRUE;
modInfoUtf8.TypeInfo = TRUE;
modInfoUtf8.SourceIndexed = TRUE;
modInfoUtf8.Publics = TRUE;
callbackInfo.modInfo = &modInfoUtf8;
callbackInfo.modname = modname;
plugincbcall(CB_LOADDLL, &callbackInfo);

View File

@ -254,6 +254,11 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &info.fileHandle, &info.loadedSize, &info.fileMap, &info.fileMapVA))
{
GetModuleInfo(info, info.fileMapVA);
Size = GetPE32DataFromMappedFile(info.fileMapVA, 0, UE_SIZEOFIMAGE);
info.size = Size;
dprintf("Module Size: %08X\n", info.size);
}
else
{
@ -281,7 +286,7 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
SymbolSourcePDB::isLibraryAvailable())
{
SymbolSourcePDB *symSource = new SymbolSourcePDB();
if (symSource->loadPDB(info.path, info.base))
if (symSource->loadPDB(info.path, Base))
{
symSource->resizeSymbolBitmap(info.size);
@ -300,7 +305,7 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
{
}
if (info.symbols->isLoaded())
if (info.symbols->isLoaded() == false)
{
std::string msg = StringUtils::sprintf("No symbols loaded for: %s\n", info.path);
GuiAddLogMessage(msg.c_str());

View File

@ -1244,7 +1244,6 @@ bool PDBDiaFile::convertSymbolInfo(IDiaSymbol *symbol, DiaSymbol_t& symbolInfo,
if (symbolInfo.virtualAddress == symbolInfo.offset)
{
// Bogus address, observed this at 32 bit COA.
return false;
}

View File

@ -57,7 +57,6 @@ private:
std::string getSymbolNameString(IDiaSymbol *sym);
std::string getSymbolUndecoratedNameString(IDiaSymbol *sym);
// Container::String toString(BSTR str);
bool enumerateCompilandScope(IDiaSymbol *compiland, std::function<void(DiaSymbol_t&)>& callback, std::unordered_set<uint32_t>& visited, const bool collectUndecoratedNames);
bool processFunctionSymbol(IDiaSymbol *profilerFunction, std::function<void(DiaSymbol_t&)>& callback, std::unordered_set<uint32_t>& visited, const bool collectUndecoratedNames);

View File

@ -46,6 +46,17 @@ public:
std::advance(_it, 1);
return *this;
}
iterator operator--()
{
auto temp = *this;
std::prev(_it, 1);
return temp;
}
iterator operator--(int)
{
std::prev(_it, 1);
return *this;
}
ref_type operator*()
{
return reinterpret_cast<ref_type>(*_it);
@ -65,6 +76,11 @@ public:
};
public:
bool empty() const
{
return _map.empty();
}
void insert(const _K& key, const _V& val)
{
// Do we require room?
@ -97,11 +113,24 @@ public:
return end();
}
const EntryElem_t& elem = itr->second;
return iterator(itr);
}
iterator lower_bound(const _K& key)
{
auto itr = _map.lower_bound(key);
if (itr == _map.end())
{
return end();
}
return iterator(itr);
}
iterator begin()
{
return iterator(_map.begin());
}
iterator end()
{
return iterator(_map.end());

View File

@ -33,7 +33,7 @@ public:
std::fill(_symbolBitmap.begin(), _symbolBitmap.end(), false);
}
void markAdressInvalid(uint32_t rva)
void markAdressInvalid(duint rva)
{
if (_symbolBitmap.empty())
return;
@ -41,7 +41,7 @@ public:
_symbolBitmap[rva] = true;
}
bool isAddressInvalid(uint32_t rva) const
bool isAddressInvalid(duint rva) const
{
if (_symbolBitmap.empty())
return false;

View File

@ -30,7 +30,7 @@ bool SymbolSourcePDB::findSymbolExact(duint rva, SymbolInfo& symInfo)
auto it = _symbols.find(rva);
if (it != _symbols.end())
{
symInfo = it->second;
symInfo = (*it).second;
return true;
}
@ -44,7 +44,7 @@ bool SymbolSourcePDB::findSymbolExact(duint rva, SymbolInfo& symInfo)
symInfo.undecoratedName = sym.undecoratedName;
symInfo.valid = true;
_symbols.insert(std::make_pair(rva, symInfo));
_symbols.insert(rva, symInfo);
return true;
}
@ -61,9 +61,9 @@ typename A::iterator findExactOrLower(A& ctr, const B key)
auto itr = ctr.lower_bound(key);
if (itr == ctr.begin() && itr->first != key)
if (itr == ctr.begin() && (*itr).first != key)
return ctr.end();
else if (itr == ctr.end() || itr->first != key)
else if (itr == ctr.end() || (*itr).first != key)
return --itr;
return itr;
@ -74,8 +74,8 @@ bool SymbolSourcePDB::findSymbolExactOrLower(duint rva, SymbolInfo& symInfo)
auto it = findExactOrLower(_symbols, rva);
if (it != _symbols.end())
{
symInfo = it->second;
symInfo.disp = rva - symInfo.addr;
symInfo = (*it).second;
symInfo.disp = (int32_t)(rva - symInfo.addr);
return true;
}

View File

@ -3,12 +3,13 @@
#include "pdbdiafile.h"
#include "symbolsourcebase.h"
#include "sortedlru.h"
class SymbolSourcePDB : public SymbolSourceBase
{
private:
PDBDiaFile _pdb;
std::map<duint, SymbolInfo> _symbols;
SortedLRU<duint, SymbolInfo> _symbols;
public:
static bool isLibraryAvailable()