Skip to content

Commit ed84aa6

Browse files
authored
Eliminate avoidable SymSrv init / cleanup (#98)
1 parent 01b2a52 commit ed84aa6

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

Engine/SafeNativeMethods.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,5 @@ public static extern bool SymFindFileInPath(IntPtr hProcess,
7272
[Out, MarshalAs(UnmanagedType.LPWStr)] StringBuilder filePath,
7373
IntPtr callback,
7474
IntPtr context);
75-
76-
[DllImport("dbghelp.dll")]
77-
public static extern bool SymCleanup(IntPtr hProcess);
78-
79-
[DllImport("dbghelp.dll", CharSet = CharSet.Unicode)]
80-
public static extern bool SymInitialize(
81-
IntPtr hProcess,
82-
[MarshalAs(UnmanagedType.LPWStr)] string UserSearchPath,
83-
bool fInvadeProcess);
8475
}
8576
}

Engine/SymSrvHelpers.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,15 @@
22
// Licensed under the MIT License - see LICENSE file in this repo.
33
namespace Microsoft.SqlServer.Utils.Misc.SQLCallStackResolver {
44
public static class SymSrvHelpers {
5-
static readonly int processId = Process.GetCurrentProcess().Id;
6-
7-
/// Wrapper around the symsrv.dll functionality to initialize the symbol load handler for this process.
8-
private static bool InitSymSrv(string symPath) {
9-
return SafeNativeMethods.SymInitialize((IntPtr)processId, symPath, false);
10-
}
11-
12-
/// Un-initialize the symbol load handler for this process.
13-
private static bool CleanupSymSrv() {
14-
return SafeNativeMethods.SymCleanup((IntPtr)processId);
15-
}
16-
175
/// Private method to locate the local path for a matching PDB. Implicitly handles symbol download if needed.
18-
private static string GetLocalSymbolFolderForModule(string pdbFilename, string pdbGuid, int pdbAge) {
6+
private static string GetLocalSymbolFolderForModule(string pdbFilename, string pdbGuid, int pdbAge, string symPath) {
197
const int MAX_PATH = 4096;
208
StringBuilder outPath = new(MAX_PATH);
219
var guid = Guid.Parse(pdbGuid);
2210
int rawsize = Marshal.SizeOf(guid);
2311
IntPtr buffer = Marshal.AllocHGlobal(rawsize);
2412
Marshal.StructureToPtr(guid, buffer, false);
25-
bool success = SafeNativeMethods.SymFindFileInPath((IntPtr)processId, null, pdbFilename, buffer, pdbAge, 0, 8, outPath, IntPtr.Zero, IntPtr.Zero);
13+
bool success = SafeNativeMethods.SymFindFileInPath(IntPtr.Zero, symPath, pdbFilename, buffer, pdbAge, 0, 8, outPath, IntPtr.Zero, IntPtr.Zero);
2614
if (!success) return String.Empty;
2715
return outPath.ToString();
2816
}
@@ -34,11 +22,10 @@ public static List<string> GetFolderPathsForPDBs(StackResolver parent, string sy
3422
var retval = new List<string>();
3523
Contract.Requires(null != syms);
3624
Contract.Requires(null != parent);
37-
if (!InitSymSrv(symPath)) return retval;
3825
int progress = 0;
3926
foreach (var sym in syms) {
4027
parent.StatusMessage = string.Format(CultureInfo.CurrentCulture, $"Finding local PDB path for {sym.PDBName}");
41-
var path = GetLocalSymbolFolderForModule(sym.PDBName, sym.PDBGuid, sym.PDBAge);
28+
var path = GetLocalSymbolFolderForModule(sym.PDBName, sym.PDBGuid, sym.PDBAge, symPath);
4229
if (!string.IsNullOrEmpty(path)) {
4330
retval.Add(Path.GetDirectoryName(path));
4431
parent.StatusMessage = string.Format(CultureInfo.CurrentCulture, $"Successfully found local PDB at {path}");
@@ -48,8 +35,6 @@ public static List<string> GetFolderPathsForPDBs(StackResolver parent, string sy
4835
progress++;
4936
parent.PercentComplete = (int)((double)progress / syms.Count * 100.0);
5037
}
51-
52-
CleanupSymSrv();
5338
return retval;
5439
}
5540
}

0 commit comments

Comments
 (0)