示例#1
0
        int IDebugPendingBreakpoint2.Bind()
        {
            if (!CanBind())
            {
                // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc...
                // We may want to 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);
            }
            if (_boundBreakpoint != null)
            {
                throw new NotImplementedException(); // multiple bound breakpoints are not supported
            }
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)
                                                  Marshal.GetObjectForIUnknown(_requestInfo.bpLocation.unionmember2);

            string documentName;

            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];

            EngineUtils.RequireOk(docPosition.GetFileName(out documentName));
            EngineUtils.RequireOk(docPosition.GetRange(startPosition, endPosition));

            var resolution = _manager.ResolveBreakpoint(startPosition[0]);

            _boundBreakpoint = new BoundBreakpoint(_backend, this, resolution);
            _boundBreakpoint.CompleteBind();

            _callbacks.OnBreakpointBound(_boundBreakpoint);

            return(VSConstants.S_OK);
        }
示例#2
0
        public int Bind()
        {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(m_bpRequestInfo.bpLocation.unionmember2));

            string filename;

            docPosition.GetFileName(out filename);

            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

            Command bpCommand = new BreakpointCommand(Path.GetFileName(filename), (int)startPosition[0].dwLine + 1);

            m_engine.EnqueueCommand(bpCommand);

            AD7DocumentContext docContext = new AD7DocumentContext(filename, startPosition[0], endPosition[0]);

            AD7BreakpointResolution breakpointResolution = new AD7BreakpointResolution(this.m_engine, docContext);
            AD7BoundBreakpoint      boundBreakpoint      = new AD7BoundBreakpoint(this.m_engine, this, breakpointResolution);

            string fileandline = Path.GetFileName(filename) + ((int)startPosition[0].dwLine + 1).ToString();

            m_bpManager.StoreBoundBreakpoint(fileandline, boundBreakpoint);

            return(VSConstants.S_OK);
        }
示例#3
0
        public int EnumCodeContexts(
            IDebugDocumentPosition2 docPos, out IEnumDebugCodeContexts2 contextsEnum)
        {
            contextsEnum = null;
            var startPositions = new TEXT_POSITION[1];
            var result         = docPos.GetRange(startPositions, null);

            if (result != VSConstants.S_OK)
            {
                Trace.WriteLine("Error: Unable to retrieve starting position.");
                return(result);
            }
            string fileName;

            docPos.GetFileName(out fileName);
            var codeContexts = new List <IDebugCodeContext2>();

            // TODO: Find a less hacky way of doing this
            var tempBreakpoint = _lldbTarget.BreakpointCreateByLocation(fileName,
                                                                        startPositions[0].dwLine + 1);

            if (tempBreakpoint == null)
            {
                Trace.WriteLine("Error: Failed to set temporary breakpoint used to map document " +
                                "position to code contexts.");
                return(VSConstants.E_FAIL);
            }
            try
            {
                var numLocations = tempBreakpoint.GetNumLocations();
                for (uint i = 0; i < numLocations; ++i)
                {
                    var location = tempBreakpoint.GetLocationAtIndex(i);
                    var address  = location.GetAddress();
                    if (address != null)
                    {
                        var codeContext = _codeContextFactory.Create(
                            address.GetLoadAddress(_lldbTarget),
                            address.GetFunction().GetName(),
                            _documentContextFactory.Create(address.GetLineEntry()),
                            Guid.Empty);
                        codeContexts.Add(codeContext);
                    }
                    else
                    {
                        Trace.WriteLine("Warning: Failed to obtain address for code context " +
                                        "from temporary breakpoint location. Code context skipped.");
                    }
                }
            }
            finally
            {
                _lldbTarget.BreakpointDelete(tempBreakpoint.GetId());
                tempBreakpoint = null;
            }

            contextsEnum = _codeContextEnumFactory.Create(codeContexts);
            return(VSConstants.S_OK);
        }
示例#4
0
        private TEXT_POSITION GetTextPosition()
        {
            var startPosition = new TEXT_POSITION[1];
            var endPosition   = new TEXT_POSITION[1];

            ErrorHandler.ThrowOnFailure(_documentInfo.GetRange(startPosition, endPosition));
            return(startPosition[0]);
        }
示例#5
0
        internal async Task BindAsync()
        {
            if (CanBind())
            {
                string          documentName  = null;
                TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
                TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
                string          condition     = null;

                lock (_boundBreakpoints)
                {
                    if (_bp != null)   // already bound
                    {
                        Debug.Fail("Breakpoint already bound");
                        return;
                    }
                    IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);

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

                    // Get the location in the document that the breakpoint is in.
                    EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));
                    if ((_bpRequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_CONDITION) != 0 &&
                        _bpRequestInfo.bpCondition.styleCondition == enum_BP_COND_STYLE.BP_COND_WHEN_TRUE)
                    {
                        condition = _bpRequestInfo.bpCondition.bstrCondition;
                    }
                }

                // Bind all breakpoints that match this source and line number.
                PendingBreakpoint.BindResult bindResult = await PendingBreakpoint.Bind(documentName, startPosition[0].dwLine + 1, startPosition[0].dwColumn, _engine.DebuggedProcess, condition, this);

                lock (_boundBreakpoints)
                {
                    if (bindResult.PendingBreakpoint != null)
                    {
                        _bp = bindResult.PendingBreakpoint;    // an MI breakpoint object exists: TODO: lock?
                    }
                    if (bindResult.BoundBreakpoints == null || bindResult.BoundBreakpoints.Count == 0)
                    {
                        _BPError = new AD7ErrorBreakpoint(this, bindResult.ErrorMessage);
                        _engine.Callback.OnBreakpointError(_BPError);
                    }
                    else
                    {
                        Debug.Assert(_bp != null);
                        foreach (BoundBreakpoint bp in bindResult.BoundBreakpoints)
                        {
                            AddBoundBreakpoint(bp);
                        }
                    }
                }
            }
        }
        // Binds this pending breakpoint to one or more code locations.
        int IDebugPendingBreakpoint2.Bind()
        {
            try
            {
                if (CanBind())
                {
                    IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(m_bpRequestInfo.bpLocation.unionmember2));

                    // Get the name of the document that the breakpoint was put in
                    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));


                    // Ask the symbol engine to find all addresses in all modules with symbols that match this source and line number.
                    uint[] addresses = m_engine.DebuggedProcess.GetAddressesForSourceLocation(null,
                                                                                              documentName,
                                                                                              startPosition[0].dwLine + 1,
                                                                                              startPosition[0].dwColumn);
                    lock (m_boundBreakpoints)
                    {
                        foreach (uint addr in addresses)
                        {
                            AD7BreakpointResolution breakpointResolution = new AD7BreakpointResolution(m_engine, addr, GetDocumentContext(addr));
                            AD7BoundBreakpoint      boundBreakpoint      = new AD7BoundBreakpoint(m_engine, addr, this, breakpointResolution);
                            m_boundBreakpoints.Add(boundBreakpoint);
                            m_engine.DebuggedProcess.SetBreakpoint(addr, boundBreakpoint);
                            ((IDebugBoundBreakpoint2)boundBreakpoint).Enable(m_enabled ? 1 : 0);
                        }
                    }

                    return(EngineConstants.S_OK);
                }
                else
                {
                    // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc...
                    // The sample engine does not support this, but a real world engine will want to 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(EngineConstants.S_FALSE);
                }
            }
            catch (ComponentException e)
            {
                return(e.HRESULT);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
示例#7
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            string filename;

            pDocPos.GetFileName(out filename);
            TEXT_POSITION[] beginning = new TEXT_POSITION[1], end = new TEXT_POSITION[1];

            pDocPos.GetRange(beginning, end);

            ppEnum = new AD7CodeContextEnum(new[] { new AD7MemoryAddress(this, filename, (uint)beginning[0].dwLine) });
            return(VSConstants.S_OK);
        }
示例#8
0
        public string GetLocationInfo(IDebugDocumentPosition2 docPosition, out TEXT_POSITION[] startPosition, out TEXT_POSITION[] endPosition)
        {
            string documentName;

            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            startPosition = new TEXT_POSITION[1];
            endPosition   = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

            return(documentName);
        }
 public static TextSpan GetRange(this IDebugDocumentPosition2 documentPosition)
 {
     Contract.Requires <ArgumentNullException>(documentPosition != null, "documentPosition");
     TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
     TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
     ErrorHandler.ThrowOnFailure(documentPosition.GetRange(startPosition, endPosition));
     return(new TextSpan()
     {
         iStartLine = (int)startPosition[0].dwLine,
         iStartIndex = (int)startPosition[0].dwColumn,
         iEndLine = (int)endPosition[0].dwLine,
         iEndIndex = (int)endPosition[0].dwColumn
     });
 }
示例#10
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));
        }
示例#11
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file
        // location.
        public AD7DocumentContext GetDocumentContext(uint address)
        {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(mBpRequestInfo.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(mEngine, address);

            return(new AD7DocumentContext(documentName, startPosition[0], startPosition[0], codeContext));
        }
示例#12
0
        private void Create(IDebugDocumentPosition2 docPosition)
        {
            string path;

            TEXT_POSITION[] tstart = new TEXT_POSITION[1];
            TEXT_POSITION[] tend   = new TEXT_POSITION[1];

            docPosition.GetFileName(out path);
            docPosition.GetRange(tstart, tend);

            FilePath    = path;
            StartLine   = (int)tstart[0].dwLine;
            StartColumn = (int)tstart[0].dwColumn;
            EndLine     = (int)tend[0].dwLine;
            EndColumn   = (int)tend[0].dwColumn;
        }
示例#13
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file
        // location.
        public AD7DocumentContext GetDocumentContext(ulong address, string functionName)
        {
            IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_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, address, functionName);

            return(new AD7DocumentContext(new MITextPosition(documentName, startPosition[0], startPosition[0]), codeContext));
        }
        /// <summary>
        /// Retrieves a list of the code contexts for a given position in a source file.
        /// </summary>
        /// <param name="pDocPos">An IDebugDocumentPosition2 object representing an abstract position in a source file known to the IDE.</param>
        /// <param name="ppEnum">Returns an IEnumDebugCodeContexts2 object that contains a list of the code contexts.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// This method allows the session debug manager (SDM) or IDE to map a source file position into a code
        /// position. More than one code context is returned if the source generates multiple blocks of code (for
        /// example, C++ templates).
        /// </remarks>
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            if (pDocPos == null)
            {
                throw new ArgumentNullException("pDocPos");
            }

            string fileName   = pDocPos.GetFileName();
            int    lineNumber = pDocPos.GetRange().iStartLine + 1;

            List <IDebugCodeContext2>      codeContexts = new List <IDebugCodeContext2>();
            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)
                    {
                        codeContexts.Add(new JavaDebugCodeContext(this, bindLocation));
                    }
                }
            }

            if (codeContexts.Count == 0)
            {
                ppEnum = null;
                return(VSConstants.E_FAIL);
            }

            ppEnum = new EnumDebugCodeContexts(codeContexts);
            return(VSConstants.S_OK);
        }
示例#15
0
        int IDebugProgram2.EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            ThrowIfDisposed();

            string fileName;

            Marshal.ThrowExceptionForHR(pDocPos.GetFileName(out fileName));

            var start = new TEXT_POSITION[1];
            var end   = new TEXT_POSITION[1];

            Marshal.ThrowExceptionForHR(pDocPos.GetRange(start, end));

            var addr = new AD7MemoryAddress(this, fileName, (int)start[0].dwLine);

            ppEnum = new AD7CodeContextEnum(new[] { addr });
            return(VSConstants.S_OK);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            //
            // Enumerates the code contexts for a given position in a source file.
            //

            LoggingUtils.PrintFunction();

            try
            {
                string fileName;

                TEXT_POSITION [] startPos = new TEXT_POSITION [1];

                TEXT_POSITION [] endPos = new TEXT_POSITION [1];

                LoggingUtils.RequireOk(pDocPos.GetFileName(out fileName));

                LoggingUtils.RequireOk(pDocPos.GetRange(startPos, endPos));

                string location = string.Format("\"{0}:{1}\"", fileName, startPos [0].dwLine + 1);

                DebuggeeCodeContext codeContext = m_debugger.GetCodeContextForLocation(location);

                if (codeContext == null)
                {
                    throw new InvalidOperationException("Failed evaluating code-context for location.");
                }

                DebuggeeCodeContext [] codeContexts = new DebuggeeCodeContext [] { codeContext };

                ppEnum = new DebuggeeCodeContext.Enumerator(codeContexts);

                return(Constants.S_OK);
            }
            catch (Exception e)
            {
                LoggingUtils.HandleException(e);

                ppEnum = null;

                return(Constants.E_FAIL);
            }
        }
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public int EnumCodeContexts (IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
    {
      // 
      // Enumerates the code contexts for a given position in a source file.
      // 

      LoggingUtils.PrintFunction ();

      try
      {
        string fileName;

        TEXT_POSITION [] startPos = new TEXT_POSITION [1];

        TEXT_POSITION [] endPos = new TEXT_POSITION [1];

        LoggingUtils.RequireOk (pDocPos.GetFileName (out fileName));

        LoggingUtils.RequireOk (pDocPos.GetRange (startPos, endPos));

        DebuggeeDocumentContext documentContext = new DebuggeeDocumentContext (m_debugger.Engine, fileName, startPos [0], endPos [0]);

        CLangDebuggeeCodeContext codeContext = CLangDebuggeeCodeContext.GetCodeContextForDocumentContext (m_debugger, documentContext);

        if (codeContext == null)
        {
          throw new InvalidOperationException ("Failed evaluating code-context for location.");
        }

        CLangDebuggeeCodeContext [] codeContexts = new CLangDebuggeeCodeContext [] { codeContext };

        ppEnum = new DebuggeeCodeContext.Enumerator (codeContexts);

        return Constants.S_OK;
      }
      catch (Exception e)
      {
        LoggingUtils.HandleException (e);

        ppEnum = null;

        return Constants.E_FAIL;
      }
    }
示例#18
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 docPosition, out IEnumDebugCodeContexts2 ppEnum)
        {
            string documentName;

            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            // Get the location in the document
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));
            List <IDebugCodeContext2> codeContexts = new List <IDebugCodeContext2>();

            List <ulong> addresses = null;
            uint         line      = startPosition[0].dwLine + 1;

            _debuggedProcess.WorkerThread.RunOperation(async() =>
            {
                addresses = await DebuggedProcess.StartAddressesForLine(documentName, line);
            });

            if (addresses != null && addresses.Count > 0)
            {
                foreach (var a in addresses)
                {
                    var           codeCxt = new AD7MemoryAddress(this, a, null);
                    TEXT_POSITION pos;
                    pos.dwLine   = line;
                    pos.dwColumn = 0;
                    MITextPosition textPosition = new MITextPosition(documentName, pos, pos);
                    codeCxt.SetDocumentContext(new AD7DocumentContext(textPosition, codeCxt, this.DebuggedProcess));
                    codeContexts.Add(codeCxt);
                }
                if (codeContexts.Count > 0)
                {
                    ppEnum = new AD7CodeContextEnum(codeContexts.ToArray());
                    return(Constants.S_OK);
                }
            }
            ppEnum = null;
            return(Constants.E_FAIL);
        }
示例#19
0
        private int FindBreakpointLine()
        {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(_bpRequestInfo.bpLocation.unionmember2));

            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition   = new TEXT_POSITION[1];
            docPosition.GetRange(startPosition, endPosition);
            _lineNumber    = startPosition[0].dwLine + 1;
            _beginPosition = startPosition[0];
            _endPosition   = endPosition[0];
            string fileName;

            docPosition.GetFileName(out fileName);
            if (fileName != _node.FileName)
            {
                return(VSConstants.E_FAIL);
            }
            else
            {
                return(VSConstants.S_OK);
            }
        }
示例#20
0
        // Get the document context for this pending breakpoint. A document context is a abstract representation of a source file
        // location.
        public AD7DocumentContext GetDocumentContext(ulong address, string functionName)
        {
            if ((enum_BP_LOCATION_TYPE)_bpRequestInfo.bpLocation.bpLocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE)
            {
                IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_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, address, functionName);

                return(new AD7DocumentContext(new MITextPosition(documentName, startPosition[0], startPosition[0]), codeContext, _engine.DebuggedProcess));
            }
            else
            {
                return(null);
            }
        }
示例#21
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
                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));

                lock (_boundBreakpoints) {
                    var bp = _engine.Process.AddBreakPoint(documentName, (int)(startPosition[0].dwLine + 1), _bpRequestInfo.bpCondition.bstrCondition, _bpRequestInfo.bpCondition.styleCondition == enum_BP_COND_STYLE.BP_COND_WHEN_TRUE ? false : true);
                    AD7BreakpointResolution breakpointResolution = new AD7BreakpointResolution(_engine, bp, GetDocumentContext(bp));
                    AD7BoundBreakpoint      boundBreakpoint      = new AD7BoundBreakpoint(_engine, bp, this, breakpointResolution);
                    _boundBreakpoints.Add(boundBreakpoint);
                    _bpManager.AddBoundBreakpoint(bp, boundBreakpoint);

                    if (_enabled)
                    {
                        bp.Add();
                    }
                }

                return(VSConstants.S_OK);
            }
            else
            {
                // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc...
                // The sample engine does not support this, but a real world engine will want to 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);
            }
        }
示例#22
0
        /// <summary>
        /// Retrieves a list of the code contexts for a given position in a source file.
        /// </summary>
        /// <param name="pDocPos">An IDebugDocumentPosition2 object representing an abstract position in a source file known to the IDE.</param>
        /// <param name="ppEnum">Returns an IEnumDebugCodeContexts2 object that contains a list of the code contexts.</param>
        /// <returns>If successful, returns S_OK; otherwise, returns an error code.</returns>
        /// <remarks>
        /// This method allows the session debug manager (SDM) or IDE to map a source file position into a code
        /// position. More than one code context is returned if the source generates multiple blocks of code (for
        /// example, C++ templates).
        /// </remarks>
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            if (pDocPos == null)
                throw new ArgumentNullException("pDocPos");

            string fileName = pDocPos.GetFileName();
            int lineNumber = pDocPos.GetRange().iStartLine + 1;

            List<IDebugCodeContext2> codeContexts = new List<IDebugCodeContext2>();
            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)
                        codeContexts.Add(new JavaDebugCodeContext(this, bindLocation));
                }
            }

            if (codeContexts.Count == 0)
            {
                ppEnum = null;
                return VSConstants.E_FAIL;
            }

            ppEnum = new EnumDebugCodeContexts(codeContexts);
            return VSConstants.S_OK;
        }
示例#23
0
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "IDebugProgram2.EnumCodeContexts");

            ppEnum = null;

            string fileName;
            if (ErrorHandler.Failed(pDocPos.GetFileName(out fileName)))
                return VSConstants.E_INVALIDARG;
            var beginPosition = new TEXT_POSITION[1];
            var endPosition = new TEXT_POSITION[1];
            if (ErrorHandler.Failed(pDocPos.GetRange(beginPosition, endPosition)))
                return VSConstants.E_INVALIDARG;

            // Search matching document
            var doc = MapFile.FindDocument(fileName);
            if (doc == null)
                throw new ArgumentException("Unknown document " + fileName);

            DLog.Debug(DContext.VSDebuggerComCall, "document {0} positions {1}/{2} - {3}/{4}", fileName, (int)beginPosition[0].dwLine, (int)beginPosition[0].dwColumn, (int)endPosition[0].dwLine, (int)endPosition[0].dwColumn);

            // Search positions
            var documentPositions = doc.FindAll((int)beginPosition[0].dwLine + 1, (int)beginPosition[0].dwColumn + 1, (int)endPosition[0].dwLine + 1, (int)endPosition[0].dwColumn + 1)
                                       .ToList();

            if (documentPositions.Count == 0)
            {
                DLog.Debug(DContext.VSDebuggerComCall, "found nothing.");
                return VSConstants.E_FAIL;
            }

            List<DebugCodeContext> list = new List<DebugCodeContext>();

            foreach (var pos in documentPositions)
            {
                var loc = GetLocationFromPositionAsync(pos).Await(VmTimeout);
                if (loc == null)
                    continue;

                // only find one location per method.
                if(list.Any(c=>c.Location.IsSameMethod(loc.Location)))
                    continue;

                var ctx = new DebugCodeContext(loc.Location);
                ctx.DocumentContext = new DebugDocumentContext(loc, ctx);

                DLog.Debug(DContext.VSDebuggerComCall, "found {0}: {1}", loc.Description, loc.Location);
                list.Add(ctx);
            }

            DLog.Debug(DContext.VSDebuggerComCall, "done.");
            if (list.Count == 0)
                return VSConstants.E_FAIL;

            ppEnum = new CodeContextEnum(list);
            return VSConstants.S_OK;
        }
示例#24
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            if (_mixedMode) {
                ppEnum = null;
                return VSConstants.E_NOTIMPL;
            }

            string filename;
            pDocPos.GetFileName(out filename);
            TEXT_POSITION[] beginning = new TEXT_POSITION[1], end = new TEXT_POSITION[1];

            pDocPos.GetRange(beginning, end);

            ppEnum = new AD7CodeContextEnum(new[] { new AD7MemoryAddress(this, filename, (uint)beginning[0].dwLine) });
            return VSConstants.S_OK;
        }
示例#25
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
                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));

                lock (_boundBreakpoints) {
                    if (_bpRequestInfo.guidLanguage == DebuggerConstants.guidLanguagePython)
                    {
                        var 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)
                        {
                            bp.Add();
                        }

                        return(VSConstants.S_OK);
                    }
                    else if (_bpRequestInfo.guidLanguage == DebuggerConstants.guidLanguageDjangoTemplate)
                    {
                        // bind a Django template
                        var 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)
                        {
                            bp.Add();
                        }

                        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);
        }
示例#26
0
        internal async Task BindAsync()
        {
            if (CanBind())
            {
                string                 documentName  = null;
                string                 functionName  = null;
                TEXT_POSITION[]        startPosition = new TEXT_POSITION[1];
                TEXT_POSITION[]        endPosition   = new TEXT_POSITION[1];
                string                 condition     = null;
                string                 address       = null;
                ulong                  codeAddress   = 0;
                uint                   size          = 0;
                IEnumerable <Checksum> checksums     = null;

                lock (_boundBreakpoints)
                {
                    if (_bp != null)   // already bound
                    {
                        Debug.Fail("Breakpoint already bound");
                        return;
                    }
                    if ((_bpRequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_CONDITION) != 0 &&
                        _bpRequestInfo.bpCondition.styleCondition == enum_BP_COND_STYLE.BP_COND_WHEN_TRUE)
                    {
                        condition = _bpRequestInfo.bpCondition.bstrCondition;
                    }
                    if ((_bpRequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_BPLOCATION) != 0)
                    {
                        switch ((enum_BP_LOCATION_TYPE)_bpRequestInfo.bpLocation.bpLocationType)
                        {
                        case enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET:
                        {
                            IDebugFunctionPosition2 functionPosition = HostMarshal.GetDebugFunctionPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);
                            EngineUtils.CheckOk(functionPosition.GetFunctionName(out functionName));
                            break;
                        }

                        case enum_BP_LOCATION_TYPE.BPLT_CODE_CONTEXT:
                        {
                            IDebugCodeContext2 codePosition = HostMarshal.GetDebugCodeContextForIntPtr(_bpRequestInfo.bpLocation.unionmember1);
                            if (!(codePosition is AD7MemoryAddress))
                            {
                                goto default;           // context is not from this engine
                            }
                            codeAddress = ((AD7MemoryAddress)codePosition).Address;
                            break;
                        }

                        case enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE:
                        {
                            IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);

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

                            // Get the location in the document that the breakpoint is in.
                            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));

                            // Get the document checksum
                            // TODO: This and all other AD7 interface calls need to be moved so that they are only
                            // executed from the main thread.
                            // Github issue: https://github.com/Microsoft/MIEngine/issues/350
                            if (_engine.DebuggedProcess.MICommandFactory.SupportsBreakpointChecksums())
                            {
                                try
                                {
                                    checksums = GetSHA1Checksums();
                                }
                                catch (Exception)
                                {
                                    // If we fail to get a checksum there's nothing else we can do
                                }
                            }

                            break;
                        }

                        case enum_BP_LOCATION_TYPE.BPLT_DATA_STRING:
                        {
                            address = HostMarshal.GetDataBreakpointStringForIntPtr(_bpRequestInfo.bpLocation.unionmember3);
                            size    = (uint)_bpRequestInfo.bpLocation.unionmember4;
                            if (condition != null)
                            {
                                goto default;           // mi has no conditions on watchpoints
                            }
                            break;
                        }

                        default:
                        {
                            this.SetError(new AD7ErrorBreakpoint(this, ResourceStrings.UnsupportedBreakpoint), true);
                            return;
                        }
                        }
                    }
                }
                PendingBreakpoint.BindResult bindResult;
                // Bind all breakpoints that match this source and line number.
                if (documentName != null)
                {
                    bindResult = await PendingBreakpoint.Bind(documentName, startPosition[0].dwLine + 1, startPosition[0].dwColumn, _engine.DebuggedProcess, condition, _enabled, checksums, this);
                }
                else if (functionName != null)
                {
                    bindResult = await PendingBreakpoint.Bind(functionName, _engine.DebuggedProcess, condition, _enabled, this);
                }
                else if (codeAddress != 0)
                {
                    bindResult = await PendingBreakpoint.Bind(codeAddress, _engine.DebuggedProcess, condition, _enabled, this);
                }
                else
                {
                    bindResult = await PendingBreakpoint.Bind(address, size, _engine.DebuggedProcess, condition, this);
                }

                lock (_boundBreakpoints)
                {
                    if (bindResult.PendingBreakpoint != null)
                    {
                        _bp = bindResult.PendingBreakpoint;    // an MI breakpoint object exists: TODO: lock?
                    }
                    if (bindResult.BoundBreakpoints == null || bindResult.BoundBreakpoints.Count == 0)
                    {
                        this.SetError(new AD7ErrorBreakpoint(this, bindResult.ErrorMessage), true);
                    }
                    else
                    {
                        Debug.Assert(_bp != null);
                        foreach (BoundBreakpoint bp in bindResult.BoundBreakpoints)
                        {
                            AddBoundBreakpoint(bp);
                        }
                    }
                }
            }
        }
示例#27
0
        // Token: 0x060000CE RID: 206 RVA: 0x00004100 File Offset: 0x00002300
        protected bool DoBind()
        {
            if (this.Request.LocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE)
            {
                if ((this.Request.RequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_BPLOCATION) == 0)
                {
                    this.OnBreakpointError("Breakpoints of this type are not supported.");
                    return(false);
                }
                IDebugDocumentPosition2 debugDocumentPosition = (IDebugDocumentPosition2)Marshal.GetObjectForIUnknown(this.Request.RequestInfo.bpLocation.unionmember2);
                Utils.RequireOk(debugDocumentPosition.GetFileName(out var file));
                TEXT_POSITION[] array  = new TEXT_POSITION[1];
                TEXT_POSITION[] array2 = new TEXT_POSITION[1];
                Utils.RequireOk(debugDocumentPosition.GetRange(array, array2));
                SourceRange    range    = new SourceRange((int)(array[0].dwLine + 1U), (int)(array2[0].dwLine + 1U), (int)(array[0].dwColumn + 1U), (int)(array2[0].dwColumn + 1U));
                SourceLocation location = new SourceLocation(file, (int)(array[0].dwLine + 1U), range);
                if ((this.Request.RequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_PASSCOUNT) != 0)
                {
                    this.HitCount = (int)this.Request.RequestInfo.bpPassCount.dwPassCount;
                    switch (this.Request.RequestInfo.bpPassCount.stylePassCount)
                    {
                    case enum_BP_PASSCOUNT_STYLE.BP_PASSCOUNT_EQUAL:
                        this.HitCountMode = HitCountMode.EqualTo;
                        break;

                    case enum_BP_PASSCOUNT_STYLE.BP_PASSCOUNT_EQUAL_OR_GREATER:
                        this.HitCountMode = HitCountMode.GreaterThanOrEqualTo;
                        break;

                    case enum_BP_PASSCOUNT_STYLE.BP_PASSCOUNT_MOD:
                        this.HitCountMode = HitCountMode.MultipleOf;
                        break;

                    default:
                        this.HitCountMode = HitCountMode.None;
                        break;
                    }
                }
                if ((this.Request.RequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_CONDITION) != 0)
                {
                    this.ConditionExpression     = this.Request.RequestInfo.bpCondition.bstrCondition;
                    this.BreakIfConditionChanges = (this.Request.RequestInfo.bpCondition.styleCondition == enum_BP_COND_STYLE.BP_COND_WHEN_CHANGED);
                }
                this.Handle = this.Engine.BindBreakpoint(this, location);
                if (this.Handle == null)
                {
                    return(false);
                }
                this.Handle.Enabled = this.is_enabled;
                return(true);
            }
            else
            {
                if (this.Request.LocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET)
                {
                    this.OnBreakpointError("Function breakpoints are not supported yet.");
                    return(false);
                }
                this.OnBreakpointError("Breakpoints of this type are not supported.");
                return(false);
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public virtual int EvaluateBreakpointLocation(out DebuggeeDocumentContext documentContext, out DebuggeeCodeContext codeContext, out string location)
        {
            LoggingUtils.PrintFunction();

            documentContext = null;

            codeContext = null;

            location = string.Empty;

            try
            {
                switch (m_breakpointRequestInfo.bpLocation.bpLocationType)
                {
                case (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE:
                {
                    //
                    // Specifies the location type of the breakpoint as a line of source code.
                    //

                    string fileName;

                    IDebugDocumentPosition2 documentPostion = (IDebugDocumentPosition2)Marshal.GetObjectForIUnknown(m_breakpointRequestInfo.bpLocation.unionmember2);

                    LoggingUtils.RequireOk(documentPostion.GetFileName(out fileName));

                    bool fileInCurrentProject = true; // TODO

                    if (File.Exists(fileName) && fileInCurrentProject)
                    {
                        TEXT_POSITION [] startPos = new TEXT_POSITION [1];

                        TEXT_POSITION [] endPos = new TEXT_POSITION [1];

                        LoggingUtils.RequireOk(documentPostion.GetRange(startPos, endPos));

                        documentContext = new DebuggeeDocumentContext(m_breakpointManager.Engine, fileName, startPos [0], endPos [0]);

                        location = string.Format("\"{0}:{1}\"", fileName, startPos [0].dwLine + 1);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    break;
                }

                case (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET:
                {
                    //
                    // Specifies the location type of the breakpoint as a code function offset.
                    //

                    string function = string.Empty;

                    IDebugFunctionPosition2 functionPosition = (IDebugFunctionPosition2)Marshal.GetObjectForIUnknown(m_breakpointRequestInfo.bpLocation.unionmember2);

                    TEXT_POSITION [] textPos = new TEXT_POSITION [1];

                    LoggingUtils.RequireOk(functionPosition.GetFunctionName(out function));

                    LoggingUtils.RequireOk(functionPosition.GetOffset(textPos));

                    if (!string.IsNullOrEmpty(function))
                    {
                        location = function;
                    }

                    break;
                }

                case (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_CONTEXT:
                {
                    //
                    // Specifies the location type of the breakpoint as a code context.
                    //

                    codeContext = ((IDebugCodeContext2)Marshal.GetObjectForIUnknown(m_breakpointRequestInfo.bpLocation.unionmember1)) as DebuggeeCodeContext;

                    if (codeContext != null)
                    {
                        location = codeContext.Address.ToString();
                    }

                    break;
                }

                case (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_STRING:
                {
                    //
                    // Specifies the location type of the breakpoint as a code string.
                    //

                    throw new NotImplementedException();
                }

                case (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_ADDRESS:
                {
                    //
                    // Specifies the location type of the breakpoint as a code address.
                    //

                    string address = Marshal.PtrToStringBSTR(m_breakpointRequestInfo.bpLocation.unionmember4);

                    if (!string.IsNullOrEmpty(address))
                    {
                        location = address;
                    }

                    break;
                }

                case (uint)enum_BP_LOCATION_TYPE.BPLT_DATA_STRING:
                {
                    //
                    // Specifies the location type of the breakpoint as a data string.
                    //

                    string dataExpression = Marshal.PtrToStringBSTR(m_breakpointRequestInfo.bpLocation.unionmember3);

                    if (!string.IsNullOrEmpty(dataExpression))
                    {
                        location = dataExpression;
                    }

                    break;
                }

                default:
                {
                    break;
                }
                }

                return(Constants.S_OK);
            }
            catch (NotImplementedException e)
            {
                LoggingUtils.HandleException(e);

                return(Constants.E_NOTIMPL);
            }
            catch (Exception e)
            {
                LoggingUtils.HandleException(e);

                return(Constants.E_FAIL);
            }
        }
示例#29
0
        /// <summary>
        /// AD7BoundBreakpoint constructor for file/line breaks.
        /// </summary>
        /// <param name="engine"> AD7 Engine. </param>
        /// <param name="bpReqInfo"> Contains the information required to implement a breakpoint. </param>
        /// <param name="pendingBreakpoint"> Associated pending breakpoint. </param>
        public AD7BoundBreakpoint(AD7Engine engine, BP_REQUEST_INFO bpReqInfo, AD7PendingBreakpoint pendingBreakpoint)
        {
            if (bpReqInfo.bpLocation.bpLocationType == (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE)
            {
                string documentName;

                // Get Decument Position and File Name
                IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)(Marshal.GetObjectForIUnknown(bpReqInfo.bpLocation.unionmember2));
                docPosition.GetFileName(out documentName);

                // Need to shorten the path we send to GDB.
                StringBuilder shortPath = new StringBuilder(1024);
                GetShortPathName(documentName, shortPath, shortPath.Capacity);

                // 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];
                docPosition.GetRange(startPosition, endPosition);

                m_engine         = engine;
                m_bpLocationType = (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE;
                m_filename       = shortPath.ToString();
                m_line           = startPosition[0].dwLine + 1;

                m_pendingBreakpoint = pendingBreakpoint;
                m_enabled           = true;
                m_deleted           = false;
                m_hitCount          = 0;
                m_remoteID          = m_engine.BPMgr.RemoteAdd(this);
            }
            else if (bpReqInfo.bpLocation.bpLocationType == (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET)
            {
                string func;

                IDebugFunctionPosition2 funcPosition = (IDebugFunctionPosition2)(Marshal.GetObjectForIUnknown(bpReqInfo.bpLocation.unionmember2));
                funcPosition.GetFunctionName(out func);

                m_engine            = engine;
                m_func              = func;
                m_enabled           = true;
                m_deleted           = false;
                m_hitCount          = 0;
                m_bpLocationType    = (uint)enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET;
                m_pendingBreakpoint = pendingBreakpoint;
                m_remoteID          = m_engine.BPMgr.RemoteAdd(this);
            }

//            if ((m_remoteID == 0) && (VSNDK.AddIn.VSNDKAddIn.isDebugEngineRunning == false))
            if (m_remoteID == 0)
            {
                return;
            }

            // Set the hit count and condition
            if (bpReqInfo.bpPassCount.stylePassCount != enum_BP_PASSCOUNT_STYLE.BP_PASSCOUNT_NONE)
            {
                SetPassCount(bpReqInfo.bpPassCount);
            }
            if (bpReqInfo.bpCondition.styleCondition != enum_BP_COND_STYLE.BP_COND_NONE)
            {
                SetCondition(bpReqInfo.bpCondition);
            }

            // Get the Line Position sent back from GDB
            TEXT_POSITION tpos = new TEXT_POSITION();

            tpos.dwLine = m_GDB_linePos - 1;

            uint xAddress = UInt32.Parse(m_GDB_Address.Substring(2), System.Globalization.NumberStyles.HexNumber);

            AD7MemoryAddress   codeContext     = new AD7MemoryAddress(m_engine, xAddress);
            AD7DocumentContext documentContext = new AD7DocumentContext(m_GDB_filename, tpos, tpos, codeContext);

            m_breakpointResolution = new AD7BreakpointResolution(m_engine, xAddress, documentContext);

            m_engine.Callback.OnBreakpointBound(this, 0);
        }
示例#30
0
        int IDebugProgram2.EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum) {
            ThrowIfDisposed();

            string fileName;
            Marshal.ThrowExceptionForHR(pDocPos.GetFileName(out fileName));

            var start = new TEXT_POSITION[1];
            var end = new TEXT_POSITION[1];
            Marshal.ThrowExceptionForHR(pDocPos.GetRange(start, end));

            var addr = new AD7MemoryAddress(this, fileName, (int)start[0].dwLine);
            ppEnum = new AD7CodeContextEnum(new[] { addr });
            return VSConstants.S_OK;
        }
示例#31
0
        public int Bind()
        {
            if (_deleted)
            {
                return(AD7Constants.E_BP_DELETED);
            }

            switch ((enum_BP_LOCATION_TYPE)_requestInfo.bpLocation.bpLocationType)
            {
            case enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE:
                IDebugDocumentPosition2 documentPosition =
                    _marshal.GetDocumentPositionFromIntPtr(_requestInfo.bpLocation.unionmember2);
                if (documentPosition.GetFileName(out string fileName) != 0)
                {
                    SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noSourceFilename);
                    return(VSConstants.S_FALSE);
                }

                TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
                // TODO: Check if we need the end position or not.  This might
                // matter when setting a breakpoint on a comment.  It's possible LLDB will just
                // handle this for us and we don't need to worry about the end position.
                if (documentPosition.GetRange(startPosition, null) != VSConstants.S_OK)
                {
                    SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noSourceLineNumber);
                    return(VSConstants.S_FALSE);
                }

                // Visual Studio uses a zero based index for line numbers, where LLDB uses a one
                // based index for line numbers.  We need to add one to the line number here to
                // convert visual studio line numbers to LLDB line numbers.
                _lldbBreakpoint =
                    _target.BreakpointCreateByLocation(fileName, startPosition[0].dwLine + 1);
                break;

            case enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET:
                IDebugFunctionPosition2 functionPosition =
                    _marshal.GetFunctionPositionFromIntPtr(_requestInfo.bpLocation.unionmember2);
                uint offset = 0;
                if (functionPosition.GetFunctionName(out string functionName) != 0)
                {
                    SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noFunctionName);
                    return(VSConstants.S_FALSE);
                }
                MatchCollection matches = _funcOffsetRegex.Matches(functionName);
                if (matches.Count == 1)
                {
                    functionName = matches[0].Groups["name"].Value;
                    string offsetString = matches[0].Groups["offset"].Value;
                    if (!string.IsNullOrWhiteSpace(offsetString))
                    {
                        offset = uint.Parse(offsetString);
                    }
                }

                if (offset > 0)
                {
                    BreakpointErrorPair breakpointErrorPair =
                        _target.CreateFunctionOffsetBreakpoint(functionName, offset);
                    _lldbBreakpoint = breakpointErrorPair.breakpoint;
                    if (_lldbBreakpoint == null)
                    {
                        switch (breakpointErrorPair.error)
                        {
                        case BreakpointError.NoFunctionFound:
                            SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noFunctionFound);
                            break;

                        case BreakpointError.NoFunctionLocation:
                            SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING,
                                     _breakpointLocationNotSet);
                            break;

                        case BreakpointError.PositionNotAvailable:
                            SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING,
                                     _positionNotAvailable);
                            break;

                        default:
                            SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING,
                                     _positionNotAvailable);
                            break;
                        }
                        return(VSConstants.S_FALSE);
                    }
                }
                else
                {
                    _lldbBreakpoint = _target.BreakpointCreateByName(functionName);
                }
                break;

            case enum_BP_LOCATION_TYPE.BPLT_CODE_CONTEXT:
                IDebugCodeContext2 codeContext =
                    _marshal.GetCodeContextFromIntPtr(_requestInfo.bpLocation.unionmember1);
                if (codeContext == null)
                {
                    SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noCodeContext);
                    return(VSConstants.S_FALSE);
                }
                ulong address = codeContext.GetAddress();
                _lldbBreakpoint = _target.BreakpointCreateByAddress(address);
                break;

            case enum_BP_LOCATION_TYPE.BPLT_CODE_ADDRESS:
                string strAddress =
                    _marshal.GetStringFromIntPtr(_requestInfo.bpLocation.unionmember4);
                if (strAddress == null)
                {
                    SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _noCodeAddress);
                    return(VSConstants.S_FALSE);
                }
                ulong address2 = Convert.ToUInt64(strAddress, 16);
                _lldbBreakpoint = _target.BreakpointCreateByAddress(address2);
                break;

            default:
                SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _breakpointNotSupported);
                return(VSConstants.S_FALSE);
            }

            if (_lldbBreakpoint == null)
            {
                SetError(enum_BP_ERROR_TYPE.BPET_GENERAL_WARNING, _breakpointNotSet);
                return(VSConstants.S_FALSE);
            }

            UpdateLocations();
            _breakpointManager.RegisterPendingBreakpoint(Self);

            return(_boundBreakpoints.Count == 0
                ? VSConstants.S_FALSE
                : VSConstants.S_OK);
        }
示例#32
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum) {
            DebugWriteCommand("EnumCodeContexts");

            string filename;
            pDocPos.GetFileName(out filename);
            TEXT_POSITION[] beginning = new TEXT_POSITION[1], end = new TEXT_POSITION[1];

            pDocPos.GetRange(beginning, end);

            ppEnum = new AD7CodeContextEnum(new[] { new AD7MemoryAddress(this, filename, (int)beginning[0].dwLine, (int)beginning[0].dwColumn) });
            return VSConstants.S_OK;
        }
示例#33
0
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            DLog.Debug(DContext.VSDebuggerComCall, "IDebugProgram2.EnumCodeContexts");

            ppEnum = null;

            string fileName;

            if (ErrorHandler.Failed(pDocPos.GetFileName(out fileName)))
            {
                return(VSConstants.E_INVALIDARG);
            }
            var beginPosition = new TEXT_POSITION[1];
            var endPosition   = new TEXT_POSITION[1];

            if (ErrorHandler.Failed(pDocPos.GetRange(beginPosition, endPosition)))
            {
                return(VSConstants.E_INVALIDARG);
            }

            // Search matching document
            var doc = MapFile.FindDocument(fileName);

            if (doc == null)
            {
                throw new ArgumentException("Unknown document " + fileName);
            }

            DLog.Debug(DContext.VSDebuggerComCall, "document {0} positions {1}/{2} - {3}/{4}", fileName, (int)beginPosition[0].dwLine, (int)beginPosition[0].dwColumn, (int)endPosition[0].dwLine, (int)endPosition[0].dwColumn);

            // Search positions
            var documentPositions = doc.FindAll((int)beginPosition[0].dwLine + 1, (int)beginPosition[0].dwColumn + 1, (int)endPosition[0].dwLine + 1, (int)endPosition[0].dwColumn + 1)
                                    .ToList();

            if (documentPositions.Count == 0)
            {
                DLog.Debug(DContext.VSDebuggerComCall, "found nothing.");
                return(VSConstants.E_FAIL);
            }

            List <DebugCodeContext> list = new List <DebugCodeContext>();

            foreach (var pos in documentPositions)
            {
                var loc = GetLocationFromPositionAsync(pos).Await(VmTimeout);
                if (loc == null)
                {
                    continue;
                }

                // only find one location per method.
                if (list.Any(c => c.Location.IsSameMethod(loc.Location)))
                {
                    continue;
                }

                var ctx = new DebugCodeContext(loc.Location);
                ctx.DocumentContext = new DebugDocumentContext(loc, ctx);

                DLog.Debug(DContext.VSDebuggerComCall, "found {0}: {1}", loc.Description, loc.Location);
                list.Add(ctx);
            }

            DLog.Debug(DContext.VSDebuggerComCall, "done.");
            if (list.Count == 0)
            {
                return(VSConstants.E_FAIL);
            }

            ppEnum = new CodeContextEnum(list);
            return(VSConstants.S_OK);
        }
示例#34
0
        // Enumerates the code contexts for a given position in a source file.
        public int EnumCodeContexts(IDebugDocumentPosition2 docPosition, out IEnumDebugCodeContexts2 ppEnum)
        {
            string documentName;
            EngineUtils.CheckOk(docPosition.GetFileName(out documentName));

            // Get the location in the document
            TEXT_POSITION[] startPosition = new TEXT_POSITION[1];
            TEXT_POSITION[] endPosition = new TEXT_POSITION[1];
            EngineUtils.CheckOk(docPosition.GetRange(startPosition, endPosition));
            List<IDebugCodeContext2> codeContexts = new List<IDebugCodeContext2>();

            List<ulong> addresses = null;
            uint line = startPosition[0].dwLine + 1;
            _debuggedProcess.WorkerThread.RunOperation(async () =>
            {
                addresses = await DebuggedProcess.StartAddressesForLine(documentName, line);
            });

            if (addresses != null && addresses.Count > 0)
            {
                foreach (var a in addresses)
                {
                    var codeCxt = new AD7MemoryAddress(this, a, null);
                    TEXT_POSITION pos;
                    pos.dwLine = line;
                    pos.dwColumn = 0;
                    MITextPosition textPosition = new MITextPosition(documentName, pos, pos);
                    codeCxt.SetDocumentContext(new AD7DocumentContext(textPosition, codeCxt, this.DebuggedProcess));
                    codeContexts.Add(codeCxt);
                }
                if (codeContexts.Count > 0)
                {
                    ppEnum = new AD7CodeContextEnum(codeContexts.ToArray());
                    return Constants.S_OK;
                }
            }
            ppEnum = null;
            return Constants.E_FAIL;
        }
示例#35
0
        // Binds this pending breakpoint to one or more code locations.
        int IDebugPendingBreakpoint2.Bind()
        {
            try
            {
                if (CanBind())
                {
                    // Make sure that HostMarshal calls happen on main thread instead of poll thread.
                    lock (_boundBreakpoints)
                    {
                        if (_bp != null)   // already bound
                        {
                            Debug.Fail("Breakpoint already bound");
                            return(Constants.S_FALSE);
                        }
                        if ((_bpRequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_CONDITION) != 0 &&
                            _bpRequestInfo.bpCondition.styleCondition == enum_BP_COND_STYLE.BP_COND_WHEN_TRUE)
                        {
                            _condition = _bpRequestInfo.bpCondition.bstrCondition;
                        }
                        if ((_bpRequestInfo.dwFields & enum_BPREQI_FIELDS.BPREQI_BPLOCATION) != 0)
                        {
                            switch ((enum_BP_LOCATION_TYPE)_bpRequestInfo.bpLocation.bpLocationType)
                            {
                            case enum_BP_LOCATION_TYPE.BPLT_CODE_FUNC_OFFSET:
                                try
                                {
                                    IDebugFunctionPosition2 functionPosition = HostMarshal.GetDebugFunctionPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);
                                    EngineUtils.CheckOk(functionPosition.GetFunctionName(out _functionName));
                                }
                                finally
                                {
                                    HostMarshal.Release(_bpRequestInfo.bpLocation.unionmember2);
                                }
                                break;

                            case enum_BP_LOCATION_TYPE.BPLT_CODE_CONTEXT:
                                try
                                {
                                    IDebugCodeContext2 codePosition = HostMarshal.GetDebugCodeContextForIntPtr(_bpRequestInfo.bpLocation.unionmember1);
                                    if (!(codePosition is AD7MemoryAddress))
                                    {
                                        goto default;       // context is not from this engine
                                    }
                                    _codeAddress = ((AD7MemoryAddress)codePosition).Address;
                                }
                                finally
                                {
                                    HostMarshal.Release(_bpRequestInfo.bpLocation.unionmember1);
                                }
                                break;

                            case enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE:
                                try
                                {
                                    IDebugDocumentPosition2 docPosition = HostMarshal.GetDocumentPositionForIntPtr(_bpRequestInfo.bpLocation.unionmember2);
                                    // Get the name of the document that the breakpoint was put in
                                    EngineUtils.CheckOk(docPosition.GetFileName(out _documentName));

                                    // Get the location in the document that the breakpoint is in.
                                    EngineUtils.CheckOk(docPosition.GetRange(_startPosition, _endPosition));
                                }
                                finally
                                {
                                    HostMarshal.Release(_bpRequestInfo.bpLocation.unionmember2);
                                }

                                // Get the document checksum
                                if (_engine.DebuggedProcess.MICommandFactory.SupportsBreakpointChecksums())
                                {
                                    try
                                    {
                                        _checksums = GetSHA1Checksums();
                                    }
                                    catch (Exception)
                                    {
                                        // If we fail to get a checksum there's nothing else we can do
                                    }
                                }

                                break;

                            case enum_BP_LOCATION_TYPE.BPLT_DATA_STRING:
                                _address = HostMarshal.GetDataBreakpointStringForIntPtr(_bpRequestInfo.bpLocation.unionmember3);
                                _size    = (uint)_bpRequestInfo.bpLocation.unionmember4;
                                if (_condition != null)
                                {
                                    goto default;       // mi has no conditions on watchpoints
                                }
                                break;

                            default:
                                this.SetError(new AD7ErrorBreakpoint(this, ResourceStrings.UnsupportedBreakpoint), true);
                                return(Constants.S_FALSE);
                            }
                        }
                    }

                    Task bindTask = null;
                    _engine.DebuggedProcess.WorkerThread.RunOperation(() =>
                    {
                        bindTask = _engine.DebuggedProcess.AddInternalBreakAction(this.BindAsync);
                    });

                    bindTask.Wait(_engine.GetBPLongBindTimeout());
                    if (!bindTask.IsCompleted)
                    {
                        //send a low severity warning bp. This will allow the UI to respond quickly, and if the mi debugger doesn't end up binding, this warning will get
                        //replaced by the real mi debugger error text
                        this.SetError(new AD7ErrorBreakpoint(this, ResourceStrings.LongBind, enum_BP_ERROR_TYPE.BPET_SEV_LOW | enum_BP_ERROR_TYPE.BPET_TYPE_WARNING), true);
                        return(Constants.S_FALSE);
                    }
                    else
                    {
                        return(Constants.S_OK);
                    }
                }
                else
                {
                    // The breakpoint could not be bound. This may occur for many reasons such as an invalid location, an invalid expression, etc...
                    _engine.Callback.OnBreakpointError(_BPError);
                    return(Constants.S_FALSE);
                }
            }
            catch (MIException e)
            {
                return(e.HResult);
            }
            catch (AggregateException e)
            {
                if (e.GetBaseException() is InvalidCoreDumpOperationException)
                {
                    return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
                }
                else
                {
                    return(EngineUtils.UnexpectedException(e));
                }
            }
            catch (InvalidCoreDumpOperationException)
            {
                return(AD7_HRESULT.E_CRASHDUMP_UNSUPPORTED);
            }
            catch (Exception e)
            {
                return(EngineUtils.UnexpectedException(e));
            }
        }
 public int GetSourceRange(TEXT_POSITION[] pBegPosition, TEXT_POSITION[] pEndPosition)
 {
     return(_documentPosition.GetRange(pBegPosition, pEndPosition));
 }