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)
22 var assemblyLocProvider = GetOrCreateAssemblyLocationProvider (mvid);
24 SeqPointInfo seqPointInfo = null;
25 if (!sfData.IsILOffset && aotid != null)
26 seqPointInfo = GetOrCreateSeqPointInfo (aotid);
28 return assemblyLocProvider.TryResolveLocation (sfData, seqPointInfo);
31 Dictionary<string, AssemblyLocationProvider> assemblies = new Dictionary<string, AssemblyLocationProvider> ();
33 private AssemblyLocationProvider GetOrCreateAssemblyLocationProvider (string mvid)
35 if (assemblies.ContainsKey (mvid))
36 return assemblies[mvid];
38 var mvidDir = Path.Combine (msymDir, mvid);
39 if (!Directory.Exists (mvidDir))
40 throw new Exception (string.Format("MVID directory does not exist: {0}", mvidDir));
42 string assemblyPath = null;
43 var exeFiles = Directory.GetFiles (mvidDir, "*.exe");
44 var dllFiles = Directory.GetFiles (mvidDir, "*.dll");
46 if (exeFiles.Length + dllFiles.Length != 1)
47 throw new Exception (string.Format ("MVID directory should include one assembly: {0}", mvidDir));
49 assemblyPath = (exeFiles.Length > 0)? exeFiles[0] : dllFiles[0];
51 var locProvider = new AssemblyLocationProvider (assemblyPath);
53 assemblies.Add (mvid, locProvider);
58 Dictionary<string, SeqPointInfo> seqPointInfos = new Dictionary<string, SeqPointInfo> ();
60 private SeqPointInfo GetOrCreateSeqPointInfo (string aotid)
62 if (seqPointInfos.ContainsKey (aotid))
63 return seqPointInfos[aotid];
65 var aotidDir = Path.Combine (msymDir, aotid);
66 if (!Directory.Exists (aotidDir))
67 throw new Exception (string.Format("AOTID directory does not exist: {0}", aotidDir));
69 string msymFile = null;
70 var msymFiles = Directory.GetFiles(aotidDir, "*.msym");
71 msymFile = msymFiles[0];
73 var seqPointInfo = SeqPointInfo.Read (msymFile);
75 seqPointInfos.Add (aotid, seqPointInfo);
80 public void StoreSymbols (params string[] lookupDirs)
82 foreach (var dir in lookupDirs) {
83 var exeFiles = Directory.GetFiles (dir, "*.exe");
84 var dllFiles = Directory.GetFiles (dir, "*.dll");
85 var assemblies = exeFiles.Concat (dllFiles);
86 foreach (var assemblyPath in assemblies) {
87 var mdbPath = assemblyPath + ".mdb";
88 if (!File.Exists (mdbPath)) {
89 // assemblies without mdb files are useless
93 var assembly = AssemblyDefinition.ReadAssembly (assemblyPath);
95 var mvid = assembly.MainModule.Mvid.ToString ("N");
96 var mvidDir = Path.Combine (msymDir, mvid);
98 Directory.CreateDirectory (mvidDir);
100 var mvidAssemblyPath = Path.Combine (mvidDir, Path.GetFileName (assemblyPath));
101 File.Copy (assemblyPath, mvidAssemblyPath);
103 var mvidMdbPath = Path.Combine (mvidDir, Path.GetFileName (mdbPath));
104 File.Copy (mdbPath, mvidMdbPath);
106 // TODO create MVID dir for non main modules with links to main module MVID