/// <summary>
        /// This method generates a PowerShell script to automate download of matched PDBs from the public symbol server.
        /// </summary>
        /// <param name="dllSearchPath"></param>
        /// <param name="recurse"></param>
        /// <returns></returns>
        internal string ObtainPDBDownloadCommandsfromDLL(string dllSearchPath, bool recurse)
        {
            if (string.IsNullOrEmpty(dllSearchPath))
            {
                return(null);
            }

            var moduleNames = new string[] { "ntdll", "kernel32", "kernelbase", "ntoskrnl", "sqldk", "sqlmin", "sqllang", "sqltses", "sqlaccess", "qds", "hkruntime", "hkengine", "hkcompile", "sqlos", "sqlservr" };

            var finalCommand = new StringBuilder();

            finalCommand.AppendLine("\tNew-Item -Type Directory -Path <somepath> -ErrorAction SilentlyContinue");

            foreach (var currentModule in moduleNames)
            {
                var    splitRootPaths = dllSearchPath.Split(';');
                string finalFilePath  = null;

                foreach (var currPath in splitRootPaths)
                {
                    var foundFiles = from f in Directory.EnumerateFiles(currPath, currentModule + ".*", recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
                                     where !f.EndsWith(".pdb", StringComparison.InvariantCultureIgnoreCase)
                                     select f;

                    if (foundFiles.Count() > 0)
                    {
                        finalFilePath = foundFiles.First();
                        break;
                    }
                }

                if (!string.IsNullOrEmpty(finalFilePath))
                {
                    using (var dllFileStream = new FileStream(finalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        using (var dllFile = new PEFile(dllFileStream, false))
                        {
                            string pdbName;
                            Guid   pdbGuid;
                            int    pdbAge;

                            dllFile.GetPdbSignature(out pdbName, out pdbGuid, out pdbAge);

                            pdbName = System.IO.Path.GetFileNameWithoutExtension(pdbName);

                            var signaturePlusAge = pdbGuid.ToString("N") + pdbAge.ToString();
                            var fileVersion      = dllFile.GetFileVersionInfo().FileVersion;

                            finalCommand.Append("\t");
                            finalCommand.AppendFormat(@"Invoke-WebRequest -uri 'http://msdl.microsoft.com/download/symbols/{0}.pdb/{1}/{0}.pdb' -OutFile '<somepath>\{0}.pdb' # File version {2}", pdbName, signaturePlusAge, fileVersion);
                            finalCommand.AppendLine();
                        }
                    }
                }
            }

            return(finalCommand.ToString());
        }
示例#2
0
        SymbolModule FindPdbForModule(ModuleInfo module)
        {
            if (module == null)
            {
                return(null);
            }

            string pdbName;
            Guid   pdbGuid;
            int    rev;

            using (PEFile pefile = new PEFile(new ReadVirtualStream(m_dataReader, (long)module.ImageBase, (long)module.FileSize), true))
                if (!pefile.GetPdbSignature(out pdbName, out pdbGuid, out rev))
                {
                    return(null);
                }

            if (!File.Exists(pdbName))
            {
                ISymbolNotification notification = DefaultSymbolNotification ?? new NullSymbolNotification();
                pdbName = Path.GetFileName(pdbName);
                pdbName = SymbolReader.FindSymbolFilePath(pdbName, pdbGuid, rev, notification);

                if (string.IsNullOrEmpty(pdbName) || !File.Exists(pdbName))
                {
                    return(null);
                }
            }

            if (pdbName == null)
            {
                m_symbols[module] = null;
                return(null);
            }

            SymbolModule symbols = null;

            try
            {
                symbols           = new SymbolModule(SymbolReader, pdbName);
                m_symbols[module] = symbols;
            }
            catch
            {
                m_symbols[module] = null;
                return(null);
            }

            return(symbols);
        }
示例#3
0
        public override bool IsMatchingPdb(string pdbPath)
        {
            if (m_peFile == null)
            {
                m_peFile = new PEFile(new ReadVirtualStream(m_runtime.DataReader, (long)m_imageBase, (long)m_size), true);
            }

            string pdbName;
            Guid   pdbGuid;
            int    rev;

            if (!m_peFile.GetPdbSignature(out pdbName, out pdbGuid, out rev))
            {
                throw new ClrDiagnosticsException("Failed to get PDB signature from module.", ClrDiagnosticsException.HR.DataRequestError);
            }

            IDiaDataSource source = DiaLoader.GetDiaSourceObject();
            IDiaSession    session;

            source.loadDataFromPdb(pdbPath);
            source.openSession(out session);
            return(pdbGuid == session.globalScope.guid);
        }
示例#4
0
 /// <summary>
 ///     Looks up the debug signature information in the EXE.   Returns true and sets the parameters if it is found.
 ///     If 'first' is true then the first entry is returned, otherwise (by default) the last entry is used
 ///     (this is what debuggers do today).   Thus NGEN images put the IL PDB last (which means debuggers
 ///     pick up that one), but we can set it to 'first' if we want the NGEN PDB.
 /// </summary>
 /// <param name="pdbName">Name of the PDB.</param>
 /// <param name="pdbGuid">The PDB unique identifier.</param>
 /// <param name="pdbAge">The PDB age.</param>
 /// <param name="first">if set to <c>true</c> [first].</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 /// <inheritdoc />
 public bool GetPdbSignature(out string pdbName, out Guid pdbGuid, out int pdbAge, bool first = false) =>
 PeFile.GetPdbSignature(out pdbName, out pdbGuid, out pdbAge, first);