bool IDkmRuntimeStepper.OwnsCurrentExecutionLocation(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason)
        {
            var processData = DebugHelpers.GetOrCreateDataItem <LuaRemoteProcessData>(runtimeInstance.Process);

            // Can't handle steps without an address
            if (stepper.StartingAddress == null)
            {
                return(false);
            }

            // Stepping can be performed if we are inside the debug helper or inside luaV_execute
            var instructionAddress = stepper.StartingAddress.CPUInstructionPart.InstructionPointer;

            if (processData.locations == null)
            {
                return(false);
            }

            if (instructionAddress >= processData.locations.helperStartAddress && instructionAddress < processData.locations.helperEndAddress)
            {
                return(true);
            }

            if (instructionAddress >= processData.locations.executionStartAddress && instructionAddress < processData.locations.executionEndAddress)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 public void BeforeEnableNewStepper(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
 {
     stepper.Thread.GetCurrentFrameInfo(out global::System.UInt64 retAddr, out global::System.UInt64 frameBase, out global::System.UInt64 vframe);
     stepper.SetDataItem(DkmDataCreationDisposition.CreateAlways, new StepBeginState {
         FrameBase = frameBase
     });
 }
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance = null)
 {
     _formatter = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Exemplo n.º 4
0
 internal DkmInspectionContext CreateDkmInspectionContext(
     DkmEvaluationFlags flags = DkmEvaluationFlags.None,
     uint radix = 10,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(CreateDkmInspectionContext(_formatter, flags, radix, runtimeInstance));
 }
Exemplo n.º 5
0
            bool IDkmRuntimeStepper.OwnsCurrentExecutionLocation(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason)
            {
                var processData = DebugHelpers.GetOrCreateDataItem <NullcRemoteProcessDataItem>(runtimeInstance.Process);

                // Can't handle steps without an address
                if (stepper.StartingAddress == null)
                {
                    return(false);
                }

                var instructionAddress = stepper.StartingAddress.CPUInstructionPart.InstructionPointer;

                if (DebugHelpers.useNativeInterfaces)
                {
                    if (processData.nativeModuleInstance != null)
                    {
                        if (instructionAddress >= processData.nativeModuleInstance.BaseAddress && instructionAddress < processData.nativeModuleInstance.BaseAddress + processData.nativeModuleInstance.Size)
                        {
                            return(processData.bytecode.ConvertNativeAddressToInstruction(instructionAddress) != 0);
                        }
                    }
                }
                else
                {
                    if (processData.moduleInstance != null)
                    {
                        if (instructionAddress >= processData.moduleInstance.BaseAddress && instructionAddress < processData.moduleInstance.BaseAddress + processData.moduleInstance.Size)
                        {
                            return(processData.bytecode.ConvertNativeAddressToInstruction(instructionAddress) != 0);
                        }
                    }
                }

                return(false);
            }
Exemplo n.º 6
0
 internal DkmInspectionContext(DkmInspectionSession inspectionSession, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance)
 {
     this.InspectionSession = inspectionSession;
     this.EvaluationFlags = evaluationFlags;
     this.Radix = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Exemplo n.º 7
0
        unsafe void IDkmRuntimeInstanceLoadNotification.OnRuntimeInstanceLoad(DkmRuntimeInstance runtimeInstance, DkmEventDescriptor eventDescriptor)
        {
            if (runtimeInstance.Id.RuntimeType != Guids.PythonRuntimeTypeGuid)
            {
                Debug.Fail("OnRuntimeInstanceLoad notification for a non-Python runtime.");
                throw new NotSupportedException();
            }

            var process = runtimeInstance.Process;

            process.SetDataItem(DkmDataCreationDisposition.CreateNew, new ModuleManager(process));
            process.SetDataItem(DkmDataCreationDisposition.CreateNew, new CallStackFilter(process));
            process.SetDataItem(DkmDataCreationDisposition.CreateNew, new ExpressionEvaluator(process));
            process.SetDataItem(DkmDataCreationDisposition.CreateNew, new PyObjectAllocator(process));

            if (process.LivePart != null)
            {
                process.SetDataItem(DkmDataCreationDisposition.CreateNew, new TraceManagerLocalHelper(process, TraceManagerLocalHelper.Kind.StepIn));
            }

            // If both local and remote components are actually in the same process, they share the same DebuggerOptions, so no need to propagate it.
            if (process.Connection.Flags.HasFlag(DkmTransportConnectionFlags.MarshallingRequired))
            {
                process.SetDataItem(DkmDataCreationDisposition.CreateNew, new DebuggerOptionsPropagator(process));
            }
        }
Exemplo n.º 8
0
 internal static DkmInspectionContext CreateDkmInspectionContext(
     DkmInspectionSession inspectionSession,
     DkmEvaluationFlags flags,
     uint radix,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(new DkmInspectionContext(inspectionSession, flags, radix, runtimeInstance));
 }
Exemplo n.º 9
0
 internal static DkmInspectionContext CreateDkmInspectionContext(
     IDkmClrFormatter formatter,
     DkmEvaluationFlags flags,
     uint radix,
     DkmRuntimeInstance runtimeInstance = null)
 {
     return(new DkmInspectionContext(formatter, flags, radix, runtimeInstance));
 }
        void IDkmRuntimeStepper.OnNewControllingRuntimeInstance(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason, DkmRuntimeInstance controllingRuntimeInstance)
        {
            var process = runtimeInstance.Process;

            var processData = DebugHelpers.GetOrCreateDataItem <LuaRemoteProcessData>(runtimeInstance.Process);

            ClearStepperData(process, processData);
        }
        void IDkmRuntimeStepper.StopStep(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
        {
            var process = runtimeInstance.Process;

            var processData = DebugHelpers.GetOrCreateDataItem <LuaRemoteProcessData>(runtimeInstance.Process);

            ClearStepperData(process, processData);
        }
        void IDkmRuntimeStepper.TakeStepControl(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, bool leaveGuardsInPlace, DkmStepArbitrationReason reason, DkmRuntimeInstance callingRuntimeInstance)
        {
            var process = runtimeInstance.Process;

            var processData = DebugHelpers.GetOrCreateDataItem <LuaRemoteProcessData>(runtimeInstance.Process);

            ClearStepperData(process, processData);
        }
Exemplo n.º 13
0
        public void BeforeEnableNewStepper(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
        {
            ulong retAddr, frameBase, vframe;

            stepper.Thread.GetCurrentFrameInfo(out retAddr, out frameBase, out vframe);
            stepper.SetDataItem(DkmDataCreationDisposition.CreateAlways, new StepBeginState {
                FrameBase = frameBase
            });
        }
Exemplo n.º 14
0
 internal DkmInspectionContext(
     DkmInspectionSession inspectionSession,
     DkmEvaluationFlags evaluationFlags,
     uint radix,
     DkmRuntimeInstance runtimeInstance
     )
 {
     this.InspectionSession = inspectionSession;
     this.EvaluationFlags   = evaluationFlags;
     this.Radix             = radix;
     this.RuntimeInstance   = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Exemplo n.º 15
0
        void IDkmRuntimeStepper.TakeStepControl(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, bool leaveGuardsInPlace, DkmStepArbitrationReason reason, DkmRuntimeInstance callingRuntimeInstance)
        {
            var traceManager = runtimeInstance.Process.GetDataItem <TraceManager>();

            if (traceManager == null)
            {
                Debug.Fail("TakeStepControl called before TraceMananger is initialized.");
                throw new InvalidOperationException();
            }

            traceManager.CancelStep(stepper);
        }
Exemplo n.º 16
0
        void IDkmRuntimeStepper.StopStep(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
        {
            var traceManager = runtimeInstance.Process.GetDataItem <TraceManager>();

            if (traceManager == null)
            {
                Debug.Fail("StopStep called before TraceMananger is initialized.");
                throw new InvalidOperationException();
            }

            traceManager.CancelStep(stepper);
        }
Exemplo n.º 17
0
        void IDkmRuntimeStepper.BeforeEnableNewStepper(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
        {
            var traceManager = runtimeInstance.Process.GetDataItem <TraceManager>();

            if (traceManager == null)
            {
                Debug.Fail("OnNewControllingRuntimeInstance called before TraceMananger is initialized.");
                throw new InvalidOperationException();
            }

            traceManager.BeforeEnableNewStepper(runtimeInstance, stepper);
        }
Exemplo n.º 18
0
        unsafe void IDkmRuntimeInstanceLoadNotification.OnRuntimeInstanceLoad(DkmRuntimeInstance runtimeInstance, DkmEventDescriptor eventDescriptor)
        {
            if (runtimeInstance.Id.RuntimeType != Guids.PythonRuntimeTypeGuid)
            {
                Debug.Fail("OnRuntimeInstanceLoad notification for a non-Python runtime.");
                throw new NotSupportedException();
            }

            var process = runtimeInstance.Process;

            process.SetDataItem(DkmDataCreationDisposition.CreateNew, new TraceManagerLocalHelper(process, TraceManagerLocalHelper.Kind.StepOut));
        }
Exemplo n.º 19
0
        internal static ulong FindFunctionAddress(DkmRuntimeInstance runtimeInstance, string name)
        {
            foreach (var module in runtimeInstance.GetModuleInstances())
            {
                var address = (module as DkmNativeModuleInstance)?.FindExportName(name, IgnoreDataExports: true);

                if (address != null)
                {
                    return(address.CPUInstructionPart.InstructionPointer);
                }
            }

            return(0);
        }
 private DkmIntermediateEvaluationResult(
     DkmInspectionContext inspectionContext,
     DkmStackWalkFrame stackFrame,
     string name,
     string fullName,
     string expression,
     DkmLanguage intermediateLanguage,
     DkmRuntimeInstance targetRuntime,
     DkmDataItem dataItem)
     : base(inspectionContext, stackFrame, name, fullName, DkmEvaluationResultFlags.None, null, dataItem)
 {
     this.Expression = expression;
     this.IntermediateLanguage = intermediateLanguage;
     this.TargetRuntime = targetRuntime;
 }
Exemplo n.º 21
0
 private DkmIntermediateEvaluationResult(
     DkmInspectionContext inspectionContext,
     DkmStackWalkFrame stackFrame,
     string name,
     string fullName,
     string expression,
     DkmLanguage intermediateLanguage,
     DkmRuntimeInstance targetRuntime,
     DkmDataItem dataItem) :
     base(inspectionContext, stackFrame, name, fullName, DkmEvaluationResultFlags.None, null, dataItem)
 {
     this.Expression           = expression;
     this.IntermediateLanguage = intermediateLanguage;
     this.TargetRuntime        = targetRuntime;
 }
Exemplo n.º 22
0
 public static DkmInspectionContext Create(
     DkmInspectionSession InspectionSession,
     DkmRuntimeInstance RuntimeInstance,
     DkmThread Thread,
     uint Timeout,
     DkmEvaluationFlags EvaluationFlags,
     DkmFuncEvalFlags FuncEvalFlags,
     uint Radix,
     DkmLanguage Language,
     DkmRawReturnValue ReturnValue,
     DkmCompiledVisualizationData AdditionalVisualizationData,
     DkmCompiledVisualizationDataPriority AdditionalVisualizationDataPriority,
     ReadOnlyCollection<DkmRawReturnValueContainer> ReturnValues)
 {
     return new DkmInspectionContext(InspectionSession, EvaluationFlags, Radix, RuntimeInstance);
 }
Exemplo n.º 23
0
 public static DkmInspectionContext Create(
     DkmInspectionSession InspectionSession,
     DkmRuntimeInstance RuntimeInstance,
     DkmThread Thread,
     uint Timeout,
     DkmEvaluationFlags EvaluationFlags,
     DkmFuncEvalFlags FuncEvalFlags,
     uint Radix,
     DkmLanguage Language,
     DkmRawReturnValue ReturnValue,
     DkmCompiledVisualizationData AdditionalVisualizationData,
     DkmCompiledVisualizationDataPriority AdditionalVisualizationDataPriority,
     ReadOnlyCollection <DkmRawReturnValueContainer> ReturnValues)
 {
     return(new DkmInspectionContext(InspectionSession, EvaluationFlags, Radix, RuntimeInstance));
 }
 public static DkmIntermediateEvaluationResult Create(
     DkmInspectionContext InspectionContext,
     DkmStackWalkFrame StackFrame,
     string Name,
     string FullName,
     string Expression,
     DkmLanguage IntermediateLanguage,
     DkmRuntimeInstance TargetRuntime,
     DkmDataItem DataItem)
 {
     return new DkmIntermediateEvaluationResult(
         InspectionContext,
         StackFrame,
         Name,
         FullName,
         Expression,
         IntermediateLanguage,
         TargetRuntime,
         DataItem);
 }
Exemplo n.º 25
0
 public static DkmIntermediateEvaluationResult Create(
     DkmInspectionContext InspectionContext,
     DkmStackWalkFrame StackFrame,
     string Name,
     string FullName,
     string Expression,
     DkmLanguage IntermediateLanguage,
     DkmRuntimeInstance TargetRuntime,
     DkmDataItem DataItem)
 {
     return(new DkmIntermediateEvaluationResult(
                InspectionContext,
                StackFrame,
                Name,
                FullName,
                Expression,
                IntermediateLanguage,
                TargetRuntime,
                DataItem));
 }
Exemplo n.º 26
0
        bool IDkmRuntimeStepper.OwnsCurrentExecutionLocation(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason)
        {
            if (!DebuggerOptions.UsePythonStepping)
            {
                return(false);
            }

            var process  = runtimeInstance.Process;
            var pyrtInfo = process.GetPythonRuntimeInfo();

            if (pyrtInfo.DLLs.Python == null)
            {
                return(false);
            }

            var thread = stepper.Thread;
            var ip     = thread.GetCurrentRegisters(new DkmUnwoundRegister[0]).GetInstructionPointer();

            return(pyrtInfo.DLLs.Python.ContainsAddress(ip) ||
                   (pyrtInfo.DLLs.DebuggerHelper != null && pyrtInfo.DLLs.DebuggerHelper.ContainsAddress(ip)) ||
                   (pyrtInfo.DLLs.CTypes != null && pyrtInfo.DLLs.CTypes.ContainsAddress(ip)));
        }
        public static void VscxOnRuntimeInstanceLoad(this DkmRuntimeInstance runtime)
        {
            if (runtime.TagValue != DkmRuntimeInstance.Tag.NativeRuntimeInstance)
            {
                return;
            }

            DkmNativeRuntimeInstance nativeRuntime = (DkmNativeRuntimeInstance)runtime;
            bool isChrome      = false;
            bool isTestProcess = false;

            // Check if the process is a chrome executable, and if so, attach a CallstackFilter to the DkmProcess.
            if (ChromeUtility.IsChromeProcess(nativeRuntime.Process.Path))
            {
                isChrome = true;
            }
#if DEBUG
            string fileName = Path.GetFileName(nativeRuntime.Process.Path);
            if (fileName.Equals("vistest.exe", StringComparison.CurrentCultureIgnoreCase))
            {
                isTestProcess = true;
            }
#endif

            if (isTestProcess || isChrome)
            {
                DkmProcess process = nativeRuntime.Process;

                DebugProcessOptions         options         = DebugProcessOptions.Create(process.DebugLaunchSettings.OptionsString);
                ProcessDebugOptionsDataItem optionsDataItem = new ProcessDebugOptionsDataItem(options);
                process.SetDataItem(DkmDataCreationDisposition.CreateAlways, optionsDataItem);

                if (isTestProcess || ShouldEnableChildDebugging(nativeRuntime.Process, options))
                {
                    process.SetDataItem(DkmDataCreationDisposition.CreateAlways, new RuntimeBreakpointHandler());
                    process.SetDataItem(DkmDataCreationDisposition.CreateAlways, new AutoAttachToChildHandler());
                }
            }
        }
        void IDkmRuntimeStepper.Step(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason)
        {
            var process = runtimeInstance.Process;

            var processData = DebugHelpers.GetOrCreateDataItem <LuaRemoteProcessData>(runtimeInstance.Process);

            if (stepper.StepKind == DkmStepKind.StepIntoSpecific)
            {
                throw new NotSupportedException();
            }

            if (processData.activeStepper != null)
            {
                processData.activeStepper.CancelStepper(processData.runtimeInstance);
                processData.activeStepper = null;
            }

            if (stepper.StepKind == DkmStepKind.Over)
            {
                DebugHelpers.TryWriteIntVariable(process, processData.locations.helperStepOverAddress, 1);
            }
            else if (stepper.StepKind == DkmStepKind.Into)
            {
                DebugHelpers.TryWriteIntVariable(process, processData.locations.helperStepOverAddress, 1);
                DebugHelpers.TryWriteIntVariable(process, processData.locations.helperStepIntoAddress, 1);
            }
            else if (stepper.StepKind == DkmStepKind.Out)
            {
                DebugHelpers.TryWriteIntVariable(process, processData.locations.helperStepOutAddress, 1);
            }

            processData.activeStepper = stepper;

            processData.hadActiveStepper = true;

            UpdateHooks(process, processData);
        }
 void IDkmRuntimeStepper.BeforeEnableNewStepper(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
 {
     // Don't have anything to do here right now
 }
Exemplo n.º 30
0
 void IDkmRuntimeStepper.AfterSteppingArbitration(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason, DkmRuntimeInstance newControllingRuntimeInstance)
 {
 }
Exemplo n.º 31
0
 internal DkmInspectionContext(IDkmClrFormatter formatter, DkmEvaluationFlags evaluationFlags, uint radix, DkmRuntimeInstance runtimeInstance = null)
 {
     _formatter           = formatter;
     this.EvaluationFlags = evaluationFlags;
     this.Radix           = radix;
     this.RuntimeInstance = runtimeInstance ?? DkmClrRuntimeInstance.DefaultRuntime;
 }
Exemplo n.º 32
0
        internal static DkmEvaluationResult ExecuteRawExpression(string expression, DkmInspectionSession inspectionSession, DkmThread thread, DkmStackWalkFrame input, DkmRuntimeInstance runtimeInstance, DkmEvaluationFlags flags)
        {
            var compilerId         = new DkmCompilerId(DkmVendorId.Microsoft, DkmLanguageId.Cpp);
            var language           = DkmLanguage.Create("C++", compilerId);
            var languageExpression = DkmLanguageExpression.Create(language, DkmEvaluationFlags.None, expression, null);

            DkmInspectionContext inspectionContext;

            LuaWorkerConnectionWrapper workerConnectionWrapper = inspectionSession.Process.GetDataItem <LuaWorkerConnectionWrapper>();

            if (workerConnectionWrapper != null)
            {
                inspectionContext = workerConnectionWrapper.CreateInspectionSession(inspectionSession, runtimeInstance, thread, flags, language);
            }
            else
            {
                inspectionContext = DkmInspectionContext.Create(inspectionSession, runtimeInstance, thread, 200, flags, DkmFuncEvalFlags.None, 10, language, null);
            }

            var workList = DkmWorkList.Create(null);

            try
            {
                DkmEvaluationResult result = null;

                inspectionContext.EvaluateExpression(workList, languageExpression, input, res =>
                {
                    if (res.ErrorCode == 0)
                    {
                        result = res.ResultObject;
                    }
                });

                workList.Execute();

                return(result);
            }
            catch (OperationCanceledException)
            {
                return(null);
            }
        }
 void IDkmRuntimeStepper.AfterSteppingArbitration(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason, DkmRuntimeInstance newControllingRuntimeInstance)
 {
     // Don't have anything to do here right now
 }
 bool IDkmRuntimeStepper.StepControlRequested(DkmRuntimeInstance runtimeInstance, DkmStepper stepper, DkmStepArbitrationReason reason, DkmRuntimeInstance callingRuntimeInstance)
 {
     return(true);
 }
 void IDkmRuntimeStepper.NotifyStepComplete(DkmRuntimeInstance runtimeInstance, DkmStepper stepper)
 {
 }