public void JumpToMethod( MethodBody method )
 {
     this.CodeTool.Show( this.Window.DockPanel );
     this.CodeTool.BringToFront();
     this.CodeTool.Activate();
     this.CodeTool.SetAddress( method.Address, false );
 }
 private void jumpButton_Click( object sender, EventArgs e )
 {
     this.Method = null;
     string name = this.methodTextBox.Text.Trim();
     foreach( MethodBody method in this.Debugger.CodeCache.Methods )
     {
         if( method.Name == name )
         {
             this.Method = method;
             break;
         }
     }
     if( this.Method == null )
     {
         SystemSounds.Exclamation.Play();
         this.methodTextBox.Focus();
         this.methodTextBox.SelectAll();
         return;
     }
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Beispiel #3
0
        private MethodBody BuildMethodBody( ModuleInfo moduleInfo, Method method )
        {
            Debug.Assert( this.Debugger.DebugHost.CpuHook != null );
            uint[] codes = this.Debugger.DebugHost.CpuHook.GetMethodBody( method );

            uint instrAddress = method.Address;
            List<Instruction> instrs = new List<Instruction>( ( int )method.Length / 4 );
            for( int n = 0; n < codes.Length; n++ )
            {
                Instruction instr = new Instruction( instrAddress, codes[ n ] );
                instrs.Add( instr );
                instrAddress += 4;
            }
            MethodBody methodBody = new MethodBody( moduleInfo, method.Address, ( uint )method.Length, instrs.ToArray() );
            if( method.Type == MethodType.Bios )
            {
                if( method.Function.MethodName != null )
                    methodBody.Name = method.Function.MethodName;
                else
                    methodBody.Name = method.Function.ModuleName + "::" + method.Function.NID.ToString( "X8" );
                methodBody.Function = method.Function;
            }
            else
            {
                if( method.Name != null )
                    methodBody.Name = method.Name;
            }

            return methodBody;
        }
 private Line GetContextLine( out MethodBody method )
 {
     method = null;
     if( _contextIndex < 0 )
     {
         if( _hoveredIndex < 0 )
             return null;
         _contextIndex = _hoveredIndex;
     }
     int lineSum;
     int methodIndex = this.IndexOfMethodAt( _contextIndex, out lineSum );
     method = _debugger.CodeCache.Methods[ methodIndex ];
     int lineIndex = ( _contextIndex - lineSum );
     List<Line> lines = ( List<Line> )method.UserCache;
     return lines[ lineIndex ];
 }
        private int DrawMethod( Graphics g, MethodBody body, List<Line> lines, int x, int y, int lineOffset, int maxLines )
        {
            int addressx = x + _gutterWidth + 1;
            int codex = addressx + _addressWidth + 1 + 6;
            int opcodex = codex + _labelWidth / 3 + 6;
            int operandx = opcodex + _opcodeWidth;
            int refx = 300;

            Brush codeBrush = this.Enabled ? _instrFontBrush : _disabledFontBrush;
            Brush addressBrush = this.Enabled ? _addressFontBrush : _disabledFontBrush;

            // -- lines --
            for( int n = lineOffset; n < lines.Count; n++ )
            {
                Line line = lines[ n ];
                Instruction instr = line.Instruction;

                if( body.UserTop + n == _highlightedLine )
                {
                    g.FillRectangle( SystemBrushes.GradientInactiveCaption, codex, y, this.ClientRectangle.Width - codex - 5, _lineHeight + 2 );
                }

                switch( line.Type )
                {
                    case LineType.Header:
                        {
                            string fullName = string.Format( "// {0}::{1}", body.Module.Name, body.Name );
                            g.DrawString( fullName, _font, _commentFontBrush, codex, y );
                            g.DrawLine( _commentLinePen, codex + ( _charSize.Width * ( fullName.Length + 1 ) ), y + ( _charSize.Height / 2.0f ), this.ClientRectangle.Width - 10, y + ( _charSize.Height / 2.0f ) );
                        }
                        break;
                    case LineType.Footer:
                        {
                        }
                        break;
                    case LineType.Label:
                        {
                            g.DrawString( instr.Label.Name + ":", _font, _labelFontBrush, codex, y, _stringFormat );
                        }
                        break;
                    case LineType.Instruction:
                        {
                            // Gutter
                            if( instr.Breakpoint != null )
                            {
                                Image icon = ( instr.Breakpoint.Enabled == true ) ? _breakpointOnIcon : _breakpointOffIcon;
                                g.DrawImage( icon, x + 2, y, 15, 15 );
                            }
                            if( ( _debugger.State != DebuggerState.Running ) && ( _debugger.PC == instr.Address ) )
                            {
                                g.DrawImage( _statementIcon, x + 3, y, 14, 15 );
                            }

                            // Address
                            g.DrawString( string.Format( "{0:X8}", instr.Address ), _font, addressBrush, addressx + 6, y, _stringFormat );

                            // Instruction
                            int realx = operandx;
                            if( instr.Code == 0x0 )
                            {
                                g.DrawString( "nop", _font, _disabledFontBrush, opcodex, y, _stringFormat );
                            }
                            else
                            {
                                if( instr.Opcode == null )
                                {
                                    g.DrawString( "UNKNOWN", _font, codeBrush, opcodex, y, _stringFormat );
                                }
                                else
                                {
                                    g.DrawString( instr.Opcode.ToString(), _font, codeBrush, opcodex, y, _stringFormat );

                                    // Operands
                                    for( int m = 0; m < instr.Operands.Length; m++ )
                                    {
                                        Operand op = instr.Operands[ m ];
                                        string resolved = instr.GetResolvedOperandString( op, this.UseHex );
                                        Brush fontBrush = codeBrush;
                                        switch( op.Type )
                                        {
                                            case OperandType.BranchTarget:
                                                fontBrush = _referenceFontBrush;
                                                break;
                                            case OperandType.JumpTarget:
                                                fontBrush = _referenceFontBrush;
                                                break;
                                        }
                                        g.DrawString( resolved, _font, fontBrush, realx, y, _stringFormat );
                                        realx += ( int )_charSize.Width * resolved.Length;

                                        bool last = ( m == instr.Operands.Length - 1 );
                                        if( last == false )
                                        {
                                            g.DrawString( ", ", _font, codeBrush, realx - 2, y, _stringFormat );
                                            realx += ( int )_charSize.Width * 2 - 2;
                                        }
                                    }
                                }
                            }

                            MemoryReference memRef = instr.Reference as MemoryReference;
                            if( memRef != null )
                            {
                                Variable var = _debugger.DebugHost.Database.FindSymbol( memRef.Address ) as Variable;
                                string name;
                                if( ( var != null ) && ( var.Name != null ) )
                                    name = var.Name;
                                else
                                    name = memRef.Address.ToString( "X8" );
                                g.DrawString( name, _font, _referenceFontBrush, refx, y, _stringFormat );
                            }

                            // Annotations
                            //if( instr.Annotation != null )
                            //	g.DrawString( instr.Annotation, _font, _referenceFontBrush, realx + 10, y, _stringFormat );

                            // Comments
                            // TODO _commentFontBrush
                        }
                        break;
                }

                y += _lineHeight;

                maxLines--;
                if( maxLines == 0 )
                    break;
            }

            return y;
        }
        private List<Line> CacheMethod( MethodBody body )
        {
            List<Line> lines = new List<Line>( ( int )( body.TotalLines + ExtraLinesPerMethod ) );

            Line line = new Line();
            line.Type = LineType.Header;
            lines.Add( line );

            foreach( Instruction instruction in body.Instructions )
            {
                if( instruction.Label != null )
                {
                    line = new Line();
                    line.Type = LineType.Label;
                    line.Instruction = instruction;
                    lines.Add( line );
                }

                line = new Line();
                line.Type = LineType.Instruction;
                line.Instruction = instruction;
                lines.Add( line );
            }

            line = new Line();
            line.Type = LineType.Footer;
            lines.Add( line );

            body.UserCache = lines;
            body.UserLines = ( uint )lines.Count;
            return lines;
        }