public override bool InitializeSymbolService(string ExecutableName, FUIBroker UIBroker) { string FDsName = FStreamInfo.GlobalInstance.FileName; string FAdName; string FUcName; string FExtension = Path.GetExtension(FDsName).ToLower(); if (FExtension == ".mprof") { FAdName = Path.GetDirectoryName(FDsName) + "\\" + ExecutableName + ".udebugsymbols"; FUcName = Path.GetDirectoryName(FDsName) + "\\" + ExecutableName + ".udb"; } else { return(false); } if (!File.Exists(FAdName)) { MessageBox.Show(String.Format("Failed to look up symbol file ({0}). Please check the path and try again!", FAdName), "Memory Profiler 2", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } byte[] uncompressed = new byte[0]; bool NeedsDecompress = false; if (!File.Exists(FUcName)) { NeedsDecompress = true; } else if (File.GetCreationTimeUtc(FAdName) > File.GetCreationTimeUtc(FUcName)) { NeedsDecompress = true; } if (NeedsDecompress) { byte[] data = File.ReadAllBytes(FAdName); MemoryStream memory = new MemoryStream(data); BinaryReader reader = new BinaryReader(memory); byte[] DeCompressedBuffer = LoadCompressedChunk(reader); while (DeCompressedBuffer != null) { AppendAllBytes(FUcName, DeCompressedBuffer); DeCompressedBuffer = LoadCompressedChunk(reader); } } uncompressed = File.ReadAllBytes(FUcName); if (uncompressed != null) { MemoryStream memory = new MemoryStream(uncompressed); BinaryReader reader = new BinaryReader(memory); Database.Read(reader); } return(true); }
public override bool InitializeSymbolService(string ExecutableName, FUIBroker UIBroker) { // ask the platform code for the actual path string NmPath = GetNmPath(); bool bVerifyInfoWithUser; string DebugInfoPath = GetDebugInfoPath(ExecutableName, out bVerifyInfoWithUser); // Nm must exist!!! if (!File.Exists(NmPath)) { return(false); } // if the platform couldn't guarantee where the debug info was, let the user select it if (string.IsNullOrEmpty(DebugInfoPath) || !File.Exists(DebugInfoPath) || bVerifyInfoWithUser) { var DebugInfoFileDialog = new OpenFileDialog(); DebugInfoFileDialog.Title = "Open the debug info (or executable) that this profile was generated from"; DebugInfoFileDialog.Filter = string.Format("Debugging Info (*.{0})|*.{0}", GetDebugInfoExtension()); DebugInfoFileDialog.FileName = String.Format("{0}.{1}", ExecutableName, GetDebugInfoExtension()); DebugInfoFileDialog.SupportMultiDottedExtensions = true; DebugInfoFileDialog.RestoreDirectory = false; // prepare the file if we had a valid file already if (!string.IsNullOrEmpty(DebugInfoPath) && File.Exists(DebugInfoPath)) { DebugInfoFileDialog.Title = "Verify the expected debug info below is correct:"; DebugInfoFileDialog.InitialDirectory = Path.GetDirectoryName(DebugInfoPath); DebugInfoFileDialog.FileName = Path.GetFileName(DebugInfoPath); } DebugInfoPath = UIBroker.ShowOpenFileDialog(DebugInfoFileDialog); // early out if we canceled if (!File.Exists(DebugInfoPath)) { return(false); } } string Args = string.Format("-n -C \"{0}\"", DebugInfoPath); string Output = RunLocalProcessAndReturnStdOut(NmPath, Args); // parse the output a line at a time using (StringReader sr = new StringReader(Output)) { string Line; while ((Line = sr.ReadLine()) != null) { if (Line.StartsWith("0")) { try { // break it apart ulong Address = ulong.Parse(Line.Substring(0, 16), System.Globalization.NumberStyles.HexNumber); string Symbol = Line.Substring(19); // add to the lists Addresses.Add(Address); Symbols.Add(Symbol); } catch (Exception) { } } } } // now we can cache off the offset, and let the platform calculate it (could be slow) CachedSymbolOffset = GetSymbolOffset(); return(true); }