コード例 #1
0
ファイル: Program.cs プロジェクト: jncronin/tysos
        private static void main_loop()
        {
            Console.WriteLine("Synchronizing with target...");
            comm.gdb_send_message("?");
            await.state s = await.get_state();
            Console.WriteLine(s.ToString());

            bool cont = true;

            string[] prev_cmd = null;
            while (cont)
            {
                Console.Write("(tydb) ");
                string   orig_cmd_line = Console.ReadLine();
                string[] cmd_line      = orig_cmd_line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (cmd_line.Length == 0)
                {
                    if (prev_cmd != null)
                    {
                        cmd_line = prev_cmd;
                    }
                    else
                    {
                        continue;
                    }
                }

                string cmd = cmd_line[0];
                if ((cmd == "q") || (cmd == "quit") || (cmd == "exit"))
                {
                    cont = false;
                }
                else if ((cmd == "c") || (cmd == "cont") || (cmd == "continue"))
                {
                    comm.gdb_send_message("c");
                    s = await.get_state();
                    Console.WriteLine(s.ToString());
                }
                else if ((cmd == "si") || (cmd == "stepi"))
                {
                    comm.gdb_send_message("s");
                    s = await.get_state();
                    Console.WriteLine(s.ToString());
                }
                else if ((cmd == "s") || (cmd == "step"))
                {
                    do
                    {
                        comm.gdb_send_message("s");
                        s = await.get_state();
                    } while (s.source == null);
                    Console.WriteLine(s.ToString());
                }
                else if ((cmd == "r") || (cmd == "regs") || (cmd == "registers"))
                {
                    regs.dump_regs();
                }
                else if ((cmd == "bp") || (cmd == "break") || (cmd == "breakpoint"))
                {
                    string addr = cmd_line[1];
                    if (addr.StartsWith("0x"))
                    {
                        addr = addr.Substring(2);
                    }
                    ulong uaddr = ulong.Parse(addr, System.Globalization.NumberStyles.HexNumber);
                    comm.gdb_send_message("Z0," + uaddr.ToString("X16") + ",1");
                    if (comm.gdb_read_message() == "OK")
                    {
                        Console.WriteLine("Breakpoint set");
                    }
                    else
                    {
                        Console.WriteLine("Error setting breakpoint");
                    }
                }
                else if ((cmd == "x") || (cmd == "?"))
                {
                    //ulong addr = ulong.Parse(cmd_line[1], System.Globalization.NumberStyles.HexNumber);
                    //obj obj = obj.get_obj(addr);
                    if (s.ty_f != null)
                    {
                        libtysila.tydb.VarArg va = s.ty_f.GetVarArg(cmd_line[1]);

                        if (va != null)
                        {
                            if (va.Location.Type == libtysila.tydb.Location.LocationType.Register)
                            {
                                cmd_line[1] = va.Location.RegisterName;
                            }
                            else if (va.Location.Type == libtysila.tydb.Location.LocationType.ContentsOfLocation)
                            {
                                if (va.Location.ContentsOf.Type == libtysila.tydb.Location.LocationType.Register)
                                {
                                    ulong?val = await.get_register(s, Program.arch.get_reg(va.Location.ContentsOf.RegisterName).id);
                                    if (val.HasValue)
                                    {
                                        ulong mem_loc = val.Value;
                                        if (va.Location.Offset >= 0)
                                        {
                                            mem_loc += (ulong)va.Location.Offset;
                                        }
                                        else
                                        {
                                            mem_loc -= (ulong)(-va.Location.Offset);
                                        }

                                        cmd_line[1] = "*" + mem_loc.ToString("x" + (Program.arch.address_size * 2).ToString());
                                    }
                                }
                            }
                        }
                    }

                    dbgarch.register r = arch.get_reg(cmd_line[1]);
                    if (r != null)
                    {
                        ulong?val = await.get_register(new await.state(), r.id);
                        Console.WriteLine(r.name + " = " + (val.HasValue ? val.Value.ToString("x" + (arch.data_size * 2).ToString()) : "unknown"));
                    }
                    else
                    {
                        obj obj = var.get_var(cmd_line[1]);
                        if (obj == null)
                        {
                            Console.WriteLine("Syntax Error");
                        }
                        else
                        {
                            Console.WriteLine(obj.addr.ToString("x" + (arch.address_size * 2).ToString()) + " = " + obj.ToString());
                        }
                    }
                }
                else if (cmd == "set")
                {
                    if (orig_cmd_line == "set")
                    {
                        foreach (KeyValuePair <string, obj> kvp in var.vars)
                        {
                            Console.WriteLine(kvp.Key + " = " + kvp.Value.ToString());
                        }
                        continue;
                    }

                    int eq_pos = orig_cmd_line.IndexOf('=');

                    if (eq_pos == -1)
                    {
                        Console.WriteLine("Syntax Error");
                        continue;
                    }

                    string var_n = orig_cmd_line.Substring(4, eq_pos - 4).Trim();
                    string arg   = orig_cmd_line.Substring(eq_pos + 1).Trim();

                    if (var_n.Contains(" ") || arg.Contains(" "))
                    {
                        Console.WriteLine("Syntax Error");
                        continue;
                    }

                    obj o = var.get_var(arg);
                    if (o == null)
                    {
                        Console.WriteLine("Syntax Error");
                    }
                    else
                    {
                        var.vars[var_n] = o;
                    }
                }
                else
                {
                    Console.WriteLine("Unrecognized command: " + cmd);
                    prev_cmd = null;
                    continue;
                }

                prev_cmd = cmd_line;
            }
        }
コード例 #2
0
ファイル: await.cs プロジェクト: jncronin/tysos
        private static void read_t_reg(ref int x, string msg, state s, bool is_t_response, int reg_id)
        {
            if (((msg[x] >= '0') && (msg[x] <= '9')) || ((msg[x] >= 'a') && (msg[x] <= 'f')))
            {
                if (is_t_response)
                {
                    int reg_count = 1;
                    if ((msg[x + 1] >= '0') && (msg[x + 1] <= '9') || ((msg[x + 1] >= 'a') && (msg[x + 1] <= 'f')))
                    {
                        reg_count = 2;
                    }
                    string reg_id_str = msg.Substring(x, reg_count);
                    x     += reg_count;
                    reg_id = Int32.Parse(reg_id_str, System.Globalization.NumberStyles.HexNumber);

                    string colon = msg.Substring(x, 1);
                    if (colon != ":")
                    {
                        throw new Exception("Invalid stop-reply response");
                    }
                    x++;
                }

                if ((reg_id < 0) || (reg_id >= Program.arch.registers.Length))
                {
                    throw new Exception("Invalid register number: " + reg_id.ToString());
                }

                dbgarch.register reg_def = Program.arch.registers[reg_id];

                if (reg_def.length == 8)
                {
                    if (msg.Substring(x, 16) == "xxxxxxxxxxxxxxxx")
                    {
                        s.regs[reg_id] = null;
                    }
                    else
                    {
                        s.regs[reg_id] = read_machine_byte_order_ulong(msg.Substring(x, 16));
                    }
                    x += 16;
                }
                else if (reg_def.length == 4)
                {
                    if (msg.Substring(x, 8) == "xxxxxxxxx")
                    {
                        s.regs[reg_id] = null;
                    }
                    else
                    {
                        s.regs[reg_id] = read_machine_byte_order_uint(msg.Substring(x, 8));
                    }
                    x += 8;
                }
                else
                {
                    throw new Exception("Invalid register length for register " + reg_def.name + ": " + reg_def.length.ToString());
                }

                if (is_t_response)
                {
                    x++;    // semicolon at end
                }
            }
            else
            {
                throw new Exception("Unknown stop message: " + msg + " at index " + x.ToString());
            }
        }
コード例 #3
0
ファイル: var.cs プロジェクト: jncronin/tysos
        internal static obj get_var(string name)
        {
            if (name.Contains("."))
            {
                // Composite value
                string[] names = name.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);

                obj o = get_var(names[0]);
                if (o == null)
                {
                    return(null);
                }

                for (int i = 1; i < names.Length; i++)
                {
                    obj.field found = null;

                    if (o.value is obj.field[])
                    {
                        obj.field[] fs = o.value as obj.field[];

                        foreach (obj.field f in fs)
                        {
                            if (f.name == names[i])
                            {
                                found = f;
                                break;
                            }
                        }
                    }

                    if (found == null)
                    {
                        Console.WriteLine(o.type + " does not contain field " + names[i]);
                        return(null);
                    }

                    if (found.is_vt)
                    {
                        obj new_o = new obj();
                        new_o.addr  = o.addr + (ulong)found.offset;
                        new_o.is_vt = true;
                        new_o.type  = found.type;
                        new_o.value = mem.get_mem(new_o.addr, (int)found.size);
                        o           = new_o;
                    }
                    else
                    {
                        o = obj.get_obj((ulong)found.value);
                    }
                }

                return(o);
            }

            if (vars.ContainsKey(name))
            {
                vars[name] = obj.get_obj(vars[name].addr);
                return(vars[name]);
            }

            if (name.StartsWith("[") && name.EndsWith("]"))
            {
                string reg_name = name.Substring(1, name.Length - 2);

                dbgarch.register r = Program.arch.get_reg(reg_name);
                if (r == null)
                {
                    return(null);
                }

                ulong?r_val = await.get_register(new await.state(), r.id);
                if (r_val.HasValue)
                {
                    return(obj.get_obj(r_val.Value));
                }
                else
                {
                    return(null);
                }
            }

            if (name.StartsWith("*"))
            {
                string mem_addr = name.Substring(1);
                if (mem_addr.StartsWith("0x"))
                {
                    mem_addr = mem_addr.Substring(2);
                }

                try
                {
                    ulong m_addr_u = ulong.Parse(mem_addr, System.Globalization.NumberStyles.HexNumber);
                    return(obj.get_obj(m_addr_u));
                }
                catch (Exception)
                {
                    return(null);
                }
            }

            return(null);
        }