-
Notifications
You must be signed in to change notification settings - Fork 277
Cleanup error handling of cbmc/ folder #2703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected] | |
#include <chrono> | ||
#include <iostream> | ||
|
||
#include <util/exception_utils.h> | ||
#include <util/exit_codes.h> | ||
|
||
#include <langapi/language_util.h> | ||
|
@@ -214,9 +215,8 @@ void bmct::get_memory_model() | |
memory_model=util_make_unique<memory_model_psot>(ns); | ||
else | ||
{ | ||
error() << "Invalid memory model " << mm | ||
<< " -- use one of sc, tso, pso" << eom; | ||
throw "invalid memory model"; | ||
throw invalid_user_input_exceptiont( | ||
"invalid parameter " + mm, "--mm", "try values of sc, tso, pso"); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ int main(int argc, const char **argv) | |
#endif | ||
cbmc_parse_optionst parse_options(argc, argv); | ||
|
||
int res=parse_options.main(); | ||
int res = parse_options.main(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary change? |
||
|
||
#ifdef IREP_HASH_STATS | ||
std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << '\n'; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,9 @@ Author: Daniel Kroening, [email protected] | |
#include <fstream> | ||
#include <iostream> | ||
#include <memory> | ||
#include <string> | ||
|
||
#include <util/exception_utils.h> | ||
#include <util/make_unique.h> | ||
#include <util/unicode.h> | ||
#include <util/version.h> | ||
|
@@ -32,7 +34,8 @@ Author: Daniel Kroening, [email protected] | |
/// \return An smt2_dect::solvert giving the solver to use. | ||
smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const | ||
{ | ||
assert(options.get_bool_option("smt2")); | ||
// we shouldn't get here if this option isn't set | ||
PRECONDITION(options.get_bool_option("smt2")); | ||
|
||
smt2_dect::solvert s=smt2_dect::solvert::GENERIC; | ||
|
||
|
@@ -163,8 +166,10 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2( | |
{ | ||
if(solver==smt2_dect::solvert::GENERIC) | ||
{ | ||
error() << "please use --outfile" << eom; | ||
throw 0; | ||
throw invalid_user_input_exceptiont( | ||
"required filename not provided", | ||
"--outfile", | ||
"provide a filename with --outfile"); | ||
NlightNFotis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
auto smt2_dec = util_make_unique<smt2_dect>( | ||
|
@@ -206,8 +211,8 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2( | |
|
||
if(!*out) | ||
{ | ||
error() << "failed to open " << filename << eom; | ||
throw 0; | ||
throw invalid_user_input_exceptiont( | ||
"failed to open file: " + filename, "--outfile"); | ||
} | ||
|
||
auto smt2_conv = util_make_unique<smt2_convt>( | ||
|
@@ -231,18 +236,32 @@ void cbmc_solverst::no_beautification() | |
{ | ||
if(options.get_bool_option("beautify")) | ||
{ | ||
error() << "sorry, this solver does not support beautification" << eom; | ||
throw 0; | ||
throw invalid_user_input_exceptiont( | ||
"the chosen solver does not support beautification", "--beautify"); | ||
} | ||
} | ||
|
||
void cbmc_solverst::no_incremental_check() | ||
{ | ||
if(options.get_bool_option("all-properties") || | ||
options.get_option("cover")!="" || | ||
options.get_option("incremental-check")!="") | ||
const bool all_properties = options.get_bool_option("all-properties"); | ||
const bool cover = options.is_set("cover"); | ||
const bool incremental_check = options.is_set("incremental-check"); | ||
|
||
if(all_properties) | ||
{ | ||
throw invalid_user_input_exceptiont( | ||
"the chosen solver does not support incremental solving", | ||
"--all_properties"); | ||
} | ||
else if(cover) | ||
{ | ||
throw invalid_user_input_exceptiont( | ||
"the chosen solver does not support incremental solving", "--cover"); | ||
} | ||
else if(incremental_check) | ||
{ | ||
error() << "sorry, this solver does not support incremental solving" << eom; | ||
throw 0; | ||
throw invalid_user_input_exceptiont( | ||
"the chosen solver does not support incremental solving", | ||
"--incremental-check"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Exception helper utilities | ||
|
||
Author: Fotis Koutoulakis, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "exception_utils.h" | ||
|
||
std::string invalid_user_input_exceptiont::what() const noexcept | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally, there should also be a version hat can serialise into json and XML in a more structure way (in a future PR). |
||
{ | ||
std::string res; | ||
res += "\nInvalid User Input\n"; | ||
res += "Option: " + option + "\n"; | ||
res += "Reason: " + reason; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wishlist: please add a test for this, i.e., intentionally use CBMC with incorrect options. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need this as part of this PR, or can it go in as part of a follow up PR for example? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Up to you, as long as it happens at some point :-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We plan to make some further improvements to user error handling, so we'll definitely be adding suitable test cases as part of that work, so I'd be happy for this PR to go in, with tests following as part of the later improvements. |
||
// Print an optional correct usage message assuming correct input parameters have been passed | ||
res += correct_input + "\n"; | ||
return res; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Exception helper utilities | ||
|
||
Author: Fotis Koutoulakis, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H | ||
#define CPROVER_UTIL_EXCEPTION_UTILS_H | ||
|
||
#include <string> | ||
|
||
class invalid_user_input_exceptiont | ||
{ | ||
/// The reason this exception was generated. | ||
std::string reason; | ||
/// The full command line option (not the argument) that got | ||
/// erroneous input. | ||
std::string option; | ||
/// In case we have samples of correct input to the option. | ||
std::string correct_input; | ||
|
||
public: | ||
invalid_user_input_exceptiont( | ||
std::string reason, | ||
std::string option, | ||
std::string correct_input = "") | ||
: reason(reason), option(option), correct_input(correct_input) | ||
{ | ||
} | ||
|
||
std::string what() const noexcept; | ||
}; | ||
|
||
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected] | |
#endif | ||
|
||
#include "cmdline.h" | ||
#include "exception_utils.h" | ||
#include "exit_codes.h" | ||
#include "signal_catcher.h" | ||
|
||
parse_options_baset::parse_options_baset( | ||
|
@@ -47,23 +49,34 @@ void parse_options_baset::unknown_option_msg() | |
|
||
int parse_options_baset::main() | ||
{ | ||
if(parse_result) | ||
// catch all exceptions here so that this code is not duplicated | ||
// for each tool | ||
try | ||
{ | ||
usage_error(); | ||
unknown_option_msg(); | ||
return EX_USAGE; | ||
if(parse_result) | ||
{ | ||
usage_error(); | ||
unknown_option_msg(); | ||
return EX_USAGE; | ||
} | ||
|
||
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help")) | ||
{ | ||
help(); | ||
return EX_OK; | ||
} | ||
|
||
// install signal catcher | ||
install_signal_catcher(); | ||
|
||
return doit(); | ||
} | ||
|
||
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help")) | ||
catch(invalid_user_input_exceptiont &e) | ||
{ | ||
help(); | ||
return EX_OK; | ||
std::cerr << e.what() << "\n"; | ||
return CPROVER_EXIT_USAGE_ERROR; | ||
} | ||
|
||
// install signal catcher | ||
install_signal_catcher(); | ||
|
||
return doit(); | ||
return CPROVER_EXIT_SUCCESS; | ||
} | ||
|
||
std::string | ||
|
Uh oh!
There was an error while loading. Please reload this page.