public DummyHolder(DkmProcess process) { var pyrtInfo = process.GetPythonRuntimeInfo(); Dummy = pyrtInfo.LanguageVersion >= PythonLanguageVersion.V34 ? pyrtInfo.DLLs.Python.GetStaticVariable<PointerProxy<PyObject>>("_PySet_Dummy") : pyrtInfo.DLLs.Python.GetStaticVariable<PointerProxy<PyObject>>("dummy", "setobject.obj"); }
public InterpHeadHolder(DkmProcess process) { var pyrtInfo = process.GetPythonRuntimeInfo(); Proxy = pyrtInfo.GetRuntimeState()?.interpreters.head ?? pyrtInfo.DLLs.Python.GetStaticVariable <PointerProxy <PyInterpreterState> >("interp_head"); }
public DummyHolder(DkmProcess process) { PythonRuntimeInfo pyrtInfo = process.GetPythonRuntimeInfo(); Dummy = pyrtInfo.LanguageVersion >= PythonLanguageVersion.V34 ? pyrtInfo.DLLs.Python.GetStaticVariable <PointerProxy <PyObject> >("_PySet_Dummy") : pyrtInfo.DLLs.Python.GetStaticVariable <PointerProxy <PyObject> >("dummy", "setobject.obj"); }
public override IEnumerable <KeyValuePair <PyObject, PointerProxy <PyObject> > > ReadElements() { if (ma_keys.IsNull) { yield break; } PyDictKeysObject36 keys = ma_keys.Read(); var size = keys.dk_size.Read(); if (size <= 0) { yield break; } var n = keys.dk_nentries.Read(); ArrayProxy <PyDictKeyEntry> dk_entries = keys.dk_entries; PyDictKeyEntry entry = dk_entries[0]; if (!ma_values.IsNull) { ArrayProxy <PointerProxy <PyObject> > values = ma_values.Read(); PointerProxy <PyObject> value = values[0]; for (int i = 0; i < n; ++i) { PointerProxy <PyObject> key = entry.me_key; if (!value.IsNull && !key.IsNull) { yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key.Read(), value)); } entry = entry.GetAdjacentProxy(1); value = value.GetAdjacentProxy(1); } } else { for (int i = 0; i < n; ++i) { PointerProxy <PyObject> key = entry.me_key; PointerProxy <PyObject> value = entry.me_value; if (!key.IsNull && !value.IsNull) { yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key.Read(), value)); } entry = entry.GetAdjacentProxy(1); } } }
public static PyObject FromAddress(DkmProcess process, ulong address) { if (address == 0) { return(null); } // This is a hot code path, so avoid creating a PyTypeObject here just to check for reference equality - // read it as raw pointer, and do direct address comparisons instead. var fields = GetStructFields <PyObject, PyObject_Fields>(process); ulong typePtr = new PointerProxy(process, address.OffsetBy(fields.ob_type.Offset)).Read(); var proxyInfo = FindProxyInfoForPyType(process, typePtr) ?? ProxyInfo.Default; return(proxyInfo.ProxyFactory(process, address)); }
public override IEnumerable <KeyValuePair <PyObject, PointerProxy <PyObject> > > ReadElements() { if (ma_keys.IsNull) { yield break; } PyDictKeysObject33 keys = ma_keys.Read(); var entries = keys.dk_entries.Take(keys.dk_size.Read()); PointerProxy <ArrayProxy <PointerProxy <PyObject> > > ma_values = this.ma_values; if (ma_values.IsNull) { foreach (var entry in entries) { var key = entry.me_key.TryRead(); if (key != null) { yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key, entry.me_value)); } } } else { PointerProxy <PyObject> valuePtr = ma_values.Read()[0]; foreach (var entry in entries) { var key = entry.me_key.TryRead(); if (key != null) { yield return(new KeyValuePair <PyObject, PointerProxy <PyObject> >(key, valuePtr)); } valuePtr = valuePtr.GetAdjacentProxy(1); } } }
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 InterpHeadHolder(DkmProcess process) { Proxy = process.GetPythonRuntimeInfo().DLLs.Python.GetStaticVariable<PointerProxy<PyInterpreterState>>("interp_head"); }
public DummyHolder(DkmProcess process) { Dummy = process.GetPythonRuntimeInfo().DLLs.Python.GetStaticVariable<PointerProxy<PyObject>>("dummy", "dictobject.obj"); }
public DummyHolder(DkmProcess process) { Dummy = process.GetPythonRuntimeInfo().DLLs.Python.GetStaticVariable <PointerProxy <PyObject> >("dummy", "dictobject.obj"); }
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 InterpHeadHolder(DkmProcess process) { Proxy = process.GetPythonRuntimeInfo().DLLs.Python.GetStaticVariable <PointerProxy <PyInterpreterState> >("interp_head"); }
private IEnumerable <PythonEvaluationResult> GetDebugChildrenFromSlots() { PointerProxy <ArrayProxy <PyMemberDef> > tp_members = ob_type.Read().tp_members; if (tp_members.IsNull) { yield break; } var langVer = Process.GetPythonRuntimeInfo().LanguageVersion; var memberDefs = tp_members.Read().TakeWhile(md => !md.name.IsNull); foreach (PyMemberDef memberDef in memberDefs) { var offset = memberDef.offset.Read(); IValueStore value; switch (memberDef.type.Read()) { case PyMemberDefType.T_OBJECT: case PyMemberDefType.T_OBJECT_EX: { var objProxy = GetFieldProxy(new StructField <PointerProxy <PyObject> > { Process = Process, Offset = offset }); if (!objProxy.IsNull) { value = objProxy; } else { value = new ValueStore <PyObject>(None(Process)); } } break; case PyMemberDefType.T_STRING: { var ptr = GetFieldProxy(new StructField <PointerProxy> { Process = Process, Offset = offset }).Read(); if (ptr != 0) { CStringProxy proxy = new CStringProxy(Process, ptr); if (langVer <= PythonLanguageVersion.V27) { value = new ValueStore <AsciiString>(proxy.ReadAscii()); } else { value = new ValueStore <string>(proxy.ReadUnicode()); } } else { value = new ValueStore <PyObject>(None(Process)); } } break; case PyMemberDefType.T_STRING_INPLACE: { CStringProxy proxy = new CStringProxy(Process, Address.OffsetBy(offset)); if (langVer <= PythonLanguageVersion.V27) { value = new ValueStore <AsciiString>(proxy.ReadAscii()); } else { value = new ValueStore <string>(proxy.ReadUnicode()); } } break; case PyMemberDefType.T_BYTE: value = GetFieldProxy(new StructField <SByteProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_UBYTE: value = GetFieldProxy(new StructField <ByteProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_SHORT: value = GetFieldProxy(new StructField <Int16Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_USHORT: value = GetFieldProxy(new StructField <UInt16Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_INT: case PyMemberDefType.T_LONG: value = GetFieldProxy(new StructField <Int32Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_UINT: case PyMemberDefType.T_ULONG: value = GetFieldProxy(new StructField <UInt32Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_LONGLONG: value = GetFieldProxy(new StructField <Int64Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_ULONGLONG: value = GetFieldProxy(new StructField <UInt64Proxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_PYSSIZET: value = GetFieldProxy(new StructField <SSizeTProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_FLOAT: value = GetFieldProxy(new StructField <SingleProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_DOUBLE: value = GetFieldProxy(new StructField <DoubleProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_BOOL: value = GetFieldProxy(new StructField <BoolProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_CHAR: value = GetFieldProxy(new StructField <CharProxy> { Process = Process, Offset = offset }); break; case PyMemberDefType.T_NONE: value = new ValueStore <PyObject>(None(Process)); break; default: continue; } yield return(new PythonEvaluationResult(value, memberDef.name.Read().ReadUnicode())); } }