Example #1
0
        public void TestBreakpointFailed()
        {
            var debugger = new PythonDebugger();

            PythonThread     thread     = null;
            PythonBreakpoint breakPoint = null;
            var process = DebugProcess(debugger, DebuggerTestPath + "BreakpointTest.py", (newproc, newthread) => {
                breakPoint = newproc.AddBreakPoint("doesnotexist.py", 1);
                breakPoint.Add();
                thread = newthread;
            });

            bool bindFailed = false;

            process.BreakpointBindFailed += (sender, args) => {
                bindFailed = true;
                Assert.AreEqual(args.Breakpoint, breakPoint);
            };
            process.ExceptionRaised += (sender, args) => {
                args.Thread.Resume();
            };

            process.Start();

            process.WaitForExit();

            Assert.AreEqual(bindFailed, true);
        }
Example #2
0
 public AD7BoundBreakpoint(AD7Engine engine, PythonBreakpoint address, AD7PendingBreakpoint pendingBreakpoint, AD7BreakpointResolution breakpointResolution, bool enabled) {
     _engine = engine;
     _breakpoint = address;
     _pendingBreakpoint = pendingBreakpoint;
     _breakpointResolution = breakpointResolution;
     _enabled = enabled;
     _deleted = false;
 }
Example #3
0
 public AD7BoundBreakpoint(AD7Engine engine, PythonBreakpoint address, AD7PendingBreakpoint pendingBreakpoint, AD7BreakpointResolution breakpointResolution, bool enabled)
 {
     _engine               = engine;
     _breakpoint           = address;
     _pendingBreakpoint    = pendingBreakpoint;
     _breakpointResolution = breakpointResolution;
     _enabled              = enabled;
     _deleted              = false;
 }
Example #4
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file 
        // location.
        public AD7DocumentContext GetDocumentContext(PythonBreakpoint address) {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2));
            string documentName;
            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            // Get the location in the document that the breakpoint is in.
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

            AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, documentName, startPosition[0].dwLine);

            return new AD7DocumentContext(documentName, startPosition[0], startPosition[0], codeContext, FrameKind.Python);
        }
Example #5
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file
        // location.
        public AD7DocumentContext GetDocumentContext(PythonBreakpoint address)
        {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2));

            EngineUtils.CheckOk(docPosition.GetFileName(out global::System.String documentName));

            // Get the location in the document that the breakpoint is in.
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

            AD7MemoryAddress codeContext = new AD7MemoryAddress(_engine, documentName, startPosition[0].dwLine);

            return(new AD7DocumentContext(documentName, startPosition[0], startPosition[0], codeContext, FrameKind.Python));
        }
Example #6
0
 public AD7BoundBreakpoint GetBreakpoint(PythonBreakpoint breakpoint)
 {
     return(_breakpointMap[breakpoint]);
 }
Example #7
0
 public void RemoveBoundBreakpoint(PythonBreakpoint breakpoint)
 {
     _breakpointMap.Remove(breakpoint);
 }
Example #8
0
 public void AddBoundBreakpoint(PythonBreakpoint breakpoint, AD7BoundBreakpoint boundBreakpoint)
 {
     _breakpointMap[breakpoint] = boundBreakpoint;
 }
Example #9
0
 public AD7BreakpointResolution(AD7Engine engine, PythonBreakpoint address, AD7DocumentContext documentContext)
 {
     m_engine          = engine;
     m_address         = address;
     m_documentContext = documentContext;
 }
Example #10
0
 public BreakpointHitEventArgs(PythonBreakpoint breakpoint, PythonThread thread)
 {
     _breakpoint = breakpoint;
     _thread     = thread;
 }
Example #11
0
 public AD7BoundBreakpoint GetBreakpoint(PythonBreakpoint breakpoint) {
     return _breakpointMap[breakpoint];
 }
Example #12
0
 public void RemoveBoundBreakpoint(PythonBreakpoint breakpoint) {
     _breakpointMap.Remove(breakpoint);
 }
Example #13
0
 public void AddBoundBreakpoint(PythonBreakpoint breakpoint, AD7BoundBreakpoint boundBreakpoint) {
     _breakpointMap[breakpoint] = boundBreakpoint;
 }
Example #14
0
 public AD7BreakpointResolution(AD7Engine engine, PythonBreakpoint address, AD7DocumentContext documentContext) {
     m_engine = engine;
     m_address = address;
     m_documentContext = documentContext;
 }
Example #15
0
 public BreakpointEventArgs(PythonBreakpoint breakpoint)
 {
     _breakpoint = breakpoint;
 }
Example #16
0
        // Binds this pending breakpoint to one or more code locations.
        int IDebugPendingBreakpoint2.Bind()
        {
            if (CanBind())
            {
                IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2));

                // Get the name of the document that the breakpoint was put in
                EngineUtils.CheckOk(docPosition.GetFileName(out global::System.String documentName));


                // Get the location in the document that the breakpoint is in.
                TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
                TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
                EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

                lock (_boundBreakpoints)
                {
                    if (_bpRequestInfo.guidLanguage == DebuggerConstants.guidLanguagePython)
                    {
                        PythonBreakpoint bp = _engine.Process.AddBreakpoint(
                            documentName,
                            (int)(startPosition[0].dwLine + 1),
                            _bpRequestInfo.bpCondition.styleCondition.ToPython(),
                            _bpRequestInfo.bpCondition.bstrCondition,
                            _bpRequestInfo.bpPassCount.stylePassCount.ToPython(),
                            (int)_bpRequestInfo.bpPassCount.dwPassCount);

                        AD7BreakpointResolution breakpointResolution = new AD7BreakpointResolution(_engine, bp, GetDocumentContext(bp));
                        AD7BoundBreakpoint      boundBreakpoint      = new AD7BoundBreakpoint(_engine, bp, this, breakpointResolution, _enabled);
                        _boundBreakpoints.Add(boundBreakpoint);
                        _bpManager.AddBoundBreakpoint(bp, boundBreakpoint);

                        if (_enabled)
                        {
                            TaskHelpers.RunSynchronouslyOnUIThread(ct => bp.AddAsync(ct));
                        }

                        return(VSConstants.S_OK);
                    }
                    else if (_bpRequestInfo.guidLanguage == DebuggerConstants.guidLanguageDjangoTemplate)
                    {
                        // bind a Django template
                        PythonBreakpoint bp = _engine.Process.AddDjangoBreakpoint(
                            documentName,
                            (int)(startPosition[0].dwLine + 1)
                            );

                        AD7BreakpointResolution breakpointResolution = new AD7BreakpointResolution(_engine, bp, GetDocumentContext(bp));
                        AD7BoundBreakpoint      boundBreakpoint      = new AD7BoundBreakpoint(_engine, bp, this, breakpointResolution, _enabled);
                        _boundBreakpoints.Add(boundBreakpoint);
                        _bpManager.AddBoundBreakpoint(bp, boundBreakpoint);

                        if (_enabled)
                        {
                            TaskHelpers.RunSynchronouslyOnUIThread(ct => bp.AddAsync(ct));
                        }

                        return(VSConstants.S_OK);
                    }
                }
            }

            // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc...
            // The Python engine does not support this.
            // TODO: send an instance of IDebugBreakpointErrorEvent2 to the UI and return a valid instance of IDebugErrorBreakpoint2 from
            // IDebugPendingBreakpoint2::EnumErrorBreakpoints. The debugger will then display information about why the breakpoint did not
            // bind to the user.
            return(VSConstants.S_FALSE);
        }