示例#1
0
 protected SymStore(string path, SymStore backingStore)
 {
     if (!path.EndsWith("/"))
     {
         path += "/";
     }
     StoreRootAddress = new Uri(path);
     BackingStore     = backingStore;
 }
示例#2
0
        public void Search(string searchPathEntry, FileSearchInfo searchInfo, FileSearchResult result)
        {
            if (searchPathEntry == FileLocator.FirstSearchEntry || searchPathEntry == FileLocator.LastSearchEntry)
            {
                return;
            }
            if (searchInfo.SearchKind == FileSearchInfo.FileSearchKind.Source)
            {
                return;
            }

            // don't search for ngen images on the symbol server, we won't find them
            if (searchInfo.Path.EndsWith(".ni.dll", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            string fileName    = Path.GetFileName(searchInfo.Path);
            string indexString = ComputeIndexString(searchInfo);

            SymStore store;

            if (searchPathEntry.StartsWith("srv*"))
            {
                store = SymStore.FromPath(searchPathEntry);
            }
            else
            {
                store = SymStore.FromPath(@"srv**" + searchPathEntry);
            }
            string filePath;

            if (store.TryGetFile(fileName, indexString, out filePath))
            {
                result.CreateEntry(filePath);
            }
        }
示例#3
0
        static string GetPdbFileForModule(string fileName)
        {
            string retVal;

            // look in the "cache" of already successfully opened
            if (s_pdbFileForModule.TryGetValue(fileName, out retVal))
            {
                return(retVal);
            }

            retVal = null;
            CodeViewDebugData cvdd = CvDataFromPE(fileName);

            if (cvdd != null)
            {
                if (s_symStore == null)
                {
                    s_symStore = SymStore.FromPath(s_symbolServerPath);
                }

                if (s_symStore != null)
                {
                    Stream         pdbStream;
                    string         indexString   = cvdd.Signature.ToString().Replace("-", "").ToUpper() + cvdd.Age.ToString();
                    string         localFileName = Path.GetFileName(cvdd.PdbPath);
                    SymStoreResult symResult     = new SymStoreResult();
                    if (s_symStore.TryGetFile(localFileName, indexString, symResult, out pdbStream))
                    {
                        retVal = symResult.CachedPath;
                    }
                }
            }

            s_pdbFileForModule.Add(fileName, retVal);
            return(retVal);
        }
示例#4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }


            if (CommandLineParser(args) == -1)
            {
                PrintUsage();
                return;
            }

            foreach (string pdbName in s_pdbFileList)
            {
                if (!File.Exists(pdbName))
                {
                    continue;
                }

                try
                {
                    string moduleName = Path.GetFileNameWithoutExtension(pdbName);
                    var    pdbSession = DiaHelper.LoadPDB(pdbName);
                    if (pdbSession != null)
                    {
                        s_pdbMap[moduleName] = pdbSession;
                    }
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    return;
                }
            }

            List <string> tmpFileList = new List <string>();

            System.IO.TextReader tr;
            System.IO.TextWriter tw = null;
            if (!String.IsNullOrEmpty(s_inputFile) && File.Exists(s_inputFile))
            {
                tr = new System.IO.StreamReader(s_inputFile);
            }
            else
            {
                tr = Console.In;
            }

            if (!String.IsNullOrEmpty(s_outputFile))
            {
                // create file (appened if it exists)
                tw = new StreamWriter(s_outputFile, true);
            }
            if (tw == null)
            {
                tw = Console.Out;
            }

            string line;

            // If we are using a pre-defined
            if (!String.IsNullOrEmpty(s_symbolServerPath))
            {
                s_keepModules = true;
            }

            // Create a (unique) local temp directory
            //            string tempDir = Environment.GetEnvironmentVariable("TEMP");

            if (s_moduleToPeFileMap.Count > 0)
            {
                if (String.IsNullOrEmpty(s_symbolServerPath))
                {
                    string tempDir;
                    SHGetKnownFolderPath(KnownFolder.Downloads, 0, IntPtr.Zero, out tempDir);
                    if (tempDir == null)
                    {
                        Console.Error.WriteLine("Cannot get path for download directory");
                        tempDir = @"C:\SymbStore";
                    }

                    if (!String.IsNullOrEmpty(tempDir))
                    {
                        int  i       = 0;
                        bool created = false;
                        do
                        {
                            s_localSymbolRoot = Path.Combine(tempDir, String.Concat("PDBTemp", i.ToString()));
                            i++;
                            if (!s_keepModules && Directory.Exists(s_localSymbolRoot))
                            {
                                continue;
                            }

                            try
                            {
                                Directory.CreateDirectory(s_localSymbolRoot);
                                created = true;
                            }
                            catch (Exception)
                            {
                            }
                        } while (!created);
                    }
                    // construct our own path
                    s_symbolServerPath = "srv*" + s_localSymbolRoot + "*" + internalSymbolServer;
                }
            }

            while ((line = tr.ReadLine()) != null)
            {
                const string separator = "!<BaseAddress>+0x";
                string[]     frags     = line.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                if (frags.Length == 2)
                {
                    string moduleStr = frags[0];
                    int    idx       = moduleStr.LastIndexOf(' ');
                    if (idx < 0)
                    {
                        idx = 0;
                    }
                    string moduleName = moduleStr.Substring(idx + 1);
                    string prefix     = moduleStr.Substring(0, idx + 1);

                    string rvaStr = frags[1];
                    idx = rvaStr.IndexOf(' ');
                    if (idx < 0)
                    {
                        idx = rvaStr.Length;
                    }
                    string rva    = rvaStr.Substring(0, idx);
                    string suffix = rvaStr.Substring(idx);

                    uint        rvaNum;
                    IDiaSession pdbSession = null;
                    string      methodName;
                    if (!s_pdbMap.TryGetValue(moduleName, out pdbSession))
                    {
                        string peFileName;
                        if (s_moduleToPeFileMap.TryGetValue(moduleName, out peFileName))
                        {
                            // Try to get the pdb file from the symbol store
                            string pdbFileName = GetPdbFileForModule(peFileName);

                            if (!String.IsNullOrEmpty(pdbFileName))
                            {
                                if (!tmpFileList.Contains(pdbFileName))
                                {
                                    tmpFileList.Add(pdbFileName);
                                }
                                // Load pdb
                                pdbSession = DiaHelper.LoadPDB(pdbFileName);

                                // cache session
                                if (pdbSession != null)
                                {
                                    s_pdbMap[moduleName] = pdbSession;
                                }
                            }
                        }
                    }

                    if (pdbSession == null ||
                        (rvaNum = HexToUint(rva)) == 0 ||
                        ((methodName = DiaHelper.GetMethodName(pdbSession, rvaNum)) == null))
                    {
                        tw.WriteLine("{0}{1}{2}", moduleStr, separator, rvaStr);
                        continue;
                    }

                    tw.WriteLine("{0}{1}!{2}{3}", prefix, moduleName, methodName, suffix);
                }
                else
                {
                    tw.WriteLine(line);
                }
            }


            // clean up

            if (!String.IsNullOrEmpty(s_localSymbolRoot) && tmpFileList.Count > 0)
            {
                if (s_keepModules)
                {
                    Console.WriteLine("Downloaded symbol file{0}:", tmpFileList.Count != 1 ? "s" : "");
                    foreach (string tmpFile in tmpFileList)
                    {
                        Console.WriteLine(tmpFile);
                    }
                }
                else
                {
                    foreach (KeyValuePair <string, IDiaSession> mapPair in s_pdbMap)
                    {
                        DiaHelper.ReleaseSession(mapPair.Value);
                    }

                    // reset pdbMap (drop references to IDiaSession)
                    s_pdbMap = new Dictionary <string, IDiaSession>();
                    // reset symbol store (relinquish potential references to just downloaded pdb files)
                    s_symStore = null;

                    // let the GC finalize (release) COM objects
                    GC.Collect();
                    GC.Collect();

                    foreach (string tmpFile in tmpFileList)
                    {
                        try
                        {
                            File.Delete(tmpFile);
                        }
                        catch (Exception e)
                        {
                            Console.Error.WriteLine("Failed to delete {0}", tmpFile);
                            Console.Error.WriteLine(e.Message);
                        }
                    }
                    try
                    {
                        Directory.Delete(s_localSymbolRoot, true);
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Failed to delete directory {0}", s_localSymbolRoot);
                        Console.Error.WriteLine(e.Message);
                    }
                }
            }
        }
示例#5
0
 internal UNCSymStore(string storeRootAddress, SymStore backingStore)
     : base(storeRootAddress, backingStore)
 {
 }
示例#6
0
 internal HttpSymStore(string path, SymStore backingStore)
     : base(path, backingStore)
 {
 }
示例#7
0
 private static SymStore FromPathHelper(List<string> stores, int currentIndex, SymStore backingStore)
 {
     if (currentIndex == -1)
         return backingStore;
     string currentStorePath = RedirectStorePath(stores[currentIndex]);
     if (currentStorePath.StartsWith("http://") || currentStorePath.StartsWith("https://"))
         return FromPathHelper(stores, currentIndex - 1, new HttpSymStore(currentStorePath, backingStore));
     else
         return FromPathHelper(stores, currentIndex - 1, new UNCSymStore(currentStorePath, backingStore));
 }
示例#8
0
 protected SymStore(string path, SymStore backingStore)
 {
     if (!path.EndsWith("/"))
         path += "/";
     StoreRootAddress = new Uri(path);
     BackingStore = backingStore;
 }
示例#9
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                PrintUsage();
                return;
            }

            if (CommandLineParser(args) == -1)
            {
                PrintUsage();
                return;
            }

            foreach (string pdbName in s_pdbFileList)
            {
                if (!File.Exists(pdbName))
                {
                    continue;
                }

                try
                {
                    string moduleName = Path.GetFileNameWithoutExtension(pdbName);
                    var pdbSession = DiaHelper.LoadPDB(pdbName);
                    if (pdbSession != null)
                        s_pdbMap[moduleName] = pdbSession;
                }
                catch (Exception e)
                {
                    Console.Error.WriteLine(e.Message);
                    return;
                }
            }

            List<string> tmpFileList = new List<string>();

            System.IO.TextReader tr;
            System.IO.TextWriter tw = null;
            if (!String.IsNullOrEmpty(s_inputFile) && File.Exists(s_inputFile))
            {
                tr = new System.IO.StreamReader(s_inputFile);
            }
            else
            {
                tr = Console.In;
            }

            if (!String.IsNullOrEmpty(s_outputFile))
            {
                // create file (appened if it exists)
                tw = new StreamWriter(s_outputFile, true);

            }
            if (tw == null)
            {
                tw = Console.Out;
            }

            string line;

            // If we are using a pre-defined
            if (!String.IsNullOrEmpty(s_symbolServerPath))
            {
                s_keepModules = true;
            }

            // Create a (unique) local temp directory
            //            string tempDir = Environment.GetEnvironmentVariable("TEMP");

            if (s_moduleToPeFileMap.Count > 0)
            {
                if (String.IsNullOrEmpty(s_symbolServerPath))
                {
                    string tempDir;
                    SHGetKnownFolderPath(KnownFolder.Downloads, 0, IntPtr.Zero, out tempDir);
                    if (tempDir == null)
                    {
                        Console.Error.WriteLine("Cannot get path for download directory");
                        tempDir = @"C:\SymbStore";
                    }

                    if (!String.IsNullOrEmpty(tempDir))
                    {
                        int i = 0;
                        bool created = false;
                        do
                        {
                            s_localSymbolRoot = Path.Combine(tempDir, String.Concat("PDBTemp", i.ToString()));
                            i++;
                            if (!s_keepModules && Directory.Exists(s_localSymbolRoot))
                                continue;

                            try
                            {
                                Directory.CreateDirectory(s_localSymbolRoot);
                                created = true;
                            }
                            catch (Exception)
                            {
                            }
                        } while (!created);
                    }
                    // construct our own path
                    s_symbolServerPath = "srv*" + s_localSymbolRoot + "*" + internalSymbolServer;
                }
            }

            while((line = tr.ReadLine()) != null)
            {
                const string separator = "!<BaseAddress>+0x";
                string[] frags = line.Split(new string[] { separator }, StringSplitOptions.RemoveEmptyEntries);
                if (frags.Length == 2)
                {
                    string moduleStr = frags[0];
                    int idx = moduleStr.LastIndexOf(' ');
                    if (idx < 0) idx = 0;
                    string moduleName = moduleStr.Substring(idx + 1);
                    string prefix = moduleStr.Substring(0, idx + 1);

                    string rvaStr = frags[1];
                    idx = rvaStr.IndexOf(' ');
                    if (idx < 0) idx = rvaStr.Length;
                    string rva = rvaStr.Substring(0, idx);
                    string suffix = rvaStr.Substring(idx);

                    uint rvaNum;
                    IDiaSession pdbSession = null;
                    string methodName;
                    if (!s_pdbMap.TryGetValue(moduleName, out pdbSession))
                    {
                        string peFileName;
                        if (s_moduleToPeFileMap.TryGetValue(moduleName, out peFileName))
                        {
                            // Try to get the pdb file from the symbol store
                            string pdbFileName = GetPdbFileForModule(peFileName);

                            if (!String.IsNullOrEmpty(pdbFileName))
                            {

                                if (!tmpFileList.Contains(pdbFileName))
                                    tmpFileList.Add(pdbFileName);
                                // Load pdb
                                pdbSession = DiaHelper.LoadPDB(pdbFileName);

                                // cache session
                                if (pdbSession != null)
                                    s_pdbMap[moduleName] = pdbSession;
                            }

                        }
                    }

                    if (pdbSession == null ||
                        (rvaNum = HexToUint(rva)) == 0 ||
                        ((methodName = DiaHelper.GetMethodName(pdbSession, rvaNum)) == null))
                    {
                        tw.WriteLine("{0}{1}{2}", moduleStr, separator, rvaStr);
                        continue;
                    }

                    tw.WriteLine("{0}{1}!{2}{3}", prefix, moduleName, methodName, suffix);
                }
                else
                {
                    tw.WriteLine(line);
                }
            }

            // clean up

            if (!String.IsNullOrEmpty(s_localSymbolRoot) && tmpFileList.Count > 0)
            {
                if (s_keepModules)
                {
                    Console.WriteLine("Downloaded symbol file{0}:", tmpFileList.Count != 1 ? "s" : "");
                    foreach (string tmpFile in tmpFileList)
                    {
                        Console.WriteLine(tmpFile);
                    }

                }
                else
                {
                    foreach (KeyValuePair<string, IDiaSession> mapPair in s_pdbMap)
                    {
                        DiaHelper.ReleaseSession(mapPair.Value);
                    }

                    // reset pdbMap (drop references to IDiaSession)
                    s_pdbMap = new Dictionary<string, IDiaSession>();
                    // reset symbol store (relinquish potential references to just downloaded pdb files)
                    s_symStore = null;

                    // let the GC finalize (release) COM objects
                    GC.Collect();
                    GC.Collect();

                    foreach (string tmpFile in tmpFileList)
                    {
                        try
                        {
                            File.Delete(tmpFile);
                        }
                        catch (Exception e)
                        {
                            Console.Error.WriteLine("Failed to delete {0}", tmpFile);
                            Console.Error.WriteLine(e.Message);
                        }
                    }
                    try
                    {
                        Directory.Delete(s_localSymbolRoot, true);
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Failed to delete directory {0}", s_localSymbolRoot);
                        Console.Error.WriteLine(e.Message);
                    }
                }
            }
        }
示例#10
0
        static string GetPdbFileForModule(string fileName)
        {
            string retVal;

            // look in the "cache" of already successfully opened
            if (s_pdbFileForModule.TryGetValue(fileName, out retVal))
            {
                return retVal;
            }

            retVal = null;
            CodeViewDebugData cvdd = CvDataFromPE(fileName);

            if (cvdd != null)
            {
                if (s_symStore == null)
                    s_symStore = SymStore.FromPath(s_symbolServerPath);

                if (s_symStore != null)
                {
                    Stream pdbStream;
                    string indexString = cvdd.Signature.ToString().Replace("-", "").ToUpper() + cvdd.Age.ToString();
                    string localFileName = Path.GetFileName(cvdd.PdbPath);
                    SymStoreResult symResult = new SymStoreResult();
                    if (s_symStore.TryGetFile(localFileName, indexString, symResult, out pdbStream))
                    {
                        retVal = symResult.CachedPath;
                    }
                }

            }

            s_pdbFileForModule.Add(fileName, retVal);
            return retVal;
        }
示例#11
0
 internal UNCSymStore(string storeRootAddress, SymStore backingStore) : base(storeRootAddress, backingStore)
 {
 }
示例#12
0
 internal HttpSymStore(string path, SymStore backingStore) : base(path, backingStore)
 {
 }
示例#13
0
        private static SymStore FromPathHelper(List <string> stores, int currentIndex, SymStore backingStore)
        {
            if (currentIndex == -1)
            {
                return(backingStore);
            }
            string currentStorePath = RedirectStorePath(stores[currentIndex]);

            if (currentStorePath.StartsWith("http://") || currentStorePath.StartsWith("https://"))
            {
                return(FromPathHelper(stores, currentIndex - 1, new HttpSymStore(currentStorePath, backingStore)));
            }
            else
            {
                return(FromPathHelper(stores, currentIndex - 1, new UNCSymStore(currentStorePath, backingStore)));
            }
        }