Debian Codegraph @

mcs/tools/mono-symbolicate/StackFrameData.cs

raw
1 using System;
2 using System.Text.RegularExpressions;
3 using System.Globalization;
4
5 namespace Mono
6 {
7 class StackFrameData
8 {
9 static Regex regex = new Regex (@"\w*at (?<Method>.+) *(\[0x(?<IL>.+)\]|<0x.+ \+ 0x(?<NativeOffset>.+)>( (?<MethodIndex>\d+)|)) in <(?<MVID>[^>#]+)(#(?<AOTID>[^>]+)|)>:0");
10
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;
19
20 private StackFrameData (string line, string typeFullName, string methodSig, int offset, bool isILOffset, uint methodIndex, string mvid, string aotid)
21 {
22 Line = line;
23 TypeFullName = typeFullName;
24 MethodSignature = methodSig;
25 Offset = offset;
26 IsILOffset = isILOffset;
27 MethodIndex = methodIndex;
28 Mvid = mvid;
29 Aotid = aotid;
30 }
31
32 public StackFrameData Relocate (string typeName, string methodName)
33 {
34 return new StackFrameData (Line, typeName, methodName, Offset, IsILOffset, MethodIndex, Mvid, Aotid);
35 }
36
37 public static bool TryParse (string line, out StackFrameData stackFrame)
38 {
39 stackFrame = null;
40
41 var match = regex.Match (line);
42 if (!match.Success)
43 return false;
44
45 string typeFullName, methodSignature;
46 var methodStr = match.Groups ["Method"].Value.Trim ();
47 if (!ExtractSignatures (methodStr, out typeFullName, out methodSignature))
48 return false;
49
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);
53
54 uint methodIndex = 0xffffff;
55 if (!string.IsNullOrEmpty (match.Groups ["MethodIndex"].Value))
56 methodIndex = uint.Parse (match.Groups ["MethodIndex"].Value, CultureInfo.InvariantCulture);
57
58 var mvid = match.Groups ["MVID"].Value;
59 var aotid = match.Groups ["AOTID"].Value;
60
61 stackFrame = new StackFrameData (line, typeFullName, methodSignature, offset, isILOffset, methodIndex, mvid, aotid);
62
63 return true;
64 }
65
66 static bool ExtractSignatures (string str, out string typeFullName, out string methodSignature)
67 {
68 var methodNameEnd = str.IndexOf ('(');
69 if (methodNameEnd == -1) {
70 typeFullName = methodSignature = null;
71 return false;
72 }
73
74 var typeNameEnd = str.LastIndexOf ('.', methodNameEnd);
75 if (typeNameEnd == -1) {
76 typeFullName = methodSignature = null;
77 return false;
78 }
79
80 // Adjustment for Type..ctor ()
81 if (typeNameEnd > 0 && str [typeNameEnd - 1] == '.') {
82 --typeNameEnd;
83 }
84
85 typeFullName = str.Substring (0, typeNameEnd);
86 // Remove generic parameters
87 typeFullName = Regex.Replace (typeFullName, @"\[[^\[\]]*\]$", "");
88 typeFullName = Regex.Replace (typeFullName, @"\<[^\[\]]*\>$", "");
89
90 methodSignature = str.Substring (typeNameEnd + 1);
91
92 return true;
93 }
94 }
95 }