2021-06-10 06:51:56 +03:00
|
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
|
// Licensed under the MIT License - see LICENSE file in this repo.
|
|
|
|
|
namespace Microsoft.SqlServer.Utils.Misc.SQLCallStackResolver {
|
|
|
|
|
public static class SymSrvHelpers {
|
|
|
|
|
/// Private method to locate the local path for a matching PDB. Implicitly handles symbol download if needed.
|
2022-10-25 08:44:03 +03:00
|
|
|
|
private static string GetLocalSymbolFolderForModule(string pdbFilename, string pdbGuid, int pdbAge, string symPath) {
|
2021-06-10 06:51:56 +03:00
|
|
|
|
const int MAX_PATH = 4096;
|
2022-07-03 08:28:36 +03:00
|
|
|
|
StringBuilder outPath = new(MAX_PATH);
|
2021-06-10 06:51:56 +03:00
|
|
|
|
var guid = Guid.Parse(pdbGuid);
|
|
|
|
|
int rawsize = Marshal.SizeOf(guid);
|
|
|
|
|
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
|
|
|
|
|
Marshal.StructureToPtr(guid, buffer, false);
|
2022-11-09 21:03:26 +03:00
|
|
|
|
bool success = SafeNativeMethods.SymFindFileInPath((IntPtr)(-1), null, pdbFilename, buffer, pdbAge, 0, 8, outPath, IntPtr.Zero, IntPtr.Zero);
|
2022-06-12 04:48:31 +03:00
|
|
|
|
if (!success) return String.Empty;
|
2021-06-10 06:51:56 +03:00
|
|
|
|
return outPath.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-07 08:08:21 +03:00
|
|
|
|
/// <summary>
|
2021-06-10 06:51:56 +03:00
|
|
|
|
/// Public method to return local PDB file paths for specified symbols.
|
2022-06-07 08:08:21 +03:00
|
|
|
|
/// </summary>
|
2021-06-10 06:51:56 +03:00
|
|
|
|
public static List<string> GetFolderPathsForPDBs(StackResolver parent, string symPath, List<Symbol> syms) {
|
|
|
|
|
var retval = new List<string>();
|
|
|
|
|
Contract.Requires(null != syms);
|
|
|
|
|
Contract.Requires(null != parent);
|
2024-06-22 07:54:18 +03:00
|
|
|
|
|
|
|
|
|
if (!SafeNativeMethods.SymSetParentWindow(System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle)) return retval;
|
|
|
|
|
|
2022-11-09 21:03:26 +03:00
|
|
|
|
if (!SafeNativeMethods.SymInitialize((IntPtr)(-1), symPath, false)) return retval;
|
2021-06-10 06:51:56 +03:00
|
|
|
|
int progress = 0;
|
|
|
|
|
foreach (var sym in syms) {
|
|
|
|
|
parent.StatusMessage = string.Format(CultureInfo.CurrentCulture, $"Finding local PDB path for {sym.PDBName}");
|
2022-10-25 08:44:03 +03:00
|
|
|
|
var path = GetLocalSymbolFolderForModule(sym.PDBName, sym.PDBGuid, sym.PDBAge, symPath);
|
2021-06-10 06:51:56 +03:00
|
|
|
|
if (!string.IsNullOrEmpty(path)) {
|
|
|
|
|
retval.Add(Path.GetDirectoryName(path));
|
|
|
|
|
parent.StatusMessage = string.Format(CultureInfo.CurrentCulture, $"Successfully found local PDB at {path}");
|
|
|
|
|
}
|
2022-06-12 04:48:31 +03:00
|
|
|
|
else parent.StatusMessage = string.Format(CultureInfo.CurrentCulture, $"Could not find local PDB for {sym.PDBName}");
|
2021-06-10 06:51:56 +03:00
|
|
|
|
|
|
|
|
|
progress++;
|
|
|
|
|
parent.PercentComplete = (int)((double)progress / syms.Count * 100.0);
|
|
|
|
|
}
|
2022-11-09 21:03:26 +03:00
|
|
|
|
SafeNativeMethods.SymCleanup((IntPtr)(-1));
|
2021-06-10 06:51:56 +03:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|