Example #1
0
        public int GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo)
        {
            var info = new BP_RESOLUTION_INFO();

            info.pProgram = program;
            info.dwFields = enum_BPRESI_FIELDS.BPRESI_PROGRAM;

            if (Thread != null)
            {
                info.pThread   = Thread;
                info.dwFields |= enum_BPRESI_FIELDS.BPRESI_THREAD;
            }

            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION) != 0 && locationBP != null)
            {
                info.bpResLocation.bpType = (uint)enum_BP_TYPE.BPT_CODE;

                var codeContext = new DebugCodeContext(locationBP.Location);
                var docLoc      = locationBP.DocumentLocation;
                if (docLoc != null)
                {
                    codeContext.DocumentContext = new DebugDocumentContext(docLoc, codeContext);
                }

                // The debugger will not QI the IDebugCodeContex2 interface returned here. We must pass the pointer
                // to IDebugCodeContex2 and not IUnknown.
                info.bpResLocation.unionmember1 = Marshal.GetComInterfaceForObject(codeContext, typeof(IDebugCodeContext2));
                info.dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION;
            }

            pBPResolutionInfo[0] = info;
            return(VSConstants.S_OK);
        }
        public int GetResolutionInfo(enum_BPRESI_FIELDS dwFields, BP_RESOLUTION_INFO[] pBPResolutionInfo)
        {
            var info = new BP_RESOLUTION_INFO();
            info.pProgram = program;
            info.dwFields = enum_BPRESI_FIELDS.BPRESI_PROGRAM;

            if (Thread != null)
            {
                info.pThread = Thread;
                info.dwFields |= enum_BPRESI_FIELDS.BPRESI_THREAD;
            }

            if ((dwFields & enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION) != 0 && locationBP != null)
            {
                info.bpResLocation.bpType = (uint)enum_BP_TYPE.BPT_CODE;

                var codeContext = new DebugCodeContext(locationBP.Location);
                var docLoc = locationBP.DocumentLocation;
                if(docLoc != null) codeContext.DocumentContext = new DebugDocumentContext(docLoc, codeContext);

                // The debugger will not QI the IDebugCodeContex2 interface returned here. We must pass the pointer
                // to IDebugCodeContex2 and not IUnknown.
                info.bpResLocation.unionmember1 = Marshal.GetComInterfaceForObject(codeContext, typeof(IDebugCodeContext2));
                info.dwFields |= enum_BPRESI_FIELDS.BPRESI_BPRESLOCATION;
            }

            pBPResolutionInfo[0] = info;
            return VSConstants.S_OK;
        }
Example #3
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public DebugDocumentContext(DocumentLocation documentLocation, DebugCodeContext codeContext)
 {
     this.documentLocation = documentLocation;
     this.codeContext      = codeContext;
     if (codeContext != null)
     {
         codeContext.DocumentContext = this;
     }
 }
        public int GetCodeContext(ulong uCodeLocationId, out IDebugCodeContext2 ppCodeContext)
        {
            ppCodeContext = null;

            if (_method == null)
                return HResults.E_DISASM_NOTAVAILABLE;

            var location = _loc.Location.GetAtIndex((uint)uCodeLocationId);
            var ctx = new DebugCodeContext(location);

            // try to set source code.
            var source = _method.FindSourceCode((int)uCodeLocationId);
            if(source != null)
            {
                var docLoc = new DocumentLocation(location, source, _loc.ReferenceType, _loc.Method, _method.TypeEntry, _method.MethodEntry);
                ctx.DocumentContext = new DebugDocumentContext(docLoc, ctx);
            }

            ppCodeContext = ctx;
            return VSConstants.S_OK;
        }
        public int GetCodeContext(ulong uCodeLocationId, out IDebugCodeContext2 ppCodeContext)
        {
            ppCodeContext = null;

            if (_method == null)
            {
                return(HResults.E_DISASM_NOTAVAILABLE);
            }

            var location = _loc.Location.GetAtIndex((uint)uCodeLocationId);
            var ctx      = new DebugCodeContext(location);

            // try to set source code.
            var source = _method.FindSourceCode((int)uCodeLocationId);

            if (source != null)
            {
                var docLoc = new DocumentLocation(location, source, _loc.ReferenceType, _loc.Method, _method.TypeEntry, _method.MethodEntry);
                ctx.DocumentContext = new DebugDocumentContext(docLoc, ctx);
            }

            ppCodeContext = ctx;
            return(VSConstants.S_OK);
        }
 public DebugDisassemblyStream(DebugProgram program, DebugCodeContext documentContext)
 {
     _loc    = documentContext.DocumentContext.DocumentLocation;
     _method = program.DisassemblyProvider.GetFromLocation(_loc);
 }
Example #7
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public DebugDocumentContext(DocumentLocation documentLocation, DebugCodeContext codeContext)
 {
     this.documentLocation = documentLocation;
     this.codeContext = codeContext;
     if (codeContext != null) codeContext.DocumentContext = this;
 }
Example #8
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);
        }
 public DebugDisassemblyStream(DebugProgram program, DebugCodeContext documentContext)
 {
     _loc = documentContext.DocumentContext.DocumentLocation;
     _method = program.DisassemblyProvider.GetFromLocation(_loc);
 }
Example #10
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;
        }