using System; using System.IO; using System.Text; using System.Linq; using System.Collections.Generic; using System.Globalization; using Mono.Options; namespace Mono { public class Symbolicate { 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) { var showHelp = false; List extra = null; Command cmd = null; var logLevel = Logger.Level.Warning; 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 }, }; try { extra = options.Parse (args); } catch (OptionException e) { Console.WriteLine ("Option error: {0}", e.Message); showHelp = true; } if (extra.Count > 0 && extra[0] == "store-symbols") cmd = new Command (StoreSymbolsAction, 2); if (cmd != null) { extra.RemoveAt (0); } else { cmd = new Command (SymbolicateAction, 2, 2); } 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; } logger = new Logger (logLevel, msg => Console.Error.WriteLine (msg)); cmd.Action (extra); return 0; } private static void SymbolicateAction (List args) { var msymDir = args [0]; var inputFile = args [1]; var symbolManager = new SymbolManager (msymDir, logger); 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; } Console.WriteLine (line); } } } private static void StoreSymbolsAction (List args) { var msymDir = args[0]; var lookupDirs = args.Skip (1).ToArray (); var symbolManager = new SymbolManager (msymDir, logger); symbolManager.StoreSymbols (lookupDirs); } } }