コード例 #1
0
ファイル: exception.cpp プロジェクト: fabienchaix/simgrid
static void handler()
{
  // Avoid doing crazy things if we get an uncaught exception inside
  // an uncaught exception
  static std::atomic_flag lock = ATOMIC_FLAG_INIT;
  if (lock.test_and_set()) {
    XBT_ERROR("Multiple uncaught exceptions");
    std::abort();
  }

  // Get the current backtrace and exception
  auto e = std::current_exception();
  auto bt = backtrace();
  try {
    std::rethrow_exception(e);
  }

  // We manage C++ exception ourselves
  catch (std::exception& e) {
    logException(xbt_log_priority_critical, "Uncaught exception", e);
    showBacktrace(bt);
    std::abort();
  }

  // We don't know how to manage other exceptions
  catch (...) {
    // If there was another handler let's delegate to it
    if (previous_terminate_handler)
      previous_terminate_handler();
    else {
      XBT_ERROR("Unknown uncaught exception");
      showBacktrace(bt);
      std::abort();
    }
  }

}
コード例 #2
0
ファイル: trace.cpp プロジェクト: olivettikatz/mitten
	bool canDisplayMessages(string module, string method, int &mc, int mcf)
	{
		bool rtn = false;

		for (vector<string>::iterator i = moduleFilters.begin(); i != moduleFilters.end(); i++)
		{
			if (module.find(*i) != string::npos)
			{
				rtn = true;
				break;
			}
		}

		for (vector<string>::iterator i = methodFilters.begin(); i != methodFilters.end(); i++)
		{
			if (method.find(*i) != string::npos)
			{
				rtn = true;
				break;
			}
		}

		if (rtn == false && (moduleFilters.empty() && methodFilters.empty()))
			rtn = true;

		if (rtn == true)
		{
			rtn = TRACE_IS_DEBUG() && (mc++ > mcf-5);
		}

		if (rtn == true)
		{
			if (isBacktraceRequested())
			{
				cout << "Backtrace for " << method << ":\n";
				cout << showBacktrace();
			}
		}

		return rtn;
	}
コード例 #3
0
ファイル: blue.c プロジェクト: elechak/blue
int blue_main(int argc, char **argv){
    
    int arg_index;
    int mode=0;
    char  * filename = NULL;
    char * output_filename = NULL;

    /* Not enough arguments */
    if (argc < 2 ) usage();

    Global = malloc(sizeof(struct Global));
        if ( ! Global){
            printf("Out of Memory\n");
            exit(1);
        }
    
    Global->dbg_status = 0;        

    /* handle arguments to blue */
    for (arg_index=1; arg_index<argc ; arg_index++){
        if (argv[arg_index][0] == '-'){
            
            /* disassemble and quit*/
            if ( strcmp(argv[arg_index], "-d")==0 ) mode = 1;
            else if ( strcmp(argv[arg_index], "-c")==0 ) mode = 2;
            else if ( strcmp(argv[arg_index], "-g")==0 ) Global->dbg_status = 1;
                
            else if ( strcmp(argv[arg_index], "-o")==0 ){
                arg_index++;
                output_filename = argv[arg_index];
            }
                
            else if ( strcmp(argv[arg_index], "-s")==0 ){
                mode = 3 ;
            }
            
            else if ( strcmp(argv[arg_index], "-a")==0 ){
                mode = 4 ;
            }            
                      
            
            if (argc <3) return 0;

        }else{
            filename = argv[arg_index];
            break;
        }
    }

    /* Initialization routines */
        global_init();
    
    link_setThreadState(0); // turn multi-threading off until needed

    if (mode==1){
    /* DISASSEMBLE */
        Link module = create_module_filename(filename);
        string_t code = disassemble(module->value.module->bytecode);
        string_fprint(code , stdout);
        exit(0);
    } else if (mode == 2){
    /* COMPILE */
        Link module = create_module_filename(filename);
        module_save( module,  output_filename ? output_filename : "blue.blx");
        exit(0);
    }else if (mode == 3){
    /* COMPILE TO ASSEMBLY CODE */
        char * acode = compile_file( filename);
        
        if ( memcmp( acode, "ERR:",4) ==0 ){
            printf( acode+4);
            exit(0);
        }
        
        if (output_filename){
            FILE * fp = fopen( output_filename,"wb");
            fprintf(fp,acode);
            fclose(fp);            
        }else{
            printf(acode);
        }
        free(acode);
        exit(0);        

    }else if (mode == 4){
    /* ASSEMBLE THS ASSEMBLY CODE TO BYTECODE */
        char * acode = file_load(filename);
        
        if ( memcmp( acode, "ERR:",4) ==0 ){
            printf( acode+4);
            exit(0);
        }        
        
        Bytes bytes = assemble( acode );
        if (output_filename){
            bytes_save(bytes, output_filename);
        }else{
            bytes_save(bytes, "out.blx");
        }
        free(acode);
        exit(0);
    }
    
    /* Add arguments from call to this application */
        Link Arg = array_new(argc-arg_index);
        Link * Argv = array_getArray(Arg);
        Link a = NULL;

        int c = 0;

        for(c=0; c <argc-arg_index; c++){
            a = create_string_str( string_new((argv+arg_index)[c]) );
            Argv[c] =a;
        }

    /* creates and runs the module */
    Link main_ret = module_new(filename, Arg);
    link_free(Arg);

    if (main_ret){                
        showBacktrace(main_ret);
        link_free(main_ret);
    }
    
    fflush(stdout);
    fflush(stderr);

    exit(0);
    return 0;
}