Пример #1
0
        /// <summary>
        /// Get all local registers for this frame.
        /// </summary>
        /// <returns></returns>
        public Task <List <DalvikStackFrameValue> > GetRegistersAsync(bool parametersOnly = false, Jdwp.Tag type = Jdwp.Tag.Int, params int[] indizes)
        {
            if (parametersOnly && parameters != null)
            {
                return(parameters.AsTask());
            }
            if (!parametersOnly && registers != null && indizes.Length == 0)
            {
                return(registers.AsTask());
            }

            return(Task.Factory.StartNew(() =>
            {
                var ret = new List <DalvikStackFrameValue>();

                var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);

                List <Register> regDefs;

                MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);

                registerNames = registerNames ??
                                new RegisterNames(methodDiss == null ? null : methodDiss.Method.Body, HasMethodParametersInLastRegisters);

                if (indizes.Length == 0)
                {
                    if (methodDiss == null)
                    {
                        return ret;
                    }

                    var body = methodDiss.Method.Body;

                    regDefs = (parametersOnly ? body.Registers.Where(r => registerNames.IsParameter(r))
                                              : body.Registers)
                              .Where(p => indizes.Length == 0 || indizes.Contains(p.Index))
                              .OrderBy(p => p.Index)
                              .ToList();
                }
                else
                {
                    regDefs = indizes.Select(i => new Register(i)).ToList();
                }

                var requests = regDefs.Select(reg => new SlotRequest(reg.Index, type)).ToList();

                var regValues = Debugger.StackFrame.GetValuesAsync(thread.Id, Id, requests.ToArray())
                                .Await(DalvikProcess.VmTimeout);

                var process = thread.Manager.Process;
                for (int i = 0; i < regDefs.Count && i < regValues.Count; ++i)
                {
                    var reg = regDefs[i];
                    int numRegs = methodDiss == null ? int.MaxValue : methodDiss.Method.Body.Instructions.Count;
                    bool isParam = registerNames.IsParameter(reg);
                    string regName = registerNames.GetName(reg);

                    var valInfo = new VariableInfo(0, regName, null, null, numRegs, reg.Index);

                    DalvikStackFrameValue val = new DalvikStackFrameValue(regValues[i], valInfo, isParam, process);
                    ret.Add(val);
                }

                if (indizes.Length > 0)
                {
                    return ret;
                }

                if (parametersOnly)
                {
                    parameters = parameters ?? ret;
                }
                else
                {
                    registers = registers ?? ret;
                }
                return ret;
            }));
        }
Пример #2
0
        /// <summary>
        /// Get all local registers for this frame.
        /// </summary>
        /// <returns></returns>
        public Task<List<DalvikStackFrameValue>> GetRegistersAsync(bool parametersOnly = false, Jdwp.Tag type = Jdwp.Tag.Int, params int[] indizes)
        {
            if (parametersOnly && parameters != null)
                return parameters.AsTask();
            if (!parametersOnly && registers != null && indizes.Length == 0) 
                return registers.AsTask();

            return Task.Factory.StartNew(() =>
            {
                var ret = new List<DalvikStackFrameValue>();

                var loc = GetDocumentLocationAsync().Await(DalvikProcess.VmTimeout);

                List<Register> regDefs;
                
                MethodDisassembly methodDiss = thread.Manager.Process.DisassemblyProvider.GetFromLocation(loc);

                if(indizes.Length == 0)
                {
                    if (methodDiss == null)
                        return ret;

                    var body = methodDiss.Method.Body;
                    regDefs = (parametersOnly ? body.Registers.Where(r=>body.IsComing(r))
                                              : body.Registers)
                              .Where(p => indizes.Length == 0 || indizes.Contains(p.Index))
                              .OrderBy(p=>p.Index)
                              .ToList();
                }
                else
                {
                    regDefs = indizes.Select(i => new Register(i)).ToList();
                }

                var requests = regDefs.Select(reg => new SlotRequest(reg.Index, type)).ToList();
   
                var regValues = Debugger.StackFrame.GetValuesAsync(thread.Id, Id, requests.ToArray())
                                                   .Await(DalvikProcess.VmTimeout);

                var process = thread.Manager.Process;
                for (int i = 0; i < regDefs.Count && i < regValues.Count; ++i)
                {
                    var reg = regDefs[i];
                    if (methodDiss != null)
                    {
                        var body = methodDiss.Method.Body;
                        bool isParam = body.IsComing(reg);

                        string regName = MethodDisassembly.FormatRegister(reg, body);
                        var valInfo = new VariableInfo(0, regName, null, null, body.Instructions.Count, reg.Index);

                        DalvikStackFrameValue val = new DalvikStackFrameValue(regValues[i], valInfo, isParam, process);
                        ret.Add(val);
                    }
                    else
                    {
                        string regName = "r" + reg.Index;
                        var valInfo = new VariableInfo(0, regName, null, null, int.MaxValue, reg.Index);

                        var val = new DalvikStackFrameValue(regValues[i], valInfo, false, process);
                        ret.Add(val);
                    }
                }

                if (indizes.Length > 0)
                    return ret;

                if(parametersOnly)
                    parameters = parameters ?? ret;
                else
                    registers = registers ?? ret;
                return ret;
            });
        }