Esempio n. 1
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it.
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private async Task <BoundBreakpoint> GetBoundBreakpoint(TupleValue bkpt)
        {
            string            addrString = bkpt.TryFindString("addr");
            MIBreakpointState state      = StringToBreakpointState(addrString);

            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit.
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return(null);
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return(null);
            }

            var bbp = new BoundBreakpoint(this, bkpt);

            // On GDB, the returned line information is from the pending breakpoint instead of the bound breakpoint.
            // Check the address mapping to make sure the line info is correct.
            if (this.DebuggedProcess.MICommandFactory.Mode == MIMode.Gdb && !string.IsNullOrEmpty(bbp.CompiledFileName))
            {
                bbp.Line = await this.DebuggedProcess.LineForStartAddress(bbp.CompiledFileName, bbp.Addr);
            }

            return(bbp);
        }
Esempio n. 2
0
        public async Task <TupleValue <string, bool> > ImportScriptAsync(byte[] scriptBytes, bool rescan, int scanFrom,
                                                                         string passphrase, bool requireRedeemable)
        {
            if (scriptBytes == null)
            {
                throw new ArgumentNullException(nameof(scriptBytes));
            }
            if (passphrase == null)
            {
                throw new ArgumentNullException(nameof(passphrase));
            }

            var client  = new WalletService.WalletServiceClient(_channel);
            var request = new ImportScriptRequest
            {
                Script            = ByteString.CopyFrom(scriptBytes),
                Rescan            = rescan,
                Passphrase        = ByteString.CopyFromUtf8(passphrase), // Poorly named: this outputs UTF8 from a UTF16 System.String
                ScanFrom          = scanFrom,
                RequireRedeemable = requireRedeemable,
            };
            var resp = await client.ImportScriptAsync(request, cancellationToken : _tokenSource.Token);

            return(TupleValue.Create(resp.P2ShAddress, resp.Redeemable));
        }
Esempio n. 3
0
        //this constructor is private because it should only be used internally to create children
        private VariableInformation(TupleValue results, VariableInformation parent)
            : this(parent._ctx, parent._engine, parent.Client)
        {
            TypeName      = results.TryFindString("type");
            Value         = results.TryFindString("value");
            Name          = results.FindString("exp");
            CountChildren = results.FindUint("numchild");
            int index;

            if (!results.Contains("value") && (Name == TypeName || Name.Contains("::")))
            {
                // base classes show up with no value and exp==type
                // (sometimes underlying debugger does not follow this convention, when using typedefs in templated types so look for "::" in the field name too)
                Name             = "base";
                Value            = TypeName;
                VariableNodeType = NodeType.BaseClass;
            }
            else if (Int32.TryParse(this.Name, System.Globalization.NumberStyles.Integer, null, out index)) // array element
            {
                Name             = '[' + this.Name + ']';
                VariableNodeType = NodeType.ArrayElement;
            }
            else
            {
                _strippedName    = Name;
                VariableNodeType = NodeType.Field;
            }

            _internalName = results.FindString("name");
            IsChild       = true;
            _format       = parent._format; // inherit formatting
            _parent       = parent.VariableNodeType == NodeType.AccessQualifier ? parent._parent : parent;
        }
Esempio n. 4
0
        public TupleValue[] Edges; // Edge Walls

        public DebugObservation(
            float flag, float[] lidar, float travelled, float turned, bool paused,
            Tuple <float, float, float> position, List <Tuple <float, float, float> > obstacles,
            List <Tuple <float, float> > edgewalls
            ) : base(flag, lidar, travelled, turned, paused)
        {
            Pos = new TupleValue(position.Item1, position.Item2, position.Item3);

            Obs = new TupleValue[obstacles.Count];
            for (int i = 0; i < obstacles.Count; i++)
            {
                Obs[i] = new TupleValue(
                    obstacles[i].Item1,
                    obstacles[i].Item2,
                    obstacles[i].Item3);
            }

            Edges = new TupleValue[edgewalls.Count];
            for (int i = 0; i < edgewalls.Count; i++)
            {
                Edges[i] = new TupleValue(
                    edgewalls[i].Item1,
                    edgewalls[i].Item2,
                    0);
            }
        }
        private Task SaveWalletVotePreference(Agenda agenda, Agenda.Choice choice)
        {
            var walletClient = App.Current.Synchronizer.WalletRpcClient;
            var choices      = new TupleValue <string, string>[] { TupleValue.Create(agenda.ID, choice.ID) };

            return(walletClient.SetVoteChoicesAsync(choices));
        }
Esempio n. 6
0
        public async Task <TupleValue <uint, Agenda[]> > AgendasAsync()
        {
            var client   = new AgendaService.AgendaServiceClient(_channel);
            var request  = new AgendasRequest();
            var response = await client.AgendasAsync(request, cancellationToken : _tokenSource.Token);

            var agendas = response.Agendas.Select(a => new Agenda
            {
                ID          = a.Id,
                Description = a.Description,
                Choices     = a.Choices.Select(c => new Agenda.Choice
                {
                    ID          = c.Id,
                    Description = c.Description,
                    Bits        = (ushort)c.Bits,
                    IsAbstain   = c.IsAbstain,
                    IsNo        = c.IsNo,
                }).ToArray(),
                Mask       = (ushort)a.Mask,
                StartTime  = DateTimeOffsetExtras.FromUnixTimeSeconds(a.StartTime),
                ExpireTime = DateTimeOffsetExtras.FromUnixTimeSeconds(a.ExpireTime),
            }).ToArray();

            return(TupleValue.Create(response.Version, agendas));
        }
Esempio n. 7
0
        public int InsertStkKLine(TupleValue <string, StockHead> stkInfo, bool isConvert, bool isComposite, bool useTDXFile, KLineType kLineType, bool haveRecord = true)
        {
            string    fileFullName = stkInfo.Value1;
            StockHead stkHead      = stkInfo.Value2;
            string    tableName    = BLL.GetKLineDBTableName(kLineType, isComposite);
            DateTime  existMaxDay  = DateTime.MinValue;
            DataTable insTable     = _dbo.GetEmptyTable(tableName);

            if (haveRecord)
            {
                if (isConvert)
                {
                    _dbo.DeleteTable(tableName, stkHead);
                }
                else
                {
                    existMaxDay = _dbo.FindMaxExistTradeDay(tableName, stkHead);
                }
            }

            if (useTDXFile)
            {
                this.LoadDayLineFileData_TDXDayFile(fileFullName, stkHead, existMaxDay, ref insTable);
            }
            else
            {
                this.LoadDayLineFileData_exportFile(fileFullName, stkHead, existMaxDay, ref insTable);
            }

            _dbo.BulkWriteTable(insTable, DataRowState.Added);

            return(insTable.Rows.Count);
        }
Esempio n. 8
0
        public async Task <TupleValue <string, string>[]> VoteChoicesAsync()
        {
            var client   = new VotingService.VotingServiceClient(_channel);
            var request  = new VoteChoicesRequest();
            var response = await client.VoteChoicesAsync(request, cancellationToken : _tokenSource.Token);

            return(response.Choices.Select(c => TupleValue.Create(c.AgendaId, c.ChoiceId)).ToArray());
        }
Esempio n. 9
0
        //this constructor is private because it should only be used internally to create children
        private VariableInformation(TupleValue results, VariableInformation parent, string name = null)
            : this(parent._ctx, parent._engine, parent.Client)
        {
            TypeName = results.TryFindString("type");
            Value    = results.TryFindString("value");
            Name     = name ?? results.FindString("exp");
            if (results.Contains("dynamic"))
            {
                CountChildren = 1;
            }
            else
            {
                CountChildren = results.FindUint("numchild");
            }
            if (results.Contains("displayhint"))
            {
                DisplayHint = results.FindString("displayhint");
            }
            if (results.Contains("attributes"))
            {
                if (results.FindString("attributes") == "noneditable")
                {
                    _isReadonly = true;
                }
                _attribsFetched = true;
            }

            int index;

            if (!results.Contains("value") && (Name == TypeName || Name.Contains("::")))
            {
                // base classes show up with no value and exp==type
                // (sometimes underlying debugger does not follow this convention, when using typedefs in templated types so look for "::" in the field name too)
                Name             = TypeName + " (base)";
                Value            = TypeName;
                VariableNodeType = NodeType.BaseClass;
            }
            else if (Int32.TryParse(this.Name, System.Globalization.NumberStyles.Integer, null, out index)) // array element
            {
                Name             = '[' + this.Name + ']';
                VariableNodeType = NodeType.ArrayElement;
            }
            else if (this.Name.Length > 2 && this.Name[0] == '[' && this.Name[this.Name.Length - 1] == ']')
            {
                VariableNodeType = NodeType.ArrayElement;
            }
            else
            {
                _strippedName    = Name;
                VariableNodeType = NodeType.Field;
            }

            _internalName          = results.FindString("name");
            IsChild                = true;
            _format                = parent._format; // inherit formatting
            _parent                = parent.VariableNodeType == NodeType.AccessQualifier ? parent._parent : parent;
            this.PropertyInfoFlags = parent.PropertyInfoFlags;
        }
Esempio n. 10
0
 internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
 {
     // CLRDBG TODO: Support clr addresses for breakpoints
     this.Addr         = bindinfo.TryFindAddr("addr") ?? 0;
     this.FunctionName = bindinfo.TryFindString("func");
     this.HitCount     = 0;
     _parent           = parent;
     _textPosition     = MITextPosition.TryParse(bindinfo);
 }
        public static MITextPosition TryParse(TupleValue miTuple)
        {
            string filename = miTuple.TryFindString("fullname");

            if (string.IsNullOrEmpty(filename))
            {
                filename = miTuple.TryFindString("file");
            }
            if (!string.IsNullOrEmpty(filename))
            {
                filename = DebuggedProcess.UnixPathToWindowsPath(filename);
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            uint?line = miTuple.TryFindUint("line");

            if (!line.HasValue || line.Value == 0)
            {
                return(null);
            }

            uint lineValue = line.Value;

            var startPosition = new TEXT_POSITION()
            {
                dwLine   = lineValue - 1,
                dwColumn = 0
            };

            uint?startColumn = miTuple.TryFindUint("col");

            if (startColumn > 0)
            {
                startPosition.dwColumn = startColumn.Value - 1;
            }

            TEXT_POSITION endPosition = startPosition;
            uint?         endLine     = miTuple.TryFindUint("end-line");

            if (endLine > 0)
            {
                endPosition.dwLine = endLine.Value - 1;

                uint?endCol = miTuple.TryFindUint("end-col");
                if (endCol > 0)
                {
                    endPosition.dwColumn = endCol.Value - 1;
                }
            }

            return(new MITextPosition(filename, startPosition, endPosition));
        }
Esempio n. 12
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong?         pc           = frame.TryFindAddr("addr");
            MITextPosition textPosition = MITextPosition.TryParse(this._debugger, frame);
            string         func         = frame.TryFindString("func");
            uint           level        = frame.FindUint("level");
            string         from         = frame.TryFindString("from");

            return(new ThreadContext(pc, textPosition, func, level, from));
        }
Esempio n. 13
0
        }                                                           // name as it appears in the debug symbols

        internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
        {
            // CLRDBG TODO: Support clr addresses for breakpoints
            this.Addr             = bindinfo.TryFindAddr("addr") ?? 0;
            this.FunctionName     = bindinfo.TryFindString("func");
            this.Enabled          = bindinfo.TryFindString("enabled") == "n" ? false : true;
            this.HitCount         = 0;
            this.CompiledFileName = bindinfo.Contains("fullname") ? bindinfo.FindString("fullname") : bindinfo.TryFindString("file");
            _parent       = parent;
            _textPosition = MITextPosition.TryParse(parent.DebuggedProcess, bindinfo);
        }
Esempio n. 14
0
        private void dataImptBtnDayKLineImport_Click(object sender, EventArgs e)
        {
            // < 覆盖,指数,TDX文件,K线级别 >
            TupleValue <bool, bool, bool, KLineType> arg = new TupleValue <bool, bool, bool, KLineType>(
                dataImptDayKLineChkConvert.Checked,
                dataImptDayKLineChkIsComposite.Checked,
                dataImptDayKLineChkTDXFile.Checked,
                KLineType.Day);

            bkgDataImport.RunWorkerAsync(arg);
        }
Esempio n. 15
0
        private TupleValue CreateTupleValue(JToken item)
        {
            var source = Create(item["source"]);
            int index  = (int)item["index"];

            TupleValue result = source is DataReference ?  new TupleValue((DataReference)source, index) : new TupleValue((ISource)source, index);

            result.DebugInfo = GetDebugInfo(item);

            return(result);
        }
Esempio n. 16
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame)
        {
            Addr     = addr;
            HitCount = 0;
            _parent  = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition     = MITextPosition.TryParse(frame);
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Queries the RPC server for the next external BIP0044 address for an account
        /// </summary>
        /// <param name="account">Account to create address for</param>
        /// <returns>Tuple containing the address and pubkey address strings</returns>
        public async Task <TupleValue <string, string> > NextExternalAddressAsync(Account account)
        {
            var client  = new WalletService.WalletServiceClient(_channel);
            var request = new NextAddressRequest
            {
                Account = account.AccountNumber,
                Kind    = NextAddressRequest.Types.Kind.Bip0044External,
            };
            var resp = await client.NextAddressAsync(request, cancellationToken : _tokenSource.Token);

            return(TupleValue.Create(resp.Address, resp.PublicKey));
        }
Esempio n. 18
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame, string bkptno)
        {
            Addr        = addr;
            HitCount    = 0;
            Enabled     = true;
            this.Number = bkptno;
            _parent     = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition     = MITextPosition.TryParse(parent.DebuggedProcess, frame);
            }
        }
Esempio n. 19
0
        public static MITextPosition TryParse(DebuggedProcess process, TupleValue miTuple)
        {
            string filename = process.GetMappedFileFromTuple(miTuple);

            if (!string.IsNullOrEmpty(filename))
            {
                filename = DebuggedProcess.UnixPathToWindowsPath(filename);
            }

            if (string.IsNullOrWhiteSpace(filename))
            {
                return(null);
            }

            uint?line = miTuple.TryFindUint("line");

            if (!line.HasValue || line.Value == 0)
            {
                return(null);
            }

            uint lineValue = line.Value;

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION startPosition = new Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION();
            startPosition.dwLine   = lineValue - 1;
            startPosition.dwColumn = 0;

            uint?startColumn = miTuple.TryFindUint("col");

            if (startColumn > 0)
            {
                startPosition.dwColumn = startColumn.Value - 1;
            }

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION endPosition = startPosition;
            uint?endLine = miTuple.TryFindUint("end-line");

            if (endLine > 0)
            {
                endPosition.dwLine = endLine.Value - 1;

                uint?endCol = miTuple.TryFindUint("end-col");
                if (endCol > 0)
                {
                    endPosition.dwColumn = endCol.Value - 1;
                }
            }

            return(new MITextPosition(filename, startPosition, endPosition));
        }
Esempio n. 20
0
        /// <summary>
        /// Builds a tuple with the items set to the given tuple elements.
        /// The tuple represents a value of user defined type if a name is specified.
        /// Registers the value with the scope manager, unless registerWithScopeManager is set to false.
        /// Increases the reference count for the tuple elements.
        /// </summary>
        /// <param name="typeName">The name of the user defined typed that the tuple represents</param>
        /// <param name="registerWithScopeManager">Whether or not to register the built tuple with the scope manager</param>
        /// <param name="tupleElements">The tuple elements</param>
        private TupleValue CreateTuple(UserDefinedType?typeName, bool registerWithScopeManager, params IValue[] tupleElements)
        {
            var        elementTypes = tupleElements.Select(v => v.QSharpType).ToImmutableArray();
            TupleValue tuple        = new TupleValue(typeName, elementTypes, this.sharedState, registerWithScopeManager);

            PointerValue[] itemPointers = tuple.GetTupleElementPointers();

            for (var i = 0; i < itemPointers.Length; ++i)
            {
                itemPointers[i].StoreValue(tupleElements[i]);
                this.sharedState.ScopeMgr.IncreaseReferenceCount(tupleElements[i]);
            }

            return(tuple);
        }
Esempio n. 21
0
        public void TupleValueTest()
        {
            TupleValue <Int32, Int32> pair = new TupleValue <int, int>(55, 555);

            Assert.AreEqual("Item1 = 55; Item2 = 555; ", pair.ToString());
            TupleValue <Int32, Int32> pair2 = new TupleValue <int, int>(55, 55);

            TupleValue <Int32, Int32> pair3 = new TupleValue <int, int>(55, 555);

            Assert.AreEqual(pair3.GetHashCode(), pair.GetHashCode());
            Assert.AreNotEqual(pair3.GetHashCode(), pair2.GetHashCode());

            Assert.AreEqual(true, pair3.Equals(pair));
            Assert.AreEqual(false, pair3.Equals(pair2));
        }
        private async Task <TupleValue <uint, List <AgendaChoiceViewModel> > > FetchWalletVotingPreferences()
        {
            var walletClient  = App.Current.Synchronizer.WalletRpcClient;
            var agendasTask   = walletClient.AgendasAsync();
            var choicesTask   = walletClient.VoteChoicesAsync();
            var agendas       = await agendasTask;
            var choices       = await choicesTask;
            var agendaChoices = agendas.Item2.Select(a =>
            {
                var selectedAgendaChoiceID = choices.First(c => c.Item1 == a.ID).Item2;
                return(new AgendaChoiceViewModel(a, a.Choices.First(c => c.ID == selectedAgendaChoiceID), OnAgendaChoiceChanged));
            }).ToList();

            return(TupleValue.Create(agendas.Item1, agendaChoices));
        }
Esempio n. 23
0
        public async Task <TupleValue <int, BlockIdentity?> > FetchHeadersAsync()
        {
            var client   = new WalletLoaderService.WalletLoaderServiceClient(_channel);
            var request  = new FetchHeadersRequest();
            var response = await client.FetchHeadersAsync(request, cancellationToken : _tokenSource.Token);

            BlockIdentity?blockIdentity = null;

            if (response.FetchedHeadersCount != 0)
            {
                blockIdentity = new BlockIdentity(new Blake256Hash(response.FirstNewBlockHash.ToByteArray()),
                                                  response.FirstNewBlockHeight);
            }
            return(TupleValue.Create((int)response.FetchedHeadersCount, blockIdentity));
        }
Esempio n. 24
0
        /// <summary>
        /// Builds a tuple with the items set to the given tuple elements.
        /// Registers the value with the scope manager, unless registerWithScopeManager is set to false.
        /// </summary>
        /// <param name="tupleElements">The tuple elements</param>
        internal TupleValue CreateTuple(ImmutableArray <TypedExpression> tupleElements, bool registerWithScopeManager = true)
        {
            var        elementTypes = tupleElements.Select(v => v.ResolvedType).ToImmutableArray();
            TupleValue tuple        = new TupleValue(null, elementTypes, this.sharedState, registerWithScopeManager);

            PointerValue[] itemPointers = tuple.GetTupleElementPointers();

            var elements = tupleElements.Select(this.sharedState.BuildSubitem).ToArray();

            for (var i = 0; i < itemPointers.Length; ++i)
            {
                itemPointers[i].StoreValue(elements[i]);
            }

            return(tuple);
        }
Esempio n. 25
0
        public static MITextPosition TryParse(TupleValue miTuple)
        {
            string filename = miTuple.TryFindString("fullname");
            if (string.IsNullOrEmpty(filename))
            {
                filename = miTuple.TryFindString("file");
            }
            if (!string.IsNullOrEmpty(filename))
            {
                filename = DebuggedProcess.UnixPathToWindowsPath(filename);
            }

            if (string.IsNullOrWhiteSpace(filename))
                return null;

            uint? line = miTuple.TryFindUint("line");
            if (!line.HasValue || line.Value == 0)
                return null;

            uint lineValue = line.Value;

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION startPosition = new Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION();
            startPosition.dwLine = lineValue - 1;
            startPosition.dwColumn = 0;

            uint? startColumn = miTuple.TryFindUint("col");
            if (startColumn > 0)
            {
                startPosition.dwColumn = startColumn.Value - 1;
            }

            Microsoft.VisualStudio.Debugger.Interop.TEXT_POSITION endPosition = startPosition;
            uint? endLine = miTuple.TryFindUint("end-line");
            if (endLine > 0)
            {
                endPosition.dwLine = endLine.Value - 1;

                uint? endCol = miTuple.TryFindUint("end-col");
                if (endCol > 0)
                {
                    endPosition.dwColumn = endCol.Value - 1;
                }
            }

            return new MITextPosition(filename, startPosition, endPosition);
        }
Esempio n. 26
0
        internal async Task <uint> ReadProcessMemory(ulong address, uint count, byte[] bytes)
        {
            string  cmd     = "-data-read-memory-bytes " + EngineUtils.AsAddr(address) + " " + count.ToString();
            Results results = await CmdAsync(cmd, ResultClass.None);

            if (results.ResultClass == ResultClass.error)
            {
                return(uint.MaxValue);
            }
            ValueListValue mem = results.Find <ValueListValue>("memory");

            if (mem.IsEmpty())
            {
                return(0);
            }
            TupleValue res = mem.Content[0] as TupleValue;

            if (res == null)
            {
                return(0);
            }
            ulong  start   = res.FindAddr("begin");
            ulong  end     = res.FindAddr("end");
            ulong  offset  = res.FindAddr("offset"); // for some reason this is formatted as hex
            string content = res.FindString("contents");
            uint   toRead  = (uint)content.Length / 2;

            if (toRead > count)
            {
                toRead = count;
            }
            // ensure the buffer contains the desired bytes.
            if (start + offset != address)
            {
                throw new MIException(Constants.E_FAIL);
            }

            for (int pos = 0; pos < toRead; ++pos)
            {
                // Decode one byte
                string strByte = content.Substring(pos * 2, 2);
                bytes[pos] = Convert.ToByte(strByte, 16);
            }
            return(toRead);
        }
Esempio n. 27
0
        private static BindResult EvalBindWatchResult(Results bindResult, AD7PendingBreakpoint pbreak, string address, uint size)
        {
            string errormsg = "Unknown error";

            if (bindResult.ResultClass == ResultClass.error)
            {
                if (bindResult.Contains("msg"))
                {
                    errormsg = bindResult.FindString("msg");
                }
                if (String.IsNullOrWhiteSpace(errormsg))
                {
                    errormsg = "Unknown error";
                }
                return(new BindResult(errormsg));
            }
            else if (bindResult.ResultClass != ResultClass.done)
            {
                return(new BindResult(errormsg));
            }
            TupleValue bkpt = null;

            if (bindResult.Contains("wpt"))
            {
                ResultValue b = bindResult.Find("wpt");
                if (b is TupleValue)
                {
                    bkpt = b as TupleValue;
                }
            }
            else
            {
                return(new BindResult(errormsg));
            }

            string number = bkpt.FindString("number");

            PendingBreakpoint bp  = new PendingBreakpoint(pbreak, number, MIBreakpointState.Single);
            BoundBreakpoint   bbp = new BoundBreakpoint(bp, MICore.Debugger.ParseAddr(address), size);

            return(new BindResult(bp, bbp));
        }
        private Task UpdateStakepoolVotePreferences()
        {
            var voteBits    = CalculateVoteBits();
            var updateTasks = ConfiguredStakePools.OfType <StakePoolSelection>()
                              .Select(sp =>
            {
                var bestApiVersion = PoolApiClient.BestSupportedApiVersion(sp.PoolInfo.SupportedApiVersions);
                return(TupleValue.Create(sp, bestApiVersion));
            })
                              .Where(t => t.Item2 >= 2)
                              .Select(t =>
            {
                var sp             = t.Item1;
                var bestApiVersion = t.Item2;
                var client         = new PoolApiClient(bestApiVersion, sp.PoolInfo.Uri, sp.ApiToken, _httpClient);
                return(client.SetVoteBitsAsync(voteBits));
            });

            return(Task.WhenAll(updateTasks));
        }
Esempio n. 29
0
        public IValue interpret(Context context)
        {
            IValue o = expression.interpret(context);

            if (!(o is TupleValue))
            {
                throw new SyntaxError("Expecting a tuple expression, got " + o.GetType().Name);
            }
            TupleValue tuple = (TupleValue)o;

            for (int i = 0; i < names.Count; i++)
            {
                String name  = names[i];
                IValue value = tuple[i];
                if (context.getRegisteredValue <INamed>(name) == null)
                {
                    context.registerValue(new Variable(name, value.GetIType()));
                }
                context.setValue(name, value);
            }
            return(null);
        }
Esempio n. 30
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong?pc = frame.TryFindAddr("addr");

            // don't report source line info for modules marked as IgnoreSource
            bool ignoreSource = false;

            if (pc != null)
            {
                var module = _debugger.FindModule(pc.Value);
                if (module != null && module.IgnoreSource)
                {
                    ignoreSource = true;
                }
            }
            MITextPosition textPosition = !ignoreSource?MITextPosition.TryParse(this._debugger, frame) : null;

            string func  = frame.TryFindString("func");
            uint   level = frame.FindUint("level");
            string from  = frame.TryFindString("from");

            return(new ThreadContext(pc, textPosition, func, level, from));
        }
Esempio n. 31
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it.
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt)
        {
            string            addrString = bkpt.TryFindString("addr");
            MIBreakpointState state      = StringToBreakpointState(addrString);

            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit.
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return(keyval.Name == "addr"); });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return(null);
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return(null);
            }

            return(new BoundBreakpoint(this, bkpt));
        }
Esempio n. 32
0
 internal BoundBreakpoint(PendingBreakpoint parent, TupleValue bindinfo)
 {
     // CLRDBG TODO: Support clr addresses for breakpoints
     this.Addr = bindinfo.TryFindAddr("addr") ?? 0;
     this.FunctionName = bindinfo.TryFindString("func");
     this.HitCount = 0;
     _parent = parent;
     _textPosition = MITextPosition.TryParse(bindinfo);
 }
Esempio n. 33
0
        /// <summary>
        /// Decode the mi results and create a bound breakpoint from it. 
        /// </summary>
        /// <param name="bkpt">breakpoint description</param>
        /// <returns>null if breakpoint is pending</returns>
        private BoundBreakpoint GetBoundBreakpoint(TupleValue bkpt)
        {
            string addrString = bkpt.TryFindString("addr");
            MIBreakpointState state = StringToBreakpointState(addrString);
            if (state == MIBreakpointState.Multiple)
            {
                // MI gives no way to find the set of addresses a breakpoint is bound to. So bind the breakpoint to address zero until hit. 
                // When the breakpoint is hit can rebind to actual address.
                bkpt.Content.RemoveAll((keyval) => { return keyval.Name == "addr"; });
                bkpt.Content.Add(new NamedResultValue("addr", new ConstValue("0")));
            }
            else if (state == MIBreakpointState.Pending)
            {
                return null;
            }
            else if (!string.IsNullOrEmpty(addrString) && bkpt.FindAddr("addr") == BreakpointManager.INVALID_ADDRESS)
            {
                return null;
            }

            return new BoundBreakpoint(this, bkpt);
        }
Esempio n. 34
0
 private static IEnumerable<DisasmInstruction> DecodeSourceAnnotatedDisassemblyInstructions(TupleValue[] items)
 {
     foreach (var item in items)
     {
         uint line = item.FindUint("line");
         string file = item.FindString("file");
         ValueListValue asm_items = item.Find<ValueListValue>("line_asm_insn");
         uint lineOffset = 0;
         foreach (var asm_item in asm_items.Content)
         {
             DisasmInstruction disassemblyData = new DisasmInstruction();
             disassemblyData.Addr = asm_item.FindAddr("address");
             disassemblyData.AddressString = asm_item.FindString("address");
             disassemblyData.Symbol = asm_item.TryFindString("func-name");
             disassemblyData.Offset = asm_item.Contains("offset") ? asm_item.FindUint("offset") : 0;
             disassemblyData.Opcode = asm_item.FindString("inst");
             disassemblyData.Line = line;
             disassemblyData.File = file;
             if (lineOffset == 0)
             {
                 lineOffset = disassemblyData.Offset;    // offset to start of current line
             }
             disassemblyData.OffsetInLine = disassemblyData.Offset - lineOffset;
             yield return disassemblyData;
         }
     }
 }
Esempio n. 35
0
 public AD7BoundBreakpoint FindHitBreakpoint(string bkptno, ulong addr, /*OPTIONAL*/ TupleValue frame, out bool fContinue)
 {
     fContinue = false;
     lock (_pendingBreakpoints)
     {
         AD7BoundBreakpoint bbp;
         AD7PendingBreakpoint pending = BindToAddress(bkptno, addr, frame, out bbp);
         if (pending == null)
         {
             return null;
         }
         fContinue = true;
         if (!pending.Enabled || pending.Deleted || pending.PendingDelete)
         {
             return null;
         }
         if (!bbp.Enabled || bbp.Deleted)
         {
             return null;
         }
         fContinue = false;
         return bbp;
     }
 }
Esempio n. 36
0
        // Return all bound breakpoints bound to an address including the one withe matching bptno. 
        // Note that there are still cases where gdb won't return the address for a breakpoint 
        // (breakpoint that binds to multiple locations) in which case the bktpno is the best match
        // the engine can do
        private AD7BoundBreakpoint[] FindBoundBreakpointsAtAddress(string bkptno, ulong addr, /*OPTIONAL*/ TupleValue frame)
        {
            // Add all bound bps whose address match
            List<AD7BoundBreakpoint> matchingBoundBreakpoints = new List<AD7BoundBreakpoint>();
            foreach (AD7PendingBreakpoint currPending in CodeBreakpoints)
            {
                matchingBoundBreakpoints.AddRange(Array.FindAll(currPending.EnumBoundBreakpoints(), (b) => b.Addr != 0 && b.Addr == addr));
            }

            // Include the bp whose bkptno matches
            AD7BoundBreakpoint bbp;
            BindToAddress(bkptno, addr, frame, out bbp);
            if (bbp != null)
            {
                matchingBoundBreakpoints.Add(bbp);
            }

            return matchingBoundBreakpoints.Distinct().ToArray();
        }
Esempio n. 37
0
 private AD7PendingBreakpoint BindToAddress(string bkptno, ulong addr, /*OPTIONAL*/ TupleValue frame, out AD7BoundBreakpoint bbp)
 {
     bbp = null;
     AD7PendingBreakpoint pending = CodeBreakpoints.FirstOrDefault((p) => { return p.BreakpointId == bkptno; });
     if (pending == null)
     {
         return null;
     }
     // the breakpoint number is known, check to see if it is known to be bound to this address
     bbp = Array.Find(pending.EnumBoundBreakpoints(), (b) => b.Addr == addr);
     if (bbp == null)
     {
         // add this address as a bound breakpoint
         bbp = Array.Find(pending.EnumBoundBreakpoints(), (b) => b.Addr == 0);
         if (bbp != null)    // <MULTIPLE>
         {
             bbp.UpdateAddr(addr);
         }
         else
         {
             bbp = pending.AddBoundBreakpoint(new BoundBreakpoint(pending.PendingBreakpoint, addr, frame));
         }
     }
     return pending;
 }
Esempio n. 38
0
        private ThreadContext CreateContext(TupleValue frame)
        {
            ulong? pc = frame.TryFindAddr("addr");
            MITextPosition textPosition = MITextPosition.TryParse(frame);
            string func = frame.TryFindString("func");
            uint level = frame.FindUint("level");
            string from = frame.TryFindString("from");

            return new ThreadContext(pc, textPosition, func, level, from);
        }
Esempio n. 39
0
        internal BoundBreakpoint(PendingBreakpoint parent, ulong addr, /*optional*/ TupleValue frame)
        {
            Addr = addr;
            HitCount = 0;
            _parent = parent;

            if (frame != null)
            {
                this.FunctionName = frame.TryFindString("func");
                _textPosition = MITextPosition.TryParse(frame);
            }
        }
Esempio n. 40
0
        public AD7BoundBreakpoint[] FindHitBreakpoints(string bkptno, ulong addr, /*OPTIONAL*/ TupleValue frame, out bool fContinue)
        {
            fContinue = false;
            List<AD7BoundBreakpoint> hitBoundBreakpoints = new List<AD7BoundBreakpoint>();
            // match based on address and bkptno since there are many
            // cases where gdb doesn't provide the breakpoint address (multple binds to the same location)
            // This will cause the engine to send a breakpoint event accounting for all known breakpoints
            // that are hit. 
            // Clrdbg does not support addresses on its breakpoints, so the bkptno code path is the only 
            // supported path in that case
            AD7BoundBreakpoint[] hitBps = FindBoundBreakpointsAtAddress(bkptno, addr, frame);

            foreach (AD7BoundBreakpoint currBoundBp in hitBps)
            {
                if (!currBoundBp.Enabled || currBoundBp.Deleted)
                {
                    continue;
                }

                if (!currBoundBp.PendingBreakpoint.Enabled || currBoundBp.PendingBreakpoint.Deleted || currBoundBp.PendingBreakpoint.PendingDelete)
                {
                    continue;
                }

                hitBoundBreakpoints.Add(currBoundBp);
            }



            fContinue = (hitBoundBreakpoints.Count == 0);
            return hitBoundBreakpoints.Count != 0 ? hitBoundBreakpoints.ToArray() : null;
        }
Esempio n. 41
0
 private static DisasmInstruction[] DecodeDisassemblyInstructions(TupleValue[] items)
 {
     DisasmInstruction[] instructions = new DisasmInstruction[items.Length];
     for (int i = 0; i < items.Length; i++)
     {
         DisasmInstruction inst = new DisasmInstruction();
         inst.Addr = items[i].FindAddr("address");
         inst.AddressString = items[i].FindString("address");
         inst.Symbol = items[i].TryFindString("func-name");
         inst.Offset = items[i].Contains("offset") ? items[i].FindUint("offset") : 0;
         inst.Opcode = items[i].FindString("inst");
         inst.Line = 0;
         inst.File = null;
         instructions[i] = inst;
     }
     return instructions;
 }