/* * DisplayAsmLines - display all assembler lines * hwnd - dialog handle * paddr - address to start dissassembly */ static void DisplayAsmLines( HWND hwnd, address *paddr ) { int i; address addr; address flagaddr; char buff[256]; HWND hscrl; DWORD max; int curr; mad_registers *regs; addr = *paddr; regs = StatGetMadRegisters( hwnd ); GetCurrAddr( &flagaddr, regs ); for( i = STAT_DISASM_1;i <= STAT_DISASM_8; i++ ) { buff[0] = ' '; if( MADAddrComp( &addr, &flagaddr, MAF_FULL ) == 0 ) { buff[0] = '*'; } Disassemble( &addr, buff+1, FALSE, 255 ); SetDlgItemText( hwnd, i, buff ); } #ifdef __NT__ max = max; curr = curr; hscrl = GetDlgItem( hwnd, STAT_SCROLL ); SetScrollRange( hscrl, SB_CTL, 0, 2, FALSE ); SetScrollPos( hscrl, SB_CTL, 1, TRUE ); #else max = GetASelectorLimit( paddr->mach.segment ); if( max > MAXRANGE ) { curr = ( MAXRANGE * paddr->mach.offset ) / max; max = MAXRANGE; } else { curr = paddr->mach.offset; } hscrl = GetDlgItem( hwnd, STAT_SCROLL ); SetScrollRange( hscrl, SB_CTL, 0, max, FALSE); SetScrollPos( hscrl, SB_CTL, curr, TRUE ); #endif } /* DisplayAsmLines */
int ChangeCurrentLocation( bool relative, int_32 value, bool select_data ) /************************************************************************/ { if( CurrSeg == NULL ) return( ERROR ); if( relative ) { value += GetCurrAddr(); } FlushCurrSeg( ); if( select_data ) OutSelect( TRUE ); CurrSeg->seg->e.seginfo->current_loc = value; CurrSeg->seg->e.seginfo->start_loc = value; if( CurrSeg->seg->e.seginfo->current_loc >= CurrSeg->seg->e.seginfo->length ) { CurrSeg->seg->e.seginfo->length = CurrSeg->seg->e.seginfo->current_loc; } return( NOT_ERROR ); }
/* * logDisasm - log some disassembly */ static void logDisasm( ExceptDlgInfo *info ) { int i; address addr; address flagaddr; char str[256]; SetDisasmInfo( info->procinfo->prochdl, info->module ); GetCurrAddr( &flagaddr, info->regs ); addr = flagaddr; InstructionBackward( LogData.asm_bkup, &addr ); for( i = 0; i <= LogData.asm_cnt; i++ ) { if( MADAddrComp( &addr, &flagaddr, MAF_FULL ) == 0 ) { logStrPrintf( "--->" ); } else { logStrPrintf( " " ); } Disassemble( &addr, str, TRUE, 255 ); logStrPrintf( "%s\n", str ); } } /* logDisasm */
/* * ExceptionProc */ BOOL CALLBACK ExceptionProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { WORD cmd; ExceptDlgInfo *info; ProcNode *procinfo; WORD tmp; address addr; info = FaultGetExceptDlgInfo( hwnd ); switch( msg ) { case WM_INITDIALOG: /* make sure this dialog always comes up on top of everything else */ SetWindowPos( hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); SetWindowPos( hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE ); centerDialog( hwnd ); info = MemAlloc( sizeof( ExceptDlgInfo ) ); info->dbinfo = (DEBUG_EVENT *)lparam; info->rc = 0; info->action = 0; SetWindowLong( hwnd, DWL_USER, (DWORD)info ); info->procinfo = FindProcess( info->dbinfo->dwProcessId ); info->threadinfo = FindThread( info->procinfo, info->dbinfo->dwThreadId ); info->module = ModuleFromAddr( info->procinfo, info->dbinfo->u.Exception.ExceptionRecord.ExceptionAddress ); if( info->threadinfo != NULL ) { AllocMadRegisters( &(info->regs) ); LoadMADRegisters( info->regs, info->threadinfo->threadhdl ); GetCurrAddr( &( info->init_ip ), info->regs ); } if( info->module == NULL ) { info->got_dbginfo = FALSE; } else { if( !LoadDbgInfo( info->module ) ) { info->got_dbginfo = FALSE; } else { info->got_dbginfo = TRUE; } } if( LogData.autolog ) { //Just create the log and exit tmp = ConfigData.exception_action; CheckDlgButton( hwnd, INT_TERMINATE, BST_CHECKED ); SendMessage( hwnd, WM_COMMAND, MAKELONG( INT_ACT_AND_LOG, BN_CLICKED ), (LPARAM)GetDlgItem( hwnd, INT_ACT_AND_LOG ) ); ConfigData.exception_action = tmp; } else { fillExceptionDlg( hwnd, info ); } setProcessHdl( info->procinfo->prochdl ); break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case INT_ACT_AND_LOG: MakeLog( info ); /* fall through */ case INT_ACT: if( IsDlgButtonChecked( hwnd, INT_TERMINATE ) ) { ConfigData.exception_action = INT_TERMINATE; // hp = OpenProcess( PROCESS_TERMINATE, FALSE, // info->dbinfo->dwProcessId ); procinfo = FindProcess( info->dbinfo->dwProcessId ); if( procinfo == NULL ) { RCMessageBox( hwnd, STR_CANT_TERMINATE_APP, AppName, MB_OK | MB_ICONEXCLAMATION ); } else { TerminateProcess( procinfo->prochdl, -1 ); // CloseHandle( hp ); info->rc = DBG_CONTINUE; info->action = INT_TERMINATE; SendMessage( hwnd, WM_CLOSE, 0, 0L ); } } else if( IsDlgButtonChecked( hwnd, INT_CHAIN_TO_NEXT ) ) { ConfigData.exception_action = INT_CHAIN_TO_NEXT; info->rc = DBG_EXCEPTION_NOT_HANDLED; info->action = INT_CHAIN_TO_NEXT; SendMessage( hwnd, WM_CLOSE, 0, 0L ); } else if( IsDlgButtonChecked( hwnd, INT_RESTART ) ) { ConfigData.exception_action = INT_RESTART; info->rc = DBG_CONTINUE; info->action = INT_RESTART; SendMessage( hwnd, WM_CLOSE, 0, 0L ); } break; case INT_REGISTERS: SetDisasmInfo( info->procinfo->prochdl, info->module ); StatShowSymbols = TRUE; if ( DoStatDialog( hwnd ) == 1 ){ StoreMADRegisters( info->regs, info->threadinfo->threadhdl ); GetCurrAddr(&addr,info->regs); SetIp( hwnd, &addr ); } LoadMADRegisters( info->regs, info->threadinfo->threadhdl ); break; case INT_LOG_OPTIONS: SetLogOptions( hwnd ); break; } break; case WM_CLOSE: if( info->rc == 0 ) { SendMessage( hwnd, WM_COMMAND, INT_ACT, 0L ); } else { if( info->got_dbginfo ) { UnloadDbgInfo( info->module ); } EndDialog( hwnd, info->rc ); } break; case WM_DESTROY: DeAllocMadRegisters( info->regs ); MemFree( info ); break; default: return( FALSE ); break; } return( TRUE ); }
static void fillExceptionDlg( HWND hwnd, ExceptDlgInfo *info ) { char buf[BUF_SIZE]; char fname[ FNAME_BUFLEN ]; DWORD line; ProcStats stats; HWND ctl; address addr; GetCurrAddr(&addr,info->regs); SetDlgCourierFont( hwnd, INT_TASK_NAME ); SetDlgCourierFont( hwnd, INT_TASK_PATH ); SetDlgCourierFont( hwnd, INT_FAULT_TYPE ); SetDlgCourierFont( hwnd, INT_CS_IP ); SetDlgCourierFont( hwnd, INT_SOURCE_INFO ); SetDlgCourierFont( hwnd, INT_SOURCE_INFO2 ); RCsprintf( buf, STR_EXCEPTION_ENCOUNTERED, AppName ); SetWindowText( hwnd, buf ); CopyRCString( STR_PROCESS_NAME, buf, BUF_SIZE ); SetDlgItemText( hwnd, INT_TASK_NAME_TEXT, buf ); if( !info->dbinfo->u.Exception.dwFirstChance ) { if( ConfigData.exception_action == INT_CHAIN_TO_NEXT ) { ConfigData.exception_action = INT_TERMINATE; } ctl = GetDlgItem( hwnd, INT_CHAIN_TO_NEXT ); EnableWindow( ctl, FALSE ); } CheckDlgButton( hwnd, ConfigData.exception_action, BST_CHECKED ); CopyRCString( STR_PROCESS_ID, buf, BUF_SIZE ); SetDlgItemText( hwnd, INT_TASK_PATH_TEXT, buf ); while( !GetProcessInfo( info->procinfo->procid, &stats ) ) { Sleep( 100 ); RefreshInfo(); } SetDlgItemText( hwnd, INT_TASK_NAME, stats.name ); sprintf( buf, "%08lX", info->procinfo->procid ); SetDlgItemText( hwnd, INT_TASK_PATH, buf ); FormatException( buf, info->dbinfo->u.Exception.ExceptionRecord.ExceptionCode ); SetDlgItemText( hwnd, INT_FAULT_TYPE, buf ); if( info->threadinfo != NULL ) { strcpy( buf, "Fault " ); MADRegSpecialName( MSR_IP, info->regs, MAF_FULL, BUF_SIZE - 7, buf+6 ); SetDlgItemText( hwnd, INT_IP_NAME, buf ); SetIp( hwnd, &addr ); } if( info->got_dbginfo && GetLineNum( &addr,fname, FNAME_BUFLEN, &line ) ) { RCsprintf( buf, STR_LINE_X_OF, line ); SetDlgItemText( hwnd, INT_SOURCE_INFO, buf ); SetDlgItemText( hwnd, INT_SOURCE_INFO2, fname ); } else { CopyRCString( STR_N_A, buf, BUF_SIZE ); SetDlgItemText( hwnd, INT_SOURCE_INFO, buf ); SetDlgItemText( hwnd, INT_SOURCE_INFO2, "" ); } }
/* * InitStatDialog */ static void InitStatDialog( HWND hwnd ) { int i; char buff[256]; ExceptDlgInfo *info; syminfo si; CreateRegListData data; StatData *statdata; RECT c_rect; HWND combo; info = StatGetExceptDlgInfo( hwnd ); StatHdl = hwnd; statdata = MemAlloc( sizeof( StatData ) ); /* * fill in source information */ GetCurrAddr( &( statdata->curr_addr ), info->regs ); if( FindWatSymbol( &( statdata->curr_addr ), &si, TRUE ) == FOUND ) { RCsprintf( buff, STR_SRC_INFO_FMT, si.linenum, si.filename ); StatShowSymbols = TRUE; CheckDlgButton( hwnd, STAT_SYMBOLS, ( StatShowSymbols ) ? BST_CHECKED : BST_UNCHECKED ); } else { RCsprintf( buff, STR_N_A ); StatShowSymbols = FALSE; EnableWindow( GetDlgItem( hwnd, STAT_SYMBOLS ), FALSE ); } SetDlgMonoFont( hwnd, STAT_SRC_INFO ); SetDlgItemText( hwnd, STAT_SRC_INFO, buff ); #ifdef __NT__ { ProcStats procinfo; HWND button; if( GetProcessInfo( info->procinfo->procid, &procinfo ) ) { RCsprintf( buff, STR_STATUS_4_PROC_X, info->procinfo->procid, procinfo.name ); SetWindowText( hwnd, buff ); } CopyRCString( STR_VIEW_MEM_HT_KEY, buff, sizeof( buff ) ); SetDlgItemText( hwnd, STAT_SEG_MAP, buff ); button = GetDlgItem( hwnd, STAT_STACK_TRACE ); ShowWindow( button, SW_HIDE ); } #endif InstructionBackward( 2, &( statdata->curr_addr ) ); for( i = STAT_DISASM_1;i <= STAT_DISASM_8; i++ ) { SetDlgCourierFont( hwnd, i ); } DisplayAsmLines( hwnd, &( statdata->curr_addr ) ); data.index = 0; data.parent = hwnd; data.max_len = 0; combo = GetDlgItem( hwnd, STAT_REGISTER_COMBO ); MADRegSetWalk( MTK_ALL, CreateAllRegLists, &data ); if( data.index == 1 ) { SendMessage( combo, CB_GETLBTEXT, (WPARAM)0, (LPARAM)buff ); SetDlgItemText( hwnd, STAT_REGISTER_SET, buff ); DestroyWindow( combo ); } else { GetChildPos( hwnd, combo, &c_rect ); SendMessage( combo, CB_SETCURSEL, (WPARAM)0, (LPARAM)0 ); c_rect.right += data.max_len; c_rect.bottom += SendMessage( combo, CB_GETITEMHEIGHT, 0, 0 ) * ( data.index + 1); MoveWindow( combo, c_rect.left, c_rect.top, c_rect.right, c_rect.bottom, FALSE ); } SetFocus( GetDlgItem( hwnd, IDOK ) ); statdata->reg_set_index = 0; SetWindowLong(hwnd,DWL_USER,(LONG)statdata); } /* InitStatDialog */