2 using System.Text.RegularExpressions;
3 using System.Globalization;
9 static Regex regex = new Regex (@"\w*at (?<Method>.+) *(\[0x(?<IL>.+)\]|<0x.+ \+ 0x(?<NativeOffset>.+)>( (?<MethodIndex>\d+)|)) in <(?<MVID>[^>#]+)(#(?<AOTID>[^>]+)|)>:0");
11 public readonly string TypeFullName;
12 public readonly string MethodSignature;
13 public readonly int Offset;
14 public readonly bool IsILOffset;
15 public readonly uint MethodIndex;
16 public readonly string Line;
17 public readonly string Mvid;
18 public readonly string Aotid;
20 public string File { get; private set; }
21 public int LineNumber { get; private set; }
23 private StackFrameData (string line, string typeFullName, string methodSig, int offset, bool isILOffset, uint methodIndex, string mvid, string aotid)
28 TypeFullName = typeFullName;
29 MethodSignature = methodSig;
31 IsILOffset = isILOffset;
32 MethodIndex = methodIndex;
37 public static bool TryParse (string line, out StackFrameData stackFrame)
41 var match = regex.Match (line);
45 string typeFullName, methodSignature;
46 var methodStr = match.Groups ["Method"].Value.Trim ();
47 if (!ExtractSignatures (methodStr, out typeFullName, out methodSignature))
50 var isILOffset = !string.IsNullOrEmpty (match.Groups ["IL"].Value);
51 var offsetVarName = (isILOffset)? "IL" : "NativeOffset";
52 var offset = int.Parse (match.Groups [offsetVarName].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
54 uint methodIndex = 0xffffff;
55 if (!string.IsNullOrEmpty (match.Groups ["MethodIndex"].Value))
56 methodIndex = uint.Parse (match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture);
58 var mvid = match.Groups ["MVID"].Value;
59 var aotid = match.Groups ["AOTID"].Value;
61 stackFrame = new StackFrameData (line, typeFullName, methodSignature, offset, isILOffset, methodIndex, mvid, aotid);
66 static bool ExtractSignatures (string str, out string typeFullName, out string methodSignature)
68 var methodNameEnd = str.IndexOf ('(');
69 if (methodNameEnd == -1) {
70 typeFullName = methodSignature = null;
74 var typeNameEnd = str.LastIndexOf ('.', methodNameEnd);
75 if (typeNameEnd == -1) {
76 typeFullName = methodSignature = null;
80 // Adjustment for Type..ctor ()
81 if (typeNameEnd > 0 && str [typeNameEnd - 1] == '.') {
85 typeFullName = str.Substring (0, typeNameEnd);
86 // Remove generic parameters
87 typeFullName = Regex.Replace (typeFullName, @"\[[^\[\]]*\]", "");
89 methodSignature = str.Substring (typeNameEnd + 1);
94 internal void SetLocation (string file, int lineNumber)
97 LineNumber = lineNumber;
100 public override string ToString ()
102 return string.Format ("{0} in {1}:{2} ", Line.Substring (0, Line.IndexOf(" in <", StringComparison.Ordinal)), File, LineNumber);