BOOL WINAPI MgwSymInitializeW(HANDLE hProcess, PCWSTR UserSearchPath, BOOL fInvadeProcess) { BOOL ret; ret = SymInitializeW(hProcess, UserSearchPath, fInvadeProcess); if (ret) { mgwhelp_initialize(hProcess); } return ret; }
/* static */ BOOL wxDbgHelpDLL::CallSymInitialize(HANDLE hProcess, BOOL fInvadeProcess) { #ifdef UNICODE if ( SymInitializeW ) { if ( SymInitializeW(hProcess, NULL, fInvadeProcess) ) return TRUE; } #endif // UNICODE if ( SymInitialize ) { if ( SymInitialize(hProcess, NULL, fInvadeProcess) ) return TRUE; } return FALSE; }
BOOLEAN MspAcquireContext( IN PMSP_STACKTRACE_OBJECT Object, IN ULONG ProcessId ) { PMSP_STACKTRACE_CONTEXT Old; PMSP_STACKTRACE_CONTEXT New; WCHAR SymbolPath[MAX_PATH * 2]; Old = Object->Context; if (Old != NULL) { if (Old->ProcessId == ProcessId) { return TRUE; } else { SymCleanup(Old->ProcessHandle); } } New = MspLookupStackTraceContext(Object, ProcessId, TRUE); if (!New) { __debugbreak(); return FALSE; } ASSERT(New->ProcessHandle != NULL); MdbGetSymbolPath(SymbolPath, MAX_PATH * 2); SymInitializeW(New->ProcessHandle, SymbolPath, TRUE); SymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_UNDNAME | SYMOPT_INCLUDE_32BIT_MODULES | SYMOPT_LOAD_LINES | SYMOPT_OMAP_FIND_NEAREST); Object->Context = New; return TRUE; }
/** * Initializes the symbol engine if needed. */ bool FWindowsPlatformStackWalk::InitStackWalking() { // DbgHelp functions are not thread safe, but this function can potentially be called from different // threads in our engine, so we take a critical section static FCriticalSection CriticalSection; FScopeLock Lock( &CriticalSection ); // Only initialize once. if( !GStackWalkingInitialized ) { void* DllHandle = FPlatformProcess::GetDllHandle( TEXT("PSAPI.DLL") ); if( DllHandle == NULL ) { return false; } // Load dynamically linked PSAPI routines. FEnumProcesses = (TFEnumProcesses) FPlatformProcess::GetDllExport( DllHandle,TEXT("EnumProcesses")); FEnumProcessModules = (TFEnumProcessModules) FPlatformProcess::GetDllExport( DllHandle,TEXT("EnumProcessModules")); #if WINVER > 0x502 FGetModuleFileNameEx = (TFGetModuleFileNameEx) FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleFileNameExW")); FGetModuleBaseName = (TFGetModuleBaseName) FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleBaseNameW")); #else FGetModuleFileNameEx = (TFGetModuleFileNameEx) FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleFileNameExA")); FGetModuleBaseName = (TFGetModuleBaseName) FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleBaseNameA")); #endif FGetModuleInformation = (TFGetModuleInformation) FPlatformProcess::GetDllExport( DllHandle,TEXT("GetModuleInformation")); // Abort if we can't look up the functions. if( !FEnumProcesses || !FEnumProcessModules || !FGetModuleFileNameEx || !FGetModuleBaseName || !FGetModuleInformation ) { return false; } // Set up the symbol engine. uint32 SymOpts = SymGetOptions(); SymOpts |= SYMOPT_LOAD_LINES; SymOpts |= SYMOPT_FAIL_CRITICAL_ERRORS; SymOpts |= SYMOPT_DEFERRED_LOADS; SymOpts |= SYMOPT_EXACT_SYMBOLS; // This option allows for undecorated names to be handled by the symbol engine. SymOpts |= SYMOPT_UNDNAME; // Disable by default as it can be very spammy/slow. Turn it on if you are debugging symbol look-up! // SymOpts |= SYMOPT_DEBUG; // Not sure these are important or desirable // SymOpts |= SYMOPT_ALLOW_ABSOLUTE_SYMBOLS; // SymOpts |= SYMOPT_CASE_INSENSITIVE; SymSetOptions( SymOpts ); // Initialize the symbol engine. const FString RemoteStorage = GetRemoteStorage(GetDownstreamStorage()); #if WINVER > 0x502 SymInitializeW( GetCurrentProcess(), RemoteStorage.IsEmpty() ? nullptr : *RemoteStorage, true ); #else SymInitialize( GetCurrentProcess(), nullptr, true ); #endif GNeedToRefreshSymbols = false; GStackWalkingInitialized = true; if (!FPlatformProperties::IsMonolithicBuild() && FPlatformStackWalk::WantsDetailedCallstacksInNonMonolithicBuilds()) { LoadProcessModules( RemoteStorage ); } } #if WINVER > 0x502 else if (GNeedToRefreshSymbols) { // Refresh and reload symbols SymRefreshModuleList( GetCurrentProcess() ); if (!FPlatformProperties::IsMonolithicBuild() && FPlatformStackWalk::WantsDetailedCallstacksInNonMonolithicBuilds()) { const FString RemoteStorage = GetRemoteStorage( GetDownstreamStorage() ); LoadProcessModules( RemoteStorage ); } GNeedToRefreshSymbols = false; } #endif return GStackWalkingInitialized; }
int CMiniDumpReader::Open(CString sFileName, CString sSymSearchPath) { static DWORD dwProcessID = 0; if(m_bLoaded) { return 1; } m_sFileName = sFileName; m_sSymSearchPath = sSymSearchPath; m_hFileMiniDump = CreateFile( sFileName, FILE_ALL_ACCESS, 0, NULL, OPEN_EXISTING, NULL, NULL); if(m_hFileMiniDump==INVALID_HANDLE_VALUE) { Close(); return 1; } m_hFileMapping = CreateFileMapping( m_hFileMiniDump, NULL, PAGE_READONLY, 0, 0, 0); if(m_hFileMapping==NULL) { Close(); return 2; } m_pMiniDumpStartPtr = MapViewOfFile( m_hFileMapping, FILE_MAP_READ, 0, 0, 0); if(m_pMiniDumpStartPtr==NULL) { Close(); return 3; } m_DumpData.m_hProcess = (HANDLE)(++dwProcessID); DWORD dwOptions = 0; //dwOptions |= SYMOPT_DEFERRED_LOADS; // Symbols are not loaded until a reference is made requiring the symbols be loaded. dwOptions |= SYMOPT_EXACT_SYMBOLS; // Do not load an unmatched .pdb file. dwOptions |= SYMOPT_FAIL_CRITICAL_ERRORS; // Do not display system dialog boxes when there is a media failure such as no media in a drive. dwOptions |= SYMOPT_UNDNAME; // All symbols are presented in undecorated form. SymSetOptions(dwOptions); strconv_t strconv; BOOL bSymInit = SymInitializeW( m_DumpData.m_hProcess, strconv.t2w(sSymSearchPath), FALSE); if(!bSymInit) { m_DumpData.m_hProcess = NULL; Close(); return 5; } /*SymRegisterCallbackW64( m_DumpData.m_hProcess, SymRegisterCallbackProc64, (ULONG64)this);*/ m_bReadSysInfoStream = !ReadSysInfoStream(); m_bReadModuleListStream = !ReadModuleListStream(); m_bReadThreadListStream = !ReadThreadListStream(); m_bReadMemoryListStream = !ReadMemoryListStream(); m_bReadExceptionStream = !ReadExceptionStream(); m_bLoaded = true; return 0; }