Isis 3 Programmer Reference
Isis.h
1 
6 /* SPDX-License-Identifier: CC0-1.0 */
7 
8 #ifdef __GTHREADS
9 #error *****Isis.h MUST be included before any other files!*****
10 #endif
11 
12 #include "IsisDebug.h"
13 
14 #include <signal.h>
15 
16 #include <QCoreApplication>
17 
18 #include "Application.h"
19 #include "UserInterface.h" // this is an unnecessary include
20 
21 #ifndef APPLICATION
22 #define APPLICATION IsisMain
23 #endif
24 
69 std::map<QString, void *> GuiHelpers();
70 #ifndef GUIHELPERS
71 std::map<QString, void *> GuiHelpers() {
72  std::map<QString, void *> empty;
73  return empty;
74 }
75 #endif
76 
77 void APPLICATION();
78 
79 void startMonitoringMemory();
80 void stopMonitoringMemory();
81 void SegmentationFault(int);
82 void Abort(int);
83 void InterruptSignal(int);
84 
93 int main(int argc, char *argv[]) {
94  // Verify ISISROOT was set
95  // Note: as printing and logging IExceptions requires ISISROOT to be set (for preferences),
96  // The case below cannot be handled with IExceptions
97  if (getenv("ISISROOT") == NULL || QString(getenv("ISISROOT")) == "") {
98  std::cerr << "Please set ISISROOT before running any Isis applications" << std::endl;
99  exit(1);
100  }
101 
102 #ifdef CWDEBUG
103  startMonitoringMemory();
104  signal(SIGSEGV, SegmentationFault);
105  signal(SIGABRT, Abort);
106  signal(SIGINT, InterruptSignal);
107 #endif
108 
109  Isis::Application::p_applicationForceGuiApp = false;
110 
111 #ifdef USE_GUI_QAPP
112  Isis::Application::p_applicationForceGuiApp = true;
113 #endif
114 
115  Isis::Application *app = new Isis::Application(argc, argv);
117  int status = app->Run(APPLICATION);
118  delete app;
119  delete QCoreApplication::instance();
120  return status;
121 }
122 
123 #ifdef CWDEBUG
124 void startMonitoringMemory() {
125 #ifndef NOMEMCHECK
126  MyMutex *mutex = new MyMutex();
127  std::fstream *alloc_output = new std::fstream("/dev/null");
128  Debug(make_all_allocations_invisible_except(NULL));
129  ForAllDebugChannels(if(debugChannel.is_on()) debugChannel.off());
130  Debug(dc::malloc.on());
131  Debug(libcw_do.on());
132  Debug(libcw_do.set_ostream(alloc_output));
133  Debug(libcw_do.set_ostream(alloc_output, mutex));
134  atexit(stopMonitoringMemory);
135 #endif
136 }
137 
138 
139 void stopMonitoringMemory() {
140 #ifndef NOMEMCHECK
141  Debug(
142  alloc_filter_ct alloc_filter;
143  std::vector<std::string> objmasks;
144  objmasks.push_back("libc.so*");
145  objmasks.push_back("libstdc++*");
146  std::vector<std::string> srcmasks;
147  srcmasks.push_back("*new_allocator.h*");
148  srcmasks.push_back("*set_ostream.inl*");
149  alloc_filter.hide_objectfiles_matching(objmasks);
150  alloc_filter.hide_sourcefiles_matching(srcmasks);
151  alloc_filter.hide_unknown_locations();
152  delete libcw_do.get_ostream();
153  libcw_do.set_ostream(&std::cout);
154  list_allocations_on(libcw_do, alloc_filter);
155  dc::malloc.off();
156  libcw_do.off()
157  );
158 #endif
159 }
160 
161 
162 void SegmentationFault(int) {
163  std::vector<std::string> currentStack;
164  StackTrace::GetStackTrace(&currentStack);
165 
166  std::cerr << "Segmentation Fault" << std::endl;
167  for(unsigned int i = 1; i < currentStack.size(); i++) {
168  std::cerr << currentStack[i] << std::endl;
169  }
170 
171  exit(1);
172 }
173 
174 void Abort(int) {
175  std::vector<std::string> currentStack;
176  StackTrace::GetStackTrace(&currentStack);
177 
178  std::cerr << "Abort" << std::endl;
179  for(unsigned int i = 1; i < currentStack.size(); i++) {
180  std::cerr << currentStack[i] << std::endl;
181  }
182 
183  exit(1);
184 }
185 
186 
187 void InterruptSignal(int) {
188  exit(1);
189 }
190 
191 #endif
Isis::Application
Definition: Application.h:101
Isis::Application::RegisterGuiHelpers
void RegisterGuiHelpers(std::map< QString, void * > helpers)
Definition: Application.h:122
GuiHelpers
std::map< QString, void * > GuiHelpers()
Base include file for all Isis applications.
Definition: Isis.h:71
Isis::Application::Run
int Run(void(*funct)())
Runs the program defined in the function funct.
Definition: Application.cpp:177