From 18884ed80558c7c03d2a6abc43932911068802bc Mon Sep 17 00:00:00 2001 From: pohky Date: Mon, 1 Nov 2021 16:07:51 +0100 Subject: [PATCH 1/2] Update veh.cpp - remove redundant SymInitialize call --- Dalamud.Boot/veh.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dalamud.Boot/veh.cpp b/Dalamud.Boot/veh.cpp index 884b029ee..94154702c 100644 --- a/Dalamud.Boot/veh.cpp +++ b/Dalamud.Boot/veh.cpp @@ -250,8 +250,6 @@ bool veh::add_handler() if (g_veh_handle) return false; g_veh_handle = AddVectoredExceptionHandler(0, exception_handler); - // init the symbol handler, the game already does it in WinMain but just in case - SymInitializeW(GetCurrentProcess(), nullptr, true); return g_veh_handle != nullptr; } From f791d0ae2bec7bfbf25172ce9543d5745ac58870 Mon Sep 17 00:00:00 2001 From: pohky Date: Mon, 1 Nov 2021 17:53:53 +0100 Subject: [PATCH 2/2] symbolhandler init in dalamud - add the pdb and dalamud directory to the symbol search path --- Dalamud/EntryPoint.cs | 27 +++++++++++++++++++++++++++ Dalamud/NativeFunctions.cs | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/Dalamud/EntryPoint.cs b/Dalamud/EntryPoint.cs index 22320e8db..58114309a 100644 --- a/Dalamud/EntryPoint.cs +++ b/Dalamud/EntryPoint.cs @@ -4,10 +4,12 @@ using System.IO; using System.Linq; using System.Net; using System.Runtime.InteropServices; +using System.Text; using System.Threading; using System.Threading.Tasks; using Dalamud.Configuration.Internal; +using Dalamud.Game; using Dalamud.Logging.Internal; using Dalamud.Support; using Newtonsoft.Json; @@ -74,6 +76,8 @@ namespace Dalamud // This is due to GitHub not supporting TLS 1.0, so we enable all TLS versions globally ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls; + InitSymbolHandler(info); + var dalamud = new Dalamud(info, levelSwitch, finishSignal, configuration); Log.Information("Starting a session.."); @@ -99,6 +103,29 @@ namespace Dalamud } } + private static void InitSymbolHandler(DalamudStartInfo info) + { + try + { + if (string.IsNullOrEmpty(info.AssetDirectory)) + return; + + var symbolPath = Path.Combine(info.AssetDirectory, "UIRes", "pdb"); + var dalamudPath = Path.GetDirectoryName(typeof(EntryPoint).Assembly.Location); + var searchPath = $".;{symbolPath};{dalamudPath}"; + + // Remove any existing Symbol Handler and Init a new one with our search path added + SymCleanup(GetCurrentProcess()); + + if (!SymInitialize(GetCurrentProcess(), searchPath, true)) + throw new Win32Exception(); + } + catch (Exception ex) + { + Log.Error(ex, "SymbolHandler Initialize Failed."); + } + } + private static LoggingLevelSwitch InitLogging(string baseDirectory) { #if DEBUG diff --git a/Dalamud/NativeFunctions.cs b/Dalamud/NativeFunctions.cs index a4c00ba7c..e23a7d237 100644 --- a/Dalamud/NativeFunctions.cs +++ b/Dalamud/NativeFunctions.cs @@ -1826,6 +1826,39 @@ namespace Dalamud MiniDumpWithFullMemory, } + /// + /// Initializes the symbol handler for a process. + /// + /// + /// A handle that identifies the caller. + /// This value should be unique and nonzero, but need not be a process handle. + /// However, if you do use a process handle, be sure to use the correct handle. + /// If the application is a debugger, use the process handle for the process being debugged. + /// Do not use the handle returned by GetCurrentProcess when debugging another process, because calling functions like SymLoadModuleEx can have unexpected results. + /// This parameter cannot be NULL. + /// + /// The path, or series of paths separated by a semicolon (;), that is used to search for symbol files. + /// If this parameter is NULL, the library attempts to form a symbol path from the following sources: + /// - The current working directory of the application + /// - The _NT_SYMBOL_PATH environment variable + /// - The _NT_ALTERNATE_SYMBOL_PATH environment variable + /// Note that the search path can also be set using the SymSetSearchPath function. + /// + /// + /// If this value is , enumerates the loaded modules for the process and effectively calls the SymLoadModule64 function for each module. + /// + /// Whether or not the function succeeded. + [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern bool SymInitialize(IntPtr hProcess, string userSearchPath, bool fInvadeProcess); + + /// + /// Deallocates all resources associated with the process handle. + /// + /// A handle to the process that was originally passed to the function. + /// Whether or not the function succeeded. + [DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Auto)] + public static extern bool SymCleanup(IntPtr hProcess); + /// /// Creates a minidump. ///