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 MethodDisassembly GetFromLocation(DocumentLocation loc)
        {
            string className = null, methodName= null, methodSignature = null;

            if (loc == null)
                return null;

            if (loc.Method != null)
            {
                var type = loc.Method.DeclaringType.GetSignatureAsync().Await(DalvikProcess.VmTimeout);
                var typeDef = Descriptors.ParseClassType(type);
                className = typeDef.ClassName.Replace("/", ".");

                methodName = loc.Method.Name;
                methodSignature = loc.Method.Signature;
            }

            if (className == null && loc.TypeEntry != null)
                className = loc.TypeEntry.DexName;

            if (methodName == null && loc.MethodEntry != null)
            {
                methodName = loc.MethodEntry.DexName;
                methodSignature = loc.MethodEntry.Signature;
            }

            if (methodName == null || className == null)
                return null;

            var methodDef = _dex.Value.GetMethod(className, methodName, methodSignature);

            if (methodDef == null)
                return null;

            var typeEntry   = loc.TypeEntry   ?? _mapFile.GetTypeByDexName(className);
            var methodEntry = loc.MethodEntry ?? _mapFile.GetMethodByDexSignature(className, methodName, methodSignature);

            return new MethodDisassembly(methodDef, _mapFile, typeEntry, methodEntry);
        }
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 DebugDisassemblyStream(DebugProgram program, DebugCodeContext documentContext)
 {
     _loc = documentContext.DocumentContext.DocumentLocation;
     _method = program.DisassemblyProvider.GetFromLocation(_loc);
 }
Example #5
0
 /// <summary>
 /// Convert the dalvik location into a document location.
 /// </summary>
 public Task<DocumentLocation> GetDocumentLocationAsync()
 {
     if (documentLocation != null) return documentLocation.AsTask();
     return thread.Manager.Process.ResolveAsync(Location).SaveAndReturn(x => documentLocation = x);
 }
 public DebugLocationBreakpoint(Location location, DebugBoundBreakpoint<DebugLocationBreakpoint> boundBreakpoint, DocumentLocation documentLocation = null)
     : base(location, documentLocation)
 {
     this.boundBreakpoint = boundBreakpoint;
 }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DalvikLocationBreakpoint(Location location, DocumentLocation documentLocation=null)
     : base(Jdwp.EventKind.BreakPoint)
 {
     this.location = location;
     this.documentLocation = documentLocation;
 }
        private Location TryGetLocation(DalvikProcess process)
        {
            if (location != null)
                return location;

            // Lookup classid & methodid
            var signature = typeEntry.DexSignature;
            var referenceTypeManager = process.ReferenceTypeManager;

            // Register a callback for when the class is prepared.
            if (classPrepareCookie == null)
            {
                classPrepareCookie = referenceTypeManager.RegisterClassPrepareHandler(signature, evt => TryBind(process));
            }

            // Now try to find the type
            var refType = referenceTypeManager.FindBySignature(signature);
            if (refType == null)
            {
                // Not possible yet
                return null;
            }

            // We've found the type, we're no longer interested in class prepare events
            if (classPrepareCookie != null)
            {
                referenceTypeManager.Remove(classPrepareCookie);
            }

            var refTypeMethods = refType.GetMethodsAsync().Await(DalvikProcess.VmTimeout);
            var dmethod = refTypeMethods.FirstOrDefault(x => x.IsMatch(methodEntry));
            if (dmethod == null)
            {
                throw new ArgumentException(string.Format("Cannot find method {0}", methodEntry.Name));
            }

            // return location.
            var pos = SourceCodePosition;

            location = new Location(refType.Id, dmethod.Id, (ulong) pos.Position.MethodOffset);
            documentLocation = new DocumentLocation(location, pos, refType, dmethod, typeEntry, methodEntry);

            return location;
        }
 /// <summary>
 /// Default ctor
 /// </summary>
 public DalvikLocationBreakpoint(Location location, DocumentLocation documentLocation = null)
     : base(Jdwp.EventKind.BreakPoint)
 {
     this.location         = location;
     this.documentLocation = documentLocation;
 }