public void HandleThreadStart(JvmEventsService.JvmVirtualMachineRemoteHandle virtualMachine, JvmEventsService.JvmThreadRemoteHandle threadHandle)
            {
                int id = _nextThreadId++;

                //JvmToolsService.jvmtiError result = Program.ToolsService.SetTag(virtualMachine, threadHandle, id);
                //Contract.Assert(result == JvmToolsService.jvmtiError.None);

                //long tag;
                //result = Program.ToolsService.GetTag(out tag, virtualMachine, threadHandle);
                //Contract.Assert(result == JvmToolsService.jvmtiError.None);
                //Contract.Assert(tag == id);

                int hashCode;

                JvmToolsService.jvmtiError result = Program.ToolsService.GetObjectHashCode(out hashCode, virtualMachine, threadHandle);

                JavaDebugThread thread = new JavaDebugThread(Program, virtualMachine, threadHandle, id);

                Program._threads[hashCode] = thread;

                DebugEvent           @event = new DebugThreadCreateEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS);
                Guid                 guid   = typeof(IDebugThreadCreateEvent2).GUID;
                enum_EVENTATTRIBUTES attrib = @event.GetAttributes();

                Program.Callback.Event(Program.DebugEngine, Program.Process, Program, thread, @event, ref guid, (uint)attrib);
            }
        /// <summary>
        /// Continues running this program from a stopped state. Any previous execution state (such
        /// as a step) is preserved, and the program starts executing again.
        /// </summary>
        /// <param name="pThread">An IDebugThread2 object that represents the thread.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// This method is called on this program regardless of how many programs are being debugged,
        /// or which program generated the stopping event. The implementation must retain the previous
        /// execution state (such as a step) and continue execution as though it had never stopped
        /// before completing its prior execution. That is, if a thread in this program was doing a
        /// step-over operation and was stopped because some other program stopped, and then this
        /// method was called, the program must complete the original step-over operation.
        ///
        /// Do not send a stopping event or an immediate (synchronous) event to IDebugEventCallback2.Event
        /// while handling this call; otherwise the debugger might stop responding.
        /// </remarks>
        public int Continue(IDebugThread2 pThread)
        {
#if true
            if (_suspended != 0)
            {
                Interlocked.Decrement(ref _suspended);
                Task.Factory.StartNew(VirtualMachine.Resume).HandleNonCriticalExceptions();
            }

            return(VSConstants.S_OK);
#else
            if (pThread == null)
            {
                Task.Factory.StartNew(VirtualMachine.Resume).HandleNonCriticalExceptions();
                return(VSConstants.S_OK);
            }

            JavaDebugThread javaThread = pThread as JavaDebugThread;
            if (javaThread == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            Task.Factory.StartNew(() => javaThread.Resume()).HandleNonCriticalExceptions();
            return(VSConstants.S_OK);
#endif
        }
Пример #3
0
        public void Bind(JavaDebugProgram program, JavaDebugThread thread, IReferenceType type, IEnumerable <string> sourcePaths)
        {
            IVirtualMachine virtualMachine = program.VirtualMachine;

            IEnumerable <string> validPaths = sourcePaths.Where(i => string.Equals(Path.GetFileName(RequestLocation.DocumentPosition.GetFileName()), Path.GetFileName(i), StringComparison.OrdinalIgnoreCase));

            List <JavaDebugBoundBreakpoint> boundBreakpoints = new List <JavaDebugBoundBreakpoint>();
            List <IDebugErrorBreakpoint2>   errorBreakpoints = new List <IDebugErrorBreakpoint2>();

            foreach (var path in validPaths)
            {
                TextSpan range = RequestLocation.DocumentPosition.GetRange();
                try
                {
                    ReadOnlyCollection <ILocation> locations = type.GetLocationsOfLine(range.iStartLine + 1);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null && IsFirstOnLine())
                    {
                        IEventRequestManager eventRequestManager = virtualMachine.GetEventRequestManager();

                        IBreakpointRequest eventRequest = eventRequestManager.CreateBreakpointRequest(bindLocation);
                        eventRequest.SuspendPolicy = SuspendPolicy.All;

                        JavaDebugCodeContext             codeContext     = new JavaDebugCodeContext(program, bindLocation);
                        BreakpointResolutionLocationCode location        = new BreakpointResolutionLocationCode(codeContext);
                        DebugBreakpointResolution        resolution      = new DebugBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location);
                        JavaDebugBoundBreakpoint         boundBreakpoint = new JavaDebugBoundBreakpoint(this, program, eventRequest, resolution);
                        if (!_disabled)
                        {
                            boundBreakpoint.Enable(1);
                        }

                        boundBreakpoints.Add(boundBreakpoint);
                    }
                }
                catch (MissingInformationException)
                {
                }
            }

            _boundBreakpoints.AddRange(boundBreakpoints);
            if (boundBreakpoints.Count > 0)
            {
                _errorBreakpoints.Clear();
            }

            _errorBreakpoints.AddRange(errorBreakpoints);

            if (boundBreakpoints.Count > 0)
            {
                DebugEvent debugEvent = new DebugBreakpointBoundEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS, this, new EnumDebugBoundBreakpoints(boundBreakpoints));
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }

            foreach (var errorBreakpoint in errorBreakpoints)
            {
                DebugEvent debugEvent = new DebugBreakpointErrorEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, errorBreakpoint);
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }
        }
            public void HandleClassLoad(JvmEventsService.JvmVirtualMachineRemoteHandle virtualMachine, JvmEventsService.JvmThreadRemoteHandle threadHandle, JvmEventsService.JvmClassRemoteHandle @class)
            {
                // The format of the message created by the .NET debugger is this:
                // 'devenv.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.VisualStudio.Windows.Forms\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Windows.Forms.dll'
                string programName = Program.GetName();
                string debuggerName;
                Guid   debuggerGuid;

                ErrorHandler.ThrowOnFailure(Program.GetEngineInfo(out debuggerName, out debuggerGuid));

                string signature;
                string generic;
                var    result = Program.ToolsService.GetClassSignature(out signature, out generic, virtualMachine, @class);

                JavaDebugThread thread = null;

                if (threadHandle.Handle != 0)
                {
                    int hashCode;
                    result = Program.ToolsService.GetObjectHashCode(out hashCode, virtualMachine, threadHandle);
                    Program._threads.TryGetValue(hashCode, out thread);
                }

                string               message = string.Format("'{0}' ({1}): Loaded class '{2}'" + Environment.NewLine, programName, debuggerName, signature);
                DebugEvent           @event  = new DebugOutputStringEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS, message);
                Guid                 guid    = typeof(IDebugOutputStringEvent2).GUID;
                enum_EVENTATTRIBUTES attrib  = @event.GetAttributes();

                Program.Callback.Event(Program.DebugEngine, Program.Process, Program, thread, @event, ref guid, (uint)attrib);
            }
Пример #5
0
        public JavaDebugStackFrame(JavaDebugThread thread, IStackFrame stackFrame)
        {
            Contract.Requires<ArgumentNullException>(thread != null, "thread");
            Contract.Requires<ArgumentNullException>(stackFrame != null, "stackFrame");

            _thread = thread;
            _stackFrame = stackFrame;

            _nativeMethod = stackFrame.GetLocation().GetMethod().GetIsNative();
            if (!_nativeMethod)
                _debugProperty = new StackFrameDebugProperty(this);
        }
Пример #6
0
        internal void BindVirtualizedBreakpoints(JavaDebugProgram program, JavaDebugThread thread, IReferenceType type, IEnumerable <string> sourcePaths)
        {
            Contract.Requires <ArgumentNullException>(program != null, "program");
            Contract.Requires <ArgumentNullException>(sourcePaths != null, "sourcePaths");

            var breakpoints = VirtualizedBreakpoints.ToArray();

            foreach (var breakpoint in breakpoints)
            {
                breakpoint.Bind(program, thread, type, sourcePaths);
            }
        }
        public JavaDebugStackFrame(JavaDebugThread thread, IStackFrame stackFrame)
        {
            Contract.Requires <ArgumentNullException>(thread != null, "thread");
            Contract.Requires <ArgumentNullException>(stackFrame != null, "stackFrame");

            _thread     = thread;
            _stackFrame = stackFrame;

            _nativeMethod = stackFrame.GetLocation().GetMethod().GetIsNative();
            if (!_nativeMethod)
            {
                _debugProperty = new StackFrameDebugProperty(this);
            }
        }
            public void HandleThreadEnd(JvmEventsService.JvmVirtualMachineRemoteHandle virtualMachine, JvmEventsService.JvmThreadRemoteHandle threadHandle)
            {
                int hashCode;

                JvmToolsService.jvmtiError result = Program.ToolsService.GetObjectHashCode(out hashCode, virtualMachine, threadHandle);
                if (result == 0)
                {
                    JavaDebugThread thread = Program._threads[hashCode];

                    DebugEvent           @event = new DebugThreadDestroyEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS, 0);
                    Guid                 guid   = typeof(IDebugThreadDestroyEvent2).GUID;
                    enum_EVENTATTRIBUTES attrib = @event.GetAttributes();
                    Program.Callback.Event(Program.DebugEngine, Program.Process, Program, thread, @event, ref guid, (uint)attrib);

                    Program._threads.Remove(hashCode);
                }
            }
        private void HandleThreadStart(object sender, ThreadEventArgs e)
        {
            if (e.SuspendPolicy == SuspendPolicy.All)
            {
                Interlocked.Increment(ref _suspended);
            }

            // nothing to do if this thread is already started
            JavaDebugThread thread;

            if (_threads.TryGetValue(e.Thread.GetUniqueId(), out thread))
            {
                switch (e.SuspendPolicy)
                {
                case SuspendPolicy.All:
                    Continue(thread);
                    break;

                case SuspendPolicy.EventThread:
                    Task.Factory.StartNew(e.Thread.Resume).HandleNonCriticalExceptions();
                    break;

                case SuspendPolicy.None:
                    break;
                }

                return;
            }

            thread = new JavaDebugThread(this, e.Thread, ThreadCategory.Worker);
            lock (this._threads)
            {
                this._threads.Add(e.Thread.GetUniqueId(), thread);
            }

            DebugEvent debugEvent = new DebugThreadCreateEvent(GetAttributesForEvent(e));

            SetEventProperties(debugEvent, e, true);
            Callback.Event(DebugEngine, Process, this, thread, debugEvent);

            ManualContinueFromEvent(e);
        }
Пример #10
0
        private void HandleVirtualMachineStart(object sender, ThreadEventArgs e)
        {
            if (e.SuspendPolicy == SuspendPolicy.All)
                Interlocked.Increment(ref _suspended);

            var requestManager = _virtualMachine.GetEventRequestManager();

            var threadStartRequest = requestManager.CreateThreadStartRequest();
            threadStartRequest.SuspendPolicy = SuspendPolicy.EventThread;
            threadStartRequest.IsEnabled = true;

            var threadDeathRequest = requestManager.CreateThreadDeathRequest();
            threadDeathRequest.SuspendPolicy = SuspendPolicy.EventThread;
            threadDeathRequest.IsEnabled = true;

            var classPrepareRequest = requestManager.CreateClassPrepareRequest();
            classPrepareRequest.SuspendPolicy = SuspendPolicy.EventThread;
            classPrepareRequest.IsEnabled = true;

            var exceptionRequest = requestManager.CreateExceptionRequest(null, true, true);
            exceptionRequest.SuspendPolicy = SuspendPolicy.All;
            exceptionRequest.IsEnabled = true;

            var virtualMachineDeathRequest = requestManager.CreateVirtualMachineDeathRequest();
            virtualMachineDeathRequest.SuspendPolicy = SuspendPolicy.All;
            virtualMachineDeathRequest.IsEnabled = true;

            DebugEvent debugEvent = new DebugLoadCompleteEvent(enum_EVENTATTRIBUTES.EVENT_ASYNC_STOP);
            SetEventProperties(debugEvent, e, false);
            Callback.Event(DebugEngine, Process, this, null, debugEvent);

            _isLoaded = true;

            JavaDebugThread mainThread = null;
            ReadOnlyCollection<IThreadReference> threads = VirtualMachine.GetAllThreads();
            for (int i = 0; i < threads.Count; i++)
            {
                bool isMainThread = threads[i].Equals(e.Thread);
                JavaDebugThread thread = new JavaDebugThread(this, threads[i], isMainThread ? ThreadCategory.Main : ThreadCategory.Worker);
                if (isMainThread)
                    mainThread = thread;

                lock (this._threads)
                {
                    this._threads.Add(threads[i].GetUniqueId(), thread);
                }

                debugEvent = new DebugThreadCreateEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS);
                Callback.Event(DebugEngine, Process, this, thread, debugEvent);
            }

            if (DebugEngine.VirtualizedBreakpoints.Count > 0)
            {
                ReadOnlyCollection<IReferenceType> classes = VirtualMachine.GetAllClasses();
                foreach (var type in classes)
                {
                    if (!type.GetIsPrepared())
                        continue;

                    ReadOnlyCollection<string> sourceFiles = type.GetSourcePaths(type.GetDefaultStratum());
                    DebugEngine.BindVirtualizedBreakpoints(this, mainThread, type, sourceFiles);
                }
            }

            JavaDebugThread thread2;
            lock (_threads)
            {
                this._threads.TryGetValue(e.Thread.GetUniqueId(), out thread2);
            }

            debugEvent = new DebugEntryPointEvent(GetAttributesForEvent(e));
            SetEventProperties(debugEvent, e, false);
            Callback.Event(DebugEngine, Process, this, thread2, debugEvent);
        }
Пример #11
0
        private void HandleThreadStart(object sender, ThreadEventArgs e)
        {
            if (e.SuspendPolicy == SuspendPolicy.All)
                Interlocked.Increment(ref _suspended);

            // nothing to do if this thread is already started
            JavaDebugThread thread;
            if (_threads.TryGetValue(e.Thread.GetUniqueId(), out thread))
            {
                switch (e.SuspendPolicy)
                {
                case SuspendPolicy.All:
                    Continue(thread);
                    break;

                case SuspendPolicy.EventThread:
                    Task.Factory.StartNew(e.Thread.Resume).HandleNonCriticalExceptions();
                    break;

                case SuspendPolicy.None:
                    break;
                }

                return;
            }

            thread = new JavaDebugThread(this, e.Thread, ThreadCategory.Worker);
            lock (this._threads)
            {
                this._threads.Add(e.Thread.GetUniqueId(), thread);
            }

            DebugEvent debugEvent = new DebugThreadCreateEvent(GetAttributesForEvent(e));
            SetEventProperties(debugEvent, e, true);
            Callback.Event(DebugEngine, Process, this, thread, debugEvent);

            ManualContinueFromEvent(e);
        }
        public void Bind(JavaDebugProgram program, JavaDebugThread thread, IReferenceType type, IEnumerable<string> sourcePaths)
        {
            IVirtualMachine virtualMachine = program.VirtualMachine;

            IEnumerable<string> validPaths = sourcePaths.Where(i => string.Equals(Path.GetFileName(RequestLocation.DocumentPosition.GetFileName()), Path.GetFileName(i), StringComparison.OrdinalIgnoreCase));

            List<JavaDebugBoundBreakpoint> boundBreakpoints = new List<JavaDebugBoundBreakpoint>();
            List<IDebugErrorBreakpoint2> errorBreakpoints = new List<IDebugErrorBreakpoint2>();
            foreach (var path in validPaths)
            {
                TextSpan range = RequestLocation.DocumentPosition.GetRange();
                try
                {
                    ReadOnlyCollection<ILocation> locations = type.GetLocationsOfLine(range.iStartLine + 1);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null && IsFirstOnLine())
                    {
                        IEventRequestManager eventRequestManager = virtualMachine.GetEventRequestManager();

                        IBreakpointRequest eventRequest = eventRequestManager.CreateBreakpointRequest(bindLocation);
                        eventRequest.SuspendPolicy = SuspendPolicy.All;

                        JavaDebugCodeContext codeContext = new JavaDebugCodeContext(program, bindLocation);
                        BreakpointResolutionLocationCode location = new BreakpointResolutionLocationCode(codeContext);
                        DebugBreakpointResolution resolution = new DebugBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location);
                        JavaDebugBoundBreakpoint boundBreakpoint = new JavaDebugBoundBreakpoint(this, program, eventRequest, resolution);
                        if (!_disabled)
                            boundBreakpoint.Enable(1);

                        boundBreakpoints.Add(boundBreakpoint);
                    }
                }
                catch (MissingInformationException)
                {
                }
            }

            _boundBreakpoints.AddRange(boundBreakpoints);
            if (boundBreakpoints.Count > 0)
            {
                _errorBreakpoints.Clear();
            }

            _errorBreakpoints.AddRange(errorBreakpoints);

            if (boundBreakpoints.Count > 0)
            {
                DebugEvent debugEvent = new DebugBreakpointBoundEvent(enum_EVENTATTRIBUTES.EVENT_SYNCHRONOUS, this, new EnumDebugBoundBreakpoints(boundBreakpoints));
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }

            foreach (var errorBreakpoint in errorBreakpoints)
            {
                DebugEvent debugEvent = new DebugBreakpointErrorEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, errorBreakpoint);
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }
        }
Пример #13
0
        /// <summary>
        /// Determines whether this pending breakpoint can bind to a code location.
        /// </summary>
        /// <param name="ppErrorEnum">
        /// [out] Returns an IEnumDebugErrorBreakpoints2 object that contains a list of IDebugErrorBreakpoint2
        /// objects if there could be errors.
        /// </param>
        /// <returns>
        /// If successful, returns S_OK. Returns S_FALSE if the breakpoint cannot bind, in which case the errors
        /// are returned by the ppErrorEnum parameter. Otherwise, returns an error code. Returns E_BP_DELETED if
        /// the breakpoint has been deleted.
        /// </returns>
        /// <remarks>
        /// This method is called to determine what would happen if this pending breakpoint was bound. Call the
        /// IDebugPendingBreakpoint2::Bind method to actually bind the pending breakpoint.
        /// </remarks>
        public int CanBind(out IEnumDebugErrorBreakpoints2 ppErrorEnum)
        {
            if (_deleted)
            {
                ppErrorEnum = null;
                return(AD7Constants.E_BP_DELETED);
            }

            string fileName            = RequestLocation.DocumentPosition.GetFileName();
            int    lineNumber          = RequestLocation.DocumentPosition.GetRange().iStartLine + 1;
            bool   errorNotFirstOnLine = false;

            IEnumerable <JavaDebugProgram> programs = DebugEngine.Programs.ToArray();

            foreach (var program in programs)
            {
                if (!program.IsLoaded)
                {
                    continue;
                }

                IVirtualMachine virtualMachine = program.VirtualMachine;
                ReadOnlyCollection <IReferenceType> classes = virtualMachine.GetAllClasses();
                foreach (var @class in classes)
                {
                    if ([email protected]())
                    {
                        continue;
                    }

                    ReadOnlyCollection <ILocation> locations = @class.GetLocationsOfLine(@class.GetDefaultStratum(), Path.GetFileName(fileName), lineNumber);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null)
                    {
                        if (IsFirstOnLine())
                        {
                            ppErrorEnum = null;
                            return(VSConstants.S_OK);
                        }
                        else
                        {
                            errorNotFirstOnLine = true;
                            break;
                        }
                    }
                }

                if (errorNotFirstOnLine)
                {
                    break;
                }
            }

            foreach (var program in programs)
            {
                JavaDebugThread              thread      = null;
                IDebugCodeContext2           codeContext = new DebugDocumentCodeContext(RequestLocation.DocumentPosition);
                BreakpointResolutionLocation location    = new BreakpointResolutionLocationCode(codeContext);
                string message = "The class is not yet loaded, or the location is not present in the debug symbols for this document.";
                if (errorNotFirstOnLine)
                {
                    message = "Only breakpoints on the first statement on a line can be bound at this time.";
                }

                DebugErrorBreakpointResolution resolution      = new DebugErrorBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location, enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, message);
                DebugErrorBreakpoint           errorBreakpoint = new DebugErrorBreakpoint(this, resolution);
                _errorBreakpoints.Add(errorBreakpoint);

                DebugEvent debugEvent = new DebugBreakpointErrorEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, errorBreakpoint);
                program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
            }

            if (_errorBreakpoints.Count == 0)
            {
                JavaDebugProgram             program     = null;
                JavaDebugThread              thread      = null;
                IDebugCodeContext2           codeContext = new DebugDocumentCodeContext(RequestLocation.DocumentPosition);
                BreakpointResolutionLocation location    = new BreakpointResolutionLocationCode(codeContext);
                string message = "The binding process is not yet implemented.";

                DebugErrorBreakpointResolution resolution      = new DebugErrorBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location, enum_BP_ERROR_TYPE.BPET_GENERAL_ERROR, message);
                DebugErrorBreakpoint           errorBreakpoint = new DebugErrorBreakpoint(this, resolution);
                _errorBreakpoints.Add(errorBreakpoint);
            }

            ppErrorEnum = new EnumDebugErrorBreakpoints(_errorBreakpoints);
            return(VSConstants.S_FALSE);
        }
Пример #14
0
        private void AsyncBindImpl()
        {
            UnbindAllBreakpoints(enum_BP_UNBOUND_REASON.BPUR_BREAKPOINT_REBIND);

            string fileName            = RequestLocation.DocumentPosition.GetFileName();
            int    lineNumber          = RequestLocation.DocumentPosition.GetRange().iStartLine + 1;
            bool   errorNotFirstOnLine = false;

            List <JavaDebugBoundBreakpoint> boundBreakpoints = new List <JavaDebugBoundBreakpoint>();
            IEnumerable <JavaDebugProgram>  programs         = DebugEngine.Programs.ToArray();

            foreach (var program in programs)
            {
                if (!program.IsLoaded)
                {
                    continue;
                }

                IVirtualMachine virtualMachine = program.VirtualMachine;
                ReadOnlyCollection <IReferenceType> classes = virtualMachine.GetAllClasses();
                foreach (var @class in classes)
                {
                    if ([email protected]())
                    {
                        continue;
                    }

                    ReadOnlyCollection <ILocation> locations = @class.GetLocationsOfLine(@class.GetDefaultStratum(), Path.GetFileName(fileName), lineNumber);
                    ILocation bindLocation = locations.OrderBy(i => i.GetCodeIndex()).FirstOrDefault();
                    if (bindLocation != null)
                    {
                        if (!IsFirstOnLine())
                        {
                            errorNotFirstOnLine = true;
                            break;
                        }

                        IEventRequestManager eventRequestManager = virtualMachine.GetEventRequestManager();
                        IBreakpointRequest   eventRequest        = eventRequestManager.CreateBreakpointRequest(bindLocation);
                        eventRequest.SuspendPolicy = SuspendPolicy.All;

                        JavaDebugCodeContext             codeContext     = new JavaDebugCodeContext(program, bindLocation);
                        BreakpointResolutionLocationCode location        = new BreakpointResolutionLocationCode(codeContext);
                        DebugBreakpointResolution        resolution      = new DebugBreakpointResolution(program, null, enum_BP_TYPE.BPT_CODE, location);
                        JavaDebugBoundBreakpoint         boundBreakpoint = new JavaDebugBoundBreakpoint(this, program, eventRequest, resolution);
                        if (!_disabled)
                        {
                            boundBreakpoint.Enable(1);
                        }

                        boundBreakpoints.Add(boundBreakpoint);
                    }
                }

                if (errorNotFirstOnLine)
                {
                    break;
                }
            }

            _boundBreakpoints.AddRange(boundBreakpoints);

            if (_boundBreakpoints.Count == 0)
            {
                foreach (var program in programs)
                {
                    JavaDebugThread              thread      = null;
                    IDebugCodeContext2           codeContext = new DebugDocumentCodeContext(RequestLocation.DocumentPosition);
                    BreakpointResolutionLocation location    = new BreakpointResolutionLocationCode(codeContext);
                    string message = "The class is not yet loaded, or the location is not present in the debug symbols for this document.";
                    if (errorNotFirstOnLine)
                    {
                        message = "Only breakpoints on the first statement on a line can be bound at this time.";
                    }

                    DebugErrorBreakpointResolution resolution      = new DebugErrorBreakpointResolution(program, thread, enum_BP_TYPE.BPT_CODE, location, enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, message);
                    DebugErrorBreakpoint           errorBreakpoint = new DebugErrorBreakpoint(this, resolution);
                    _errorBreakpoints.Add(errorBreakpoint);

                    DebugEvent debugEvent = new DebugBreakpointErrorEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, errorBreakpoint);
                    program.Callback.Event(DebugEngine, program.Process, program, null, debugEvent);
                }
            }

            foreach (var group in boundBreakpoints.GroupBy(i => i.Program))
            {
                DebugEvent debugEvent = new DebugBreakpointBoundEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, this, new EnumDebugBoundBreakpoints(group));
                group.Key.Callback.Event(DebugEngine, group.Key.Process, group.Key, null, debugEvent);
            }
        }
Пример #15
0
        internal void BindVirtualizedBreakpoints(JavaDebugProgram program, JavaDebugThread thread, IReferenceType type, IEnumerable<string> sourcePaths)
        {
            Contract.Requires<ArgumentNullException>(program != null, "program");
            Contract.Requires<ArgumentNullException>(sourcePaths != null, "sourcePaths");

            var breakpoints = VirtualizedBreakpoints.ToArray();
            foreach (var breakpoint in breakpoints)
            {
                breakpoint.Bind(program, thread, type, sourcePaths);
            }
        }
        private void HandleVirtualMachineStart(object sender, ThreadEventArgs e)
        {
            if (e.SuspendPolicy == SuspendPolicy.All)
            {
                Interlocked.Increment(ref _suspended);
            }

            var requestManager = _virtualMachine.GetEventRequestManager();

            var threadStartRequest = requestManager.CreateThreadStartRequest();

            threadStartRequest.SuspendPolicy = SuspendPolicy.EventThread;
            threadStartRequest.IsEnabled     = true;

            var threadDeathRequest = requestManager.CreateThreadDeathRequest();

            threadDeathRequest.SuspendPolicy = SuspendPolicy.EventThread;
            threadDeathRequest.IsEnabled     = true;

            var classPrepareRequest = requestManager.CreateClassPrepareRequest();

            classPrepareRequest.SuspendPolicy = SuspendPolicy.EventThread;
            classPrepareRequest.IsEnabled     = true;

            var exceptionRequest = requestManager.CreateExceptionRequest(null, true, true);

            exceptionRequest.SuspendPolicy = SuspendPolicy.All;
            exceptionRequest.IsEnabled     = true;

            var virtualMachineDeathRequest = requestManager.CreateVirtualMachineDeathRequest();

            virtualMachineDeathRequest.SuspendPolicy = SuspendPolicy.All;
            virtualMachineDeathRequest.IsEnabled     = true;

            DebugEvent debugEvent = new DebugLoadCompleteEvent(enum_EVENTATTRIBUTES.EVENT_ASYNC_STOP);

            SetEventProperties(debugEvent, e, false);
            Callback.Event(DebugEngine, Process, this, null, debugEvent);

            _isLoaded = true;

            JavaDebugThread mainThread = null;
            ReadOnlyCollection <IThreadReference> threads = VirtualMachine.GetAllThreads();

            for (int i = 0; i < threads.Count; i++)
            {
                bool            isMainThread = threads[i].Equals(e.Thread);
                JavaDebugThread thread       = new JavaDebugThread(this, threads[i], isMainThread ? ThreadCategory.Main : ThreadCategory.Worker);
                if (isMainThread)
                {
                    mainThread = thread;
                }

                lock (this._threads)
                {
                    this._threads.Add(threads[i].GetUniqueId(), thread);
                }

                debugEvent = new DebugThreadCreateEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS);
                Callback.Event(DebugEngine, Process, this, thread, debugEvent);
            }

            if (DebugEngine.VirtualizedBreakpoints.Count > 0)
            {
                ReadOnlyCollection <IReferenceType> classes = VirtualMachine.GetAllClasses();
                foreach (var type in classes)
                {
                    if (!type.GetIsPrepared())
                    {
                        continue;
                    }

                    ReadOnlyCollection <string> sourceFiles = type.GetSourcePaths(type.GetDefaultStratum());
                    DebugEngine.BindVirtualizedBreakpoints(this, mainThread, type, sourceFiles);
                }
            }

            JavaDebugThread thread2;

            lock (_threads)
            {
                this._threads.TryGetValue(e.Thread.GetUniqueId(), out thread2);
            }

            debugEvent = new DebugEntryPointEvent(GetAttributesForEvent(e));
            SetEventProperties(debugEvent, e, false);
            Callback.Event(DebugEngine, Process, this, thread2, debugEvent);
        }
        public int Step(IDebugThread2 pThread, enum_STEPKIND sk, enum_STEPUNIT Step)
        {
            JavaDebugThread thread = pThread as JavaDebugThread;

            if (thread == null)
            {
                return(VSConstants.E_INVALIDARG);
            }

            StepSize  size;
            StepDepth depth;

            switch (Step)
            {
            case enum_STEPUNIT.STEP_INSTRUCTION:
                size = StepSize.Instruction;
                break;

            case enum_STEPUNIT.STEP_LINE:
                size = StepSize.Line;
                break;

            case enum_STEPUNIT.STEP_STATEMENT:
                size = VirtualMachine.GetCanStepByStatement() ? StepSize.Statement : StepSize.Line;
                break;

            default:
                throw new NotSupportedException();
            }

            switch (sk)
            {
            case enum_STEPKIND.STEP_INTO:
                depth = StepDepth.Into;
                break;

            case enum_STEPKIND.STEP_OUT:
                depth = StepDepth.Out;
                break;

            case enum_STEPKIND.STEP_OVER:
                depth = StepDepth.Over;
                break;

            case enum_STEPKIND.STEP_BACKWARDS:
            default:
                throw new NotSupportedException();
            }

            IStepRequest stepRequest = thread.GetStepRequest(size, depth);

            if (stepRequest == null)
            {
                throw new InvalidOperationException();
            }

            Task.Factory.StartNew(() =>
            {
                // make sure the global "Break All" step request is disabled
                this._causeBreakRequest.IsEnabled = false;
                stepRequest.IsEnabled             = true;
                VirtualMachine.Resume();
                Interlocked.Decrement(ref _suspended);
            }).HandleNonCriticalExceptions();

            return(VSConstants.S_OK);
        }