-void real_main() {
- thrd_t user_thread;
- ucontext_t main_context;
-
- //Create the singleton snapshotStack object
- snapshotObject = new snapshotStack();
-
- model = new ModelChecker();
-
- if (getcontext(&main_context))
- return;
-
- model->set_system_context(&main_context);
-
- do {
- /* Start user program */
- model->add_thread(new Thread(&user_thread, &user_main, NULL));
-
- /* Wait for all threads to complete */
- thread_wait_finish();
- } while (model->next_execution());
-
- delete model;
-
- DEBUG("Exiting\n");
+static void parse_options(struct model_params *params, int argc, char **argv)
+{
+ const char *shortopts = "hdnt:o:u:x:v::";
+ const struct option longopts[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"verbose", optional_argument, NULL, 'v'},
+ {"uninitialized", required_argument, NULL, 'u'},
+ {"analysis", required_argument, NULL, 't'},
+ {"options", required_argument, NULL, 'o'},
+ {"maxexecutions", required_argument, NULL, 'x'},
+ {0, 0, 0, 0} /* Terminator */
+ };
+ int opt, longindex;
+ bool error = false;
+ while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
+ switch (opt) {
+ case 'h':
+ print_usage(argv[0], params);
+ break;
+ case 'd':
+ params->threadsnocleanup = true;
+ break;
+ case 'n':
+ params->nofork = true;
+ break;
+ case 'x':
+ params->maxexecutions = atoi(optarg);
+ break;
+ case 'v':
+ params->verbose = optarg ? atoi(optarg) : 1;
+ break;
+ case 'u':
+ params->uninitvalue = atoi(optarg);
+ break;
+ case 't':
+ if (install_plugin(optarg))
+ error = true;
+ break;
+ case 'o':
+ {
+ ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
+ if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
+ error = true;
+ }
+ break;
+ default: /* '?' */
+ error = true;
+ break;
+ }
+ }
+
+ /* Pass remaining arguments to user program */
+ params->argc = argc - (optind - 1);
+ params->argv = argv + (optind - 1);
+
+ /* Reset program name */
+ params->argv[0] = argv[0];
+
+ /* Reset (global) optind for potential use by user program */
+ optind = 1;
+
+ if (error)
+ print_usage(argv[0], params);