X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Ftools%2Fmono-symbolicate%2Fsymbolicate.cs;h=2c04a27eef04e84b37cd51a2b4b9b78a83be4358;hb=c467c938ddb50af1cc6bc03154392c42d529e5ac;hp=4dd23e3d1bd16fea494ae918bcfd269b2532bc09;hpb=559ad5b34bc086b51af2e589b32ea2eae0f78820;p=mono.git diff --git a/mcs/tools/mono-symbolicate/symbolicate.cs b/mcs/tools/mono-symbolicate/symbolicate.cs index 4dd23e3d1bd..2c04a27eef0 100644 --- a/mcs/tools/mono-symbolicate/symbolicate.cs +++ b/mcs/tools/mono-symbolicate/symbolicate.cs @@ -1,89 +1,106 @@ using System; using System.IO; +using System.Text; +using System.Linq; +using System.Collections.Generic; using System.Globalization; -using System.Text.RegularExpressions; +using Mono.Options; -namespace Symbolicate +namespace Mono { - public class Program + public class Symbolicate { - static Regex regex = new Regex (@"\w*at (?.+) *(\[0x(?.+)\]|<0x.+ \+ 0x(?.+)>( (?\d+)|)) in :0"); + class Command { + public readonly int MinArgCount; + public readonly int MaxArgCount; + public readonly Action> Action; + + public Command (Action> action, int minArgCount = 0, int maxArgCount = int.MaxValue) + { + Action = action; + MinArgCount = minArgCount; + MaxArgCount = maxArgCount; + } + } + + static Logger logger; public static int Main (String[] args) { - if (args.Length < 2) { - Console.Error.WriteLine ("Usage: symbolicate [lookup directories]"); - return 1; - } - - var assemblyPath = args [0]; - var inputFile = args [1]; + var showHelp = false; + List extra = null; - var locProvider = new LocationProvider (); + Command cmd = null; - for (var i = 2; i < args.Length; i++) - locProvider.AddDirectory (args [i]); + var logLevel = Logger.Level.Warning; - locProvider.AddAssembly (assemblyPath); + var options = new OptionSet { + { "h|help", "Show this help", v => showHelp = true }, + { "q", "Quiet, warnings are not displayed", v => logLevel = Logger.Level.Error }, + { "v", "Verbose, log debug messages", v => logLevel = Logger.Level.Debug }, + }; - using (StreamReader r = new StreamReader (inputFile)) { - for (var line = r.ReadLine (); line != null; line = r.ReadLine ()) { - line = SymbolicateLine (line, locProvider); - Console.WriteLine (line); - } + try { + extra = options.Parse (args); + } catch (OptionException e) { + Console.WriteLine ("Option error: {0}", e.Message); + showHelp = true; } - return 0; - } + if (extra.Count > 0 && extra[0] == "store-symbols") + cmd = new Command (StoreSymbolsAction, 2); - static string SymbolicateLine (string line, LocationProvider locProvider) - { - var match = regex.Match (line); - if (!match.Success) - return line; - - string typeFullName; - var methodStr = match.Groups ["Method"].Value.Trim (); - if (!TryParseMethodType (methodStr, out typeFullName)) - return line; + if (cmd != null) { + extra.RemoveAt (0); + } else { + cmd = new Command (SymbolicateAction, 2, 2); + } - var isOffsetIL = !string.IsNullOrEmpty (match.Groups ["IL"].Value); - var offsetVarName = (isOffsetIL)? "IL" : "NativeOffset"; - var offset = int.Parse (match.Groups [offsetVarName].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture); + if (showHelp || extra == null || extra.Count < cmd.MinArgCount || extra.Count > cmd.MaxArgCount) { + Console.Error.WriteLine ("Usage: symbolicate [options] "); + Console.Error.WriteLine (" symbolicate [options] store-symbols []+"); + Console.WriteLine (); + Console.WriteLine ("Available options:"); + options.WriteOptionDescriptions (Console.Out); + return 1; + } - uint methodIndex = 0xffffff; - if (!string.IsNullOrEmpty (match.Groups ["MethodIndex"].Value)) - methodIndex = uint.Parse (match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture); + logger = new Logger (logLevel, msg => Console.Error.WriteLine (msg)); - Location location; - if (!locProvider.TryGetLocation (methodStr, typeFullName, offset, isOffsetIL, methodIndex, out location)) - return line; + cmd.Action (extra); - return line.Replace (":0", string.Format ("{0}:{1}", location.FileName, location.Line)); + return 0; } - static bool TryParseMethodType (string str, out string typeFullName) + private static void SymbolicateAction (List args) { - typeFullName = null; + var msymDir = args [0]; + var inputFile = args [1]; - var methodNameEnd = str.IndexOf ("("); - if (methodNameEnd == -1) - return false; + var symbolManager = new SymbolManager (msymDir, logger); - // Remove parameters - str = str.Substring (0, methodNameEnd); + using (StreamReader r = new StreamReader (inputFile)) { + for (var line = r.ReadLine (); line != null; line = r.ReadLine ()) { + StackFrameData sfData; + if (StackFrameData.TryParse (line, out sfData) && + symbolManager.TryResolveLocation (sfData)) { + Console.WriteLine (sfData.ToString ()); + continue; + } - // Remove generic parameters - str = Regex.Replace (str, @"\[[^\[\]]*\]", ""); + Console.WriteLine (line); + } + } + } - var typeNameEnd = str.LastIndexOf ("."); - if (methodNameEnd == -1 || typeNameEnd == -1) - return false; + private static void StoreSymbolsAction (List args) + { + var msymDir = args[0]; + var lookupDirs = args.Skip (1).ToArray (); - // Remove method name - typeFullName = str.Substring (0, typeNameEnd); + var symbolManager = new SymbolManager (msymDir, logger); - return true; + symbolManager.StoreSymbols (lookupDirs); } } -} \ No newline at end of file +}