public BreakpointLocationCodeFileLine(BP_LOCATION location, bool releaseComObjects)
        {
            Contract.Requires <ArgumentException>((enum_BP_LOCATION_TYPE)location.bpLocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE);

            try
            {
                if (location.unionmember1 != IntPtr.Zero)
                {
                    _context = Marshal.PtrToStringBSTR(location.unionmember1);
                }
                if (location.unionmember2 != IntPtr.Zero)
                {
                    _documentPosition = Marshal.GetObjectForIUnknown(location.unionmember2) as IDebugDocumentPosition2;
                }
            }
            finally
            {
                if (releaseComObjects)
                {
                    if (location.unionmember1 != IntPtr.Zero)
                    {
                        Marshal.FreeBSTR(location.unionmember1);
                    }
                    if (location.unionmember2 != IntPtr.Zero)
                    {
                        Marshal.Release(location.unionmember2);
                    }
                }
            }
        }
        public TextPositionInfo(BP_REQUEST_INFO reqInfo)
        {
            IDebugDocumentPosition2 docPosition = (IDebugDocumentPosition2)Marshal.GetObjectForIUnknown(reqInfo.bpLocation.unionmember2);

            Create(docPosition);
            Marshal.ReleaseComObject(docPosition);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
0
        public Breakpoint(Program program, IDebugBreakpointRequest2 request, IDebugDocumentPosition2 documentInfo)
        {
            _program      = program;
            _request      = request;
            _documentInfo = documentInfo;

            ErrorHandler.ThrowOnFailure(_documentInfo.GetFileName(out _sourcePath));
        }
        public static IDebugDocument2 GetDocument(this IDebugDocumentPosition2 documentPosition)
        {
            Contract.Requires <ArgumentNullException>(documentPosition != null, "documentPosition");

            IDebugDocument2 document;

            ErrorHandler.ThrowOnFailure(documentPosition.GetDocument(out document));
            return(document);
        }
        public static string GetFileName(this IDebugDocumentPosition2 documentPosition)
        {
            Contract.Requires <ArgumentNullException>(documentPosition != null, "documentPosition");

            string fileName;

            ErrorHandler.ThrowOnFailure(documentPosition.GetFileName(out fileName));
            return(fileName);
        }
        // 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));
            }
        }
Beispiel #10
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);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            TextPositionInfo posInfo = new TextPositionInfo(pDocPos);

            MonoDocumentContext docCtx    = new MonoDocumentContext(posInfo, null);
            MonoMemoryContext   memoryCtx = new MonoMemoryContext(docCtx, 0);

            ppEnum = new MonoCodeContextEnumerator(new IDebugCodeContext2[] { memoryCtx });

            return(S_OK);
        }
Beispiel #12
0
        public static IntPtr RegisterDocumentPosition(IDebugDocumentPosition2 documentPosition)
        {
            if (documentPosition == null)
            {
                throw new ArgumentNullException("documentPosition");
            }

            lock (s_documentPositions)
            {
                return((IntPtr)s_documentPositions.Create(documentPosition));
            }
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

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

            LoggingUtils.PrintFunction();

            ppEnum = null;

            try
            {
                List <IDebugCodeContext2> codeContexts = new List <IDebugCodeContext2> ();

                uint count;

                {
                    LoggingUtils.RequireOk(AttachedEngine.NativeDebugger.NativeProgram.EnumCodeContexts(pDocPos, out ppEnum));

                    LoggingUtils.RequireOk(ppEnum.GetCount(out count));

                    IDebugCodeContext2 [] codeContextArray = new IDebugCodeContext2 [count];

                    LoggingUtils.RequireOk(ppEnum.Next(count, codeContextArray, ref count));

                    codeContexts.AddRange(codeContextArray);
                }

#if false
                {
                    LoggingUtils.RequireOk(AttachedEngine.JavaDebugger.JavaProgram.EnumCodeContexts(pDocPos, out ppEnum));

                    LoggingUtils.RequireOk(ppEnum.GetCount(out count));

                    IDebugCodeContext2 [] codeContextArray = new IDebugCodeContext2 [count];

                    LoggingUtils.RequireOk(ppEnum.Next(count, codeContextArray, ref count));

                    codeContexts.AddRange(codeContextArray);
                }
#endif

                ppEnum = new DebuggeeCodeContext.Enumerator(codeContexts);

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

                return(Constants.E_FAIL);
            }
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
 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
     });
 }
Beispiel #17
0
        public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
        {
            TEXT_POSITION[] startPosition;
            TEXT_POSITION[] endPosition;
            var             documentName = breakpointManager.Engine.GetLocationInfo(pDocPos, out startPosition, out endPosition);

            var textPosition = new TEXT_POSITION {
                dwLine = startPosition[0].dwLine + 1
            };
            var documentContext = new MonoDocumentContext(documentName, textPosition, textPosition, null);

            ppEnum = new MonoCodeContextEnum(new[] { new MonoMemoryAddress(this, 0, documentContext) });
            return(VSConstants.S_OK);
        }
Beispiel #18
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));
        }
        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;
        }
Beispiel #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(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));
        }
Beispiel #21
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);
        }
Beispiel #23
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;
      }
    }
Beispiel #26
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);
        }
        // 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);
            }
        }
Beispiel #28
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);
            }
        }
Beispiel #29
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);
            }
        }
        public BreakpointLocationCodeFileLine(BP_LOCATION location, bool releaseComObjects)
        {
            Contract.Requires<ArgumentException>((enum_BP_LOCATION_TYPE)location.bpLocationType == enum_BP_LOCATION_TYPE.BPLT_CODE_FILE_LINE);

            try
            {
                if (location.unionmember1 != IntPtr.Zero)
                    _context = Marshal.PtrToStringBSTR(location.unionmember1);
                if (location.unionmember2 != IntPtr.Zero)
                    _documentPosition = Marshal.GetObjectForIUnknown(location.unionmember2) as IDebugDocumentPosition2;
            }
            finally
            {
                if (releaseComObjects)
                {
                    if (location.unionmember1 != IntPtr.Zero)
                        Marshal.FreeBSTR(location.unionmember1);
                    if (location.unionmember2 != IntPtr.Zero)
                        Marshal.Release(location.unionmember2);
                }
            }
        }
Beispiel #31
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;
        }
Beispiel #32
0
 public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
     ppEnum = null;
     return(VSConstants.E_NOTIMPL);
 }
 /// <summary>
 /// Retrieves a list of the code contexts for a given position in a source file. Not implemented. 
 /// (http://msdn.microsoft.com/en-us/library/bb145902.aspx)
 /// </summary>
 /// <param name="pDocPos"> An 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> Not implemented. </returns>
 public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Beispiel #34
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;
        }
Beispiel #35
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;
        }
 int IDebugProgram2.EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
   Debug.WriteLine("AD7ProgramNode: Entering EnumCodeContexts");
   throw new NotImplementedException();
 }
        // 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;
        }
 public DebugDocumentCodeContext(IDebugDocumentPosition2 documentPosition)
 {
     Contract.Requires<ArgumentNullException>(documentPosition != null, "documentPosition");
     _documentPosition = documentPosition;
 }
Beispiel #39
0
 // Enumerates the code contexts for a given position in a source file.
 public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
     ppEnum = null;
     return VSConstants.E_NOTIMPL;
 }
Beispiel #40
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;
        }
Beispiel #41
0
 int IDebugProgram3.EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum) {
     return IDebugProgram2.EnumCodeContexts(pDocPos, out ppEnum);
 }
Beispiel #42
0
 public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
     DLog.Debug(DContext.VSDebuggerComCall, "IDebugProgram2.EnumCodeContexts");
     throw new NotImplementedException();
 }
Beispiel #43
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;
        }
 public int EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum) {
     throw new NotImplementedException();
 }
 int Microsoft.VisualStudio.Debugger.Interop.IDebugProgram2.EnumCodeContexts(IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum)
 {
     ppEnum = null;
     return Utility.COM_HResults.S_OK;
 }
 /// <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 virtual int EnumCodeContexts( IDebugDocumentPosition2 pDocPos, out IEnumDebugCodeContexts2 ppEnum )
 {
     Logger.Debug( string.Empty );
     ppEnum = null;
     return VSConstants.E_NOTIMPL;
 }