Ejemplo n.º 1
0
        public unsafe void RegisterJITTracing(PyInterpreterState istate)
        {
            Debug.Assert(_pyrtInfo.LanguageVersion >= PythonLanguageVersion.V36);

            var current = istate.eval_frame.Read();

            if (current != _evalFrameFunc.GetPointer())
            {
                _defaultEvalFrameFunc.Write(current);
                istate.eval_frame.Write(_evalFrameFunc.GetPointer());
            }
        }
Ejemplo n.º 2
0
        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.GetRuntimeState()?.ceval.tracing_possible
                                    ?? _pyrtInfo.DLLs.Python.GetStaticVariable <Int32Proxy>("_Py_TracingPossible");

            if (kind == Kind.StepIn)
            {
                CliStructProxy <FieldOffsets> fieldOffsets = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <FieldOffsets> >("fieldOffsets");
                fieldOffsets.Write(new FieldOffsets(process, _pyrtInfo));

                CliStructProxy <Types> types = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <Types> >("types");
                types.Write(new Types(process, _pyrtInfo));

                CliStructProxy <FunctionPointers> functionPointers = _pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable <CliStructProxy <FunctionPointers> >("functionPointers");
                functionPointers.Write(new FunctionPointers(process, _pyrtInfo));

                PointerProxy 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())
                {
                    StepInGateAttribute 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))
                    {
                        StepInGateHandler 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);
                }
            }
        }