示例#1
0
 void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(
     DkmModuleInstance moduleInstance,
     DkmWorkList workList,
     DkmEventDescriptorS eventDescriptor
     )
 {
     OnModuleLoad(moduleInstance, workList);
 }
    public static void VscxOnRuntimeBreakpointReceived(
        this DkmProcess process,
        DkmRuntimeBreakpoint bp,
        DkmThread thread,
        bool hasException,
        DkmEventDescriptorS eventDescriptor) {
      RuntimeBreakpointHandler handler = process.GetDataItem<RuntimeBreakpointHandler>();
      if (handler == null)
        return;

      handler.OnRuntimeBreakpointReceived(bp, thread, hasException, eventDescriptor);
    }
 public void OnRuntimeBreakpointReceived(
     DkmRuntimeBreakpoint bp,
     DkmThread thread,
     bool hasException,
     DkmEventDescriptorS eventDescriptor) {
   FunctionTraceDataItem traceDataItem = bp.GetDataItem<FunctionTraceDataItem>();
   if (traceDataItem != null && traceDataItem.Tracer != null) {
     if (bp.SourceId == Guids.Source.FunctionTraceEnter)
       traceDataItem.Tracer.OnEntryBreakpointHit(bp, thread, hasException);
     else if (bp.SourceId == Guids.Source.FunctionTraceExit)
       traceDataItem.Tracer.OnExitBreakpointHit(bp, thread, hasException);
   }
 }
示例#4
0
        public static void VscxOnRuntimeBreakpointReceived(
            this DkmProcess process,
            DkmRuntimeBreakpoint bp,
            DkmThread thread,
            bool hasException,
            DkmEventDescriptorS eventDescriptor)
        {
            RuntimeBreakpointHandler handler = process.GetDataItem <RuntimeBreakpointHandler>();

            if (handler == null)
            {
                return;
            }

            handler.OnRuntimeBreakpointReceived(bp, thread, hasException, eventDescriptor);
        }
示例#5
0
        public void OnRuntimeBreakpointReceived(
            DkmRuntimeBreakpoint bp,
            DkmThread thread,
            bool hasException,
            DkmEventDescriptorS eventDescriptor)
        {
            FunctionTraceDataItem traceDataItem = bp.GetDataItem <FunctionTraceDataItem>();

            if (traceDataItem != null && traceDataItem.Tracer != null)
            {
                if (bp.SourceId == Guids.Source.FunctionTraceEnter)
                {
                    traceDataItem.Tracer.OnEntryBreakpointHit(bp, thread, hasException);
                }
                else if (bp.SourceId == Guids.Source.FunctionTraceExit)
                {
                    traceDataItem.Tracer.OnExitBreakpointHit(bp, thread, hasException);
                }
            }
        }
示例#6
0
        void IDkmExceptionTriggerHitNotification.OnExceptionTriggerHit(DkmExceptionTriggerHit hit, DkmEventDescriptorS eventDescriptor) {
            ThreadHelper.Generic.Invoke(() => {
                var exceptionInfo = hit.Exception as VisualStudio.Debugger.Native.DkmWin32ExceptionInformation;

                if (exceptionInfo.Code == RemoteDebugStartExceptionCode) {
                    // Parameters expected are the flag to indicate the debugger is present and JSON to write to the target for configuration
                    // of the debugger
                    const int exceptionParameterCount = 3;

                    if (exceptionInfo.ExceptionParameters.Count == exceptionParameterCount) {
                        // If we have a port and debug id, we'll go ahead and tell the client we are present
                        if (Instance.AttachRemoteProcessFunction != null && Instance.RemoteDebugCommandInfo != null) {
                            if (Instance.RemoteDebugCommandInfo.Length <= (int)exceptionInfo.ExceptionParameters[2]) {
                                // Write back that debugger is present
                                hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[0], BitConverter.GetBytes(true));

                                // Write back the details of the debugger arguments
                                hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[1], Instance.RemoteDebugCommandInfo);
                            }
                        }
                    }
                } else if (exceptionInfo.Code == RemoteDebugAttachExceptionCode) {
                    // Parameters expected are the flag to indicate the debugger is present and XML to write to the target for configuration
                    // of the debugger
                    const int exceptionAttachParameterCount = 1;

                    if (exceptionInfo.ExceptionParameters.Count == exceptionAttachParameterCount) {
                        // If we have a port and debug id, we'll go ahead and tell the client we are present
                        if (Instance.AttachRemoteProcessFunction != null) {
                            // Write back that debugger is present
                            hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[0], BitConverter.GetBytes(true));

                            // Start the task to attach to the remote Python debugger session
                            System.Threading.Tasks.Task.Factory.StartNew(Instance.AttachRemoteProcessFunction);
                        }
                    }
                }
            });

            eventDescriptor.Suppress();
        }
示例#7
0
 void IDkmAsyncBreakCompleteReceived.OnAsyncBreakCompleteReceived(DkmProcess process, DkmAsyncBreakStatus status, DkmThread thread, DkmEventDescriptorS eventDescriptor)
 {
     new LocalComponent.AsyncBreakReceivedNotification {
         ThreadId = thread.UniqueId
     }.SendHigher(process);
 }
示例#8
0
 void IDkmRuntimeBreakpointReceived.OnRuntimeBreakpointReceived(DkmRuntimeBreakpoint runtimeBreakpoint, DkmThread thread, bool hasException, DkmEventDescriptorS eventDescriptor)
 {
     if (runtimeBreakpoint.SourceId == Guids.LocalComponentGuid)
     {
         ulong retAddr, frameBase, vframe;
         thread.GetCurrentFrameInfo(out retAddr, out frameBase, out vframe);
         new LocalComponent.HandleBreakpointRequest {
             BreakpointId  = runtimeBreakpoint.UniqueId,
             ThreadId      = thread.UniqueId,
             FrameBase     = frameBase,
             VFrame        = vframe,
             ReturnAddress = retAddr
         }.SendHigher(thread.Process);
     }
     else if (runtimeBreakpoint.SourceId == Guids.PythonTraceManagerSourceGuid || runtimeBreakpoint.SourceId == Guids.PythonStepTargetSourceGuid)
     {
         var traceManager = runtimeBreakpoint.Process.GetDataItem <TraceManager>();
         if (traceManager != null)
         {
             traceManager.OnNativeBreakpointHit(runtimeBreakpoint, thread);
         }
     }
     else
     {
         Debug.Fail("RemoteComponent received a notification for a breakpoint that it does not know how to handle.");
         throw new ArgumentException();
     }
 }
示例#9
0
        void IDkmRuntimeBreakpointReceived.OnRuntimeBreakpointReceived(DkmRuntimeBreakpoint bp, DkmThread thread, bool hasException, DkmEventDescriptorS eventDescriptor)
        {
            DkmProcess process = bp.Process;

            process.VscxOnRuntimeBreakpointReceived(bp, thread, hasException, eventDescriptor);
        }
示例#10
0
 public void OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
 {
     moduleInstance.Process.VscxOnModuleInstanceLoad(moduleInstance, workList);
 }
        void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
        {
            var process = moduleInstance.Process;

            var engines = process.DebugLaunchSettings.EngineFilter;

            if (engines == null || !engines.Contains(AD7Engine.DebugEngineGuid))
            {
                return;
            }

            if (moduleInstance.RuntimeInstance == process.GetNativeRuntimeInstance())
            {
                new LocalComponent.NativeModuleInstanceLoadedNotification {
                    ModuleInstanceId = moduleInstance.UniqueId
                }.SendLower(process);
            }
        }
示例#12
0
        void IDkmExceptionTriggerHitNotification.OnExceptionTriggerHit(DkmExceptionTriggerHit hit, DkmEventDescriptorS eventDescriptor)
        {
            ThreadHelper.Generic.Invoke(() => {
                var exceptionInfo = hit.Exception as VisualStudio.Debugger.Native.DkmWin32ExceptionInformation;

                if (exceptionInfo.Code == RemoteDebugStartExceptionCode)
                {
                    // Parameters expected are the flag to indicate the debugger is present and JSON to write to the target for configuration
                    // of the debugger
                    const int exceptionParameterCount = 3;

                    if (exceptionInfo.ExceptionParameters.Count == exceptionParameterCount)
                    {
                        // If we have a port and debug id, we'll go ahead and tell the client we are present
                        if (Instance.AttachRemoteProcessFunction != null && Instance.RemoteDebugCommandInfo != null)
                        {
                            if (Instance.RemoteDebugCommandInfo.Length <= (int)exceptionInfo.ExceptionParameters[2])
                            {
                                // Write back that debugger is present
                                hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[0], BitConverter.GetBytes(true));

                                // Write back the details of the debugger arguments
                                hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[1], Instance.RemoteDebugCommandInfo);
                            }
                        }
                    }
                }
                else if (exceptionInfo.Code == RemoteDebugAttachExceptionCode)
                {
                    // Parameters expected are the flag to indicate the debugger is present and XML to write to the target for configuration
                    // of the debugger
                    const int exceptionAttachParameterCount = 1;

                    if (exceptionInfo.ExceptionParameters.Count == exceptionAttachParameterCount)
                    {
                        // If we have a port and debug id, we'll go ahead and tell the client we are present
                        if (Instance.AttachRemoteProcessFunction != null)
                        {
                            // Write back that debugger is present
                            hit.Process.WriteMemory(exceptionInfo.ExceptionParameters[0], BitConverter.GetBytes(true));

                            // Start the task to attach to the remote Python debugger session
                            System.Threading.Tasks.Task.Factory.StartNew(Instance.AttachRemoteProcessFunction);
                        }
                    }
                }
            });

            eventDescriptor.Suppress();
        }
 public void OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
 {
     if (moduleInstance.Name.Contains("mono-2.0"))
     {
         _enabled = true;
     }
 }
示例#14
0
        void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
        {
            var module = moduleInstance as DkmClrModuleInstance;

            Debug.Assert(module != null); // <Filter><RuntimeId RequiredValue="DkmRuntimeId.Clr"/></Filter> should ensure this.
            if (module == null)
            {
                // Only interested in managed modules.
                return;
            }

            OnModuleLoad(module.Process, module);
        }
 /// <summary>
 /// <see cref="IDkmModuleInstanceLoadNotification"/> is implemented by components that want to listen
 /// for the ModuleInstanceLoad event. When this notification fires, the target process
 /// will be suspended and can be examined. ModuleInstanceLoad is fired when a module is
 /// loaded by a target process. Among other things, this event is used for symbol
 /// providers to load symbols, and for the breakpoint manager to set breakpoints.
 /// ModuleInstanceLoad fires for all modules, even if there are no symbols loaded.
 /// </summary>
 void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
 {
     if (moduleInstance is DkmClrModuleInstance clrModuleInstance)
     {
         _listener.OnManagedModuleInstanceLoaded(clrModuleInstance);
     }
 }
 public void OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
 {
     moduleInstance.Process.VscxOnModuleInstanceLoad(moduleInstance, workList);
 }
 void IDkmRuntimeBreakpointReceived.OnRuntimeBreakpointReceived(DkmRuntimeBreakpoint bp, DkmThread thread, bool hasException, DkmEventDescriptorS eventDescriptor)
 {
     DkmProcess process = bp.Process;
       process.VscxOnRuntimeBreakpointReceived(bp, thread, hasException, eventDescriptor);
 }
示例#18
0
        void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
        {
            var nativeModuleInstance = moduleInstance as DkmNativeModuleInstance;

            if (nativeModuleInstance != null && PythonDLLs.CTypesNames.Contains(moduleInstance.Name))
            {
                var pyrtInfo = moduleInstance.Process.GetPythonRuntimeInfo();
                pyrtInfo.DLLs.CTypes = nativeModuleInstance;
                nativeModuleInstance.FlagAsTransitionModule();
            }
        }
        void IDkmRuntimeBreakpointReceived.OnRuntimeBreakpointReceived(DkmRuntimeBreakpoint runtimeBreakpoint, DkmThread thread, bool hasException, DkmEventDescriptorS eventDescriptor)
        {
            var process = thread.Process;

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

            if (runtimeBreakpoint.SourceId == Guids.luaSupportBreakpointGuid)
            {
                if (processData.locations != null)
                {
                    if (runtimeBreakpoint.UniqueId == processData.locations.breakpointLuaHelperBreakpointHit)
                    {
                        // Breakpoint can get hit again after expression evaluation 'slips' the thread
                        if (processData.pauseBreakpoints)
                        {
                            return;
                        }

                        eventDescriptor.Suppress();

                        var breakpointPos = DebugHelpers.ReadUintVariable(process, processData.locations.helperBreakHitIdAddress);

                        if (!breakpointPos.HasValue)
                        {
                            return;
                        }

                        if (breakpointPos.Value < processData.activeBreakpoints.Count)
                        {
                            try
                            {
                                var breakpoint = processData.activeBreakpoints[(int)breakpointPos.Value];

                                if (breakpoint.runtimeBreakpoint != null)
                                {
                                    breakpoint.runtimeBreakpoint.OnHit(thread, false);
                                }
                            }
                            catch (System.ObjectDisposedException)
                            {
                                // Breakpoint was implicitly closed
                                processData.activeBreakpoints.RemoveAt((int)breakpointPos.Value);
                            }
                            catch (DkmException)
                            {
                                // In case another component evaluates a function
                            }
                        }

                        return;
                    }
                    else if (runtimeBreakpoint.UniqueId == processData.locations.breakpointLuaHelperStepComplete)
                    {
                        if (processData.activeStepper != null)
                        {
                            var activeStepper = processData.activeStepper;

                            ClearStepperData(process, processData);

                            activeStepper.OnStepComplete(thread, false);
                        }

                        return;
                    }
                    else if (runtimeBreakpoint.UniqueId == processData.locations.breakpointLuaHelperStepInto)
                    {
                        if (processData.activeStepper != null)
                        {
                            var activeStepper = processData.activeStepper;

                            ClearStepperData(process, processData);

                            activeStepper.OnStepComplete(thread, false);
                        }

                        return;
                    }
                    else if (runtimeBreakpoint.UniqueId == processData.locations.breakpointLuaHelperStepOut)
                    {
                        if (processData.activeStepper != null)
                        {
                            var activeStepper = processData.activeStepper;

                            ClearStepperData(process, processData);

                            activeStepper.OnStepComplete(thread, false);
                        }

                        return;
                    }
                }

                thread.GetCurrentFrameInfo(out ulong retAddr, out ulong frameBase, out ulong vframe);

                var data = new SupportBreakpointHitMessage
                {
                    breakpointId = runtimeBreakpoint.UniqueId,
                    threadId     = thread.UniqueId,
                    retAddr      = retAddr,
                    frameBase    = frameBase,
                    vframe       = vframe
                };

                var message = DkmCustomMessage.Create(process.Connection, process, MessageToLocal.guid, MessageToLocal.luaSupportBreakpointHit, data.Encode(), null);

                var response = message.SendHigher();

                if (response?.MessageCode == MessageToRemote.throwException)
                {
                    if (runtimeBreakpoint is DkmRuntimeInstructionBreakpoint runtimeInstructionBreakpoint)
                    {
                        var exceptionInformation = DkmCustomExceptionInformation.Create(processData.runtimeInstance, Guids.luaExceptionGuid, thread, runtimeInstructionBreakpoint.InstructionAddress, "LuaError", 0, DkmExceptionProcessingStage.Thrown | DkmExceptionProcessingStage.UserVisible | DkmExceptionProcessingStage.Unhandled, null, new ReadOnlyCollection <byte>(response.Parameter1 as byte[]));

                        exceptionInformation.OnDebugMonitorException();
                    }
                }
            }
        }
示例#20
0
            void IDkmDebugMonitorExceptionNotification.OnDebugMonitorException(DkmExceptionInformation exception, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
            {
                var processData = DebugHelpers.GetOrCreateDataItem <NullcRemoteProcessDataItem>(exception.Process);

                if (exception.InstructionAddress == null)
                {
                    return;
                }

                ulong address = exception.InstructionAddress.CPUInstructionPart.InstructionPointer;

                // Breakpoint
                if (exception.Code == 0x80000003)
                {
                    // Internal stepper breakpoints are silenced but te debugger is notified to break the process
                    if (processData.stepBreakpoint != null && processData.stepBreakpoint.InstructionAddress.CPUInstructionPart.InstructionPointer == address)
                    {
                        eventDescriptor.Suppress();

                        exception.Thread.OnEmbeddedBreakpointHit(exception.InstructionAddress, false);
                    }

                    if (processData.secondaryStepBreakpoint != null && processData.secondaryStepBreakpoint.InstructionAddress.CPUInstructionPart.InstructionPointer == address)
                    {
                        eventDescriptor.Suppress();

                        exception.Thread.OnEmbeddedBreakpointHit(exception.InstructionAddress, false);
                    }

                    // Second stage of breakpoint handling - supress exception, notify debugger to break the process and remember what breakpoint has to be resotred later
                    if (processData.activeBreakpointLocations.Contains(address))
                    {
                        eventDescriptor.Suppress();

                        exception.Thread.OnEmbeddedBreakpointHit(exception.InstructionAddress, false);

                        // Schedule restore of this breakpoint when process continues
                        processData.lastHitBreakpointLocation = address;

                        processData.singleStepThread = exception.Thread;
                    }
                }
            }
 void IDkmModuleInstanceLoadNotification.OnModuleInstanceLoad(DkmModuleInstance moduleInstance, DkmWorkList workList, DkmEventDescriptorS eventDescriptor)
 {
     if (moduleInstance is DkmClrModuleInstance clrModuleInstance)
     {
         Contract.ThrowIfNull(_encService);
         _encService.OnManagedModuleInstanceLoaded(clrModuleInstance.Mvid);
     }
 }
示例#22
0
            void IDkmSingleStepCompleteReceived.OnSingleStepCompleteReceived(DkmSingleStepRequest singleStepRequest, DkmEventDescriptorS eventDescriptor)
            {
                var processData = DebugHelpers.GetOrCreateDataItem <NullcRemoteProcessDataItem>(singleStepRequest.Thread.Process);

                // Last stage of breakpoint handling - restore debug break instruction now that we have moved from the breakpoint location
                if (processData.lastHitBreakpointLocation != 0)
                {
                    // Restore breakpoint instruction
                    singleStepRequest.Thread.Process.InvisibleWriteMemory(processData.lastHitBreakpointLocation, new byte[1] {
                        0xcc
                    });

                    processData.lastHitBreakpointLocation = 0;

                    eventDescriptor.Suppress();
                }
            }