Xamarin Public Jenkins (auto-signing) b95516a3dd Imported Upstream version 4.6.0.150
Former-commit-id: 73e3bb1e96dd09dc931c1dfe559d2c7f7b8b02c7
2016-08-23 13:20:38 +00:00

107 lines
2.7 KiB
C#

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<List<string>> Action;
public Command (Action<List<string>> 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<string> 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] <msym dir> <input file>");
Console.Error.WriteLine (" symbolicate [options] store-symbols <msym dir> [<dir>]+");
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<string> 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<string> args)
{
var msymDir = args[0];
var lookupDirs = args.Skip (1).ToArray ();
var symbolManager = new SymbolManager (msymDir, logger);
symbolManager.StoreSymbols (lookupDirs);
}
}
}