public static unsafe PyFrameObject TryCreate(DkmStackWalkFrame frame) { var process = frame.Process; var PyEval_EvalFrameEx = process.CreateNativeInstructionAddress(process.GetPythonRuntimeInfo().DLLs.Python.GetFunctionAddress("PyEval_EvalFrameEx")); if (frame.InstructionAddress == null) { return null; } if (frame.RuntimeInstance.Id.RuntimeType != Guids.PythonRuntimeTypeGuid && !frame.InstructionAddress.IsInSameFunction(PyEval_EvalFrameEx)) { return null; } var cppLanguage = DkmLanguage.Create("C++", new DkmCompilerId(Guids.MicrosoftVendorGuid, Guids.CppLanguageGuid)); var inspectionSession = DkmInspectionSession.Create(process, null); var inspectionContext = DkmInspectionContext.Create(inspectionSession, process.GetNativeRuntimeInstance(), frame.Thread, 0, DkmEvaluationFlags.TreatAsExpression | DkmEvaluationFlags.NoSideEffects, DkmFuncEvalFlags.None, 10, cppLanguage, null); CppExpressionEvaluator cppEval; try { cppEval = new CppExpressionEvaluator(inspectionContext, frame); } catch (ArgumentException) { Debug.Fail("Failed to create C++ expression evaluator while obtaining PyFrameObject from a native frame."); return null; } ulong framePtr; try { framePtr = cppEval.EvaluateUInt64("f"); } catch (CppEvaluationException) { Debug.Fail("Failed to evaluate the 'f' parameter to PyEval_EvalFrameEx while obtaining PyFrameObject from a native frame."); return null; } return new PyFrameObject(frame.Process, framePtr); }
public static unsafe PyFrameObject TryCreate(DkmStackWalkFrame frame) { var process = frame.Process; if (frame.InstructionAddress == null) { return(null); } if (frame.RuntimeInstance.Id.RuntimeType != Guids.PythonRuntimeTypeGuid && !IsInEvalFrame(frame)) { return(null); } var cppLanguage = DkmLanguage.Create("C++", new DkmCompilerId(Guids.MicrosoftVendorGuid, Guids.CppLanguageGuid)); var inspectionSession = DkmInspectionSession.Create(process, null); var inspectionContext = DkmInspectionContext.Create(inspectionSession, process.GetNativeRuntimeInstance(), frame.Thread, 0, DkmEvaluationFlags.TreatAsExpression | DkmEvaluationFlags.NoSideEffects, DkmFuncEvalFlags.None, 10, cppLanguage, null); CppExpressionEvaluator cppEval; try { cppEval = new CppExpressionEvaluator(inspectionContext, frame); } catch (ArgumentException) { Debug.Fail("Failed to create C++ expression evaluator while obtaining PyFrameObject from a native frame."); return(null); } ulong framePtr; try { framePtr = cppEval.EvaluateUInt64("f"); } catch (CppEvaluationException) { Debug.Fail("Failed to evaluate the 'f' parameter to PyEval_EvalFrameEx while obtaining PyFrameObject from a native frame."); return(null); } return(new PyFrameObject(frame.Process, framePtr)); }