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 PySetObject(DkmProcess process, ulong address) : base(process, address) { InitializeStruct(this, out _fields); CheckPyType<PySetObject>(); _dummy = Process.GetOrCreateDataItem(() => new DummyHolder(Process)).Dummy.TryRead(); }
protected PyIntObject(DkmProcess process, ulong address, bool checkType) : base(process, address) { InitializeStruct(this, out _fields); if (checkType) { CheckPyType<PyIntObject>(); } }
public PyFrameObject_FieldOffsets(DkmProcess process) { var fields = StructProxy.GetStructFields<PyFrameObject, PyFrameObject.Fields>(process); f_code = fields.f_code.Offset; f_globals = fields.f_globals.Offset; f_locals = fields.f_locals.Offset; f_lineno = fields.f_lineno.Offset; }
public static PyInterpreterState TryCreate(DkmProcess process, ulong address) { if (address == 0) { return null; } return new PyInterpreterState(process, address); }
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 void ClearExceptionTriggers(DkmProcess process, Guid sourceId) { if (_monitoredExceptions.Count != 0) { _monitoredExceptions.Clear(); new LocalComponent.MonitorExceptionsRequest { MonitorExceptions = false }.SendHigher(process); } process.ClearExceptionTriggers(sourceId); }
public static PyIntObject Create(DkmProcess process, int value) { var allocator = process.GetDataItem<PyObjectAllocator>(); Debug.Assert(allocator != null); var result = allocator.Allocate<PyIntObject>(); result.ob_ival.Write(value); return result; }
public static PyComplexObject Create(DkmProcess process, Complex value) { var allocator = process.GetDataItem<PyObjectAllocator>(); Debug.Assert(allocator != null); var result = allocator.Allocate<PyComplexObject>(); result.cval.real.Write(value.Real); result.cval.imag.Write(value.Imaginary); return result; }
public static PyBytesObject Create(DkmProcess process, AsciiString value) { var allocator = process.GetDataItem<PyObjectAllocator>(); Debug.Assert(allocator != null); var result = allocator.Allocate<PyBytesObject>(value.Bytes.Length); result.ob_size.Write(value.Bytes.Length); process.WriteMemory(result.ob_sval.Address, value.Bytes); return result; }
public CppExpressionEvaluator(DkmThread thread, ulong frameBase, ulong vframe) { _process = thread.Process; var inspectionSession = DkmInspectionSession.Create(_process, null); _cppInspectionContext = DkmInspectionContext.Create(inspectionSession, _process.GetNativeRuntimeInstance(), thread, Timeout, DkmEvaluationFlags.TreatAsExpression | DkmEvaluationFlags.NoSideEffects, DkmFuncEvalFlags.None, 10, CppLanguage, null); const int CV_ALLREG_VFRAME = 0x00007536; var vframeReg = DkmUnwoundRegister.Create(CV_ALLREG_VFRAME, new ReadOnlyCollection<byte>(BitConverter.GetBytes(vframe))); var regs = thread.GetCurrentRegisters(new[] { vframeReg }); var iaddr = _process.CreateNativeInstructionAddress(regs.GetInstructionPointer()); _nativeFrame = DkmStackWalkFrame.Create(thread, iaddr, frameBase, 0, DkmStackWalkFrameFlags.None, null, regs, null); }
public PyFrameObject(DkmProcess process, ulong address) : base(process, address) { var pythonInfo = process.GetPythonRuntimeInfo(); if (pythonInfo.LanguageVersion <= PythonLanguageVersion.V35) { Fields_27_35 fields; InitializeStruct(this, out fields); _fields = fields; } else { Fields_36 fields; InitializeStruct(this, out fields); _fields = fields; } CheckPyType<PyFrameObject>(); }
public ExpressionEvaluator(DkmProcess process) { _process = process; var pyrtInfo = process.GetPythonRuntimeInfo(); _evalLoopThreadId = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopThreadId"); _evalLoopFrame = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopFrame"); _evalLoopResult = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopResult"); _evalLoopExcType = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopExcType"); _evalLoopExcValue = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopExcValue"); _evalLoopExcStr = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt64Proxy>("evalLoopExcStr"); _evalLoopSEHCode = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<UInt32Proxy>("evalLoopSEHCode"); _evalLoopInput = pyrtInfo.DLLs.DebuggerHelper.GetExportedStaticVariable<CStringProxy>("evalLoopInput"); LocalComponent.CreateRuntimeDllExportedFunctionBreakpoint(pyrtInfo.DLLs.DebuggerHelper, "OnEvalComplete", OnEvalComplete, enable: true); }
public static PyUnicodeObject27 Create(DkmProcess process, string value) { // Allocate string buffer together with the object itself in a single block. var allocator = process.GetDataItem<PyObjectAllocator>(); Debug.Assert(allocator != null); var result = allocator.Allocate<PyUnicodeObject27>(value.Length * 2); result.length.Write(value.Length); var str = result.Address.OffsetBy(StructProxy.SizeOf<PyUnicodeObject27>(process)); result.str.Raw.Write(str); var buf = Encoding.Unicode.GetBytes(value); process.WriteMemory(str, buf); return result; }
public PyFrameObject_FieldOffsets(DkmProcess process) { if (process.GetPythonRuntimeInfo().LanguageVersion <= PythonLanguageVersion.V35) { var fields = StructProxy.GetStructFields<PyFrameObject, PyFrameObject.Fields_27_35>(process); f_back = -1; f_code = fields.f_code.Offset; f_globals = fields.f_globals.Offset; f_locals = fields.f_locals.Offset; f_lineno = fields.f_lineno.Offset; } else { var fields = StructProxy.GetStructFields<PyFrameObject, PyFrameObject.Fields_36>(process); f_back = fields.f_back.Offset; f_code = fields.f_code.Offset; f_globals = fields.f_globals.Offset; f_locals = fields.f_locals.Offset; f_lineno = fields.f_lineno.Offset; } }
private static bool ShouldEnableChildDebugging(DkmProcess process, DebugProcessOptions options) { if (options.ChildDebuggingMode == ChildDebuggingMode.AlwaysAttach) return true; if (options.ChildDebuggingMode == ChildDebuggingMode.UseDefault) { Logger.LogInfo( "Requesting default child process debugging mode for process {0}.", process.UniqueId); DkmCustomMessage attachRequest = DkmCustomMessage.Create( process.Connection, process, PackageServices.VsPackageMessageGuid, (int)VsPackageMessage.IsChildDebuggingEnabled, process.UniqueId, process.Connection.UniqueId); // This needs to happen synchronously in order to guarantee that child debugging is enabled // before the process finishes initializing. attachRequest.SendToVsService(PackageServices.DkmComponentEventHandler, true); } return false; }
public void AddExceptionTrigger(DkmProcess process, Guid sourceId, DkmExceptionTrigger trigger) { var nameTrigger = trigger as DkmExceptionNameTrigger; if (nameTrigger != null && nameTrigger.ExceptionCategory == AD7Engine.DebugEngineGuid) { string name = nameTrigger.Name; bool wasEmpty = _monitoredExceptions.Count == 0; if (nameTrigger.ProcessingStage.HasFlag(DkmExceptionProcessingStage.Thrown) || nameTrigger.ProcessingStage.HasFlag(DkmExceptionProcessingStage.UserCodeSearch) ) { _monitoredExceptions.Add(nameTrigger.Name); } else { _monitoredExceptions.Remove(nameTrigger.Name); } bool isEmpty = _monitoredExceptions.Count == 0; if (wasEmpty != isEmpty) { new LocalComponent.MonitorExceptionsRequest { MonitorExceptions = !isEmpty }.SendHigher(process); } } process.AddExceptionTrigger(sourceId, trigger); }
public static PyLongObject Create(DkmProcess process, BigInteger value) { var allocator = process.GetDataItem<PyObjectAllocator>(); Debug.Assert(allocator != null); var bitsInDigit = process.Is64Bit() ? 30 : 15; var bytesInDigit = process.Is64Bit() ? 4 : 2; var absValue = BigInteger.Abs(value); long numDigits = 0; for (var t = absValue; t != 0; ) { ++numDigits; t >>= bitsInDigit; } var result = allocator.Allocate<PyLongObject>(numDigits * bytesInDigit); if (value == 0) { result.ob_size.Write(0); } else if (value > 0) { result.ob_size.Write(numDigits); } else if (value < 0) { result.ob_size.Write(-numDigits); } if (bitsInDigit == 15) { for (var digitPtr = new UInt16Proxy(process, result.ob_digit.Address); absValue != 0; digitPtr = digitPtr.GetAdjacentProxy(1)) { digitPtr.Write((ushort)(absValue % (1 << bitsInDigit))); absValue >>= bitsInDigit; } } else { for (var digitPtr = new UInt32Proxy(process, result.ob_digit.Address); absValue != 0; digitPtr = digitPtr.GetAdjacentProxy(1)) { digitPtr.Write((uint)(absValue % (1 << bitsInDigit))); absValue >>= bitsInDigit; } } return result; }
public CppExpressionEvaluator(DkmInspectionContext inspectionContext, DkmStackWalkFrame stackFrame) { _process = stackFrame.Process; var thread = stackFrame.Thread; if (stackFrame.InstructionAddress is DkmNativeInstructionAddress) { _nativeFrame = stackFrame; } else { var customAddr = stackFrame.InstructionAddress as DkmCustomInstructionAddress; if (customAddr == null) { throw new ArgumentException(); } var loc = new SourceLocation(customAddr.AdditionalData, _process); if (loc.NativeAddress == null) { throw new ArgumentException(); } _nativeFrame = DkmStackWalkFrame.Create(thread, loc.NativeAddress, stackFrame.FrameBase, stackFrame.FrameSize, DkmStackWalkFrameFlags.None, null, stackFrame.Registers, null); } _cppInspectionContext = DkmInspectionContext.Create(inspectionContext.InspectionSession, _process.GetNativeRuntimeInstance(), thread, Timeout, DkmEvaluationFlags.TreatAsExpression | DkmEvaluationFlags.NoSideEffects, DkmFuncEvalFlags.None, inspectionContext.Radix, CppLanguage, null); }
public static IEnumerable<PyInterpreterState> GetInterpreterStates(DkmProcess process) { for (var interp = interp_head(process).TryRead(); interp != null; interp = interp.next.TryRead()) { yield return interp; } }
public static PointerProxy<PyInterpreterState> interp_head(DkmProcess process) { return process.GetOrCreateDataItem(() => new InterpHeadHolder(process)).Proxy; }
public InterpHeadHolder(DkmProcess process) { Proxy = process.GetPythonRuntimeInfo().DLLs.Python.GetStaticVariable<PointerProxy<PyInterpreterState>>("interp_head"); }
public PyInterpreterState(DkmProcess process, ulong address) : base(process, address) { InitializeStruct(this, out _fields); }
public PyMemberDef(DkmProcess process, ulong address) : base(process, address) { InitializeStruct(this, out _fields); }
public PyObjectEvaluationResult(DkmProcess process, string fullName, IValueStore<PyObject> valueStore, string cppTypeName, bool hasCppView, bool isOwned) { Process = process; FullName = fullName; ValueStore = valueStore; CppTypeName = cppTypeName; HasCppView = hasCppView; IsOwned = isOwned; }
public PyListObject(DkmProcess process, ulong address) : base(process, address) { InitializeStruct(this, out _fields); CheckPyType<PyListObject>(); }
public PyBytesObject_FieldOffsets(DkmProcess process) { var fields = StructProxy.GetStructFields<PyBytesObject, PyBytesObject.Fields>(process); ob_sval = fields.ob_sval.Offset; }
public PyCodeObject_FieldOffsets(DkmProcess process) { var fields = StructProxy.GetStructFields<PyCodeObject, PyCodeObject.Fields>(process); co_varnames = fields.co_varnames.Offset; co_filename = fields.co_filename.Offset; co_name = fields.co_name.Offset; }
public PyVarObject_FieldOffsets(DkmProcess process) { var fields = StructProxy.GetStructFields<PyVarObject, PyVarObject.PyVarObject_Fields>(process); ob_size = fields.ob_size.Offset; }
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); } } }