Ejemplo n.º 1
0
        public Target(DebugView view)
            : base(view)
        {
            _window = new Window(10, 10, 30, 7, "Target");
            _window.Visible = false;
            View.Desktop.Add(_window);

            var codeError = new Label(1, 1, 26, 2, "");
            _window.Add(codeError);

            _codeText = new TextBox(1, 3, 18);
            _window.Add(_codeText);

            var codeButton = new Button(20, 3, 7, "Load");
            codeButton.Clicked += () =>
            {
                if (Target == null || _codeText.Value.Length == 0)
                    return;

                try
                {
                    Target.Load(Assets.ReloadCode(_codeText.Value));
                    codeError.Caption = "";
                    _needUpdate = true;
                }
                catch
                {
                    codeError.Caption = "Failed to load code";
                }
            };
            _window.Add(codeButton);

            // TODO: put target stats in this window

            _needUpdate = true;
        }
Ejemplo n.º 2
0
        public Cpu(DebugView view)
            : base(view)
        {
            #region Widget Creation
            _window = new Window(10, 10, 110, 41, "CPU");
            View.Desktop.Add(_window);

            _disassembly = new Disassembly(1, 1, 79, 37);
            _disassembly.Clicked += (addr, button) =>
            {
                if (Target == null)
                    return;

                if (button == Mouse.Button.Left)
                    Target.AddBreakpoint(addr);
                else if (button == Mouse.Button.Right)
                    Target.RemoveBreakpoint(addr);
            };
            _window.Add(_disassembly);

            var y = 1;

            _registers = new Label[RegisterNames.Length];
            for (var i = 0; i < _registers.Length; i++, y++)
            {
                _registers[i] = new Label(82, y, 25, 1, "");
                _window.Add(_registers[i]);
            }

            y++;

            _flags = new Label[FlagNames.Length];
            for (var i = 0; i < _flags.Length; i++, y++)
            {
                _flags[i] = new Label(82, y, 25, 1, "");
                _window.Add(_flags[i]);
            }

            y++;
            _ivt = new Label(82, y++, 25, 1, "");
            _window.Add(_ivt);

            _error = new Label(82, ++y, 25, 4, "");
            _window.Add(_error);

            _skipInterrupt = new Checkbox(82, 29, 25, "Skip Interrupts");
            _skipInterrupt.Changed += () =>
            {
                if (Target != null)
                    Target.SkipInterrupts = _skipInterrupt.Checked;
            };
            _window.Add(_skipInterrupt);

            _step = new Button(82, 31, 25, "Step");
            _step.Clicked += () =>
            {
                if (Target == null || !Target.Paused)
                    return;

                Target.Step = true;
                _autoMove = true;
            };
            _window.Add(_step);

            _pause = new Button(82, 34, 25, "Pause");
            _pause.Clicked += () =>
            {
                if (Target == null)
                    return;

                if (!Target.Paused)
                    _autoMove = true;

                Target.Paused = !Target.Paused;
                Target.Step = true;
            };
            _window.Add(_pause);

            var gotoInput = new TextBox(82, 37, 17);
            _window.Add(gotoInput);

            var gotoButton = new Button(100, 37, 7, "Goto");
            gotoButton.Clicked += () =>
            {
                if (Target == null || gotoInput.Value.Length == 0)
                    return;

                try
                {
                    _gotoError = null;
                    var expr = WatchExpression.Compile(gotoInput.Value);
                    Goto(expr(Target));
                }
                catch (Exception e)
                {
                    _gotoError = string.Format("Goto: {0}", e.Message);
                }
            };
            _window.Add(gotoButton);
            #endregion
        }
Ejemplo n.º 3
0
        public Watch(DebugView view)
            : base(view)
        {
            _window = new Window(25, 25, 80, 25, "Watch");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _watchView = new ListView<WatchItem>(1, 1, 76, 19);
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Name", 14, w => w.Name));
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Expression", 40, w => w.Expression, false));
            _watchView.Columns.Add(new ListView<WatchItem>.Column("Value", 20, null, false, w =>
            {
                if (Target == null)
                    return "No Target";

                if (w.Error != null)
                    return w.Error;

                try
                {
                    var value = w.Function(Target);
                    return string.Format("{0:X8} {0,11}", value);
                }
                catch (WatchException e)
                {
                    return e.Message;
                }
                catch
                {
                    return "Error";
                }
            }));

            _watchView.Clicked += (item, button) =>
            {
                if (button == Mouse.Button.Right)
                {
                    _watchView.Items.Remove(item);
                }
                else if (button == Mouse.Button.Middle)
                {
                    _editing = item;
                    _name.Value = _editing.Name;
                    _expression.Value = _editing.Expression;
                }
            };

            _window.Add(_watchView);

            _name = new TextBox(1, 21, 13);
            _window.Add(_name);

            _expression = new TextBox(15, 21, 50);
            _window.Add(_expression);

            _button = new Button(66, 21, 11, "Add");
            _button.Clicked += () =>
            {
                if (_expression.Value.Length == 0)
                    return;

                WatchItem item;

                if (_editing == null)
                {
                    item = new WatchItem();
                    _watchView.Items.Add(item);
                }
                else
                {
                    item = _editing;
                }

                item.Name = _name.Value;
                item.Expression = _expression.Value;

                try
                {
                    item.Function = WatchExpression.Compile(item.Expression);
                    item.Error = null;
                }
                catch (WatchException e)
                {
                    item.Error = e.Message;
                }

                _name.Value = "";
                _expression.Value = "";
                _editing = null;
            };
            _window.Add(_button);
        }