GscPreferencesWindow::GscPreferencesWindow(BaseObjectType* gtkcobj, const app_ui_res_ref_t& ref_ui) : AppUIResWidget<GscPreferencesWindow, true>(gtkcobj, ref_ui), device_options_treeview(0) { // Connect callbacks APP_GTKMM_CONNECT_VIRTUAL(delete_event); // make sure the event handler is called Gtk::Button* window_cancel_button = 0; APP_UI_RES_AUTO_CONNECT(window_cancel_button, clicked); Gtk::Button* window_ok_button = 0; APP_UI_RES_AUTO_CONNECT(window_ok_button, clicked); Gtk::Button* window_reset_all_button = 0; APP_UI_RES_AUTO_CONNECT(window_reset_all_button, clicked); Gtk::Button* smartctl_binary_browse_button = 0; APP_UI_RES_AUTO_CONNECT(smartctl_binary_browse_button, clicked); Gtk::Button* device_options_add_device_button = 0; APP_UI_RES_AUTO_CONNECT(device_options_add_device_button, clicked); Gtk::Button* device_options_remove_device_button = 0; APP_UI_RES_AUTO_CONNECT(device_options_remove_device_button, clicked); Gtk::Entry* device_options_device_entry = 0; APP_UI_RES_AUTO_CONNECT(device_options_device_entry, changed); Gtk::Entry* device_options_parameter_entry = 0; APP_UI_RES_AUTO_CONNECT(device_options_parameter_entry, changed); // Accelerators Glib::RefPtr<Gtk::AccelGroup> accel_group = this->get_accel_group(); if (window_cancel_button) { window_cancel_button->add_accelerator("clicked", accel_group, GDK_Escape, Gdk::ModifierType(0), Gtk::AccelFlags(0)); } // create Device Options treeview get_ui()->get_widget_derived("device_options_treeview", device_options_treeview); device_options_treeview->set_preferences_window(this); // we can't do this in treeview's constructor, it doesn't know about this window yet. this->device_widget_set_remove_possible(false); // initial state // hide win32-only options for non-win32. #ifndef _WIN32 Gtk::CheckButton* smartctl_search_check = this->lookup_widget<Gtk::CheckButton*>("search_in_smartmontools_first_check"); if (smartctl_search_check) smartctl_search_check->hide(); #endif // --------------- import_config(); // show(); }
void fichier_local::open(const string & chemin, gf_mode m, U_I permission, bool fail_if_exists, bool erase, bool furtive_mode) { U_I o_mode = O_BINARY; const char *name = chemin.c_str(); adv = advise_normal; switch(m) { case gf_read_only : o_mode |= O_RDONLY; break; case gf_write_only : o_mode |= O_WRONLY; break; case gf_read_write : o_mode |= O_RDWR; break; default: throw SRC_BUG; } if(m != gf_read_only) { o_mode |= O_CREAT; if(fail_if_exists) o_mode |= O_EXCL; if(erase) o_mode |= O_TRUNC; } #if FURTIVE_READ_MODE_AVAILABLE if(furtive_mode) // only used for read-only, but available for write-only and read-write modes o_mode |= O_NOATIME; #else if(furtive_mode) throw Ecompilation(gettext("Furtive read mode")); #endif try { do { if(m != gf_read_only) filedesc = ::open(name, o_mode, permission); else filedesc = ::open(name, o_mode); if(filedesc < 0) { switch(errno) { case ENOSPC: if(get_mode() == gf_read_only) throw SRC_BUG; // in read_only mode we do not need to create a new inode !!! get_ui().pause(gettext("No space left for inode, you have the opportunity to make some room now. When done : can we continue ?")); break; case EEXIST: throw Esystem("fichier_local::open", tools_strerror_r(errno), Esystem::io_exist); case ENOENT: throw Esystem("fichier_local::open", tools_strerror_r(errno), Esystem::io_absent); default: throw Erange("fichier_local::open", string(gettext("Cannot open file : ")) + tools_strerror_r(errno)); } } } while(filedesc < 0 && errno == ENOSPC); } catch(...) { if(filedesc >= 0) { ::close(filedesc); filedesc = -1; } throw; } }
void symex_parse_optionst::report_properties( const path_searcht::property_mapt &property_map) { if(get_ui()==ui_message_handlert::PLAIN) status() << "\n** Results:" << eom; for(path_searcht::property_mapt::const_iterator it=property_map.begin(); it!=property_map.end(); it++) { if(get_ui()==ui_message_handlert::XML_UI) { xmlt xml_result("result"); xml_result.set_attribute("claim", id2string(it->first)); std::string status_string; switch(it->second.status) { case path_searcht::SUCCESS: status_string="SUCCESS"; break; case path_searcht::FAILURE: status_string="FAILURE"; break; case path_searcht::NOT_REACHED: status_string="SUCCESS"; break; } xml_result.set_attribute("status", status_string); std::cout << xml_result << "\n"; } else { status() << "[" << it->first << "] " << it->second.description << ": "; switch(it->second.status) { case path_searcht::SUCCESS: status() << "SUCCESS"; break; case path_searcht::FAILURE: status() << "FAILURE"; break; case path_searcht::NOT_REACHED: status() << "SUCCESS"; break; } status() << eom; } if((cmdline.isset("show-trace") || cmdline.isset("trace")) && it->second.is_failure()) show_counterexample(it->second.error_trace); } if(!cmdline.isset("property")) { status() << eom; unsigned failed=0; for(path_searcht::property_mapt::const_iterator it=property_map.begin(); it!=property_map.end(); it++) if(it->second.is_failure()) failed++; status() << "** " << failed << " of " << property_map.size() << " failed" << eom; } }
void MainWindow::clear_console_slot() { get_ui()->textEdit_sr->clear(); }
int symex_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); register_language(new_java_bytecode_language); // // command line options // optionst options; get_command_line_options(options); eval_verbosity(); goto_model.set_message_handler(get_message_handler()); if(goto_model(cmdline.args)) return 6; if(process_goto_program(options)) return 6; label_properties(goto_model); if(cmdline.isset("show-properties")) { show_properties(goto_model, get_ui()); return 0; } if(set_properties()) return 7; if(cmdline.isset("show-locs")) { const namespacet ns(goto_model.symbol_table); locst locs(ns); locs.build(goto_model.goto_functions); locs.output(std::cout); return 0; } // do actual Symex try { const namespacet ns(goto_model.symbol_table); path_searcht path_search(ns); path_search.set_message_handler(get_message_handler()); if(cmdline.isset("depth")) path_search.set_depth_limit(unsafe_string2unsigned(cmdline.get_value("depth"))); if(cmdline.isset("context-bound")) path_search.set_context_bound(unsafe_string2unsigned(cmdline.get_value("context-bound"))); if(cmdline.isset("branch-bound")) path_search.set_branch_bound(unsafe_string2unsigned(cmdline.get_value("branch-bound"))); if(cmdline.isset("unwind")) path_search.set_unwind_limit(unsafe_string2unsigned(cmdline.get_value("unwind"))); if(cmdline.isset("dfs")) path_search.set_dfs(); if(cmdline.isset("bfs")) path_search.set_bfs(); if(cmdline.isset("locs")) path_search.set_locs(); if(cmdline.isset("show-vcc")) { path_search.show_vcc=true; path_search(goto_model.goto_functions); return 0; } path_search.eager_infeasibility= cmdline.isset("eager-infeasibility"); if(cmdline.isset("cover")) { // test-suite generation path_search(goto_model.goto_functions); report_cover(path_search.property_map); return 0; } else { // do actual symex, for assertion checking switch(path_search(goto_model.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 }
bool symex_parse_optionst::process_goto_program(const optionst &options) { try { // we add the library status() << "Adding CPROVER library" << eom; link_to_library(goto_model, ui_message_handler); // do partial inlining status() << "Partial Inlining" << eom; goto_partial_inline(goto_model, ui_message_handler); // add generic checks status() << "Generic Property Instrumentation" << eom; goto_check(options, goto_model); // remove stuff remove_complex(goto_model); remove_vector(goto_model); remove_virtual_functions(goto_model); // recalculate numbers, etc. goto_model.goto_functions.update(); // add loop ids goto_model.goto_functions.compute_loop_numbers(); if(cmdline.isset("cover")) { std::string criterion=cmdline.get_value("cover"); coverage_criteriont c; if(criterion=="assertion" || criterion=="assertions") c=coverage_criteriont::ASSERTION; else if(criterion=="path" || criterion=="paths") c=coverage_criteriont::PATH; else if(criterion=="branch" || criterion=="branches") c=coverage_criteriont::BRANCH; else if(criterion=="location" || criterion=="locations") c=coverage_criteriont::LOCATION; else if(criterion=="decision" || criterion=="decisions") c=coverage_criteriont::DECISION; else if(criterion=="condition" || criterion=="conditions") c=coverage_criteriont::CONDITION; else if(criterion=="mcdc") c=coverage_criteriont::MCDC; else if(criterion=="cover") c=coverage_criteriont::COVER; else { error() << "unknown coverage criterion" << eom; return true; } status() << "Instrumenting coverge goals" << eom; instrument_cover_goals(symbol_table, goto_model.goto_functions, c); goto_model.goto_functions.update(); } // show it? if(cmdline.isset("show-loops")) { show_loop_ids(get_ui(), goto_model.goto_functions); return true; } // show it? if(cmdline.isset("show-goto-functions")) { const namespacet ns(goto_model.symbol_table); goto_model.goto_functions.output(ns, std::cout); return true; } } catch(const char *e) { error() << e << eom; return true; } catch(const std::string e) { error() << e << eom; return true; } catch(int) { return true; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return true; } return false; }
bool symex_parseoptionst::process_goto_program( const optionst &options, goto_functionst &goto_functions) { try { namespacet ns(symbol_table); // do partial inlining status() << "Partial Inlining" << eom; goto_partial_inline(goto_functions, ns, ui_message_handler); // add generic checks status() << "Generic Property Instrumentation" << eom; goto_check(ns, options, goto_functions); // recalculate numbers, etc. goto_functions.update(); // add loop ids goto_functions.compute_loop_numbers(); // if we aim to cover, replace // all assertions by false to prevent simplification if(cmdline.isset("cover-assertions")) make_assertions_false(goto_functions); // show it? if(cmdline.isset("show-loops")) { show_loop_ids(get_ui(), goto_functions); return true; } // show it? if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); return true; } } catch(const char *e) { error(e); return true; } catch(const std::string e) { error(e); return true; } catch(int) { return true; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return true; } return false; }
bool escape_catalogue::read(const cat_entree * & ref) const { escape_catalogue *ceci = const_cast<escape_catalogue *>(this); const cat_directory *ref_dir = NULL; const cat_eod *ref_eod = NULL; bool stop = false; if(pdesc.esc == NULL) throw SRC_BUG; ref = NULL; // if we have already read the whole archive contents (included detruits object), // we do not need inspect the archive again, we instead use the data in memory if(status == ec_completed) return catalogue::read(ref); pdesc.stack->flush_read_above(pdesc.esc); try { while(ref == NULL && !stop) { switch(status) { case ec_init: ceci->status = ec_marks; // no break; case ec_marks: if(min_read_offset > pdesc.esc->get_position()) { // for some reason, like datacorruption, bad CRC or missing CRC in hard linked inode // we skipped back to the hard linked inode information (it failed to be restored the first time) // We must not read again and again the same data, so we skip forward to min_read_offset ceci->pdesc.esc->skip(min_read_offset); } if(pdesc.esc->skip_to_next_mark(escape::seqt_file, true)) { ceci->min_read_offset = pdesc.esc->get_position(); try { ref = cat_entree::read(get_ui(), get_pool(), pdesc, x_reading_ver, ceci->access_stats(), ceci->corres, ceci->x_default_algo, false, // lax mode false, // only_detruit true); // always a small read in that context if(pdesc.esc->next_to_read_is_mark(escape::seqt_failed_backup)) { if(!pdesc.esc->skip_to_next_mark(escape::seqt_failed_backup, false)) throw SRC_BUG; if(ref != NULL) { delete ref; ref = NULL; } continue; // restarts the while loop } ref_dir = dynamic_cast<const cat_directory *>(ref); if(ref_dir != NULL) ++(ceci->depth); ref_eod = dynamic_cast<const cat_eod *>(ref); if(ref_eod != NULL) { if(depth > 0) --(ceci->depth); else if(!x_lax) throw Erange("escape_catalogue::read", gettext("Escape sequences used for reading lead the archive to place some files out of the specified root. To overcome this problem, try reading the archive in direct mode (not using sequential reading), try repairing the archive using Parchive if redundancy data has been created or in last resort try using the lax mode")); else // lax mode { get_ui().warning(gettext("LAX MODE: Archive directory structure is corrupted, it would lead to place some files out of the specified root directory. Restoring different directory contents at the root not out of it, which will put files of different directories in the specified root directory")); if(ref == NULL) throw SRC_BUG; delete ref; // this is the CAT_EOD object ref = NULL; continue; // restarts the while loop } } } catch(Erange & e) { if(!x_lax) throw; else { get_ui().warning(gettext("LAX MODE: found unknown catalogue entry, assuming data corruption occurred. Skipping to the next entry, this may lead to improper directory structure being restored, if the corrupted data was a directory")); ref = NULL; continue; // restarts the while loop } } if(ref == NULL) throw Erange("escape_catalogue::read", gettext("Corrupted entry following an escape mark in the archive")); else { bool is_eod = ref_eod != NULL; cat_entree *ref_nc = const_cast<cat_entree *>(ref); ceci->add(ref_nc); if(wait_parent_depth > 0) // we must not return this object as it is member of a skipped dir { if(depth < wait_parent_depth) // we are back out of the skipped directory { if(is_eod) ceci->wait_parent_depth = 0; else throw SRC_BUG; // we should get out of the directory reading a CAT_EOD ! } ref = NULL; // must not release object except, they are now part of catalogue continue; // ignore this entry and skip to the next one } if(is_eod) ref = get_r_eod_address(); } } else // no more file to read from in-sequence marks { if(depth != 0) { get_ui().warning(gettext("Uncompleted archive! Assuming it has been interrupted during the backup process. If an error has been reported just above, simply ignore it, this is about the file that was saved at the time of the interruption.")); ceci->status = ec_eod; ref = get_r_eod_address(); if(ref == NULL) throw SRC_BUG; --(ceci->depth); } else { // we no more need the hard link correspondance map so we free the memory it uses ceci->corres.clear(); ceci->status = ec_detruits; label tmp; tmp.clear(); if(pdesc.compr == NULL) throw SRC_BUG; if(pdesc.compr->is_compression_suspended()) { pdesc.compr->resume_compression(); if(pdesc.compr->get_algo() != none) pdesc.stack->flush_read_above(pdesc.compr); } // build the catalogue to get detruit objects if(pdesc.esc->skip_to_next_mark(escape::seqt_catalogue, true)) { bool only_detruit = !is_empty(); // we read the whole catalogue if we could not find any entry before the catalogue mark // this situation is either an extracted catalogue, or a normal archive which only has detruit objects // in any case, it does not hurt considering the whole catalogue ceci->cat_det = new (get_pool()) catalogue(get_ui(), pdesc, x_reading_ver, x_default_algo, x_lax, // lax tmp, // we do not modify the catalogue data_name even in lax mode only_detruit); // only_detruit if(ceci->cat_det == NULL) throw Ememory("escape_catalogue::read"); cat_det->reset_read(); if(only_detruit) ceci->status = ec_detruits; else { ceci->status = ec_completed; ceci->swap_stuff(*(ceci->cat_det)); delete ceci->cat_det; ceci->cat_det = NULL; } stop = false; ref = NULL; } else // no more file and no catalogue entry found (interrupted archive) { ceci->status = ec_completed; if(!x_lax) throw Erange("escape_catalogue::read", gettext("Cannot extract from the internal catalogue the list of files to remove")); else { get_ui().warning("LAX MODE: Cannot extract from the internal catalogue the list of files to remove, skipping this step"); ref = NULL; stop = true; } } } } break; case ec_eod: if(depth > 0) { ref = get_r_eod_address(); if(ref == NULL) throw SRC_BUG; --(ceci->depth); } else ceci->status = ec_marks; break; case ec_detruits: if(cat_det == NULL) throw SRC_BUG; if(!cat_det->read(ref)) { ceci->merge_cat_det(); ceci->status = ec_completed; ref = NULL; stop = true; } else if(ref == NULL) throw SRC_BUG; break; case ec_completed: return catalogue::read(ref); default: throw SRC_BUG; } } } catch(...) { if(ref != NULL && cat_det == NULL && ref != get_r_eod_address()) // we must not delete objects owned by cat_det delete ref; ref = NULL; throw; } return ref != NULL; }
void crypto_asym::build_key_list(const vector<string> & recipients_email, gpgme_key_t * & ciphering_keys, bool signatories) { U_I size = recipients_email.size() + 1; ciphering_keys = new (nothrow) gpgme_key_t[size]; if(ciphering_keys == NULL) throw Ememory("crypto_asym::build_key_list"); // clearing all fields in order to be able to know which // index has been allocated and need to be restored in case of error for(U_I i = 0; i < size ; ++i) ciphering_keys[i] = NULL; try { gpgme_error_t err = GPG_ERR_NO_ERROR; gpgme_user_id_t id = NULL; bool found = false; bool eof = false; bool loop = false; U_I offset = 0; // for each recipient, listing all keys to find a match for(U_I i = 0; i < recipients_email.size(); ++i) { err = gpgme_op_keylist_start(context, NULL, 0); switch(gpgme_err_code(err)) { case GPG_ERR_NO_ERROR: break; case GPG_ERR_INV_VALUE: throw SRC_BUG; default: throw Erange("crypto_asym::decrypt", string(gettext("Unexpected error reported by GPGME: ")) + tools_gpgme_strerror_r(err)); } found = false; eof = false; do { // getting the next key err = gpgme_op_keylist_next(context, &(ciphering_keys[i - offset])); switch(gpgme_err_code(err)) { case GPG_ERR_EOF: eof = true; break; case GPG_ERR_NO_ERROR: id = ciphering_keys[i - offset]->uids; loop = true; // for each key, listing all identies associated with it to find a match do { found = (strncmp(recipients_email[i].c_str(), id->email, recipients_email[i].size()) == 0); if(found) { if(ciphering_keys[i - offset]->revoked || ciphering_keys[i - offset]->expired || ciphering_keys[i - offset]->disabled || ciphering_keys[i - offset]->invalid) found = false; if(signatories) { if(!ciphering_keys[i - offset]->can_sign) found = false; } else { if(!ciphering_keys[i - offset]->can_encrypt) found = false; } } if(!found && id->next != NULL) id = id->next; else loop = false; } while(loop); // if not identity match found for that key deleting the key if(!found) { gpgme_key_unref(ciphering_keys[i - offset]); ciphering_keys[i - offset] = NULL; } break; default: throw Erange("crypto_asym::decrypt", string(gettext("Unexpected error reported by GPGME: ")) + tools_gpgme_strerror_r(err)); } } while(!found && !eof); // if we exit before gpgme_op_keylist_next() return GPG_ERR_EOF // we must update the state of the context to end the key listing operation if(!eof) (void)gpgme_op_keylist_end(context); if(!found) { if(signatories) get_ui().printf(gettext("No valid signing key could be find for %S"), &(recipients_email[i])); else get_ui().printf(gettext("No valid encryption key could be find for %S"), &(recipients_email[i])); get_ui().pause("Do you want to continue without this recipient?"); ++offset; } } // if no recipient could be found at all aborting the operation if(offset + 1 >= size) { if(signatories) throw Erange("crypto_asym::build_key_list", gettext("No signatory remain with a valid key, signing is impossible, aborting")); else throw Erange("crypto_asym::build_key_list", gettext("No recipient remain with a valid key, encryption is impossible, aborting")); } // the key list must end wth a NULL entry if(ciphering_keys[size - 1 - offset] != NULL) throw SRC_BUG; } catch(...) { release_key_list(ciphering_keys); throw; } }
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 }
bool cbmc_parseoptionst::process_goto_program( const optionst &options, goto_functionst &goto_functions) { try { namespacet ns(context); if(cmdline.isset("string-abstraction")) string_instrumentation( context, get_message_handler(), goto_functions); status("Function Pointer Removal"); remove_function_pointers(ns, goto_functions, cmdline.isset("pointer-check")); status("Partial Inlining"); // do partial inlining goto_partial_inline(goto_functions, ns, ui_message_handler); status("Generic Property Instrumentation"); // add generic checks goto_check(ns, options, goto_functions); if(cmdline.isset("string-abstraction")) { status("String Abstraction"); string_abstraction(context, get_message_handler(), goto_functions); } // add failed symbols // needs to be done before pointer analysis add_failed_symbols(context); if(cmdline.isset("pointer-check") || cmdline.isset("show-value-sets")) { status("Pointer Analysis"); value_set_analysist value_set_analysis(ns); value_set_analysis(goto_functions); // show it? if(cmdline.isset("show-value-sets")) { show_value_sets(get_ui(), goto_functions, value_set_analysis); return true; } status("Adding Pointer Checks"); // add pointer checks pointer_checks( goto_functions, context, options, value_set_analysis); } // recalculate numbers, etc. goto_functions.update(); // add loop ids goto_functions.compute_loop_numbers(); // if we aim to cover, replace // all assertions by false to prevent simplification if(cmdline.isset("cover-assertions")) make_assertions_false(goto_functions); // show it? if(cmdline.isset("show-loops")) { show_loop_numbers(get_ui(), goto_functions); return true; } // show it? if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); return true; } } catch(const char *e) { error(e); return true; } catch(const std::string e) { error(e); return true; } catch(int) { return true; } catch(std::bad_alloc) { error("Out of memory"); return true; } return false; }
void symex_parse_optionst::report_cover( const path_searcht::property_mapt &property_map) { // report unsigned goals_covered=0; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) goals_covered++; switch(get_ui()) { case ui_message_handlert::uit::PLAIN: { status() << "\n** coverage results:" << eom; for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; status() << "[" << prop_pair.first << "]"; if(property.source_location.is_not_nil()) status() << ' ' << property.source_location; if(!property.description.empty()) status() << ' ' << property.description; status() << ": " << (property.is_failure()?"SATISFIED":"FAILED") << eom; } status() << '\n'; break; } case ui_message_handlert::uit::XML_UI: { for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; xmlt xml_result("result"); xml_result.set_attribute("goal", id2string(prop_pair.first)); xml_result.set_attribute( "description", id2string(property.description)); xml_result.set_attribute( "status", property.is_failure()?"SATISFIED":"FAILED"); if(property.source_location.is_not_nil()) xml_result.new_element()=xml(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { convert(ns, property.error_trace, xml_result.new_element()); } else { xmlt &xml_test=xml_result.new_element("test"); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { xmlt &xml_input=xml_test.new_element("input"); xml_input.set_attribute("id", id2string(step.io_id)); if(step.io_args.size()==1) xml_input.new_element("value")= xml(step.io_args.front(), ns); } } } } std::cout << xml_result << "\n"; } break; } case ui_message_handlert::uit::JSON_UI: { json_objectt json_result; json_arrayt &result_array=json_result["results"].make_array(); for(const auto &prop_pair : property_map) { const auto &property=prop_pair.second; json_objectt &result=result_array.push_back().make_object(); result["status"]= json_stringt(property.is_failure()?"satisfied":"failed"); result["goal"]=json_stringt(id2string(prop_pair.first)); result["description"]=json_stringt(id2string(property.description)); if(property.source_location.is_not_nil()) result["sourceLocation"]=json(property.source_location); if(property.is_failure()) { const namespacet ns(goto_model.symbol_table); if(cmdline.isset("trace")) { jsont &json_trace=result["trace"]; convert(ns, property.error_trace, json_trace); } else { json_arrayt &json_test=result["test"].make_array(); for(const auto &step : property.error_trace.steps) { if(step.is_input()) { json_objectt json_input; json_input["id"]=json_stringt(id2string(step.io_id)); if(step.io_args.size()==1) json_input["value"]=json(step.io_args.front(), ns); json_test.push_back(json_input); } } } } } json_result["totalGoals"]= json_numbert(std::to_string(property_map.size())); json_result["goalsCovered"]=json_numbert(std::to_string(goals_covered)); std::cout << ",\n" << json_result; break; } } status() << "** " << goals_covered << " of " << property_map.size() << " covered (" << std::fixed << std::setw(1) << std::setprecision(1) << (property_map.empty()? 100.0:100.0*goals_covered/property_map.size()) << "%)" << eom; if(get_ui()==ui_message_handlert::uit::PLAIN) { std::set<std::string> tests; for(const auto &prop_pair : property_map) if(prop_pair.second.is_failure()) tests.insert(get_test(prop_pair.second.error_trace)); std::cout << "Test suite:" << '\n'; for(const auto &t : tests) std::cout << t << '\n'; } }
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 }
bool cbmc_parse_optionst::process_goto_program( const optionst &options, goto_functionst &goto_functions) { try { namespacet ns(symbol_table); // Remove inline assembler; this needs to happen before // adding the library. remove_asm(symbol_table, goto_functions); // add the library status() << "Adding CPROVER library (" << config.ansi_c.arch << ")" << eom; link_to_library(symbol_table, goto_functions, ui_message_handler); if(cmdline.isset("string-abstraction")) string_instrumentation( symbol_table, get_message_handler(), goto_functions); // remove function pointers status() << "Function Pointer Removal" << eom; remove_function_pointers(symbol_table, goto_functions, cmdline.isset("pointer-check")); // full slice? if(cmdline.isset("full-slice")) { status() << "Performing a full slice" << eom; full_slicer(goto_functions, ns); } // do partial inlining status() << "Partial Inlining" << eom; goto_partial_inline(goto_functions, ns, ui_message_handler); // remove returns, gcc vectors, complex remove_returns(symbol_table, goto_functions); remove_vector(symbol_table, goto_functions); remove_complex(symbol_table, goto_functions); // add generic checks status() << "Generic Property Instrumentation" << eom; goto_check(ns, options, goto_functions); if(cmdline.isset("string-abstraction")) { status() << "String Abstraction" << eom; string_abstraction(symbol_table, get_message_handler(), goto_functions); } // add failed symbols // needs to be done before pointer analysis add_failed_symbols(symbol_table); // recalculate numbers, etc. goto_functions.update(); // add loop ids goto_functions.compute_loop_numbers(); // if we aim to cover assertions, replace // all assertions by false to prevent simplification if(cmdline.isset("cover") && cmdline.get_value("cover")=="assertions") make_assertions_false(goto_functions); // show it? if(cmdline.isset("show-loops")) { show_loop_ids(get_ui(), goto_functions); return true; } // show it? if(cmdline.isset("show-goto-functions")) { goto_functions.output(ns, std::cout); return true; } } catch(const char *e) { error() << e << eom; return true; } catch(const std::string e) { error() << e << eom; return true; } catch(int) { return true; } catch(std::bad_alloc) { error() << "Out of memory" << eom; return true; } return false; }
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); }