|
6 | 6 |
|
7 | 7 | namespace PmipMyCallStack
|
8 | 8 | {
|
9 |
| - class PmipRunner |
10 |
| - { |
11 |
| - private static readonly DkmLanguage CppLanguage = DkmLanguage.Create("C++", new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp)); |
12 |
| - |
13 |
| - private readonly DkmStackContext _stackContext; |
14 |
| - private readonly DkmStackWalkFrame _frame; |
15 |
| - private readonly DkmInspectionContext _inspectionContext; |
16 |
| - |
17 |
| - public PmipRunner(DkmStackContext stackContext, DkmStackWalkFrame frame) |
18 |
| - { |
19 |
| - _stackContext = stackContext; |
20 |
| - _frame = frame; |
21 |
| - _inspectionContext = CreateInspectionContext(stackContext, frame); |
22 |
| - } |
23 |
| - |
24 |
| - public DkmStackWalkFrame PmipStackFrame() |
25 |
| - { |
26 |
| - PmipFunctionDataItem pmipFunction; |
27 |
| - if (!TryGetPmipFunction(out pmipFunction)) |
28 |
| - return _frame; |
29 |
| - |
30 |
| - var ip = $"0x{_frame.InstructionAddress.CPUInstructionPart.InstructionPointer:X}"; |
31 |
| - var call = $"((char*(*)(void*)){pmipFunction.PmipFunction})((void*){ip})"; |
32 |
| - |
33 |
| - var result = "<ERROR>"; |
34 |
| - var isNull = true; |
35 |
| - |
36 |
| - var eval = EvaluateExpression(call, r => |
37 |
| - { |
38 |
| - isNull = r.Address.InstructionAddress.CPUInstructionPart.InstructionPointer == 0; |
39 |
| - if (r.Value != null) |
40 |
| - { |
41 |
| - try |
42 |
| - { |
43 |
| - int afterBeginQuote = r.Value.IndexOf("\"", StringComparison.Ordinal) + 1; |
44 |
| - int beforeEndQuote = r.Value.Length - 1; |
45 |
| - result = r.Value.Substring(afterBeginQuote, beforeEndQuote - afterBeginQuote); |
46 |
| - } |
47 |
| - catch (Exception) |
48 |
| - { |
49 |
| - } |
50 |
| - |
51 |
| - } |
52 |
| - |
53 |
| - }); |
54 |
| - |
55 |
| - if (!eval || isNull) |
56 |
| - return _frame; |
| 9 | + //class PmipRunner |
| 10 | + //{ |
| 11 | + // private readonly DkmStackContext _stackContext; |
| 12 | + // private readonly DkmStackWalkFrame _frame; |
| 13 | + // private readonly DkmInspectionContext _inspectionContext; |
| 14 | + |
| 15 | + // public PmipRunner(DkmStackContext stackContext, DkmStackWalkFrame frame) |
| 16 | + // { |
| 17 | + // _stackContext = stackContext; |
| 18 | + // _frame = frame; |
| 19 | + // _inspectionContext = PmipUtils.CreateInspectionContext(stackContext, frame); |
| 20 | + // } |
| 21 | + |
| 22 | + // public DkmStackWalkFrame PmipStackFrame() |
| 23 | + // { |
| 24 | + // PmipFunctionDataItem pmipFunction; |
| 25 | + // if (!TryGetPmipFunction(out pmipFunction)) |
| 26 | + // return _frame; |
| 27 | + |
| 28 | + // var ip = $"0x{_frame.InstructionAddress.CPUInstructionPart.InstructionPointer:X}"; |
| 29 | + // var call = $"((char*(*)(void*)){pmipFunction.PmipFunction})((void*){ip})"; |
| 30 | + |
| 31 | + // var result = "<ERROR>"; |
| 32 | + // var isNull = true; |
| 33 | + |
| 34 | + // var eval = PmipUtils.EvaluateExpression(_inspectionContext, _frame ,call, r => |
| 35 | + // { |
| 36 | + // isNull = r.Address.InstructionAddress.CPUInstructionPart.InstructionPointer == 0; |
| 37 | + // result = r.Value; |
| 38 | + // }); |
| 39 | + |
| 40 | + // if (!eval || isNull) |
| 41 | + // return _frame; |
57 | 42 |
|
58 |
| - return DkmStackWalkFrame.Create( |
59 |
| - _stackContext.Thread, |
60 |
| - _frame.InstructionAddress, |
61 |
| - _frame.FrameBase, |
62 |
| - _frame.FrameSize, |
63 |
| - _frame.Flags, |
64 |
| - result, |
65 |
| - _frame.Registers, |
66 |
| - _frame.Annotations); |
67 |
| - } |
68 |
| - |
69 |
| - private DkmNativeInstructionAddress FindInstructionAddress(string functionName) |
70 |
| - { |
71 |
| - foreach (var module in this._frame.RuntimeInstance.GetModuleInstances()) |
72 |
| - { |
73 |
| - var address = (module as DkmNativeModuleInstance)?.FindExportName(functionName, |
74 |
| - IgnoreDataExports: true); |
75 |
| - if(address != null) |
76 |
| - return address; |
77 |
| - } |
78 |
| - return null; |
79 |
| - } |
80 |
| - |
81 |
| - private bool TryGetPmipFunction(out PmipFunctionDataItem pmipFunction) |
82 |
| - { |
83 |
| - pmipFunction = _stackContext.GetDataItem<PmipFunctionDataItem>(); |
84 |
| - if (pmipFunction != null) |
85 |
| - return true; |
86 |
| - |
87 |
| - var pmipOrig = FindInstructionAddress("mono_pmip"); |
88 |
| - var pmipPretty = FindInstructionAddress("mono_pmip_pretty"); |
89 |
| - |
90 |
| - var pmipFnToUse = pmipPretty ?? pmipOrig; |
91 |
| - |
92 |
| - if (pmipFnToUse == null) |
93 |
| - return false; |
94 |
| - |
95 |
| - var item = new PmipFunctionDataItem { PmipFunction = "0x" + pmipFnToUse.CPUInstructionPart.InstructionPointer.ToString("X") }; |
96 |
| - pmipFunction = item; |
97 |
| - _stackContext.SetDataItem(DkmDataCreationDisposition.CreateAlways, item); |
98 |
| - |
99 |
| - return true; |
100 |
| - } |
101 |
| - |
102 |
| - private static DkmLanguageExpression CppExpression(string expression) |
103 |
| - { |
104 |
| - return DkmLanguageExpression.Create(CppLanguage, DkmEvaluationFlags.None, expression, null); |
105 |
| - } |
106 |
| - |
107 |
| - private static DkmInspectionContext CreateInspectionContext(DkmStackContext stackContext, DkmStackWalkFrame frame) |
108 |
| - { |
109 |
| - return DkmInspectionContext.Create( |
110 |
| - stackContext.InspectionSession, |
111 |
| - frame.RuntimeInstance, |
112 |
| - frame.Thread, |
113 |
| - 1000, |
114 |
| - DkmEvaluationFlags.None, |
115 |
| - DkmFuncEvalFlags.None, |
116 |
| - 10, |
117 |
| - CppLanguage, |
118 |
| - null); |
119 |
| - } |
120 |
| - |
121 |
| - private bool EvaluateExpression(string expression, Action<DkmSuccessEvaluationResult> onSuccess) |
122 |
| - { |
123 |
| - var workList = DkmWorkList.Create(null); |
124 |
| - var success = false; |
125 |
| - |
126 |
| - _inspectionContext.EvaluateExpression(workList, CppExpression(expression), _frame, res => |
127 |
| - { |
128 |
| - var resObj = res.ResultObject; |
129 |
| - var result = resObj as DkmSuccessEvaluationResult; |
130 |
| - if (result != null) |
131 |
| - { |
132 |
| - success = true; |
133 |
| - onSuccess(result); |
134 |
| - } |
135 |
| - |
136 |
| - resObj.Close(); |
137 |
| - }); |
138 |
| - |
139 |
| - workList.Execute(); |
140 |
| - return success; |
141 |
| - } |
142 |
| - } |
| 43 | + // return DkmStackWalkFrame.Create( |
| 44 | + // _stackContext.Thread, |
| 45 | + // _frame.InstructionAddress, |
| 46 | + // _frame.FrameBase, |
| 47 | + // _frame.FrameSize, |
| 48 | + // _frame.Flags, |
| 49 | + // result, |
| 50 | + // _frame.Registers, |
| 51 | + // _frame.Annotations); |
| 52 | + // } |
| 53 | + |
| 54 | + |
| 55 | + //} |
143 | 56 | }
|
0 commit comments