5 using System.Collections.Generic;
8 using Mono.Collections.Generic;
12 public class SymbolManager
16 public SymbolManager (string msymDir) {
17 this.msymDir = msymDir;
20 internal bool TryResolveLocation (StackFrameData sfData, string mvid, string aotid)
25 var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (mvid);
26 if (assemblyLocProvider == null)
29 SeqPointInfo seqPointInfo = null;
30 if (!sfData.IsILOffset && aotid != null)
31 seqPointInfo = GetOrCreateSeqPointInfo (aotid);
33 return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo);
36 Dictionary<string, AssemblyLocationProvider> assemblies = new Dictionary<string, AssemblyLocationProvider> ();
38 private AssemblyLocationProvider GetOrCreateAssemblyLocationProvider (string mvid)
40 if (assemblies.ContainsKey (mvid))
41 return assemblies[mvid];
43 var mvidDir = Path.Combine (msymDir, mvid);
44 if (!Directory.Exists (mvidDir)) {
45 Console.Error.WriteLine ("MVID directory does not exist: {0}", mvidDir);
49 string assemblyPath = null;
50 var exeFiles = Directory.GetFiles (mvidDir, "*.exe");
51 var dllFiles = Directory.GetFiles (mvidDir, "*.dll");
53 if (exeFiles.Length + dllFiles.Length != 1)
54 throw new Exception (string.Format ("MVID directory should include one assembly: {0}", mvidDir));
56 assemblyPath = (exeFiles.Length > 0)? exeFiles[0] : dllFiles[0];
58 var locProvider = new AssemblyLocationProvider (assemblyPath);
60 assemblies.Add (mvid, locProvider);
65 Dictionary<string, SeqPointInfo> seqPointInfos = new Dictionary<string, SeqPointInfo> ();
67 private SeqPointInfo GetOrCreateSeqPointInfo (string aotid)
69 if (seqPointInfos.ContainsKey (aotid))
70 return seqPointInfos[aotid];
72 var aotidDir = Path.Combine (msymDir, aotid);
73 if (!Directory.Exists (aotidDir))
74 throw new Exception (string.Format("AOTID directory does not exist: {0}", aotidDir));
76 string msymFile = null;
77 var msymFiles = Directory.GetFiles(aotidDir, "*.msym");
78 msymFile = msymFiles[0];
80 var seqPointInfo = SeqPointInfo.Read (msymFile);
82 seqPointInfos.Add (aotid, seqPointInfo);
87 public void StoreSymbols (params string[] lookupDirs)
89 foreach (var dir in lookupDirs) {
90 var exeFiles = Directory.GetFiles (dir, "*.exe");
91 var dllFiles = Directory.GetFiles (dir, "*.dll");
92 var assemblies = exeFiles.Concat (dllFiles);
93 foreach (var assemblyPath in assemblies) {
94 var mdbPath = assemblyPath + ".mdb";
95 if (!File.Exists (mdbPath)) {
96 // assemblies without mdb files are useless
100 var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
102 var mvid = assembly.MainModule.Mvid.ToString ("N");
103 var mvidDir = Path.Combine (msymDir, mvid);
105 if (Directory.Exists (mvidDir))
106 Directory.Delete (mvidDir, true);
108 Directory.CreateDirectory (mvidDir);
110 var mvidAssemblyPath = Path.Combine (mvidDir, Path.GetFileName (assemblyPath));
111 File.Copy (assemblyPath, mvidAssemblyPath);
113 var mvidMdbPath = Path.Combine (mvidDir, Path.GetFileName (mdbPath));
114 File.Copy (mdbPath, mvidMdbPath);
116 // TODO create MVID dir for non main modules with links to main module MVID