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

@ -477,7 +477,7 @@ void DebugUpdateGui(duint disasm_addr, bool stack)
InterlockedExchange((volatile unsigned long long*)&cacheCsp, csp); InterlockedExchange((volatile unsigned long long*)&cacheCsp, csp);
#else #else
InterlockedExchange((volatile unsigned long*)&cacheCsp, csp); InterlockedExchange((volatile unsigned long*)&cacheCsp, csp);
#endif //_WIN64 #endif //_WIN64
updateCallStackAsync(csp); updateCallStackAsync(csp);
updateSEHChainAsync(); updateSEHChainAsync();
} }
@ -1345,19 +1345,7 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
DbLoad(DbLoadSaveType::DebugData); DbLoad(DbLoadSaveType::DebugData);
bDatabaseLoaded = true; bDatabaseLoaded = true;
SafeSymSetOptions(SYMOPT_IGNORE_CVREC | SYMOPT_DEBUG | SYMOPT_LOAD_LINES | SYMOPT_FAVOR_COMPRESSED | SYMOPT_IGNORE_NT_SYMPATH); ModLoad((duint)base, 1, DebugFileName);
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());
char modname[256] = ""; char modname[256] = "";
if(ModNameFromAddr((duint)base, modname, true)) if(ModNameFromAddr((duint)base, modname, true))
@ -1412,28 +1400,29 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
IMAGEHLP_MODULE64 modInfoUtf8; IMAGEHLP_MODULE64 modInfoUtf8;
memset(&modInfoUtf8, 0, sizeof(modInfoUtf8)); memset(&modInfoUtf8, 0, sizeof(modInfoUtf8));
modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8); modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8);
modInfoUtf8.BaseOfImage = modInfo.BaseOfImage; modInfoUtf8.BaseOfImage = (DWORD64)base;
modInfoUtf8.ImageSize = modInfo.ImageSize; modInfoUtf8.ImageSize = 0;
modInfoUtf8.TimeDateStamp = modInfo.TimeDateStamp; modInfoUtf8.TimeDateStamp = 0;
modInfoUtf8.CheckSum = modInfo.CheckSum; modInfoUtf8.CheckSum = 0;
modInfoUtf8.NumSyms = modInfo.NumSyms; modInfoUtf8.NumSyms = 1;
modInfoUtf8.SymType = modInfo.SymType; modInfoUtf8.SymType = SymDia;
strncpy_s(modInfoUtf8.ModuleName, StringUtils::Utf16ToUtf8(modInfo.ModuleName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.ModuleName, DebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.ImageName, DebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, StringUtils::Utf16ToUtf8(modInfo.LoadedImageName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.LoadedImageName, "", _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, StringUtils::Utf16ToUtf8(modInfo.LoadedPdbName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.LoadedPdbName, "", _TRUNCATE);
modInfoUtf8.CVSig = modInfo.CVSig;
strncpy_s(modInfoUtf8.CVData, StringUtils::Utf16ToUtf8(modInfo.CVData).c_str(), _TRUNCATE); modInfoUtf8.CVSig = 0;
modInfoUtf8.PdbSig = modInfo.PdbSig; strncpy_s(modInfoUtf8.CVData, "", _TRUNCATE);
modInfoUtf8.PdbSig70 = modInfo.PdbSig70; modInfoUtf8.PdbSig = 0;
modInfoUtf8.PdbAge = modInfo.PdbAge; modInfoUtf8.PdbAge = 0;
modInfoUtf8.PdbUnmatched = modInfo.PdbUnmatched; modInfoUtf8.PdbUnmatched = FALSE;
modInfoUtf8.DbgUnmatched = modInfo.DbgUnmatched; modInfoUtf8.DbgUnmatched = FALSE;
modInfoUtf8.LineNumbers = modInfo.LineNumbers; modInfoUtf8.LineNumbers = TRUE;
modInfoUtf8.GlobalSymbols = modInfo.GlobalSymbols; modInfoUtf8.GlobalSymbols = 0;
modInfoUtf8.TypeInfo = modInfo.TypeInfo; modInfoUtf8.TypeInfo = TRUE;
modInfoUtf8.SourceIndexed = modInfo.SourceIndexed; modInfoUtf8.SourceIndexed = TRUE;
modInfoUtf8.Publics = modInfo.Publics; modInfoUtf8.Publics = TRUE;
callbackInfo.modInfo = &modInfoUtf8; callbackInfo.modInfo = &modInfoUtf8;
callbackInfo.DebugFileName = DebugFileName; callbackInfo.DebugFileName = DebugFileName;
callbackInfo.fdProcessInfo = fdProcessInfo; 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)) if(!GetFileNameFromHandle(LoadDll->hFile, DLLDebugFileName) && !GetFileNameFromModuleHandle(fdProcessInfo->hProcess, HMODULE(base), DLLDebugFileName))
strcpy_s(DLLDebugFileName, GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "??? (GetFileNameFromHandle failed)"))); 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); ModLoad((duint)base, 1, DLLDebugFileName);
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());
// Update memory map // Update memory map
MemUpdateMapAsync(); 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); dprintf(QT_TRANSLATE_NOOP("DBG", "DLL Loaded: %p %s\n"), base, DLLDebugFileName);
//plugin callback //plugin callback
PLUG_CB_LOADDLL callbackInfo; PLUG_CB_LOADDLL callbackInfo;
callbackInfo.LoadDll = LoadDll; callbackInfo.LoadDll = LoadDll;
IMAGEHLP_MODULE64 modInfoUtf8; IMAGEHLP_MODULE64 modInfoUtf8;
memset(&modInfoUtf8, 0, sizeof(modInfoUtf8)); memset(&modInfoUtf8, 0, sizeof(modInfoUtf8));
modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8); modInfoUtf8.SizeOfStruct = sizeof(modInfoUtf8);
modInfoUtf8.BaseOfImage = modInfo.BaseOfImage; modInfoUtf8.BaseOfImage = (DWORD64)base;
modInfoUtf8.ImageSize = modInfo.ImageSize; modInfoUtf8.ImageSize = 0;
modInfoUtf8.TimeDateStamp = modInfo.TimeDateStamp; modInfoUtf8.TimeDateStamp = 0;
modInfoUtf8.CheckSum = modInfo.CheckSum; modInfoUtf8.CheckSum = 0;
modInfoUtf8.NumSyms = modInfo.NumSyms; modInfoUtf8.NumSyms = 0;
modInfoUtf8.SymType = modInfo.SymType; modInfoUtf8.SymType = SymDia;
strncpy_s(modInfoUtf8.ModuleName, StringUtils::Utf16ToUtf8(modInfo.ModuleName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.ModuleName, DLLDebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.ImageName, StringUtils::Utf16ToUtf8(modInfo.ImageName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.ImageName, DLLDebugFileName, _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedImageName, StringUtils::Utf16ToUtf8(modInfo.LoadedImageName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.LoadedImageName, "", _TRUNCATE);
strncpy_s(modInfoUtf8.LoadedPdbName, StringUtils::Utf16ToUtf8(modInfo.LoadedPdbName).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.LoadedPdbName, "", _TRUNCATE);
modInfoUtf8.CVSig = modInfo.CVSig; modInfoUtf8.CVSig = 0;
strncpy_s(modInfoUtf8.CVData, StringUtils::Utf16ToUtf8(modInfo.CVData).c_str(), _TRUNCATE); strncpy_s(modInfoUtf8.CVData, "", _TRUNCATE);
modInfoUtf8.PdbSig = modInfo.PdbSig; modInfoUtf8.PdbSig = 0;
modInfoUtf8.PdbSig70 = modInfo.PdbSig70; modInfoUtf8.PdbAge = 0;
modInfoUtf8.PdbAge = modInfo.PdbAge; modInfoUtf8.PdbUnmatched = FALSE;
modInfoUtf8.PdbUnmatched = modInfo.PdbUnmatched; modInfoUtf8.DbgUnmatched = FALSE;
modInfoUtf8.DbgUnmatched = modInfo.DbgUnmatched; modInfoUtf8.LineNumbers = 0;
modInfoUtf8.LineNumbers = modInfo.LineNumbers; modInfoUtf8.GlobalSymbols = TRUE;
modInfoUtf8.GlobalSymbols = modInfo.GlobalSymbols; modInfoUtf8.TypeInfo = TRUE;
modInfoUtf8.TypeInfo = modInfo.TypeInfo; modInfoUtf8.SourceIndexed = TRUE;
modInfoUtf8.SourceIndexed = modInfo.SourceIndexed; modInfoUtf8.Publics = TRUE;
modInfoUtf8.Publics = modInfo.Publics;
callbackInfo.modInfo = &modInfoUtf8; callbackInfo.modInfo = &modInfoUtf8;
callbackInfo.modname = modname; callbackInfo.modname = modname;
plugincbcall(CB_LOADDLL, &callbackInfo); plugincbcall(CB_LOADDLL, &callbackInfo);

View File

@ -222,7 +222,7 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
// Copy information to struct // Copy information to struct
strcpy_s(info.name, file); strcpy_s(info.name, file);
info.base = Base; info.base = Base;
info.size = Size; info.size = Size;
info.fileHandle = nullptr; info.fileHandle = nullptr;
info.loadedSize = 0; info.loadedSize = 0;
info.fileMap = nullptr; info.fileMap = nullptr;
@ -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)) if(StaticFileLoadW(wszFullPath.c_str(), UE_ACCESS_READ, false, &info.fileHandle, &info.loadedSize, &info.fileMap, &info.fileMapVA))
{ {
GetModuleInfo(info, info.fileMapVA); GetModuleInfo(info, info.fileMapVA);
Size = GetPE32DataFromMappedFile(info.fileMapVA, 0, UE_SIZEOFIMAGE);
info.size = Size;
dprintf("Module Size: %08X\n", info.size);
} }
else else
{ {
@ -281,7 +286,7 @@ bool ModLoad(duint Base, duint Size, const char* FullPath)
SymbolSourcePDB::isLibraryAvailable()) SymbolSourcePDB::isLibraryAvailable())
{ {
SymbolSourcePDB *symSource = new SymbolSourcePDB(); SymbolSourcePDB *symSource = new SymbolSourcePDB();
if (symSource->loadPDB(info.path, info.base)) if (symSource->loadPDB(info.path, Base))
{ {
symSource->resizeSymbolBitmap(info.size); 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); std::string msg = StringUtils::sprintf("No symbols loaded for: %s\n", info.path);
GuiAddLogMessage(msg.c_str()); GuiAddLogMessage(msg.c_str());

View File

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

View File

@ -57,7 +57,6 @@ private:
std::string getSymbolNameString(IDiaSymbol *sym); std::string getSymbolNameString(IDiaSymbol *sym);
std::string getSymbolUndecoratedNameString(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 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); 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); std::advance(_it, 1);
return *this; 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*() ref_type operator*()
{ {
return reinterpret_cast<ref_type>(*_it); return reinterpret_cast<ref_type>(*_it);
@ -65,6 +76,11 @@ public:
}; };
public: public:
bool empty() const
{
return _map.empty();
}
void insert(const _K& key, const _V& val) void insert(const _K& key, const _V& val)
{ {
// Do we require room? // Do we require room?
@ -97,11 +113,24 @@ public:
return end(); return end();
} }
const EntryElem_t& elem = itr->second;
return iterator(itr); 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() iterator end()
{ {
return iterator(_map.end()); return iterator(_map.end());

View File

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

View File

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

View File

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