Inheritance: ISymbolReaderProvider
Exemplo n.º 1
0
		public void LoadFrom (FilePath assemblyPath)
		{
			FileName = assemblyPath;
			
			var tid = Runtime.SystemAssemblyService.GetTargetFrameworkForAssembly (Runtime.SystemAssemblyService.DefaultRuntime, assemblyPath);
			if (tid != null)
				targetFramework = Runtime.SystemAssemblyService.GetTargetFramework (tid);
			
			AssemblyDefinition adef = AssemblyDefinition.ReadAssembly (assemblyPath);
			MdbReaderProvider mdbProvider = new MdbReaderProvider ();
			try {
				ISymbolReader reader = mdbProvider.GetSymbolReader (adef.MainModule, assemblyPath);
				adef.MainModule.ReadSymbols (reader);
			} catch {
				// Ignore
			}
			var files = new HashSet<FilePath> ();
			
			foreach (TypeDefinition type in adef.MainModule.Types) {
				foreach (MethodDefinition met in type.Methods) {
					if (met.HasBody && met.Body.Instructions != null && met.Body.Instructions.Count > 0) {
						SequencePoint sp = met.Body.Instructions[0].SequencePoint;
						if (sp != null)
							files.Add (sp.Document.Url);
					}
				}
			}
			
			FilePath rootPath = FilePath.Empty;
			foreach (FilePath file in files) {
				AddFile (file, BuildAction.Compile);
				if (rootPath.IsNullOrEmpty)
					rootPath = file.ParentDirectory;
				else if (!file.IsChildPathOf (rootPath))
					rootPath = FindCommonRoot (rootPath, file);
			}
			
			if (!rootPath.IsNullOrEmpty)
				BaseDirectory = rootPath;
/*
			foreach (AssemblyNameReference aref in adef.MainModule.AssemblyReferences) {
				if (aref.Name == "mscorlib")
					continue;
				string asm = assemblyPath.ParentDirectory.Combine (aref.Name);
				if (File.Exists (asm + ".dll"))
					References.Add (new ProjectReference (ReferenceType.Assembly, asm + ".dll"));
				else if (File.Exists (asm + ".exe"))
					References.Add (new ProjectReference (ReferenceType.Assembly, asm + ".exe"));
				else
					References.Add (new ProjectReference (ReferenceType.Package, aref.FullName));
			}*/
		}
Exemplo n.º 2
0
 private ISymbolReader ResolveSymbolReader()
 {
     string symbolLocation = null;
     string pdbLocation = Path.ChangeExtension(AssemblyLocation, "pdb");
     string mdbLocation = AssemblyLocation + ".mdb";
     ISymbolReaderProvider provider = null;
     if (File.Exists(pdbLocation))
     {
         symbolLocation = pdbLocation;
         provider = new PdbReaderProvider();
     }
     else if (File.Exists(mdbLocation))
     {
         symbolLocation = AssemblyLocation;
         provider = new MdbReaderProvider();
     }
     if (provider == null) return null;
     var reader = provider.GetSymbolReader(Definition, symbolLocation);
     return reader;
 }
Exemplo n.º 3
0
        public static void SaveAssembly(AssemblyDefinition assembly, string destination)
        {
            bool symbols = assembly.MainModule.HasSymbols;
            // re-write symbols, if available, so the new tokens will match
            assembly.Write (destination, new WriterParameters () { WriteSymbols = symbols });

            if (symbols) {
                // re-load symbols (cecil will dispose MdbReader and will crash later if we need to save again)
                var provider = new MdbReaderProvider ();
                assembly.MainModule.ReadSymbols (provider.GetSymbolReader (assembly.MainModule, destination));
            } else {
                // if we're not saving the symbols then we must not leave stale/old files to be used by other tools
                string dest_mdb = destination + ".mdb";
                if (File.Exists (dest_mdb))
                    File.Delete (dest_mdb);
            }
        }