Isis 3.0 Developer's Reference (API) |
Home |
00001 00024 #ifdef __GTHREADS 00025 #error *****Isis.h MUST be included before any other files!***** 00026 #endif 00027 00028 #include "IsisDebug.h" 00029 00030 #include <signal.h> 00031 00032 #include <QCoreApplication> 00033 00034 #include "Application.h" 00035 #include "UserInterface.h" // this is an unnecessary include 00036 00037 #ifndef APPLICATION 00038 #define APPLICATION IsisMain 00039 #endif 00040 00085 std::map<QString, void *> GuiHelpers(); 00086 #ifndef GUIHELPERS 00087 std::map<QString, void *> GuiHelpers() { 00088 std::map<QString, void *> empty; 00089 return empty; 00090 } 00091 #endif 00092 00093 void APPLICATION(); 00094 00095 void startMonitoringMemory(); 00096 void stopMonitoringMemory(); 00097 void SegmentationFault(int); 00098 void Abort(int); 00099 void InterruptSignal(int); 00100 00109 int main(int argc, char *argv[]) { 00110 #ifdef CWDEBUG 00111 startMonitoringMemory(); 00112 signal(SIGSEGV, SegmentationFault); 00113 signal(SIGABRT, Abort); 00114 signal(SIGINT, InterruptSignal); 00115 #endif 00116 00117 Isis::Application::p_applicationForceGuiApp = false; 00118 00119 #ifdef USE_GUI_QAPP 00120 Isis::Application::p_applicationForceGuiApp = true; 00121 #endif 00122 00123 Isis::Application *app = new Isis::Application(argc, argv); 00124 app->RegisterGuiHelpers(GuiHelpers()); 00125 int status = app->Run(APPLICATION); 00126 delete app; 00127 delete QCoreApplication::instance(); 00128 return status; 00129 } 00130 00131 #ifdef CWDEBUG 00132 void startMonitoringMemory() { 00133 #ifndef NOMEMCHECK 00134 MyMutex *mutex = new MyMutex(); 00135 std::fstream *alloc_output = new std::fstream("/dev/null"); 00136 Debug(make_all_allocations_invisible_except(NULL)); 00137 ForAllDebugChannels(if(debugChannel.is_on()) debugChannel.off()); 00138 Debug(dc::malloc.on()); 00139 Debug(libcw_do.on()); 00140 Debug(libcw_do.set_ostream(alloc_output)); 00141 Debug(libcw_do.set_ostream(alloc_output, mutex)); 00142 atexit(stopMonitoringMemory); 00143 #endif 00144 } 00145 00146 00147 void stopMonitoringMemory() { 00148 #ifndef NOMEMCHECK 00149 Debug( 00150 alloc_filter_ct alloc_filter; 00151 std::vector<std::string> objmasks; 00152 objmasks.push_back("libc.so*"); 00153 objmasks.push_back("libstdc++*"); 00154 std::vector<std::string> srcmasks; 00155 srcmasks.push_back("*new_allocator.h*"); 00156 srcmasks.push_back("*set_ostream.inl*"); 00157 alloc_filter.hide_objectfiles_matching(objmasks); 00158 alloc_filter.hide_sourcefiles_matching(srcmasks); 00159 alloc_filter.hide_unknown_locations(); 00160 delete libcw_do.get_ostream(); 00161 libcw_do.set_ostream(&std::cout); 00162 list_allocations_on(libcw_do, alloc_filter); 00163 dc::malloc.off(); 00164 libcw_do.off() 00165 ); 00166 #endif 00167 } 00168 00169 00170 void SegmentationFault(int) { 00171 std::vector<std::string> currentStack; 00172 StackTrace::GetStackTrace(¤tStack); 00173 00174 std::cerr << "Segmentation Fault" << std::endl; 00175 for(unsigned int i = 1; i < currentStack.size(); i++) { 00176 std::cerr << currentStack[i] << std::endl; 00177 } 00178 00179 exit(1); 00180 } 00181 00182 void Abort(int) { 00183 std::vector<std::string> currentStack; 00184 StackTrace::GetStackTrace(¤tStack); 00185 00186 std::cerr << "Abort" << std::endl; 00187 for(unsigned int i = 1; i < currentStack.size(); i++) { 00188 std::cerr << currentStack[i] << std::endl; 00189 } 00190 00191 exit(1); 00192 } 00193 00194 00195 void InterruptSignal(int) { 00196 exit(1); 00197 } 00198 00199 #endif