/* * 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 ); }
/* * WindowProc - main window message handler */ LONG CALLBACK MainWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ) { WORD cmd; about_info ai; HMENU mh; CommunicationBuffer *dbginfo; switch ( msg ) { case WM_CREATE: setupSystemMenu( hwnd ); MainLBox = CreateListBox( hwnd ); mh = GetMenu( hwnd ); if( ConfigData.auto_attatch ) { CheckMenuItem( mh, MENU_AUTO_ATTATCH, MF_BYCOMMAND | MF_CHECKED ); } if( ConfigData.continue_exception ) { CheckMenuItem( mh, MENU_EXCEPTION_CONTINUE, MF_BYCOMMAND | MF_CHECKED ); } LBPrintf( MainLBox, STR_DRNT_STARTED, AppName ); break; case WM_SIZE: MoveListBox( MainLBox, 0, 0, LOWORD( lparam ), HIWORD( lparam ) ); ClearAlert(); break; case WM_SYSCOMMAND: switch( wparam ) { case MENU_LOG_CURRENT_STATE: case MENU_LOG_OPTIONS: case MENU_TASK_CTL: SendMessage( hwnd, WM_COMMAND, wparam, 0 ); break; default: return( DefWindowProc( hwnd, msg, wparam, lparam ) ); } break; case WM_COMMAND: cmd = LOWORD( wparam ); switch( cmd ) { case LISTBOX_1: break; case MENU_EXCEPTION_CONTINUE: ConfigData.continue_exception = !ConfigData.continue_exception; mh = GetMenu( hwnd ); if( ConfigData.continue_exception ) { CheckMenuItem( mh, MENU_EXCEPTION_CONTINUE, MF_BYCOMMAND | MF_CHECKED ); } else { CheckMenuItem( mh, MENU_EXCEPTION_CONTINUE, MF_BYCOMMAND | MF_UNCHECKED ); } break; case MENU_LOG_VIEW: ViewLog(); break; case MENU_NEW_TASK: CallProcCtl( MENU_NEW_TASK, NULL, NULL ); break; case MENU_AUTO_ATTATCH: ConfigData.auto_attatch = ! ConfigData.auto_attatch; mh = GetMenu( hwnd ); if( ConfigData.auto_attatch ) { CheckMenuItem( mh, MENU_AUTO_ATTATCH, MF_BYCOMMAND | MF_CHECKED ); } else { CheckMenuItem( mh, MENU_AUTO_ATTATCH, MF_BYCOMMAND | MF_UNCHECKED ); } break; case MENU_SHOW_DIP_STATUS: ShowDIPStatus( hwnd ); break; case MENU_CLEAR: ClearListBox( MainLBox ); break; case MENU_SAVE_AS: SaveListBox( SLB_SAVE_AS, SaveExtra, "", AppName, hwnd, GetListBoxHwnd( MainLBox ) ); break; case MENU_SAVE: SaveListBox( SLB_SAVE_TMP, SaveExtra, ".\\drwat.txt", AppName, hwnd, GetListBoxHwnd( MainLBox ) ); break; case MENU_FONT: if( ChooseMonoFont( hwnd ) ) { SetListBoxFont( MainLBox ); } break; case MENU_MARK: ProcessMark( hwnd, Instance, MarkPrint ); break; case MENU_ABOUT: ai.owner = hwnd; ai.inst = Instance; ai.name = AllocRCString( STR_ABOUT_NAME ); ai.version = AllocRCString( STR_ABOUT_VERSION ); ai.first_cr_year = "1993"; ai.title = AllocRCString( STR_ABOUT_TITLE ); DoAbout( &ai ); FreeRCString( ai.name ); FreeRCString( ai.version ); FreeRCString( ai.title ); break; case MENU_HELP_CONTENTS: if( !WHtmlHelp( hwnd, DR_CHM_FILE, HELP_CONTENTS, 0 ) ) { WWinHelp( hwnd, DR_HELP_FILE, HELP_CONTENTS, 0 ); } break; case MENU_HELP_SRCH: if( !WHtmlHelp( hwnd, DR_CHM_FILE, HELP_PARTIALKEY, (HELP_DATA)"" ) ) { WWinHelp( hwnd, DR_HELP_FILE, HELP_PARTIALKEY, (HELP_DATA)"" ); } break; case MENU_HELP_ON_HELP: WWinHelp( hwnd, HELP_HELP_FILE, HELP_HELPONHELP, 0 ); break; case MENU_TASK_CTL: DisplayProcList(); break; case MENU_LOG_CURRENT_STATE: MakeLog( NULL ); break; case MENU_ERASE_LOG_FILE: EraseLog(); break; case MENU_LOG_OPTIONS: SetLogOptions( hwnd ); break; case MENU_EXIT: SendMessage( hwnd, WM_CLOSE, 0, 0L ); break; default: MessageBox( hwnd, "This function is not yet available", AppName, MB_OK ); break; } break; case DR_DEBUG_EVENT: dbginfo = (CommunicationBuffer *)lparam; dbginfo->action = DebugEventHandler( &dbginfo->dbginfo ); break; case WM_COPYDATA: { COPYDATASTRUCT *copydata; copydata = (COPYDATASTRUCT *)lparam; ProcessCommandLine( copydata->lpData ); } break; case WM_CLOSE: if( QueryEnd( hwnd ) ) { SendMessage( hwnd, WM_DESTROY, 0, 0L ); } break; case WM_DESTROY: FiniListBox( MainLBox ); PutProfileInfo(); DestroyMonoFonts(); WWinHelp( hwnd, DR_HELP_FILE, HELP_QUIT, 0 ); PostQuitMessage( 0 ); break; default: return( DefWindowProc( hwnd, msg, wparam, lparam ) ); } return( 0L ); } /* WindowProc */
/* * Common functionality of CfFOut and CfOut. */ static void VLog(FILE *fh, OutputLevel level, const char *errstr, const char *fmt, va_list args) { char buffer[CF_BUFSIZE], output[CF_BUFSIZE]; Item *mess = NULL; if ((fmt == NULL) || (strlen(fmt) == 0)) { return; } memset(output, 0, CF_BUFSIZE); vsnprintf(buffer, CF_BUFSIZE - 1, fmt, args); if (Chop(buffer, CF_EXPANDSIZE) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator"); } AppendItem(&mess, buffer, NULL); if ((errstr == NULL) || (strlen(errstr) > 0)) { snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr()); AppendItem(&mess, output, NULL); } switch (level) { case OUTPUT_LEVEL_INFORM: if (INFORM || VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } break; case OUTPUT_LEVEL_VERBOSE: if (VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } break; case OUTPUT_LEVEL_ERROR: case OUTPUT_LEVEL_REPORTING: case OUTPUT_LEVEL_CMDOUT: LogList(fh, mess, VERBOSE); MakeLog(mess, level); break; case OUTPUT_LEVEL_LOG: if (VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } MakeLog(mess, OUTPUT_LEVEL_VERBOSE); break; default: ProgrammingError("Report level unknown"); break; } DeleteItemList(mess); }
void cfPS(OutputLevel level, char status, char *errstr, const Promise *pp, Attributes attr, char *fmt, ...) { va_list ap; char buffer[CF_BUFSIZE], output[CF_BUFSIZE], *v, handle[CF_MAXVARSIZE]; const char *sp; Item *mess = NULL; int verbose; Rval retval; if ((fmt == NULL) || (strlen(fmt) == 0)) { return; } va_start(ap, fmt); vsnprintf(buffer, CF_BUFSIZE - 1, fmt, ap); va_end(ap); if (Chop(buffer, CF_EXPANDSIZE) == -1) { CfOut(OUTPUT_LEVEL_ERROR, "", "Chop was called on a string that seemed to have no terminator"); } AppendItem(&mess, buffer, NULL); if ((errstr == NULL) || (strlen(errstr) > 0)) { snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr()); AppendItem(&mess, output, NULL); } if (level == OUTPUT_LEVEL_ERROR) { if (GetVariable("control_common", "version", &retval) != DATA_TYPE_NONE) { v = (char *) retval.item; } else { v = "not specified"; } if ((sp = ConstraintGetRvalValue("handle", pp, RVAL_TYPE_SCALAR)) || (sp = PromiseID(pp))) { strncpy(handle, sp, CF_MAXVARSIZE - 1); } else { strcpy(handle, "(unknown)"); } if (INFORM || VERBOSE || DEBUG) { snprintf(output, CF_BUFSIZE - 1, "I: Report relates to a promise with handle \"%s\"", handle); AppendItem(&mess, output, NULL); } if (pp && (pp->audit)) { snprintf(output, CF_BUFSIZE - 1, "I: Made in version \'%s\' of \'%s\' near line %zu", v, pp->audit->filename, pp->offset.line); } else { snprintf(output, CF_BUFSIZE - 1, "I: Promise is made internally by cfengine"); } AppendItem(&mess, output, NULL); if (pp != NULL) { switch (pp->promisee.type) { case RVAL_TYPE_SCALAR: snprintf(output, CF_BUFSIZE - 1, "I: The promise was made to: \'%s\'", (char *) pp->promisee.item); AppendItem(&mess, output, NULL); break; case RVAL_TYPE_LIST: snprintf(output, CF_BUFSIZE - 1, "I: The promise was made to (stakeholders): "); RlistPrint(output+strlen(output), CF_BUFSIZE, (Rlist *)pp->promisee.item); AppendItem(&mess, output, NULL); break; default: break; } if (pp->ref) { snprintf(output, CF_BUFSIZE - 1, "I: Comment: %s\n", pp->ref); AppendItem(&mess, output, NULL); } } } verbose = (attr.transaction.report_level == OUTPUT_LEVEL_VERBOSE) || VERBOSE; switch (level) { case OUTPUT_LEVEL_INFORM: if (INFORM || verbose || DEBUG || (attr.transaction.report_level == OUTPUT_LEVEL_INFORM)) { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == OUTPUT_LEVEL_INFORM) { MakeLog(mess, level); } break; case OUTPUT_LEVEL_REPORTING: case OUTPUT_LEVEL_CMDOUT: if (attr.report.to_file) { FileReport(mess, verbose, attr.report.to_file); } else { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == OUTPUT_LEVEL_INFORM) { MakeLog(mess, level); } break; case OUTPUT_LEVEL_VERBOSE: if (verbose || DEBUG) { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == OUTPUT_LEVEL_VERBOSE) { MakeLog(mess, level); } break; case OUTPUT_LEVEL_ERROR: if (attr.report.to_file) { FileReport(mess, verbose, attr.report.to_file); } else { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == OUTPUT_LEVEL_ERROR) { MakeLog(mess, level); } break; case OUTPUT_LEVEL_LOG: MakeLog(mess, level); break; default: break; } if (pp != NULL) { LogPromiseResult(pp->promiser, pp->promisee.type, pp->promisee.item, status, attr.transaction.log_level, mess); } /* Now complete the exits status classes and auditing */ if (pp != NULL) { ClassAuditLog(pp, attr, status, buffer); } DeleteItemList(mess); }
/* * Common functionality of CfFOut and CfOut. */ static void VLog(FILE *fh, enum cfreport level, const char *errstr, const char *fmt, va_list args) { char buffer[CF_BUFSIZE], output[CF_BUFSIZE]; Item *mess = NULL; if ((fmt == NULL) || (strlen(fmt) == 0)) { return; } memset(output, 0, CF_BUFSIZE); vsnprintf(buffer, CF_BUFSIZE - 1, fmt, args); Chop(buffer); AppendItem(&mess, buffer, NULL); if ((errstr == NULL) || (strlen(errstr) > 0)) { snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr()); AppendItem(&mess, output, NULL); } switch (level) { case cf_inform: if (INFORM || VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } break; case cf_verbose: if (VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } break; case cf_error: case cf_reporting: case cf_cmdout: LogList(fh, mess, VERBOSE); MakeLog(mess, level); break; case cf_log: if (VERBOSE || DEBUG) { LogList(fh, mess, VERBOSE); } MakeLog(mess, cf_verbose); break; default: FatalError("Report level unknown"); break; } DeleteItemList(mess); }
void cfPS(enum cfreport level, char status, char *errstr, const Promise *pp, Attributes attr, char *fmt, ...) { va_list ap; char buffer[CF_BUFSIZE], output[CF_BUFSIZE], *v, handle[CF_MAXVARSIZE]; const char *sp; Item *ip, *mess = NULL; int verbose; Rval retval; if ((fmt == NULL) || (strlen(fmt) == 0)) { return; } va_start(ap, fmt); vsnprintf(buffer, CF_BUFSIZE - 1, fmt, ap); va_end(ap); Chop(buffer); AppendItem(&mess, buffer, NULL); if ((errstr == NULL) || (strlen(errstr) > 0)) { snprintf(output, CF_BUFSIZE - 1, " !!! System reports error for %s: \"%s\"", errstr, GetErrorStr()); AppendItem(&mess, output, NULL); } if (level == cf_error) { if (GetVariable("control_common", "version", &retval) != cf_notype) { v = (char *) retval.item; } else { v = "not specified"; } if ((sp = GetConstraintValue("handle", pp, CF_SCALAR)) || (sp = PromiseID(pp))) { strncpy(handle, sp, CF_MAXVARSIZE - 1); } else { strcpy(handle, "(unknown)"); } if (INFORM || VERBOSE || DEBUG) { snprintf(output, CF_BUFSIZE - 1, "I: Report relates to a promise with handle \"%s\"", handle); AppendItem(&mess, output, NULL); } if (pp && pp->audit) { snprintf(output, CF_BUFSIZE - 1, "I: Made in version \'%s\' of \'%s\' near line %zu", v, pp->audit->filename, pp->offset.line); } else { snprintf(output, CF_BUFSIZE - 1, "I: Promise is made internally by cfengine"); } AppendItem(&mess, output, NULL); if (pp != NULL) { switch (pp->promisee.rtype) { case CF_SCALAR: snprintf(output, CF_BUFSIZE - 1, "I: The promise was made to: \'%s\'", (char *) pp->promisee.item); AppendItem(&mess, output, NULL); break; case CF_LIST: snprintf(output, CF_BUFSIZE - 1, "I: The promise was made to (stakeholders): "); PrintRlist(output+strlen(output), CF_BUFSIZE, (Rlist *)pp->promisee.item); AppendItem(&mess, output, NULL); break; } if (pp->ref) { snprintf(output, CF_BUFSIZE - 1, "I: Comment: %s\n", pp->ref); AppendItem(&mess, output, NULL); } } } verbose = (attr.transaction.report_level == cf_verbose) || VERBOSE; switch (level) { case cf_inform: if (INFORM || verbose || DEBUG || attr.transaction.report_level == cf_inform) { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == cf_inform) { MakeLog(mess, level); } break; case cf_reporting: case cf_cmdout: if (attr.report.to_file) { FileReport(mess, verbose, attr.report.to_file); } else { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == cf_inform) { MakeLog(mess, level); } break; case cf_verbose: if (verbose || DEBUG) { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == cf_verbose) { MakeLog(mess, level); } break; case cf_error: if (attr.report.to_file) { FileReport(mess, verbose, attr.report.to_file); } else { LogList(stdout, mess, verbose); } if (attr.transaction.log_level == cf_error) { MakeLog(mess, level); } break; case cf_log: MakeLog(mess, level); break; default: break; } if (pp != NULL) { LogPromiseResult(pp->promiser, pp->promisee.rtype, pp->promisee.item, status, attr.transaction.log_level, mess); } /* Now complete the exits status classes and auditing */ if (pp != NULL) { for (ip = mess; ip != NULL; ip = ip->next) { ClassAuditLog(pp, attr, ip->name, status, buffer); } } DeleteItemList(mess); }