예제 #1
0
        public StackFrame[] GetStackFrames(int firstIndex, int lastIndex)
        {
            List <StackFrame> frames = new List <StackFrame> ();

            if (firstIndex == 0 && firstFrame != null)
            {
                frames.Add(firstFrame);
                firstIndex++;
            }

            if (lastIndex >= fcount)
            {
                lastIndex = fcount - 1;
            }

            if (firstIndex > lastIndex)
            {
                return(frames.ToArray());
            }

            session.SelectThread(threadId);
            GdbCommandResult res   = session.RunCommand("-stack-list-frames", firstIndex.ToString(), lastIndex.ToString());
            ResultData       stack = res.GetObject("stack");

            for (int n = 0; n < stack.Count; n++)
            {
                ResultData frd = stack.GetObject(n);
                frames.Add(CreateFrame(frd.GetObject("frame")));
            }
            return(frames.ToArray());
        }
예제 #2
0
        public ObjectValue[] GetParameters(int frameIndex, EvaluationOptions options)
        {
            List <ObjectValue> values = new List <ObjectValue> ();

            SelectFrame(frameIndex);
            GdbCommandResult res = session.RunCommand("-stack-list-arguments", "0", frameIndex.ToString(), frameIndex.ToString());

            foreach (ResultData data in res.GetObject("stack-args").GetObject(0).GetObject("frame").GetObject("args"))
            {
                values.Add(CreateVarObject(data.GetValue("name")));
            }

            return(values.ToArray());
        }
예제 #3
0
        public ObjectValue[] GetLocalVariables(int frameIndex, EvaluationOptions options)
        {
            List <ObjectValue> values = new List <ObjectValue> ();

            SelectFrame(frameIndex);

            GdbCommandResult res = session.RunCommand("-stack-list-locals", "0");

            foreach (ResultData data in res.GetObject("locals"))
            {
                values.Add(CreateVarObject(data.GetValue("name")));
            }

            return(values.ToArray());
        }
예제 #4
0
        public ObjectValue[] GetChildren(ObjectPath path, int index, int count, EvaluationOptions options)
        {
            List <ObjectValue> children = new List <ObjectValue> ();

            session.SelectThread(threadId);
            GdbCommandResult res   = session.RunCommand("-var-list-children", "2", path.Join("."));
            ResultData       cdata = res.GetObject("children");

            // The response may not contain the "children" list at all.
            if (cdata == null)
            {
                return(children.ToArray());
            }

            if (index == -1)
            {
                index = 0;
                count = cdata.Count;
            }

            for (int n = index; n < cdata.Count && n < index + count; n++)
            {
                ResultData data  = cdata.GetObject(n);
                ResultData child = data.GetObject("child");

                string name = child.GetValue("exp");
                if (name.Length > 0 && char.IsNumber(name [0]))
                {
                    name = "[" + name + "]";
                }

                // C++ structures may contain typeless children named
                // "public", "private" and "protected".
                if (child.GetValue("type") == null)
                {
                    ObjectPath    childPath   = new ObjectPath(child.GetValue("name").Split('.'));
                    ObjectValue[] subchildren = GetChildren(childPath, -1, -1, options);
                    children.AddRange(subchildren);
                }
                else
                {
                    ObjectValue val = CreateObjectValue(name, child);
                    children.Add(val);
                }
            }
            return(children.ToArray());
        }
예제 #5
0
 void UpdateHitCountData()
 {
     foreach (BreakEventInfo bp in breakpointsWithHitCount)
     {
         GdbCommandResult res = RunCommand("-break-info", bp.Handle.ToString());
         string           val = res.GetObject("BreakpointTable").GetObject("body").GetObject(0).GetObject("bkpt").GetValue("ignore");
         if (val != null)
         {
             NotifyBreakEventUpdate(bp, int.Parse(val), null);
         }
         else
         {
             NotifyBreakEventUpdate(bp, 0, null);
         }
     }
     breakpointsWithHitCount.Clear();
 }
예제 #6
0
        protected override BreakEventInfo OnInsertBreakEvent(BreakEvent be)
        {
            Breakpoint bp = be as Breakpoint;

            if (bp == null)
            {
                throw new NotSupportedException();
            }

            BreakEventInfo bi = new BreakEventInfo();

            lock (gdbLock) {
                bool dres = InternalStop();
                try {
                    string extraCmd = string.Empty;
                    if (bp.HitCount > 0)
                    {
                        extraCmd += "-i " + bp.HitCount;
                        breakpointsWithHitCount.Add(bi);
                    }
                    if (!string.IsNullOrEmpty(bp.ConditionExpression))
                    {
                        if (!bp.BreakIfConditionChanges)
                        {
                            extraCmd += " -c " + bp.ConditionExpression;
                        }
                    }

                    // Breakpoint locations must be double-quoted if files contain spaces.
                    // For example: -break-insert "\"C:/Documents and Settings/foo.c\":17"

                    RunCommand("-environment-directory", Escape(Path.GetDirectoryName(bp.FileName)));
                    GdbCommandResult res      = null;
                    string           errorMsg = null;
                    try {
                        res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(bp.FileName) + ":" + bp.Line));
                    } catch (Exception ex) {
                        errorMsg = ex.Message;
                    }

                    if (res == null)
                    {
                        try {
                            res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(Path.GetFileName(bp.FileName)) + ":" + bp.Line));
                        }
                        catch {
                            // Ignore
                        }
                    }
                    if (res == null)
                    {
                        bi.SetStatus(BreakEventStatus.Invalid, errorMsg);
                        return(bi);
                    }
                    int bh = res.GetObject("bkpt").GetInt("number");
                    if (!be.Enabled)
                    {
                        RunCommand("-break-disable", bh.ToString());
                    }
                    breakpoints [bh] = bi;
                    bi.Handle        = bh;
                    bi.SetStatus(BreakEventStatus.Bound, null);
                    return(bi);
                } finally {
                    InternalResume(dres);
                }
            }
        }
예제 #7
0
        public CompletionData GetExpressionCompletionData(int frameIndex, string exp)
        {
            SelectFrame(frameIndex);

            bool pointer = exp.EndsWith("->");
            int  i;

            if (pointer || exp.EndsWith("."))
            {
                exp = exp.Substring(0, exp.Length - (pointer ? 2 : 1));
                i   = 0;
                while (i < exp.Length)
                {
                    ObjectValue val = CreateVarObject(exp);
                    if (!val.IsUnknown && !val.IsError)
                    {
                        CompletionData data = new CompletionData();
                        foreach (ObjectValue cv in val.GetAllChildren())
                        {
                            data.Items.Add(new CompletionItem(cv.Name, cv.Flags));
                        }
                        data.ExpressionLenght = 0;
                        return(data);
                    }
                    i++;
                }
                return(null);
            }

            i = exp.Length - 1;
            bool lastWastLetter = false;

            while (i >= 0)
            {
                char c = exp [i--];
                if (!char.IsLetterOrDigit(c) && c != '_')
                {
                    break;
                }
                lastWastLetter = !char.IsDigit(c);
            }

            if (lastWastLetter)
            {
                string partialWord = exp.Substring(i + 1);

                CompletionData cdata = new CompletionData();
                cdata.ExpressionLenght = partialWord.Length;

                // Local variables

                GdbCommandResult res = session.RunCommand("-stack-list-locals", "0");
                foreach (ResultData data in res.GetObject("locals"))
                {
                    string name = data.GetValue("name");
                    if (name.StartsWith(partialWord))
                    {
                        cdata.Items.Add(new CompletionItem(name, ObjectValueFlags.Variable));
                    }
                }

                // Parameters

                res = session.RunCommand("-stack-list-arguments", "0", frameIndex.ToString(), frameIndex.ToString());
                foreach (ResultData data in res.GetObject("stack-args").GetObject(0).GetObject("frame").GetObject("args"))
                {
                    string name = data.GetValue("name");
                    if (name.StartsWith(partialWord))
                    {
                        cdata.Items.Add(new CompletionItem(name, ObjectValueFlags.Parameter));
                    }
                }

                if (cdata.Items.Count > 0)
                {
                    return(cdata);
                }
            }
            return(null);
        }
예제 #8
0
        protected override object OnInsertBreakEvent(BreakEvent be, bool activate)
        {
            Breakpoint bp = be as Breakpoint;

            if (bp == null)
            {
                return(null);
            }

            lock (gdbLock) {
                bool dres = InternalStop();
                try {
                    string extraCmd = string.Empty;
                    if (bp.HitCount > 0)
                    {
                        extraCmd += "-i " + bp.HitCount;
                        breakpointsWithHitCount.Add(bp);
                    }
                    if (!string.IsNullOrEmpty(bp.ConditionExpression))
                    {
                        if (!bp.BreakIfConditionChanges)
                        {
                            extraCmd += " -c " + bp.ConditionExpression;
                        }
                    }

                    // Breakpoint locations must be double-quoted if files contain spaces.
                    // For example: -break-insert "\"C:/Documents and Settings/foo.c\":17"

                    RunCommand("-environment-directory", Escape(Path.GetDirectoryName(bp.FileName)));
                    GdbCommandResult res      = null;
                    string           errorMsg = null;
                    try {
                        res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(bp.FileName) + ":" + bp.Line));
                    } catch (Exception ex) {
                        errorMsg = ex.Message;
                    }

                    if (res == null)
                    {
                        try {
                            res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(Path.GetFileName(bp.FileName)) + ":" + bp.Line));
                        }
                        catch {
                            // Ignore
                        }
                    }
                    if (res == null)
                    {
                        OnDebuggerOutput(true, "Could not set breakpoint: " + errorMsg);
                        return(null);
                    }
                    int bh = res.GetObject("bkpt").GetInt("number");
                    if (!activate)
                    {
                        RunCommand("-break-disable", bh.ToString());
                    }
                    breakpoints [bh] = bp;
                    return(bh);
                } finally {
                    InternalResume(dres);
                }
            }
        }