int xmain(int argc, char **argv) { MuscleContext *ctx = getMuscleContext(); #if WIN32 // Multi-tasking does not work well in CPU-bound // console apps running under Win32. // Reducing the process priority allows GUI apps // to run responsively in parallel. SetPriorityClass(GetCurrentProcess(), BELOW_NORMAL_PRIORITY_CLASS); #endif ctx->muscle.g_argc = argc; ctx->muscle.g_argv = argv; SetNewHandler(); SetStartTime(); ProcessArgVect(argc - 1, argv + 1); SetParams(); SetLogFile(); //extern void TestSubFams(const char *); //TestSubFams(g_pstrInFileName); //return 0; if (ctx->params.g_bVersion) { printf(MUSCLE_LONG_VERSION "\n"); exit(EXIT_SUCCESS); } if (!ctx->params.g_bQuiet) //Credits(); if (MissingCommand() && isatty(0)) { Usage(); exit(EXIT_SUCCESS); } if (ctx->params.g_bCatchExceptions) { try { Run(); } catch (...) { OnException(); exit(EXIT_Except); } } else Run(); #ifdef _CRTDBG_MAP_ALLOC delete ctx; _CrtDumpMemoryLeaks(); //to Output window of MSVC #endif exit(EXIT_Success); }
Bool HawkAppFrame::Run() { if (HawkApp::Run()) { UInt32 iTickTime = 0; while (m_bRunning && !m_bBreakLoop) { m_iSysTime = (UInt32)HawkOSOperator::GetSysTime(); iTickTime = HawkOSOperator::GetTickCount(); m_iElapseTime = iTickTime - m_iTickTime; m_iTickTime = iTickTime; //Hawk体系帧更新 HawkUtil::Tick(m_iElapseTime); //网关代理器更新 if (m_pGateProxy && !m_pGateProxy->Update()) { HawkSleep(DEFAULT_SLEEP); } //逻辑帧更新 OnTick(m_iElapseTime); } //服务器关闭异常 OnException(0); //关闭服务器 Stop(); return true; } return false; }
Bool HawkAppFrame::OnGateProxyDisconnect() { //网关断开连接异常 OnException(0); m_mSidAddr.Clear(); return true; }
int TCPServer_Exception(SOCKET iSocket) { if(iSocket <= 0) { return -1; } int iRet = OnException(iSocket); if(iRet < 0) { XLOG_ERROR(m_pLogger, "OnException Error: iRet = %d", iRet); } return 0; }
qtDLGNanomite::qtDLGNanomite(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags), m_IsRestart(false) { setupUi(this); setAcceptDrops(true); QApplication::setStyle(new QPlastiqueStyle); QFontDatabase::addApplicationFont(":/Fonts/Fonts/consola.ttf"); this->setStyleSheet(clsHelperClass::LoadStyleSheet()); qRegisterMetaType<DWORD>("DWORD"); qRegisterMetaType<quint64>("quint64"); qRegisterMetaType<BPStruct>("BPStruct"); qRegisterMetaType<HANDLE>("HANDLE"); clsAPIImport::LoadFunctions(); coreBPManager = new clsBreakpointManager; coreDebugger = new clsDebugger(coreBPManager); coreDisAs = new clsDisassembler; PEManager = new clsPEManager; dlgDetInfo = new qtDLGDetailInfo(this,Qt::Window); dlgDbgStr = new qtDLGDebugStrings(this,Qt::Window); dlgBPManager = new qtDLGBreakPointManager(this,Qt::Window); dlgTraceWindow = new qtDLGTrace(this,Qt::Window); dlgPatchManager = new qtDLGPatchManager(this,Qt::Window); dlgBookmark = new qtDLGBookmark(this, Qt::Window); qtNanomiteDisAsColor = new qtNanomiteDisAsColorSettings; qtDLGMyWindow = this; lExceptionCount = 0; LoadWidgets(); settings->CheckIfFirstRun(); settings->LoadDebuggerSettings(coreDebugger); settings->LoadDisassemblerColor(qtNanomiteDisAsColor); settings->LoadRecentDebuggedFiles(m_recentDebuggedFiles); LoadRecentFileMenu(true); DisAsGUI = new qtDLGDisassembler(this); this->setCentralWidget(DisAsGUI); // Callbacks from Debugger Thread to GUI connect(coreDebugger,SIGNAL(OnThread(DWORD,DWORD,quint64,bool,DWORD,bool)), dlgDetInfo,SLOT(OnThread(DWORD,DWORD,quint64,bool,DWORD,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnPID(DWORD,QString,DWORD,quint64,bool)), dlgDetInfo,SLOT(OnPID(DWORD,QString,DWORD,quint64,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnException(QString,QString,quint64,quint64,DWORD,DWORD)), dlgDetInfo,SLOT(OnException(QString,QString,quint64,quint64,DWORD,DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDbgString(QString,DWORD)), dlgDbgStr,SLOT(OnDbgString(QString,DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDll(QString,DWORD,quint64,bool)), dlgDetInfo,SLOT(OnDll(QString,DWORD,quint64,bool)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnLog(QString)), logView,SLOT(OnLog(QString)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(AskForException(DWORD)),this,SLOT(AskForException(DWORD)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDebuggerBreak()),this,SLOT(OnDebuggerBreak()),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnDebuggerTerminated()),this,SLOT(OnDebuggerTerminated()),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),dlgBPManager,SLOT(UpdateCompleter(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),dlgBookmark,SLOT(UpdateBookmarks(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(UpdateOffsetsPatches(HANDLE,int)),dlgPatchManager,SLOT(UpdateOffsetPatch(HANDLE,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(UpdateOffsetsPatches(HANDLE,int)),dlgBookmark,SLOT(BookmarkUpdateOffsets(HANDLE,int)),Qt::QueuedConnection); connect(coreBPManager,SIGNAL(OnBreakpointAdded(BPStruct,int)),dlgBPManager,SLOT(OnUpdate(BPStruct,int)),Qt::QueuedConnection); connect(coreBPManager,SIGNAL(OnBreakpointDeleted(quint64)),dlgBPManager,SLOT(OnDelete(quint64)),Qt::QueuedConnection); // Callbacks from Debugger to PEManager connect(coreDebugger,SIGNAL(OnNewPID(QString,int)),PEManager,SLOT(InsertPIDForFile(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(DeletePEManagerObject(QString,int)),PEManager,SLOT(CloseFile(QString,int)),Qt::QueuedConnection); connect(coreDebugger,SIGNAL(CleanPEManager()),PEManager,SLOT(CleanPEManager()),Qt::QueuedConnection); // Actions for the MainMenu and Toolbar connect(actionFile_OpenNew, SIGNAL(triggered()), this, SLOT(action_FileOpenNewFile())); connect(actionFile_AttachTo, SIGNAL(triggered()), this, SLOT(action_FileAttachTo())); connect(actionFile_Detach, SIGNAL(triggered()), this, SLOT(action_FileDetach())); connect(actionFile_Exit, SIGNAL(triggered()), this, SLOT(action_FileTerminateGUI())); connect(actionFile_Load, SIGNAL(triggered()), this, SLOT(action_FileLoad())); connect(actionFile_Save, SIGNAL(triggered()), this, SLOT(action_FileSave())); connect(actionDebug_Start, SIGNAL(triggered()), this, SLOT(action_DebugStart())); connect(actionDebug_Stop, SIGNAL(triggered()), this, SLOT(action_DebugStop())); connect(actionDebug_Restart, SIGNAL(triggered()), this, SLOT(action_DebugRestart())); connect(actionDebug_Suspend, SIGNAL(triggered()), this, SLOT(action_DebugSuspend())); connect(actionDebug_Step_In, SIGNAL(triggered()), this, SLOT(action_DebugStepIn())); connect(actionDebug_Step_Out, SIGNAL(triggered()), this, SLOT(action_DebugStepOut())); connect(actionDebug_Step_Over, SIGNAL(triggered()), this, SLOT(action_DebugStepOver())); connect(actionOptions_About, SIGNAL(triggered()), this, SLOT(action_OptionsAbout())); connect(actionOptions_Options, SIGNAL(triggered()), this, SLOT(action_OptionsOptions())); connect(actionOptions_Update, SIGNAL(triggered()), this, SLOT(action_OptionsUpdate())); connect(actionWindow_Detail_Information, SIGNAL(triggered()), this, SLOT(action_WindowDetailInformation())); connect(actionWindow_Breakpoint_Manager, SIGNAL(triggered()), this, SLOT(action_WindowBreakpointManager())); connect(actionWindow_Show_Patches, SIGNAL(triggered()), this, SLOT(action_WindowPatches())); connect(actionWindow_Show_Memory, SIGNAL(triggered()), this, SLOT(action_WindowShowMemory())); connect(actionWindow_Show_Heap, SIGNAL(triggered()), this, SLOT(action_WindowShowHeap())); connect(actionWindow_Show_Strings, SIGNAL(triggered()), this, SLOT(action_WindowShowStrings())); connect(actionWindow_Show_Debug_Output, SIGNAL(triggered()), this, SLOT(action_WindowShowDebugOutput())); connect(actionWindow_Show_Handles, SIGNAL(triggered()), this, SLOT(action_WindowShowHandles())); connect(actionWindow_Show_Windows, SIGNAL(triggered()), this, SLOT(action_WindowShowWindows())); connect(actionWindow_Show_Functions, SIGNAL(triggered()), this, SLOT(action_WindowShowFunctions())); connect(actionWindow_Show_Privileges, SIGNAL(triggered()), this, SLOT(action_WindowShowPrivileges())); connect(actionWindow_Show_Bookmarks, SIGNAL(triggered()), this, SLOT(action_WindowShowBookmarks())); connect(action_Debug_Run_to_UserCode,SIGNAL(triggered()), this, SLOT(action_DebugRunToUserCode())); connect(actionDebug_Trace_Start, SIGNAL(triggered()), this, SLOT(action_DebugTraceStart())); connect(actionDebug_Trace_Stop, SIGNAL(triggered()), this, SLOT(action_DebugTraceStop())); connect(actionDebug_Trace_Show, SIGNAL(triggered()), this, SLOT(action_DebugTraceShow())); connect(actionWindow_Show_PEEditor, SIGNAL(triggered()), this, SLOT(action_WindowShowPEEditor())); // Callbacks to display disassembly connect(dlgTraceWindow,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(cpuRegView,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(dlgDetInfo,SIGNAL(ShowInDisassembler(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(coreDisAs,SIGNAL(DisAsFinished(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64)),Qt::QueuedConnection); connect(dlgBPManager,SIGNAL(OnDisplayDisassembly(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); connect(dlgBookmark,SIGNAL(ShowInDisassembler(quint64)),DisAsGUI,SLOT(OnDisplayDisassembly(quint64))); // Callbacks from PatchManager to GUI connect(dlgPatchManager,SIGNAL(OnReloadDebugger()),this,SLOT(OnDebuggerBreak())); // Callbacks from Disassembler GUI to GUI connect(DisAsGUI,SIGNAL(OnDebuggerBreak()),this,SLOT(OnDebuggerBreak())); // Callbacks to StateBar connect(dlgTraceWindow,SIGNAL(OnUpdateStatusBar(int,quint64)),this,SLOT(UpdateStateBar(int,quint64))); actionDebug_Trace_Stop->setDisabled(true); ParseCommandLineArgs(); }
bool EngineApp::OnAssert(const char* psz, const char* pszFile, int line, const char* pszModule) { OnException(0, NULL); return Win32App::OnAssert(psz, pszFile, line, pszModule); }
int CCgiApplication::Run(void) { // Value to return from this method Run() int result; // Try to run as a Fast-CGI loop if ( x_RunFastCGI(&result) ) { return result; } /// Run as a plain CGI application // Make sure to restore old diagnostic state after the Run() CDiagRestorer diag_restorer; #if defined(NCBI_OS_UNIX) // Disable SIGPIPE if not allowed. if ( !TParamAllowSigpipe::GetDefault() ) { signal(SIGPIPE, SIG_IGN); struct sigaction sigterm, sigtermold; memset(&sigterm, 0, sizeof(sigterm)); sigterm.sa_handler = SigTermHandler; sigterm.sa_flags = SA_RESETHAND; if (sigaction(SIGTERM, &sigterm, &sigtermold) == 0 && sigtermold.sa_handler != SIG_DFL) { sigaction(SIGTERM, &sigtermold, 0); } } // Compose diagnostics prefix PushDiagPostPrefix(NStr::IntToString(getpid()).c_str()); #endif PushDiagPostPrefix(GetEnvironment().Get(m_DiagPrefixEnv).c_str()); // Timing CTime start_time(CTime::eCurrent); // Logging for statistics bool is_stat_log = GetConfig().GetBool("CGI", "StatLog", false, 0, CNcbiRegistry::eReturn); bool skip_stat_log = false; auto_ptr<CCgiStatistics> stat(is_stat_log ? CreateStat() : 0); CNcbiOstream* orig_stream = NULL; //int orig_fd = -1; CNcbiStrstream result_copy; auto_ptr<CNcbiOstream> new_stream; try { _TRACE("(CGI) CCgiApplication::Run: calling ProcessRequest"); GetDiagContext().SetAppState(eDiagAppState_RequestBegin); m_Context.reset( CreateContext() ); _ASSERT(m_Context.get()); m_Context->CheckStatus(); ConfigureDiagnostics(*m_Context); x_AddLBCookie(); try { // Print request start message x_OnEvent(eStartRequest, 0); VerifyCgiContext(*m_Context); ProcessHttpReferer(); LogRequest(); try { m_Cache.reset( GetCacheStorage() ); } catch( exception& ex ) { ERR_POST_X(1, "Couldn't create cache : " << ex.what()); } bool skip_process_request = false; bool caching_needed = IsCachingNeeded(m_Context->GetRequest()); if (m_Cache.get() && caching_needed) { skip_process_request = GetResultFromCache(m_Context->GetRequest(), m_Context->GetResponse().out()); } if (!skip_process_request) { if( m_Cache.get() ) { list<CNcbiOstream*> slist; orig_stream = m_Context->GetResponse().GetOutput(); slist.push_back(orig_stream); slist.push_back(&result_copy); new_stream.reset(new CWStream(new CMultiWriter(slist), 0,0, CRWStreambuf::fOwnWriter)); m_Context->GetResponse().SetOutput(new_stream.get()); } GetDiagContext().SetAppState(eDiagAppState_Request); result = CCgiContext::ProcessCORSRequest( m_Context->GetRequest(), m_Context->GetResponse()) ? 0 : ProcessRequest(*m_Context); GetDiagContext().SetAppState(eDiagAppState_RequestEnd); m_Context->GetResponse().Finalize(); if (result != 0) { SetHTTPStatus(500); m_ErrorStatus = true; } else { if (m_Cache.get()) { m_Context->GetResponse().Flush(); if (m_IsResultReady) { if(caching_needed) SaveResultToCache(m_Context->GetRequest(), result_copy); else { auto_ptr<CCgiRequest> request(GetSavedRequest(m_RID)); if (request.get()) SaveResultToCache(*request, result_copy); } } else if (caching_needed) { SaveRequest(m_RID, m_Context->GetRequest()); } } } } } catch (CCgiException& e) { if ( x_DoneHeadRequest() ) { // Ignore errors after HEAD request has been finished. GetDiagContext().SetAppState(eDiagAppState_RequestEnd); } else { if ( e.GetStatusCode() < CCgiException::e200_Ok || e.GetStatusCode() >= CCgiException::e400_BadRequest ) { throw; } GetDiagContext().SetAppState(eDiagAppState_RequestEnd); // If for some reason exception with status 2xx was thrown, // set the result to 0, update HTTP status and continue. m_Context->GetResponse().SetStatus(e.GetStatusCode(), e.GetStatusMessage()); } result = 0; } #ifdef NCBI_OS_MSWIN // Logging - on MSWin this must be done before flushing the output. if ( is_stat_log && !skip_stat_log ) { stat->Reset(start_time, result); stat->Submit(stat->Compose()); } is_stat_log = false; #endif _TRACE("CCgiApplication::Run: flushing"); m_Context->GetResponse().Flush(); _TRACE("CCgiApplication::Run: return " << result); x_OnEvent(result == 0 ? eSuccess : eError, result); x_OnEvent(eExit, result); } catch (exception& e) { GetDiagContext().SetAppState(eDiagAppState_RequestEnd); if ( x_DoneHeadRequest() ) { // Ignore errors after HEAD request has been finished. result = 0; x_OnEvent(eSuccess, result); } else { // Call the exception handler and set the CGI exit code result = OnException(e, NcbiCout); x_OnEvent(eException, result); // Logging {{ string msg = "(CGI) CCgiApplication::ProcessRequest() failed: "; msg += e.what(); if ( is_stat_log ) { stat->Reset(start_time, result, &e); msg = stat->Compose(); stat->Submit(msg); skip_stat_log = true; // Don't print the same message again } }} // Exception reporting. Use different severity for broken connection. ios_base::failure* fex = dynamic_cast<ios_base::failure*>(&e); CNcbiOstream* os = m_Context.get() ? m_Context->GetResponse().GetOutput() : NULL; if ((fex && os && !os->good()) || m_OutputBroken) { if ( !TClientConnIntOk::GetDefault() ) { ERR_POST_X(13, Severity(TClientConnIntSeverity::GetDefault()) << "Connection interrupted"); } } else { NCBI_REPORT_EXCEPTION_X(13, "(CGI) CCgiApplication::Run", e); } } } #ifndef NCBI_OS_MSWIN // Logging if ( is_stat_log && !skip_stat_log ) { stat->Reset(start_time, result); stat->Submit(stat->Compose()); } #endif x_OnEvent(eEndRequest, 120); x_OnEvent(eExit, result); if (m_Context.get()) { m_Context->GetResponse().SetOutput(NULL); } return result; }