Example #1
0
        private void ReceivedEvaluateResponse(DAPRequest request, DAPEvaulateRequest req, ThreadState state, BkEvaluateResponse response)
        {
            DAPEvaluateResponse evalResponse = new DAPEvaluateResponse
            {
                result             = "",
                namedVariables     = 0,
                indexedVariables   = 0,
                variablesReference = 0,
            };

            if (response.Result == null)
            {
                evalResponse.result = "(None)";
            }
            else
            {
                evalResponse.result = DbgValueToString(response.Result);

                if (response.Result.Variables != null)
                {
                    var varsRef = BackendVariableReference.FromDbg(state.Context, response.Result.Variables);
                    var varsIdx = NextVariableReference++;
                    VariableRefs.Add(varsIdx, varsRef);
                    evalResponse.variablesReference = MakeVariableRef(varsIdx);
                }
            }

            DAP.Stream.SendReply(request, evalResponse);
        }
Example #2
0
        public static BackendVariableReference FromDbg(DbgContext context, MsgVariablesRef dbgRef)
        {
            var ret = new BackendVariableReference
            {
                Context     = context,
                VariableRef = dbgRef.VariableRef,
                Frame       = dbgRef.Frame,
                Local       = dbgRef.Local,
                Keys        = new List <Key>()
            };

            if (dbgRef.Key != null)
            {
                foreach (var key in dbgRef.Key)
                {
                    if (key.Type == MsgTableKey.Types.Type.Numeric)
                    {
                        ret.Keys.Add(new Key
                        {
                            Index = key.Index
                        });
                    }
                    else
                    {
                        ret.Keys.Add(new Key
                        {
                            String = key.Key
                        });
                    }
                }
            }

            return(ret);
        }
Example #3
0
        private void OnVariablesReceived(DAPRequest request, DAPVariablesRequest msg, ThreadState state, BkGetVariablesResponse response)
        {
            int startIndex = msg.start == null ? 0 : (int)msg.start;
            int numVars    = (msg.count == null || msg.count == 0) ? response.Result.Count : (int)msg.count;
            int lastIndex  = Math.Min(startIndex + numVars, response.Result.Count);
            // TODO req.filter, format

            var variables = new List <DAPVariable>();

            for (var i = startIndex; i < startIndex + numVars; i++)
            {
                var variable = response.Result[i];
                var dapVar   = new DAPVariable
                {
                    value = DbgValueToString(variable.Value),
                    type  = variable.Value.TypeId.ToString()
                };

                if (variable.Type == MsgChildValue.Types.Type.Numeric)
                {
                    dapVar.name = variable.Index.ToString();
                }
                else
                {
                    dapVar.name = variable.Name;
                }


                if (variable.Value.Variables != null)
                {
                    var varsRef = BackendVariableReference.FromDbg(state.Context, variable.Value.Variables);
                    var varsIdx = NextVariableReference++;
                    VariableRefs.Add(varsIdx, varsRef);
                    dapVar.variablesReference = MakeVariableRef(varsIdx);
                }

                variables.Add(dapVar);
            }

            var reply = new DAPVariablesResponse
            {
                variables = variables
            };

            DAP.Stream.SendReply(request, reply);
        }
Example #4
0
        private void RequestStackVariables(DAPRequest request, DAPVariablesRequest msg, int threadId, int frameIndex, int scopeIndex)
        {
            var state = DAP.GetThread(threadId);

            if (!state.Stopped)
            {
                throw new RequestFailedException("Cannot get scopes when thread is not stopped");
            }

            if (frameIndex < 0 || frameIndex >= state.Stack.Count)
            {
                throw new RequestFailedException($"Requested variables for unknown frame {frameIndex}");
            }

            var varRef = new BackendVariableReference();

            varRef.Context     = state.Context;
            varRef.VariableRef = -1;
            varRef.Frame       = frameIndex;
            varRef.Local       = -1;
            uint seq = DAP.DbgCli.SendGetVariables(varRef);

            PendingGetVariablesRequests.Add(seq, (uint replySeq, StatusCode status, BkGetVariablesResponse response) =>
            {
                if (status == StatusCode.Success)
                {
                    // Filter locals/upvalues based on requested scope type
                    var results = response.Result.Where(result => ((result.Index >= 0) == (scopeIndex == 0))).ToList();
                    response.Result.Clear();
                    response.Result.AddRange(results);

                    OnVariablesReceived(request, msg, state, response);
                }
                else if (status == StatusCode.EvalFailed && response != null)
                {
                    DAP.Stream.SendReply(request, response.ErrorMessage);
                }
                else
                {
                    DAP.Stream.SendReply(request, $"Backend returned error: {status}");
                }
            });
        }
Example #5
0
        public UInt32 SendGetVariables(BackendVariableReference vref)
        {
            var eval = new DbgGetVariables
            {
                Context     = vref.Context,
                VariableRef = vref.VariableRef,
                Frame       = vref.Frame,
                Local       = vref.Local
            };

            if (vref.Keys != null)
            {
                foreach (var key in vref.Keys)
                {
                    var keyItem = new MsgTableKey();
                    if (key.String != null)
                    {
                        keyItem.Type = MsgTableKey.Types.Type.Text;
                        keyItem.Key  = key.String;
                    }
                    else
                    {
                        keyItem.Type  = MsgTableKey.Types.Type.Numeric;
                        keyItem.Index = key.Index.Value;
                    }

                    eval.Key.Add(keyItem);
                }
            }

            var msg = new DebuggerToBackend
            {
                GetVariables = eval
            };

            return(Send(msg));
        }