22// Licensed under the MIT License - see LICENSE file in this repo.
33namespace 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