⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 log.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    logPrintf( STR_ERR_OCCURRED_AT_X_Y, buf, addr_buf );
    if( type == EXCEPTION_ACCESS_VIOLATION ) {
        if( info->dbinfo->u.Exception.ExceptionRecord.ExceptionInformation[0] ) {
            gptype = STR_LOG_INV_WRITE_TO;
        } else {
            gptype = STR_LOG_INV_READ_FROM;
        }
        logPrintf( gptype,
          info->dbinfo->u.Exception.ExceptionRecord.ExceptionInformation[1] );
    }
    str = SrchMsg( info->action, Actions, NULL );
    if( str != NULL ) {
        logStrPrintf( "%s\n", str );
    }

    logPrintf( STR_MODULES_LOADED );
    logModules( info->procinfo->procid, INDENT );
    logRegisters( info );
    logPrintf( STR_SOURCE_INFORMATION );
    if( info->got_dbginfo && GetLineNum( &info->init_ip, fname,
            FNAME_BUFLEN, &line ) ) {
        logPrintf( STR_LOG_LINE_X_OF_FILE, INDENT, "", line, fname );
    } else {
        logPrintf( STR_LOG_N_A, INDENT, "" );
    }
    logPrintf( STR_DISASSEMBLY );
    logDisasm( info );
    logStack( info );
#ifndef CHICAGO
    if( LogData.log_mem_manager ) {
        logMemManInfo( info->procinfo->procid );
    }
#endif
    if( LogData.log_mem_dmp ) {
        logMemDmp( info );
    }
}

/*
 * MakeLog - make the log file
 */
void MakeLog( ExceptDlgInfo *faultinfo )
{
    RefreshCostlyInfo();
    if( startLogFile() ) {
        char    err_buf[ _MAX_PATH + 100 ];
        RCsprintf( err_buf, STR_CANT_OPEN_LOG, LogData.logname );
        MessageBox( NULL, err_buf, AppName, MB_OK | MB_ICONEXCLAMATION
                                            | MB_SETFOREGROUND );
        return;
    }
    logSysInfo( faultinfo );
    notesAdded = FALSE;
    if( LogData.query_notes ) {
        AnotateLog( MainHwnd, Instance, NotePrint );
    }
    if( faultinfo != NULL ) {
        logFaultInfo( faultinfo );
    }
    if( LogData.log_process ) {
        logProcessList();
    }
    logStrPrintf( logLine );
    finishLogFile();
}

/*
 * EraseLog
 */
void EraseLog( void ) {

    char        buf[500];
    int         ret;

    RCsprintf( buf, STR_ERASE_LOG_FILE, LogData.logname );
    ret = MessageBox( NULL, buf, AppName, MB_YESNO | MB_ICONQUESTION );
    if( ret == IDYES ) {
        remove( LogData.logname );
        ignoreLogChecks = FALSE;
    }
}

/*
 * ViewLog
 */
void ViewLog( void ) {

    char                        buf[ MAX_CMDLINE + _MAX_PATH ];
    BOOL                        ret;
    STARTUPINFO                 startinfo;
    PROCESS_INFORMATION         procinfo;

    if( access( LogData.logname, R_OK ) ) {
        RCsprintf( buf, STR_CANT_OPEN_LOG_FILE, LogData.logname );
        MessageBox( MainHwnd, buf, AppName,
                    MB_OK | MB_ICONEXCLAMATION | MB_SETFOREGROUND );
        return;
    }
    memset( &startinfo, 0, sizeof( STARTUPINFO ) );
    startinfo.cb = sizeof( STARTUPINFO );
    strcpy( buf, LogData.editor );
    strcat( buf, " " );
    strcat( buf, LogData.editor_cmdline );
    strcat( buf, " " );
    strcat( buf, LogData.logname );

    ret = CreateProcess( NULL,                  /* application path */
                   buf,                         /* command line */
                   NULL,                        /* process security
                                                   attributes */
                   NULL,                        /* main thread security
                                                   attributes */
                   FALSE,                       /* inherits parent handles */
                   NORMAL_PRIORITY_CLASS,       /* create parameters */
                   NULL,                        /* environment block */
                   NULL,                        /* current directory */
                   &startinfo,                  /* other startup info */
                   &procinfo );                 /* structure to get process
                                                   info */
    if( ret )  return;
    strcpy( buf, "notepad.exe" );
    strcat( buf, " " );
    strcat( buf, LogData.logname );
    ret = CreateProcess( NULL,                  /* application path */
                   buf,                         /* command line */
                   NULL,                        /* process security
                                                   attributes */
                   NULL,                        /* main thread security
                                                   attributes */
                   FALSE,                       /* inherits parent handles */
                   NORMAL_PRIORITY_CLASS,       /* create parameters */
                   NULL,                        /* environment block */
                   NULL,                        /* current directory */
                   &startinfo,                  /* other startup info */
                   &procinfo );                 /* structure to get process
                                                   info */
    if( !ret ) {
        RCMessageBox( MainHwnd, STR_CANT_START_EDITOR,
                      AppName, MB_OK | MB_ICONEXCLAMATION );
    }
}

/*
 * fillLogOptions
 */
static void fillLogOptions( HWND hwnd ) {

    char        buf[50];

    if( LogData.log_process ) {
        CheckDlgButton( hwnd, LOG_TASKS, TRUE );
    }
    if( LogData.log_stacktrace ) {
        CheckDlgButton( hwnd, LOG_STACK_TRACE, TRUE );
    }
    if( LogData.log_mem_manager ) {
        CheckDlgButton( hwnd, LOG_MEM, TRUE );
    }
    if( LogData.log_mem_dmp ) {
        CheckDlgButton( hwnd, LOG_MEM_DMP, TRUE );
    }
    if( LogData.query_notes ) {
        CheckDlgButton( hwnd, LOG_QUERY_NOTES, TRUE );
    }
    if( LogData.autolog ) {
        CheckDlgButton( hwnd, LOG_AUTOLOG, TRUE );
    }
    if( LogData.log_modules ) {
        CheckDlgButton( hwnd, LOG_LOADED_MODULES, TRUE );
    }
    sprintf( buf, "%ld", LogData.max_flen );
    SetDlgItemText( hwnd, LOG_MAXFL, buf );
    sprintf( buf, "%ld", LogData.asm_cnt );
    SetDlgItemText( hwnd, LOG_DISASM_LINES, buf );
    sprintf( buf, "%ld", LogData.asm_bkup );
    SetDlgItemText( hwnd, LOG_DISASM_BACKUP, buf );
    SetDlgItemText( hwnd, LOG_VIEWER, strlwr( LogData.editor ) );
    SetDlgItemText( hwnd, LOG_FILE_NAME, strlwr( LogData.logname ) );

    SendDlgItemMessage( hwnd, LOG_MAXFL, EM_LIMITTEXT, BUF_SIZE - 1, 0 );
    SendDlgItemMessage( hwnd, LOG_DISASM_BACKUP, EM_LIMITTEXT,
                        BUF_SIZE - 1, 0 );
    SendDlgItemMessage( hwnd, LOG_DISASM_LINES, EM_LIMITTEXT,
                        BUF_SIZE - 1, 0 );
    SendDlgItemMessage( hwnd, LOG_VIEWER, EM_LIMITTEXT, BUF_SIZE - 1, 0 );
    SendDlgItemMessage( hwnd, LOG_FILE_NAME, EM_LIMITTEXT, BUF_SIZE - 1, 0 );
}

#define NUM_HELP_SIZE   150
static BOOL readLogOptions( HWND hwnd, char *buf ) {

    DWORD       asm_lines;
    DWORD       asm_bkup;
    DWORD       max_fsize;
    char        numhelp[NUM_HELP_SIZE];

    CopyRCString( STR_FIELD_MUST_BE_NUMERIC, numhelp, NUM_HELP_SIZE );
    GetDlgItemText( hwnd, LOG_MAXFL, buf, BUF_SIZE );
    if( !ParseNumeric( buf, FALSE, &max_fsize ) ) {
        RCsprintf( buf, STR_MAX_LOG_FILE_SIZE_INV, numhelp );
        MessageBox( hwnd, buf, AppName, MB_OK | MB_ICONEXCLAMATION );
        return( FALSE );
    }
    GetDlgItemText( hwnd, LOG_DISASM_LINES, buf, BUF_SIZE );
    if( !ParseNumeric( buf, FALSE, &asm_lines ) ) {
        RCsprintf( buf, STR_DISASM_LINES_INVALID, numhelp );
        MessageBox( hwnd, buf, AppName, MB_OK | MB_ICONEXCLAMATION );
        return( FALSE );
    }
    GetDlgItemText( hwnd, LOG_DISASM_BACKUP, buf, BUF_SIZE );
    if( !ParseNumeric( buf, FALSE, &asm_bkup ) ) {
        RCsprintf( buf, STR_DISASM_BKUP_INVALID, numhelp );
        MessageBox( hwnd, buf, AppName, MB_OK | MB_ICONEXCLAMATION );
        return( FALSE );
    }
    GetDlgItemText( hwnd, LOG_FILE_NAME, LogData.logname, BUF_SIZE );
    GetDlgItemText( hwnd, LOG_VIEWER, LogData.editor, BUF_SIZE );
    LogData.asm_cnt = asm_lines;
    LogData.asm_bkup = asm_bkup;
    LogData.max_flen = max_fsize;
    LogData.log_process = IsDlgButtonChecked( hwnd, LOG_TASKS );
    LogData.log_stacktrace = IsDlgButtonChecked( hwnd, LOG_STACK_TRACE );
    LogData.log_mem_manager = IsDlgButtonChecked( hwnd, LOG_MEM );
    LogData.log_mem_dmp = IsDlgButtonChecked( hwnd, LOG_MEM_DMP );
    LogData.query_notes = IsDlgButtonChecked( hwnd, LOG_QUERY_NOTES );
    LogData.autolog = IsDlgButtonChecked( hwnd, LOG_AUTOLOG );
    LogData.log_modules = IsDlgButtonChecked( hwnd, LOG_LOADED_MODULES );
    return( TRUE );
}

/*
 * getNewLogName
 */
static BOOL getNewLogName( HWND parent, char *buf, char *title, BOOL outfile ) {
    OPENFILENAME        of;
    BOOL                ret;
    char                filter[100];
    char                *ptr;

    memset( &of, 0, sizeof( OPENFILENAME ) );
    of.lStructSize = sizeof( OPENFILENAME );
    of.hwndOwner = parent;
    of.hInstance = Instance;
    of.lpstrDefExt = NULL;
    of.lpstrFile = buf;
    of.nMaxFile = BUF_SIZE;
    CopyRCString( STR_ALL_FILE_FILTER, filter, sizeof( filter ) );
    ptr = filter + strlen( filter ) + 1;
    strcpy( ptr, "*.*" );
    ptr += strlen( ptr ) + 1;
    *ptr = '\0';
    of.lpstrFilter = filter;
    of.nFilterIndex = 1L;
    of.lpstrTitle = title;
    if( outfile ) {
        of.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST;
        ret = GetSaveFileName( &of );
    } else {
        of.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
        ret = GetOpenFileName( &of );
    }
    return( ret );
}

/*
 * LogOptsDlgProc
 */
BOOL CALLBACK LogOptsDlgProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
    WORD                cmd;
    char                buf[BUF_SIZE];
    char                title[BUF_SIZE];

    lparam = lparam;
    switch( msg ) {
    case WM_INITDIALOG:
        fillLogOptions( hwnd );
        break;
    case WM_COMMAND:
        cmd = LOWORD( wparam );
        switch( cmd ) {
        case IDOK:
            if( readLogOptions( hwnd, buf ) ) {
                SendMessage( hwnd, WM_CLOSE, 0, 0 );
            }
            break;
        case IDCANCEL:
            SendMessage( hwnd, WM_CLOSE, 0, 0 );
            break;
        case LOG_BROWSE_FILE:
            CopyRCString( STR_PICK_LOG_FILE, title, BUF_SIZE );
            strcpy( buf, LogData.logname );
            if( getNewLogName( hwnd, buf, title, TRUE ) ) {
                strlwr( buf );
                SetDlgItemText( hwnd, LOG_FILE_NAME, buf );
            }
            break;
        case LOG_BROWSE_VIEWER:
            CopyRCString( STR_PICK_LOG_VIEWER, title, BUF_SIZE );
            strcpy( buf, LogData.editor );
            if( getNewLogName( hwnd, buf, title, FALSE ) ) {
                strlwr( buf );
                SetDlgItemText( hwnd, LOG_VIEWER, buf );
            }
            break;
        }
        break;
    case WM_CLOSE:
        EndDialog( hwnd, 0 );
        break;
    default:
        return( FALSE );
        break;
    }
    return( TRUE );
}

/*
 * SetLogOptions
 */
void SetLogOptions( HWND hwnd ) {
    JDialogBox( Instance, "LOG", hwnd, LogOptsDlgProc );
}

⌨️ 快捷键说明

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