Merge pull request #668 from pohky/veh

This commit is contained in:
goaaats 2021-11-01 18:18:11 +01:00 committed by GitHub
commit 5f10285e35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 60 additions and 2 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -1826,6 +1826,39 @@ namespace Dalamud
MiniDumpWithFullMemory,
}
/// <summary>
/// Initializes the symbol handler for a process.
/// </summary>
/// <param name="hProcess">
/// 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.</param>
/// <param name="userSearchPath">
/// 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.
/// </param>
/// <param name="fInvadeProcess">
/// If this value is <see langword="true"/>, enumerates the loaded modules for the process and effectively calls the SymLoadModule64 function for each module.
/// </param>
/// <returns>Whether or not the function succeeded.</returns>
[DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SymInitialize(IntPtr hProcess, string userSearchPath, bool fInvadeProcess);
/// <summary>
/// Deallocates all resources associated with the process handle.
/// </summary>
/// <param name="hProcess">A handle to the process that was originally passed to the <seealso cref="SymInitialize"/> function.</param>
/// <returns>Whether or not the function succeeded.</returns>
[DllImport("dbghelp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SymCleanup(IntPtr hProcess);
/// <summary>
/// Creates a minidump.
/// </summary>