public override AssemblyLine[] GetLines(long startAddr, long endAddr)
        {
            GdbCommandResult data = null;

            data = session.RunCommand("-data-disassemble", "-s", startAddr.ToString(), "-e", endAddr.ToString(), "--", "0");

            if (data.Status == CommandStatus.Done)
            {
                ResultData ins = data.GetObject("asm_insns");

                AssemblyLine[] alines = new AssemblyLine[ins.Count];

                for (int n = 0; n < ins.Count; n++)
                {
                    ResultData   aline = ins.GetObject(n);
                    long         addr  = long.Parse(aline.GetValue("address").Substring(2), NumberStyles.HexNumber);
                    AssemblyLine line  = new AssemblyLine(addr, aline.GetValue("inst"));
                    alines[n] = line;
                }

                return(alines);
            }
            else
            {
                long           range    = endAddr - startAddr;
                AssemblyLine[] badlines = new AssemblyLine[range];
                for (int n = 0; n < range; n++)
                {
                    badlines[n] = new AssemblyLine(startAddr + n, "Unable to read data.");
                }

                return(badlines);
            }
        }
Beispiel #2
0
        private BreakEventInfo OnInsertWatchPoint(BreakEvent be)
        {
            var bi = new BreakEventInfo();
            var wp = be as WatchPoint;

            lock (gdbLock)
            {
                bool dres = InternalStop();
                try
                {
                    string           errorMsg = string.Empty;
                    GdbCommandResult res      = null;

                    try
                    {
                        if (wp.TriggerOnRead && wp.TriggerOnWrite)
                        {
                            res = RunCommand("-break-watch", wp.Expression, "-a");
                        }
                        else if (wp.TriggerOnRead && !wp.TriggerOnWrite)
                        {
                            res = RunCommand("-break-watch", wp.Expression, "-r");
                        }
                        else
                        {
                            res = RunCommand("-break-watch", wp.Expression);
                        }
                    }
                    catch (Exception ex)
                    {
                        errorMsg = ex.Message;
                    }

                    if (res == null || res.Status != CommandStatus.Done)
                    {
                        bi.SetStatus(BreakEventStatus.Invalid, errorMsg);
                        return(bi);
                    }

                    int bh = res.GetObject("wpt").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);
                }
            }
        }
Beispiel #3
0
        protected override AssemblyLine[] OnDisassembleFile(string file)
        {
            List <AssemblyLine> lines = new List <AssemblyLine>();
            int cline = 1;

            do
            {
                GdbCommandResult data = null;
                try
                {
                    data = RunCommand("-data-disassemble", "-f", file, "-l", cline.ToString(), "--", "1");
                }
                catch
                {
                    break;
                }

                int newLine = cline;

                if (data.Status == CommandStatus.Done)
                {
                    ResultData asm_insns = data.GetObject("asm_insns");

                    for (int n = 0; n < asm_insns.Count; n++)
                    {
                        ResultData src_and_asm_line = asm_insns.GetObject(n).GetObject("src_and_asm_line");
                        newLine = src_and_asm_line.GetInt("line");
                        ResultData line_asm_insn = src_and_asm_line.GetObject("line_asm_insn");
                        for (int i = 0; i < line_asm_insn.Count; i++)
                        {
                            ResultData asm  = line_asm_insn.GetObject(i);
                            long       addr = long.Parse(asm.GetValue("address").Substring(2), NumberStyles.HexNumber);
                            string     code = asm.GetValue("inst");
                            lines.Add(new AssemblyLine(addr, code, newLine));
                        }
                    }
                }

                if (newLine <= cline)
                {
                    break;
                }

                cline = newLine + 1;
            }while (true);

            return(lines.ToArray());
        }
Beispiel #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());
        }
Beispiel #5
0
 private 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();
 }
Beispiel #6
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());

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

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

            SelectFrame(frameIndex);

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

            if (res.Status == CommandStatus.Done)
            {
                foreach (ResultData data in res.GetObject("locals"))
                {
                    values.Add(CreateVarObject(data.GetValue("name")));
                }
            }

            return(values.ToArray());
        }
Beispiel #8
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());

            if (res.Status == CommandStatus.Done)
            {
                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());
        }
Beispiel #9
0
        private BreakEventInfo OnInsertBreakPoint(BreakEvent be)
        {
            var bi = new BreakEventInfo();
            var bp = be as Breakpoint;

            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;
                        }
                    }

                    GdbCommandResult res      = null;
                    string           errorMsg = null;

                    if (bp is FunctionBreakpoint)
                    {
                        try
                        {
                            res = RunCommand("-break-insert", extraCmd.Trim(), ((FunctionBreakpoint)bp).FunctionName);
                        }
                        catch (Exception ex)
                        {
                            errorMsg = ex.Message;
                        }
                    }
                    else
                    {
                        // 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).ToAvalonPath()));

                        try
                        {
                            res = RunCommand("-break-insert", extraCmd.Trim(), Escape(Escape(bp.FileName.ToAvalonPath()) + ":" + 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 || res.Status != CommandStatus.Done)
                    {
                        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);
                }
            }
        }
Beispiel #10
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.ExpressionLength = 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.ExpressionLength = 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);
        }