Ejemplo n.º 1
0
 /// <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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
        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;
        }
Ejemplo n.º 4
0
 /// <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;
 }
Ejemplo n.º 5
0
        /// <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;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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];
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 12
0
 /// <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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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));
 }
Ejemplo n.º 15
0
 /// <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();
 }
Ejemplo n.º 16
0
 /// <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;
 }
Ejemplo n.º 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));
         }
     }
 }
Ejemplo n.º 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++;
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 20
0
		/// <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);
		}
Ejemplo n.º 21
0
 /// <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));
 }