/// <summary>
 /// Default ctor
 /// </summary>
 public DalvikLocationBreakpoint(Jdwp.EventKind eventKind, DocumentPosition documentPosition, TypeEntry typeEntry, MethodEntry methodEntry)
     : base(eventKind)
 {
     this.documentPosition = documentPosition;
     this.typeEntry = typeEntry;
     this.methodEntry = methodEntry;
 }
 public CacheEntry(MethodBody body, MethodEntry methodEntry, IList<SourceCodePosition> sourceCodePositions, string classSourceFile)
 {
     Body = body;
     MethodEntry = methodEntry;
     ClassSourceFile = classSourceFile;
     SourceCodePositions = sourceCodePositions != null ? new ReadOnlyCollection<SourceCodePosition>(sourceCodePositions) : null;
 }
        public MethodDisassembly(MethodDefinition methodDef, MapFileLookup mapFile = null, TypeEntry typeEntry = null, MethodEntry methodEntry = null)
        {
            _typeEntry = typeEntry;
            _methodEntry = methodEntry;
            _methodDef = methodDef;
            _mapFile = mapFile;

            JumpTargetOffsets=new HashSet<int>();
            ExceptionHandlerOffsets = new HashSet<int>();

            if (methodDef.Body != null)
            {
                foreach (var i in methodDef.Body.Instructions)
                {
                    var op = i.Operand as Instruction;
                    if (op != null)
                        JumpTargetOffsets.Add(op.Offset);
                }
                foreach (var e in methodDef.Body.Exceptions)
                {
                    foreach(var c in e.Catches)
                        ExceptionHandlerOffsets.Add(c.Instruction.Offset);
                    if (e.CatchAll != null)
                        ExceptionHandlerOffsets.Add(e.CatchAll.Offset);
                }
            }

            Format = FormatOptions.Default;
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DalvikLocationBreakpoint(Jdwp.EventKind eventKind, SourceCodePosition sourcePosition, TypeEntry typeEntry, MethodEntry methodEntry)
     : base(eventKind)
 {
     this.typeEntry = typeEntry;
     this.methodEntry = methodEntry;
     SourceCodePosition = sourcePosition;
 }
        /// <summary>
        /// Create a new location breakpoint.
        /// </summary>
        protected override DalvikLocationBreakpoint CreateLocationBreakpoint(SourceCodePosition sourceCode, TypeEntry typeEntry, MethodEntry methodEntry, object data)
        {
            // Create breakpoint objects
            var pendingBreakpoint = (DebugPendingBreakpoint)data;
            var boundBreakpoint = new DebugBoundBreakpoint<DebugLocationBreakpoint>(pendingBreakpoint, this, enum_BP_TYPE.BPT_CODE, x => new DebugLocationBreakpoint(Jdwp.EventKind.BreakPoint, sourceCode, typeEntry, methodEntry, x));

            // Return breakpoint
            return boundBreakpoint.Breakpoint;
        }
Exemple #6
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public DocumentLocation(Location location, SourceCodePosition sourceCode, DalvikReferenceType referenceType, DalvikMethod method, TypeEntry typeEntry, MethodEntry methodEntry)
 {
     if (location == null)
         throw new ArgumentNullException("location");
     Location = location;
     SourceCode = sourceCode;
     ReferenceType = referenceType;
     Method = method;
     this.typeEntry = typeEntry;
     this.methodEntry = methodEntry;
 }
Exemple #7
0
 /// <summary>
 /// Default ctor
 /// </summary>
 public DocumentLocation(Location location, Document document, DocumentPosition position, DalvikReferenceType referenceType, DalvikMethod method, TypeEntry typeEntry, MethodEntry methodEntry)
 {
     if (location == null)
         throw new ArgumentNullException("location");
     Location = location;
     Document = document;
     Position = position;
     ReferenceType = referenceType;
     Method = method;
     this.typeEntry = typeEntry;
     this.methodEntry = methodEntry;
 }
Exemple #8
0
        /// <summary>
        /// Beginning at offset, returns the next available source code position.
        /// Will not return positions with "IsSpecial" flag set.
        /// </summary>
        /// <returns>null, if not found</returns>
        public SourceCodePosition FindNextSourceCode(MethodEntry method, int methodOffset)
        {
            var loc = GetSourceCodePositions(method);

            int idx = loc.FindFirstIndexGreaterThanOrEqualTo(methodOffset, p => p.Position.MethodOffset);

            for (;idx != -1 && idx < loc.Count; ++idx)
            {
                var ret = loc[idx];
                if (ret.IsSpecial)
                    continue;
                return ret;
            }
            return null;
        }
Exemple #9
0
 /// <summary>
 /// Does this method method the name and signature in the given method entry?
 /// </summary>
 public bool IsMatch(MethodEntry entry)
 {
     return (Name == entry.DexName) && (Signature == entry.DexSignature);
 }
Exemple #10
0
 /// <summary>
 /// Get all source code positions for the given type and method. The returned list will be
 /// ordered by MethodOffset.
 /// </summary>
 public IList<SourceCodePosition> GetSourceCodePositions(MethodEntry method)
 {
     List<SourceCodePosition> posList;
     if (_positionsByMethodId.TryGetValue(method.Id, out posList))
     {
         return posList.AsReadOnly();
     }
     return new SourceCodePosition[0];
 }
Exemple #11
0
        /// <summary>
        /// Try to find the document location that belongs to the given method + offset.
        /// </summary>
        /// <returns>null, if not found. If we know the document, but the offset is marked to
        /// have no source code attached (compiler generated), the returned position will
        /// be marked as IsSpecial.</returns>
        public SourceCodePosition FindSourceCode(MethodEntry method, int methodOffset, bool allowSpecial = true)
        {
            var locs = GetSourceCodePositions(method);

            // perform a binary search
            int idx = locs.FindLastIndexSmallerThanOrEqualTo(methodOffset, p => p.Position.MethodOffset);

            if (idx != -1 && (allowSpecial || !locs[idx].IsSpecial))
                return locs[idx];

            if (allowSpecial && locs.Count > 0)
            {
                // this can only happen at the beginning of the method.
                // forge a special location.
                var pos = locs[0].Position;
                var forgedPos = new DocumentPosition(pos.Start.Line,pos.Start.Column, pos.End.Line, pos.End.Column, pos.TypeId, pos.MethodId, DocumentPosition.SpecialOffset);
                return new SourceCodePosition(locs[0].Document, forgedPos);
            }

            return null;
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DebugLocationBreakpoint(Jdwp.EventKind eventKind, SourceCodePosition sourcePosition, TypeEntry typeEntry, MethodEntry methodEntry, DebugBoundBreakpoint<DebugLocationBreakpoint> boundBreakpoint)
     : base(eventKind, sourcePosition, typeEntry, methodEntry)
 {
     this.boundBreakpoint = boundBreakpoint;
 }
Exemple #13
0
        public static MethodEntry RecordMapping(TypeEntry typeEntry, XMethodDefinition xMethod, MethodDefinition method, DexLib.MethodDefinition dmethod, CompiledMethod compiledMethod)
        {
            var scopeId = xMethod.ScopeId;

            StringBuilder netSignature = new StringBuilder();
            method.MethodSignatureFullName(netSignature);

            var entry = new MethodEntry(method.OriginalName, netSignature.ToString(), dmethod.Name, dmethod.Prototype.ToSignature(), dmethod.MapFileId,
                                        scopeId);

            typeEntry.Methods.Add(entry);

            if (compiledMethod != null)
            {
                compiledMethod.RecordMapping(entry);
            }

            return entry;
        }
Exemple #14
0
 /// <summary>
 /// Create a new location breakpoint.
 /// </summary>
 protected virtual DalvikLocationBreakpoint CreateLocationBreakpoint(SourceCodePosition sourcePosition, TypeEntry typeEntry, MethodEntry methodEntry, object data)
 {
     return(new DalvikLocationBreakpoint(Jdwp.EventKind.BreakPoint, sourcePosition, typeEntry, methodEntry));
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DebugLocationBreakpoint(Jdwp.EventKind eventKind, SourceCodePosition sourcePosition, TypeEntry typeEntry, MethodEntry methodEntry, BreakpointBookmark bookmark)
     : base(eventKind, sourcePosition, typeEntry, methodEntry)
 {
     this.bookmark = bookmark;
     InvalidateBookmark();
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DebugLocationBreakpoint(Jdwp.EventKind eventKind, DocumentPosition documentPosition, TypeEntry typeEntry, MethodEntry methodEntry, DebugBoundBreakpoint<DebugLocationBreakpoint> boundBreakpoint)
     : base(eventKind, documentPosition, typeEntry, methodEntry)
 {
     this.boundBreakpoint = boundBreakpoint;
 }
Exemple #17
0
 /// <summary>
 /// Get all locations for the given type and method.
 /// </summary>
 public IEnumerable <Tuple <Document, DocumentPosition> > GetLocations(TypeEntry type, MethodEntry method)
 {
     foreach (var doc in documents.Values)
     {
         foreach (var docPos in doc.Positions)
         {
             if ((docPos.TypeId != type.Id) || (docPos.MethodId != method.Id))
             {
                 continue;
             }
             yield return(Tuple.Create(doc, docPos));
         }
     }
 }
Exemple #18
0
 /// <summary>
 /// Record the mapping from .NET to Dex
 /// </summary>
 public void RecordMapping(MethodEntry methodEntry)
 {
     if (methodEntry == null)
         throw new ArgumentNullException("methodEntry");
     if (regMapper == null)
         return;
     var frame = InvocationFrame;
     var paramIndex = 0;
     foreach (var argSpec in frame.Arguments)
     {
         var dreg = regMapper[argSpec.Register];
         if (dreg == null)
             throw new Dot42Exception(string.Format("Cannot find dex register for {0}", argSpec.Register));
         var paramName = (argSpec.Parameter != null) ? argSpec.Parameter.Name : null;
         paramName = paramName ?? string.Format("p{0}", paramIndex);
         methodEntry.Parameters.Add(new Mapping.Parameter(dreg.Index, paramName));
         paramIndex++;
     }
     var varIndex = 0;
     foreach (var varSpec in frame.Variables)
     {
         if (regMapper.ContainsKey(varSpec.Register))
         {
             var dreg = regMapper[varSpec.Register];
             if (dreg == null)
                 throw new Dot42Exception(string.Format("Cannot find dex register for {0}", varSpec.Register));
             var varName = (varSpec.Variable != null) ? varSpec.Variable.OriginalName : null;
             varName = varName ?? string.Format("v{0}", varIndex);
             methodEntry.Variables.Add(new Mapping.Variable(dreg.Index, varName));
         }
         varIndex++;
     }
 }
Exemple #19
0
        /// <summary>
        /// Record the mapping from .NET to Dex
        /// </summary>
        public void RecordMapping(TypeEntry typeEntry)
        {
            var entry = new MethodEntry(method.Name, "", dmethod.Name, dmethod.Prototype.ToSignature(), dmethod.MapFileId);
            typeEntry.Methods.Add(entry);

            if (compiledMethod != null)
            {
                compiledMethod.RecordMapping(entry);
            }
        }
		/// <summary>
		/// Create custom breakpoint.
		/// </summary>
		protected override DalvikLocationBreakpoint CreateLocationBreakpoint(DocumentPosition documentPosition, TypeEntry typeEntry, MethodEntry methodEntry, object data)
		{
			return new DebugLocationBreakpoint(Jdwp.EventKind.BreakPoint, documentPosition, typeEntry, methodEntry, (BreakpointBookmark)data);
		}
 /// <summary>
 /// Create a new location breakpoint.
 /// </summary>
 protected virtual DalvikLocationBreakpoint CreateLocationBreakpoint(DocumentPosition documentPosition, TypeEntry typeEntry, MethodEntry methodEntry, object data)
 {
     return(new DalvikLocationBreakpoint(Jdwp.EventKind.BreakPoint, documentPosition, typeEntry, methodEntry));
 }