public ModuleManager(DkmProcess process) { _process = process; _pyrtInfo = process.GetPythonRuntimeInfo(); LoadInitialPythonModules(); LocalComponent.CreateRuntimeDllFunctionBreakpoint(_pyrtInfo.DLLs.Python, "PyCode_New", PythonDllBreakpointHandlers.PyCode_New, enable: true, debugStart: true); LocalComponent.CreateRuntimeDllFunctionBreakpoint(_pyrtInfo.DLLs.Python, "PyCode_NewEmpty", PythonDllBreakpointHandlers.PyCode_NewEmpty, enable: true, debugStart: true); }
public Types(DkmProcess process, PythonRuntimeInfo pyrtInfo) { PyBytes_Type = PyObject.GetPyType <PyBytesObject>(process).Address; if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { PyUnicode_Type = PyObject.GetPyType <PyUnicodeObject27>(process).Address; } else { PyUnicode_Type = PyObject.GetPyType <PyUnicodeObject33>(process).Address; } }
private static bool Py_IsInitialized(PythonRuntimeInfo pyrtInfo) { var ver = pyrtInfo.LanguageVersion; var objName = ver < PythonLanguageVersion.V35 ? "pythonrun.obj" : ver < PythonLanguageVersion.V37 ? "pylifecycle.obj" : null; var varName = ver < PythonLanguageVersion.V37 ? "initialized" : "_Py_Initialized"; try { return(pyrtInfo.DLLs.Python.GetStaticVariable <Int32Proxy>(varName, objName).Read() != 0); } catch (ArgumentException) { return(false); } }
public FieldOffsets(DkmProcess process, PythonRuntimeInfo pyrtInfo) { PyObject = new PyObject_FieldOffsets(process); PyVarObject = new PyVarObject_FieldOffsets(process); PyFrameObject = new PyFrameObject_FieldOffsets(process); PyCodeObject = new PyCodeObject_FieldOffsets(process); PyBytesObject = new PyBytesObject_FieldOffsets(process); if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { PyUnicodeObject27 = new PyUnicodeObject27_FieldOffsets(process); PyUnicodeObject33 = new PyUnicodeObject33_FieldOffsets(); } else { PyUnicodeObject27 = new PyUnicodeObject27_FieldOffsets(); PyUnicodeObject33 = new PyUnicodeObject33_FieldOffsets(process); } }
public unsafe TraceManagerLocalHelper(DkmProcess process, Kind kind) { _process = process; _pyrtInfo = process.GetPythonRuntimeInfo(); _traceFunc = _pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("TraceFunc"); _evalFrameFunc = _pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("EvalFrameFunc"); _defaultEvalFrameFunc = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <PointerProxy>("DefaultEvalFrameFunc"); _isTracing = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <ByteProxy>("isTracing"); _pyTracingPossible = _pyrtInfo.DLLs.Python.GetStaticVariable <UInt32Proxy>("_Py_TracingPossible"); if (kind == Kind.StepIn) { var fieldOffsets = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <FieldOffsets> >("fieldOffsets"); fieldOffsets.Write(new FieldOffsets(process, _pyrtInfo)); var types = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <Types> >("types"); types.Write(new Types(process, _pyrtInfo)); var functionPointers = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <FunctionPointers> >("functionPointers"); functionPointers.Write(new FunctionPointers(process, _pyrtInfo)); var stringEquals = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <PointerProxy>("stringEquals"); if (_pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { stringEquals.Write(_pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("StringEquals27").GetPointer()); } else { stringEquals.Write(_pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("StringEquals33").GetPointer()); } foreach (var interp in PyInterpreterState.GetInterpreterStates(process)) { if (_pyrtInfo.LanguageVersion >= PythonLanguageVersion.V36) { RegisterJITTracing(interp); } foreach (var tstate in interp.GetThreadStates()) { RegisterTracing(tstate); } } _handlers = new PythonDllBreakpointHandlers(this); LocalComponent.CreateRuntimeDllFunctionExitBreakpoints(_pyrtInfo.DLLs.Python, "new_threadstate", _handlers.new_threadstate, enable: true); LocalComponent.CreateRuntimeDllFunctionExitBreakpoints(_pyrtInfo.DLLs.Python, "PyInterpreterState_New", _handlers.PyInterpreterState_New, enable: true); foreach (var methodInfo in _handlers.GetType().GetMethods()) { var stepInAttr = (StepInGateAttribute)Attribute.GetCustomAttribute(methodInfo, typeof(StepInGateAttribute)); if (stepInAttr != null && (stepInAttr.MinVersion == PythonLanguageVersion.None || _pyrtInfo.LanguageVersion >= stepInAttr.MinVersion) && (stepInAttr.MaxVersion == PythonLanguageVersion.None || _pyrtInfo.LanguageVersion <= stepInAttr.MaxVersion)) { var handler = (StepInGateHandler)Delegate.CreateDelegate(typeof(StepInGateHandler), _handlers, methodInfo); AddStepInGate(handler, _pyrtInfo.DLLs.Python, methodInfo.Name, stepInAttr.HasMultipleExitPoints); } } if (_pyrtInfo.DLLs.CTypes != null) { OnCTypesLoaded(_pyrtInfo.DLLs.CTypes); } } }
public unsafe TraceManagerLocalHelper(DkmProcess process, Kind kind) { _process = process; _pyrtInfo = process.GetPythonRuntimeInfo(); _traceFunc = _pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("TraceFunc"); _isTracing = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<ByteProxy>("isTracing"); _pyTracingPossible = _pyrtInfo.DLLs.Python.GetStaticVariable<UInt32Proxy>("_Py_TracingPossible"); if (kind == Kind.StepIn) { var fieldOffsets = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<CliStructProxy<FieldOffsets>>("fieldOffsets"); fieldOffsets.Write(new FieldOffsets(process, _pyrtInfo)); var types = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<CliStructProxy<Types>>("types"); types.Write(new Types(process, _pyrtInfo)); var functionPointers = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<CliStructProxy<FunctionPointers>>("functionPointers"); functionPointers.Write(new FunctionPointers(process, _pyrtInfo)); var stringEquals = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<PointerProxy>("stringEquals"); if (_pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { stringEquals.Write(_pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("StringEquals27").GetPointer()); } else { stringEquals.Write(_pyrtInfo.DLLs.DebuggerHelper.GetExportedFunctionAddress("StringEquals33").GetPointer()); } foreach (var interp in PyInterpreterState.GetInterpreterStates(process)) { foreach (var tstate in interp.GetThreadStates()) { RegisterTracing(tstate); } } _handlers = new PythonDllBreakpointHandlers(this); LocalComponent.CreateRuntimeDllFunctionExitBreakpoints(_pyrtInfo.DLLs.Python, "new_threadstate", _handlers.new_threadstate, enable: true); foreach (var methodInfo in _handlers.GetType().GetMethods()) { var stepInAttr = (StepInGateAttribute)Attribute.GetCustomAttribute(methodInfo, typeof(StepInGateAttribute)); if (stepInAttr != null && (stepInAttr.MinVersion == PythonLanguageVersion.None || _pyrtInfo.LanguageVersion >= stepInAttr.MinVersion) && (stepInAttr.MaxVersion == PythonLanguageVersion.None || _pyrtInfo.LanguageVersion <= stepInAttr.MaxVersion)) { var handler = (StepInGateHandler)Delegate.CreateDelegate(typeof(StepInGateHandler), _handlers, methodInfo); AddStepInGate(handler, _pyrtInfo.DLLs.Python, methodInfo.Name, stepInAttr.HasMultipleExitPoints); } } if (_pyrtInfo.DLLs.CTypes != null) { OnCTypesLoaded(_pyrtInfo.DLLs.CTypes); } } }
public FunctionPointers(DkmProcess process, PythonRuntimeInfo pyrtInfo) { Py_DecRef = pyrtInfo.DLLs.Python.GetFunctionAddress("Py_DecRef"); PyFrame_FastToLocals = pyrtInfo.DLLs.Python.GetFunctionAddress("PyFrame_FastToLocals"); PyRun_StringFlags = pyrtInfo.DLLs.Python.GetFunctionAddress("PyRun_StringFlags"); PyErr_Fetch = pyrtInfo.DLLs.Python.GetFunctionAddress("PyErr_Fetch"); PyErr_Restore = pyrtInfo.DLLs.Python.GetFunctionAddress("PyErr_Restore"); PyErr_Occurred = pyrtInfo.DLLs.Python.GetFunctionAddress("PyErr_Occurred"); PyObject_Str = pyrtInfo.DLLs.Python.GetFunctionAddress("PyObject_Str"); }
public Types(DkmProcess process, PythonRuntimeInfo pyrtInfo) { PyBytes_Type = PyObject.GetPyType<PyBytesObject>(process).Address; if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { PyUnicode_Type = PyObject.GetPyType<PyUnicodeObject27>(process).Address; } else { PyUnicode_Type = PyObject.GetPyType<PyUnicodeObject33>(process).Address; } }
public FieldOffsets(DkmProcess process, PythonRuntimeInfo pyrtInfo) { PyObject = new PyObject_FieldOffsets(process); PyVarObject = new PyVarObject_FieldOffsets(process); PyFrameObject = new PyFrameObject_FieldOffsets(process); PyCodeObject = new PyCodeObject_FieldOffsets(process); PyBytesObject = new PyBytesObject_FieldOffsets(process); if (pyrtInfo.LanguageVersion <= PythonLanguageVersion.V27) { PyUnicodeObject27 = new PyUnicodeObject27_FieldOffsets(process); PyUnicodeObject33 = new PyUnicodeObject33_FieldOffsets(); } else { PyUnicodeObject27 = new PyUnicodeObject27_FieldOffsets(); PyUnicodeObject33 = new PyUnicodeObject33_FieldOffsets(process); } }
public CallStackFilter(DkmProcess process) { _process = process; _pyrtInfo = process.GetPythonRuntimeInfo(); }
public PythonDLLs(PythonRuntimeInfo pyrtInfo) { _pyrtInfo = pyrtInfo; }
public CallStackFilter(DkmProcess process) { _process = process; _pyrtInfo = process.GetPythonRuntimeInfo(); }
public PythonDLLs(PythonRuntimeInfo pyrtInfo) { _pyrtInfo = pyrtInfo; }