5 using System.Collections.Generic;
6 using System.Globalization;
11 public class Symbolicate
14 public readonly int MinArgCount;
15 public readonly int MaxArgCount;
16 public readonly Action<List<string>> Action;
18 public Command (Action<List<string>> action, int minArgCount = 0, int maxArgCount = int.MaxValue)
21 MinArgCount = minArgCount;
22 MaxArgCount = maxArgCount;
28 public static int Main (String[] args)
31 List<string> extra = null;
35 var logLevel = Logger.Level.Warning;
37 var options = new OptionSet {
38 { "h|help", "Show this help", v => showHelp = true },
39 { "q", "Quiet, warnings are not displayed", v => logLevel = Logger.Level.Error },
40 { "v", "Verbose, log debug messages", v => logLevel = Logger.Level.Debug },
44 extra = options.Parse (args);
45 } catch (OptionException e) {
46 Console.WriteLine ("Option error: {0}", e.Message);
50 if (extra.Count > 0 && extra[0] == "store-symbols")
51 cmd = new Command (StoreSymbolsAction, 2);
56 cmd = new Command (SymbolicateAction, 2, 2);
59 if (showHelp || extra == null || extra.Count < cmd.MinArgCount || extra.Count > cmd.MaxArgCount) {
60 Console.Error.WriteLine ("Usage: symbolicate [options] <msym dir> <input file>");
61 Console.Error.WriteLine (" symbolicate [options] store-symbols <msym dir> [<dir>]+");
63 Console.WriteLine ("Available options:");
64 options.WriteOptionDescriptions (Console.Out);
68 logger = new Logger (logLevel, msg => Console.Error.WriteLine (msg));
75 private static void SymbolicateAction (List<string> args)
77 var msymDir = args [0];
78 var inputFile = args [1];
80 var symbolManager = new SymbolManager (msymDir, logger);
82 using (StreamReader r = new StreamReader (inputFile)) {
83 for (var line = r.ReadLine (); line != null; line = r.ReadLine ()) {
84 StackFrameData sfData;
85 if (StackFrameData.TryParse (line, out sfData) &&
86 symbolManager.TryResolveLocation (sfData)) {
87 Console.WriteLine (sfData.ToString ());
91 Console.WriteLine (line);
96 private static void StoreSymbolsAction (List<string> args)
98 var msymDir = args[0];
99 var lookupDirs = args.Skip (1).ToArray ();
101 var symbolManager = new SymbolManager (msymDir, logger);
103 symbolManager.StoreSymbols (lookupDirs);