/// <summary> /// Create and set a breakpoint at the given location. /// An exception is thrown if the location cannot be found. /// </summary> public DalvikLocationBreakpoint SetAtLocation(string document, int startLine, int startCol, int endLine, int endCol, object data) { // Search matching document var doc = MapFile.FindDocument(document); if (doc == null) { throw new ArgumentException("Unknown document " + document); } // Search best position var pos = doc.Find(startLine, startCol, endLine, endCol); if (pos == null) { throw new ArgumentException(string.Format("No code found at position {0},{1}-{2},{3}", startLine, startCol, endLine, endCol)); } // Lookup class & method var type = MapFile.GetTypeById(pos.Position.TypeId); if (type == null) { throw new ArgumentException(string.Format("Inconsistent map file, missing type {0}", pos.Position.TypeId)); } var method = type.GetMethodById(pos.Position.MethodId); if (method == null) { throw new ArgumentException(string.Format("Inconsistent map file, missing method {0}", pos.Position.MethodId)); } // Now create the breakpoint var bp = CreateLocationBreakpoint(pos, type, method, data); SetBreakpoint(bp); return(bp); }
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); }