dbgwmadr.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 500 行 · 第 1/2 页

C
500
字号
    mad_modify_list    *possible = _possible;
    unsigned    max;

    if( possible[i].name == MSTR_NIL ) {
        max = TXT_LEN;
        MADTypeHandleToString( MADTypePreferredRadix( possible[i].type ),
                possible[i].type, possible[i].data, &max, TxtBuff );
    } else {
        MADCliString( possible[i].name, TXT_LEN, TxtBuff );
    }
    return( TxtBuff );
}

static  WNDMODIFY RegModify;
static  void    RegModify( a_window *wnd, int row, int piece )
{
    int                 i;
    item_mach           value;
    reg_window          *reg = WndReg( wnd );
    bool                ok;
    unsigned            old;
    reg_display_piece   disp;
    mad_type_info       tinfo;
    mad_modify_list const    *possible;
    unsigned            num_possible;

    if( row < 0 ) return;
    piece >>= 1;
    i = GetRegIdx( reg, row, piece );
    if( i == -1 ) return;
    if( !GetDisplayPiece( &disp, reg, DbgRegs, i ) ) return;
    if( disp.reginfo == NULL ) return;
    if( MADRegSetDisplayModify( reg->data, disp.reginfo, &possible, &num_possible ) != MS_OK ) return;
    old = NewCurrRadix( MADTypePreferredRadix( disp.disp_type ) );
    MADRegFullName( disp.reginfo, ".", TXT_LEN, TxtBuff );
    RegValue( &value, disp.reginfo, DbgRegs );
    if( num_possible == 1 ) {
        ok = DlgMadTypeExpr( TxtBuff, &value, disp.disp_type );
        if( ok ) {
            RegNewValue( disp.reginfo, &value, possible->type );
        }
    } else {
        for( i = 0; i < num_possible; ++i ) {
            MADTypeInfo( possible[i].type, &tinfo );
            if( memcmp( &value, possible[i].data, tinfo.b.bits / BITS_PER_BYTE ) == 0 ) break;
        }
        if( num_possible == 2 ) {
            if( i == 0 ) {
                i = 1;
            } else {
                i = 0;
            }
        } else {  //MJC const cast
            i = DlgPickWithRtn( TxtBuff, (mad_modify_list*) possible, i, RegValueName, num_possible );
        }
        if( i != -1 ) {
            RegNewValue( disp.reginfo, possible[i].data, possible[i].type );
        }
    }
    NewCurrRadix( old );
}

static  WNDMENU RegMenuItem;
static void     RegMenuItem( a_window *wnd, unsigned id, int row, int piece )
{
    reg_window          *reg = WndReg( wnd );
    int                 i;
    unsigned            bit;
    mad_modify_list const *possible;
    unsigned            num_possible;
    address             addr;
    bool                valid_reg;

    i = GetRegIdx( reg, row, piece >>1 );
    switch( id ) {
    case MENU_INITIALIZE:
        valid_reg = i != -1 && reg->info[i].info != NULL &&
                    MADRegSetDisplayModify( reg->data, reg->info[i].info,
                                            &possible, &num_possible ) == MS_OK;
        WndMenuEnable( wnd, MENU_REGISTER_MODIFY, valid_reg );
        WndMenuEnable( wnd, MENU_REGISTER_INSPECT, valid_reg );
        bit = MADRegSetDisplayToggle( reg->data, 0, 0 );
        for( i = 0; i < reg->num_toggles; ++i ) {
            WndMenuCheck( wnd, MENU_REGISTER_TOGGLES + i, ( bit & 1 ) != 0 );
            bit >>= 1;
        }
        break;
    case MENU_REGISTER_INSPECT:
        if( MADRegInspectAddr( reg->info[ i ].info, &DbgRegs->mr, &addr ) == MS_OK ) {
            PushAddr( addr );
            WndInspectExprSP( "" );
        }
        break;
    case MENU_REGISTER_MODIFY:
        RegModify( wnd, row, piece );
        break;
    default:
        bit = 1 << ( id - MENU_REGISTER_TOGGLES );
        MADRegSetDisplayToggle( reg->data, bit, bit );
        RegResize( wnd );
        WndZapped( wnd );
    }
}


static WNDGETLINE RegGetLine;
static  bool    RegGetLine( a_window *wnd, int row, int piece,
                            wnd_line_piece *line )
{
    int                 column;
    int                 i;
    reg_window          *reg = WndReg( wnd );
    unsigned            max = TXT_LEN;
    unsigned            old,new;
    item_mach           value;
    reg_display_piece   disp;

    column = piece >> 1;
    if( column >= reg->up ) return( FALSE );
    i = GetRegIdx( reg, row, column );
    if( i >= reg->count ) return( FALSE );
    if( i == -1 ) return( FALSE );
    if( !GetDisplayPiece( &disp, reg, DbgRegs, i ) ) return( FALSE );
    line->text = TxtBuff;
    if( piece & 1 ) {
        line->indent = reg->indents[column].value;
        if( reg->info[i].info == NULL ) {
            strcpy( TxtBuff, "   " );
        } else {
            new = MADTypePreferredRadix( disp.disp_type );
            old = NewCurrRadix( new );
            RegValue( &value, reg->info[i].info, DbgRegs );
            max = reg->info[i].max_value + 1;
            MADTypeHandleToString( new, disp.disp_type, &value, &max, TxtBuff );
            NewCurrRadix( old );
            reg->info[i].standout = FALSE;
            if( MADRegModified( reg->data, reg->info[i].info, &PrevRegs->mr, &DbgRegs->mr ) == MS_MODIFIED_SIGNIFICANTLY ) {
                reg->info[i].standout = TRUE;
                line->attr = WND_STANDOUT;
            }
        }
    } else {
        line->indent = reg->indents[column].descript;
        strcpy( TxtBuff, disp.descript );
        if( TxtBuff[0] != '\0' ) {
            strcat( TxtBuff, ":" );
        }
        line->tabstop = FALSE;
    }
    return( TRUE );
}


static WNDREFRESH RegRefresh;
static void     RegRefresh( a_window *wnd )
{
    int                 row,rows;
    int                 reg_num;
    int                 i;
    reg_window          *reg = WndReg( wnd );
    reg_display_piece   disp;

    // if register type changes, from 16 to 32-bit,
    // this will force the mad to call back NOW, setting UP_REG_RESIZE
    GetDisplayPiece( &disp, reg, DbgRegs, 0 );
    if( WndFlags & UP_REG_RESIZE ) {
        RegResize( wnd );
        WndZapped( wnd );
        return;
    }
    if( WndFlags & UP_MAD_CHANGE ) {
        WndZapped( wnd );
        return;
    }
    rows = RegNumRows( wnd );
    for( row = 0; row < rows; ++row ) {
        for( reg_num = 0; reg_num < reg->up; ++reg_num ) {
            i = GetRegIdx( reg, row, reg_num );
            if( i == -1 ) break;
            if( reg->info[i].standout || ( reg->info[i].info != NULL &&
                MADRegModified( reg->data, reg->info[i].info, &PrevRegs->mr, &DbgRegs->mr ) != MS_OK ) ) {
                WndPieceDirty( wnd, row, reg_num*2+1 );
            }
        }
    }
}

static WNDCALLBACK RegEventProc;
static bool RegEventProc( a_window * wnd, gui_event gui_ev, void *parm )
{
    reg_window          *reg = WndReg( wnd );

    parm=parm;
    switch( gui_ev ) {
    case GUI_RESIZE:
        if( RegResize( wnd ) ) {
            WndZapped( wnd );
        }
        return( TRUE );
    case GUI_INIT_WINDOW:
        reg->info = NULL;
        reg->indents = NULL;
        RegResize( wnd );
        reg->popup = WndAppendToggles( MADRegSetDisplayToggleList( reg->data ), &reg->num_toggles, RegMenu, ArraySize( RegMenu ), MENU_REGISTER_TOGGLES );
        WndSetPopUpMenu( wnd, reg->popup, ArraySize( RegMenu ) + reg->num_toggles );
        return( TRUE );
    case GUI_DESTROY :
        WndDeleteToggles( reg->popup, ArraySize( RegMenu ), reg->num_toggles );
        WndFree( reg->info );
        WndFree( reg->indents );
        WndFree( reg );
        return( TRUE );
    }
    return( FALSE );
}

wnd_info MadRegInfo = {
    RegEventProc,
    RegRefresh,
    RegGetLine,
    RegMenuItem,
    NoScroll,
    NoBegPaint,
    NoEndPaint,
    WndFirstMenuItem,
    RegNumRows,
    NoNextRow,
    NoNotify,
    UP_MAD_CHANGE+UP_REG_CHANGE+UP_REG_RESIZE,
    DefPopUp( RegMenu )
};

void MadRegChangeOptions( a_window *wnd )
{
    RegResize( wnd );
    WndZapped( wnd );
}

extern a_window *WndMadRegOpen( mad_type_kind kind, wnd_class class, gui_resource *icon )
{
    reg_window  *reg;
    a_window    *wnd;

    reg = WndMustAlloc( sizeof( reg_window ) );
    reg->kind = kind;
    wnd = DbgWndCreate( LIT( Empty ), &MadRegInfo, class, reg, icon );
    if( wnd == NULL ) return( NULL );
    return( wnd );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?