예제 #1
0
        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);
            }
        }
예제 #2
0
        private ObjectValue CreateObjectValue(string name, ResultData data)
        {
            string vname    = data.GetValue("name");
            string typeName = data.GetValue("type");
            string value    = data.GetValue("value");
            int    nchild   = data.GetInt("numchild");

            ObjectValue      val;
            ObjectValueFlags flags = ObjectValueFlags.Variable;

            // There can be 'public' et al children for C++ structures
            if (typeName == null)
            {
                typeName = "none";
            }

            if (typeName.EndsWith("]"))
            {
                val = ObjectValue.CreateArray(this, new ObjectPath(vname), typeName, nchild, flags, null);
            }
            else if (value == "{...}" || typeName.EndsWith("*") || nchild > 0)
            {
                val = ObjectValue.CreateObject(this, new ObjectPath(vname), typeName, value, flags, null);
            }
            else
            {
                val = ObjectValue.CreatePrimitive(this, new ObjectPath(vname), typeName, new EvaluationResult(value), flags);
            }
            val.Name = name;
            return(val);
        }
예제 #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());
        }
예제 #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
        private StackFrame CreateFrame(ResultData frameData)
        {
            string lang = "Native";
            string func = frameData.GetValue("func");
            string sadr = frameData.GetValue("addr");

            if (func == "??" && session.IsMonoProcess)
            {
                // Try to get the managed func name
                try
                {
                    ResultData data = session.RunCommand("-data-evaluate-expression", "mono_pmip(" + sadr + ")");
                    string     val  = data.GetValue("value");
                    if (val != null)
                    {
                        int i = val.IndexOf('"');
                        if (i != -1)
                        {
                            func = val.Substring(i).Trim('"', ' ');
                            lang = "Mono";
                        }
                    }
                }
                catch
                {
                }
            }

            int    line  = -1;
            string sline = frameData.GetValue("line");

            if (sline != null)
            {
                line = int.Parse(sline);
            }

            string sfile = frameData.GetValue("fullname");

            if (sfile == null)
            {
                sfile = frameData.GetValue("file");
            }
            if (sfile == null)
            {
                sfile = frameData.GetValue("from");
            }
            SourceLocation loc = new SourceLocation(func ?? "?", sfile, line);

            long addr;

            if (!string.IsNullOrEmpty(sadr))
            {
                addr = long.Parse(sadr.Substring(2), NumberStyles.HexNumber);
            }
            else
            {
                addr = 0;
            }

            return(new StackFrame(addr, loc, lang));
        }