Esempio n. 1
0
        public Profiler(DebugView view)
            : base(view)
        {
            _window = new Window(30, 30, 60, 25, "Profiler");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _profilerView = new ListView<ProfilerItem>(1, 1, 56, 19);
            _profilerView.Columns.Add(new ListView<ProfilerItem>.Column("Function", 43, p => p.Function));
            _profilerView.Columns.Add(new ListView<ProfilerItem>.Column("Samples", 11, p => p.Samples, true, p => string.Format("{0,11:P}", p.Samples / (float)_totalSamples)));
            _window.Add(_profilerView);

            _start = new Button(1, 21, 10, "Start");
            _start.Clicked += () =>
            {
                if (Target == null)
                    return;

                if (!_profiling)
                    Reset();

                _profiling = !_profiling;
            };

            _window.Add(_start);

            _message = new Label(13, 21, 40, 1, "Profiling requires debug information");
            _window.Add(_message);

            _profiling = false;
            _items = new Dictionary<string, ProfilerItem>();
            _totalSamples = 0;
        }
Esempio n. 2
0
        public Options(DebugView view)
            : base(view)
        {
            #region Widget Creation
            _window = new Window(5, 5, 30, 5, "Options");
            _window.Visible = false;
            View.Desktop.Add(_window);

            var timeScaleLabel = new Label(1, 1, 13, 1, "TimeScale %:");
            _window.Add(timeScaleLabel);

            _timeScaleText = new NumericTextBox(14, 1, 13);
            _timeScaleText.Minimum = 0;
            _timeScaleText.Maximum = 200;
            _timeScaleText.Changed += () => Program.TimeScale = _timeScaleText.Value / 100f;

            _window.Add(_timeScaleText);
            #endregion
        }
Esempio n. 3
0
        public Breakpoints(DebugView view)
            : base(view)
        {
            _window = new Window(15, 15, 60, 25, "Breakpoints");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _breakpointList = new ListView<int>(1, 1, 56, 21);

            _breakpointList.Columns.Add(new ListView<int>.Column("Name", 43, null, false, addr =>
            {
                if (Target == null || Target.Code.DebugInfo == null)
                    return addr.ToString("X8");

                var debugInfo = Target.Code.DebugInfo;
                var symbol = debugInfo.FindSymbol(addr);
                if (!symbol.HasValue)
                    return addr.ToString("X8");

                return string.Format("{0}+0x{1}", symbol.Value.Name, addr - symbol.Value.Address);
            }));

            _breakpointList.Columns.Add(new ListView<int>.Column("Address", 11, null, false, addr => string.Format("{0,11:X8}", addr)));

            _breakpointList.Clicked += (addr, button) =>
            {
                if (Target == null)
                    return;

                if (button == Mouse.Button.Left)
                    View.Get<Cpu>().Goto(addr);
                else if (button == Mouse.Button.Right)
                    Target.RemoveBreakpoint(addr);
            };

            _window.Add(_breakpointList);
        }
Esempio n. 4
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;
        }
Esempio n. 5
0
        public Symbols(DebugView view)
            : base(view)
        {
            _window = new Window(20, 20, 60, 25, "Symbols");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _symbolList = new ListView<ShipDebug.Symbol>(1, 1, 56, 21);
            _symbolList.Columns.Add(new ListView<ShipDebug.Symbol>.Column("Name", 43, s => s.Name));
            _symbolList.Columns.Add(new ListView<ShipDebug.Symbol>.Column("Address", 11, s => s.Address, true, s => string.Format("{0,11:X8}", s.Address)));

            _symbolList.Clicked += (symbol, button) =>
            {
                if (Target == null)
                    return;

                if (button == Mouse.Button.Left)
                    View.Get<Cpu>().Goto(symbol.Address);
                else if (button == Mouse.Button.Right)
                    View.Get<Memory>().Goto(symbol.Address);
            };

            _window.Add(_symbolList);
        }
Esempio n. 6
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
        }
Esempio n. 7
0
        public Memory(DebugView view)
            : base(view)
        {
            #region Widget Creation
            _window = new Window(15, 15, 81, 41, "Memory");
            _window.Visible = false;
            View.Desktop.Add(_window);

            _editor = new HexEditor(1, 1, 77, 36, 16);
            _window.Add(_editor);

            _offset = new Label(1, 38, 26, 1, "");
            _window.Add(_offset);

            var byteLabel = new Label(40, 38, 4, 1, "B");
            _window.Add(byteLabel);

            _byteText = new NumericTextBox(42, 38, 10);
            _byteText.Minimum = sbyte.MinValue;
            _byteText.Maximum = sbyte.MaxValue;
            _byteText.Changed += () =>
            {
                if (_editor.Buffer == null)
                    return;

                try
                {
                    var byteOffset = _editor.SelectedOffset / 2;
                    _editor.Buffer.WriteSByte(byteOffset, (sbyte)_byteText.Value);
                }
                catch { }
            };

            _window.Add(_byteText);

            var wordLabel = new Label(53, 38, 0, 1, "W");
            _window.Add(wordLabel);

            _wordText = new NumericTextBox(55, 38, 10);
            _wordText.Minimum = short.MinValue;
            _wordText.Maximum = short.MaxValue;
            _wordText.Changed += () =>
            {
                if (_editor.Buffer == null)
                    return;

                try
                {
                    var byteOffset = _editor.SelectedOffset / 2;
                    _editor.Buffer.WriteShort(byteOffset, (short)_wordText.Value);
                }
                catch { }
            };

            _window.Add(_wordText);

            var dwordLabel = new Label(66, 38, 0, 1, "D");
            _window.Add(dwordLabel);

            _dwordText = new NumericTextBox(68, 38, 10);
            _dwordText.Minimum = int.MinValue;
            _dwordText.Maximum = int.MaxValue;
            _dwordText.Changed += () =>
            {
                if (_editor.Buffer == null)
                    return;

                try
                {
                    var byteOffset = _editor.SelectedOffset / 2;
                    _editor.Buffer.WriteInt(byteOffset, _dwordText.Value);
                }
                catch { }
            };

            _window.Add(_dwordText);
            #endregion
        }
Esempio n. 8
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);
        }