int cbmc_parseoptionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }

  //
  // unwinding of transition systems
  //

  if(cmdline.isset("module") ||
     cmdline.isset("gen-interface"))

  {
    error("This version of CBMC has no support for "
          " hardware modules. Please use hw-cbmc.");
    return 1;
  }
  
  register_languages();

  //
  // command line options
  //

  optionst options;
  get_command_line_options(options);

  bmct bmc(options, context, ui_message_handler);
  set_verbosity(bmc);
  set_verbosity(*this);
  
  if(cmdline.isset("preprocess"))
  {
    preprocessing();
    return 0;
  }

  goto_functionst goto_functions;

  if(get_goto_program(options, bmc, goto_functions))
    return 6;

  if(cmdline.isset("show-claims"))
  {
    const namespacet ns(context);
    show_claims(ns, get_ui(), goto_functions);
    return 0;
  }

  if(set_claims(goto_functions))
    return 7;

  // do actual BMC
  return do_bmc(bmc, goto_functions);
}
Esempio n. 2
0
int symex_parseoptionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }

  register_language(new_ansi_c_language);
  register_language(new_cpp_language);

  //
  // command line options
  //

  optionst options;
  get_command_line_options(options);

  eval_verbosity();

  goto_functionst goto_functions;

  if(get_goto_program(options, goto_functions))
    return 6;

  label_properties(goto_functions);

  if(cmdline.isset("show-properties"))
  {
    const namespacet ns(symbol_table);
    show_properties(ns, get_ui(), goto_functions);
    return 0;
  }

  if(set_properties(goto_functions))
    return 7;

  if(cmdline.isset("show-locs"))
  {
    const namespacet ns(symbol_table);
    locst locs(ns);
    locs.build(goto_functions);
    locs.output(std::cout);
    return 0;
  }

  // do actual Symex

  try
  {
    const namespacet ns(symbol_table);
    path_searcht path_search(ns);

    path_search.set_message_handler(get_message_handler());
    path_search.set_verbosity(get_verbosity());

    if(cmdline.isset("depth"))
      path_search.depth_limit=unsafe_string2unsigned(cmdline.getval("depth"));

    if(cmdline.isset("context-bound"))
      path_search.context_bound=unsafe_string2unsigned(cmdline.getval("context-bound"));

    if(cmdline.isset("unwind"))
      path_search.unwind_limit=unsafe_string2unsigned(cmdline.getval("unwind"));

    if(cmdline.isset("show-vcc"))
    {
      path_search.show_vcc=true;
      path_search(goto_functions);
      return 0;
    }

    // do actual symex
    switch(path_search(goto_functions))
    {
    case safety_checkert::SAFE:
      report_properties(path_search.property_map);
      report_success();
      return 0;

    case safety_checkert::UNSAFE:
      report_properties(path_search.property_map);
      report_failure();
      return 10;

    default:
      return 8;
    }
  }

  catch(const std::string error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  catch(const char *error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  #if 0
  // let's log some more statistics
  debug() << "Memory consumption:" << messaget::endl;
  memory_info(debug());
  debug() << eom;
  #endif
}
int goto_instrument_parse_optionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }
  
  if(cmdline.args.size()!=1 && cmdline.args.size()!=2)
  {
    help();
    return 0;
  }
  
  eval_verbosity();

  try
  {
    register_languages();

    get_goto_program();
    instrument_goto_program();

    if(cmdline.isset("show-value-sets"))
    {
      do_function_pointer_removal();
      do_partial_inlining();
    
      // recalculate numbers, etc.
      goto_functions.update();

      status() << "Pointer Analysis" << eom;
      namespacet ns(symbol_table);
      value_set_analysist value_set_analysis(ns);
      value_set_analysis(goto_functions);

      show_value_sets(get_ui(), goto_functions, value_set_analysis);
      return 0;
    }

    if(cmdline.isset("show-global-may-alias"))
    {
      do_function_pointer_removal();
      do_partial_inlining();
      do_remove_returns();
      parameter_assignments(symbol_table, goto_functions);

      // recalculate numbers, etc.
      goto_functions.update();
      
      namespacet ns(symbol_table);
      global_may_alias_analysist global_may_alias_analysis;
      global_may_alias_analysis(goto_functions, ns);
      global_may_alias_analysis.output(ns, goto_functions, std::cout);

      return 0;
    }

    if(cmdline.isset("show-local-bitvector-analysis"))
    {
      do_function_pointer_removal();
      do_partial_inlining();
      parameter_assignments(symbol_table, goto_functions);
    
      // recalculate numbers, etc.
      goto_functions.update();

      namespacet ns(symbol_table);

      forall_goto_functions(it, goto_functions)
      {
        local_bitvector_analysist local_bitvector_analysis(it->second);
        std::cout << ">>>>" << std::endl;
        std::cout << ">>>> " << it->first << std::endl;
        std::cout << ">>>>" << std::endl;
        local_bitvector_analysis.output(std::cout, it->second, ns);
        std::cout << std::endl;
      }

      return 0;
    }
Esempio n. 4
0
int clobber_parse_optionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }

  register_language(new_ansi_c_language);
  register_language(new_cpp_language);

  //
  // command line options
  //

  optionst options;
  get_command_line_options(options);

  eval_verbosity();

  goto_functionst goto_functions;

  if(get_goto_program(options, goto_functions))
    return 6;
    
  label_properties(goto_functions);

  if(cmdline.isset("show-properties"))
  {
    const namespacet ns(symbol_table);
    show_properties(ns, get_ui(), goto_functions);
    return 0;
  }

  if(set_properties(goto_functions))
    return 7;
    
  // do instrumentation

  try
  {
    const namespacet ns(symbol_table);
    
    std::ofstream out("simulator.c");
    
    if(!out)
      throw std::string("failed to create file simulator.c");
    
    dump_c(goto_functions, true, ns, out);
    
    status() << "instrumentation complete; compile and execute simulator.c" << eom;
    
    return 0;
  }
  
  catch(const std::string error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  catch(const char *error_msg)
  {
    error() << error_msg << messaget::eom;
    return 8;
  }

  #if 0                                         
  // let's log some more statistics
  debug() << "Memory consumption:" << messaget::endl;
  memory_info(debug());
  debug() << eom;
  #endif
}
Esempio n. 5
0
int cbmc_parse_optionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << CBMC_VERSION << std::endl;
    return 0;
  }
  
  //
  // command line options
  //

  optionst options;
  get_command_line_options(options);
  eval_verbosity();

  //
  // Print a banner
  //
  status() << "CBMC version " CBMC_VERSION " "
           << sizeof(void *)*8 << "-bit "
           << config.this_architecture() << " "
           << config.this_operating_system() << eom;

  //
  // Unwinding of transition systems is done by hw-cbmc.
  //

  if(cmdline.isset("module") ||
     cmdline.isset("gen-interface"))

  {
    error() << "This version of CBMC has no support for "
               " hardware modules. Please use hw-cbmc." << eom;
    return 1;
  }
  
  register_languages();
  
  if(cmdline.isset("test-preprocessor"))
    return test_c_preprocessor(ui_message_handler)?8:0;
  
  if(cmdline.isset("preprocess"))
  {
    preprocessing();
    return 0;
  }

  goto_functionst goto_functions;

  // get solver
  cbmc_solverst cbmc_solvers(options, symbol_table, ui_message_handler);
  cbmc_solvers.set_ui(get_ui());

  std::unique_ptr<cbmc_solverst::solvert> cbmc_solver;
  
  try
  {
    cbmc_solver=cbmc_solvers.get_solver();
  }
  
  catch(const char *error_msg)
  {
    error() << error_msg << eom;
    return 1;
  }

  prop_convt &prop_conv=cbmc_solver->prop_conv();

  bmct bmc(options, symbol_table, ui_message_handler, prop_conv);

  int get_goto_program_ret=
    get_goto_program(options, bmc, goto_functions);

  if(get_goto_program_ret!=-1)
    return get_goto_program_ret;

  label_properties(goto_functions);

  if(cmdline.isset("show-claims") || // will go away
     cmdline.isset("show-properties")) // use this one
  {
    const namespacet ns(symbol_table);
    show_properties(ns, get_ui(), goto_functions);
    return 0;
  }

  if(cmdline.isset("show-reachable-properties")) // may replace --show-properties
  {
    const namespacet ns(symbol_table);
    
    // Entry point will have been set before and function pointers removed
    status() << "Removing Unused Functions" << eom;
    remove_unused_functions(goto_functions, ui_message_handler);
    
    show_properties(ns, get_ui(), goto_functions);
    return 0;
  }

  if(set_properties(goto_functions))
    return 7;

  if(cmdline.isset("danger"))
    return run_danger(options, result(), symbol_table, goto_functions);
  if(cmdline.isset("safety"))
    return run_safety(options, result(), symbol_table, goto_functions);

  // do actual BMC
  return do_bmc(bmc, goto_functions);
}
Esempio n. 6
0
int goto_fence_inserter_parse_optionst::doit()
{
  if(cmdline.isset("version"))
  {
    std::cout << MUSKETEER_VERSION << std::endl;
    return 0;
  }

  if(cmdline.args.size()!=1 && cmdline.args.size()!=2)
  {
    help();
    return 0;
  }

  set_verbosity();

  try
  {
    register_languages();

    goto_functionst goto_functions;

    get_goto_program(goto_functions);

    instrument_goto_program(goto_functions);

    // write new binary?
    if(cmdline.args.size()==2)
    {
      status() << "Writing GOTO program to " << cmdline.args[1] << eom;

      if(write_goto_binary(
        cmdline.args[1], symbol_table, goto_functions, get_message_handler()))
        return 1;
      else
        return 0;
    }

    // help();
    return 0;
  }

  catch(const char *e)
  {
    error() << e << eom;
    return 11;
  }

  catch(const std::string e)
  {
    error() << e << eom;
    return 11;
  }

  catch(int)
  {
    return 11;
  }

  catch(std::bad_alloc)
  {
    error() << "Out of memory" << eom;
    return 11;
  }
}