public JavaDebugCodeContext(JavaDebugProgram program, ILocation location)
 {
     Contract.Requires <ArgumentNullException>(program != null, "program");
     Contract.Requires <ArgumentNullException>(location != null, "location");
     _program  = program;
     _location = location;
 }
예제 #2
0
 public JavaDebugCodeContext(JavaDebugProgram program, ILocation location)
 {
     Contract.Requires<ArgumentNullException>(program != null, "program");
     Contract.Requires<ArgumentNullException>(location != null, "location");
     _program = program;
     _location = location;
 }
예제 #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 JavaDebugThread(JavaDebugProgram program, IThreadReference thread, ThreadCategory category)
        {
            Contract.Requires <ArgumentNullException>(program != null, "program");
            Contract.Requires <ArgumentNullException>(thread != null, "thread");

            _program  = program;
            _thread   = thread;
            _category = category;
            CreateStepRequests();
        }
예제 #5
0
        public JavaDebugThread(JavaDebugProgram program, IThreadReference thread, ThreadCategory category)
        {
            Contract.Requires<ArgumentNullException>(program != null, "program");
            Contract.Requires<ArgumentNullException>(thread != null, "thread");

            _program = program;
            _thread = thread;
            _category = category;
            CreateStepRequests();
        }
        /// <summary>
        /// Watches for execution (or stops watching for execution) to occur on the given thread.
        /// </summary>
        /// <param name="pOriginatingProgram">An IDebugProgram2 object representing the program being stepped.</param>
        /// <param name="dwTid">Specifies the identifier of the thread to watch.</param>
        /// <param name="fWatch">Non-zero (TRUE) means start watching for execution on the thread identified by dwTid; otherwise, zero (FALSE) means stop watching for execution on dwTid.</param>
        /// <param name="dwFrame">
        /// Specifies a frame index that controls the step type. When this is value is zero (0), the step type is
        /// "step into" and the program should stop whenever the thread identified by dwTid executes. When dwFrame
        /// is non-zero, the step type is "step over" and the program should stop only if the thread identified by
        /// dwTid is running in a frame whose index is equal to or higher on the stack than dwFrame.
        /// </param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// When the session debug manager (SDM) steps a program, identified by the pOriginatingProgram parameter,
        /// it notifies all other attached programs by calling this method.
        ///
        /// This method is applicable only to same-thread stepping.
        /// </remarks>
        public int WatchForThreadStep(IDebugProgram2 pOriginatingProgram, uint dwTid, int fWatch, uint dwFrame)
        {
            JavaDebugProgram javaProgram = pOriginatingProgram as JavaDebugProgram;

            if (javaProgram == null)
            {
                return(VSConstants.S_OK);
            }

            throw new NotImplementedException();
        }
        /// <summary>
        /// Allows (or disallows) expression evaluation to occur on the given thread, even if the program has stopped.
        /// </summary>
        /// <param name="pOriginatingProgram">An IDebugProgram2 object representing the program that is evaluating an expression.</param>
        /// <param name="dwTid">Specifies the identifier of the thread.</param>
        /// <param name="dwEvalFlags">A combination of flags from the EVALFLAGS enumeration that specify how the evaluation is to be performed.</param>
        /// <param name="pExprCallback">An IDebugEventCallback2 object to be used to send debug events that occur during expression evaluation.</param>
        /// <param name="fWatch">If non-zero (TRUE), allows expression evaluation on the thread identified by dwTid; otherwise, zero (FALSE) disallows expression evaluation on that thread.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// When the session debug manager (SDM) asks a program, identified by the <paramref name="pOriginatingProgram"/>
        /// parameter, to evaluate an expression, it notifies all other attached programs by calling this method.
        ///
        /// Expression evaluation in one program may cause code to run in another, due to function evaluation or
        /// evaluation of any IDispatch properties. Because of this, this method allows expression evaluation to
        /// run and complete even though the thread may be stopped in this program.
        /// </remarks>
        public int WatchForExpressionEvaluationOnThread(IDebugProgram2 pOriginatingProgram, uint dwTid, uint dwEvalFlags, IDebugEventCallback2 pExprCallback, int fWatch)
        {
            JavaDebugProgram javaProgram = pOriginatingProgram as JavaDebugProgram;

            if (javaProgram == null)
            {
                return(VSConstants.S_OK);
            }

            throw new NotImplementedException();
        }
예제 #8
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 JavaDebugBoundBreakpoint(IDebugPendingBreakpoint2 pendingBreakpoint, JavaDebugProgram program, IBreakpointRequest eventRequest, DebugBreakpointResolution resolution)
        {
            Contract.Requires <ArgumentNullException>(pendingBreakpoint != null, "pendingBreakpoint");
            Contract.Requires <ArgumentNullException>(program != null, "program");
            Contract.Requires <ArgumentNullException>(eventRequest != null, "eventRequest");
            Contract.Requires <ArgumentNullException>(resolution != null, "resolution");

            _pendingBreakpoint = pendingBreakpoint;
            _program           = program;
            _eventRequest      = eventRequest;
            _resolution        = resolution;
            _disabled          = true;
        }
예제 #10
0
        public int Attach(IDebugProgram2[] rgpPrograms, IDebugProgramNode2[] rgpProgramNodes, uint celtPrograms, IDebugEventCallback2 pCallback, enum_ATTACH_REASON dwReason)
        {
            if (celtPrograms == 0)
            {
                return(VSConstants.S_OK);
            }

            if (pCallback == null)
            {
                throw new ArgumentNullException("pCallback");
            }
            if (rgpPrograms == null || rgpPrograms.Length < celtPrograms)
            {
                throw new ArgumentException();
            }
            if (rgpProgramNodes == null || rgpProgramNodes.Length < celtPrograms)
            {
                throw new ArgumentException();
            }

            if (celtPrograms > 1)
            {
                throw new NotImplementedException();
            }

            if (dwReason != enum_ATTACH_REASON.ATTACH_REASON_LAUNCH)
            {
                throw new NotImplementedException();
            }

            JavaDebugProgram program = rgpProgramNodes[0] as JavaDebugProgram;

            if (program == null)
            {
                throw new NotSupportedException();
            }

            lock (_programs)
            {
                _programs.Add(program);
            }

            DebugEvent @event = new DebugEngineCreateEvent(enum_EVENTATTRIBUTES.EVENT_ASYNCHRONOUS, this);

            pCallback.Event(this, program.GetProcess(), program, null, @event);

            program.InitializeDebuggerChannel(this, pCallback);
            return(VSConstants.S_OK);
        }
예제 #11
0
        public int ContinueFromSynchronousEvent(IDebugEvent2 pEvent)
        {
            if (pEvent == null)
            {
                throw new ArgumentNullException("pEvent");
            }
            if (!(pEvent is DebugEvent))
            {
                return(VSConstants.E_INVALIDARG);
            }

            if (pEvent is IDebugEngineCreateEvent2)
            {
                return(VSConstants.S_OK);
            }

            IPropertyOwner propertyOwner = pEvent as IPropertyOwner;

            if (propertyOwner != null)
            {
                bool manualResume;
                propertyOwner.Properties.TryGetProperty("ManualResume", out manualResume);

                SuspendPolicy suspendPolicy;
                if (!manualResume && propertyOwner.Properties.TryGetProperty(typeof(SuspendPolicy), out suspendPolicy))
                {
                    IThreadReference thread = propertyOwner.Properties.GetProperty <IThreadReference>(typeof(IThreadReference));

                    switch (suspendPolicy)
                    {
                    case SuspendPolicy.All:
                        JavaDebugProgram program = propertyOwner.Properties.GetProperty <JavaDebugProgram>(typeof(JavaDebugProgram));
                        JavaDebugThread  debugThread;
                        program.Threads.TryGetValue(thread.GetUniqueId(), out debugThread);
                        program.Continue(debugThread);
                        break;

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

                    case SuspendPolicy.None:
                        break;
                    }
                }
            }

            return(VSConstants.S_OK);
        }
예제 #12
0
        public int DestroyProgram(IDebugProgram2 program)
        {
            JavaDebugProgram javaProgram = program as JavaDebugProgram;

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

            lock (_programs)
            {
                _programs.Remove(javaProgram);
            }

            return(VSConstants.S_OK);
        }
        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);
            }
        }
예제 #14
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);
        }
예제 #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);
            }
        }
 public JvmEventsCallback(JavaDebugProgram program)
 {
     Contract.Requires(program != null);
     _program = program;
 }