Skip to content

Commit 6222487

Browse files
committed
Add callback after symex to bmct
This permits frontend programs to intervene after symex executes, either in addition to or instead of running bmc. Its current use case is to implement show-goto-functions and similar debug output options when symex-driven lazy loading means that function bodies are not populated until symex has run. When --paths is in use, the callback will be made every time symex finishes a path.
1 parent 44f454b commit 6222487

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

src/cbmc/bmc.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ safety_checkert::resultt bmct::execute(
377377
const goto_functionst &goto_functions =
378378
goto_model.get_goto_functions();
379379

380+
// This provides the frontend the opportunity to do things like a
381+
// symbol-table or goto-functions dump instead of actually running the
382+
// checker, like show-vcc except frontend specific.
383+
if(frontend_callback_after_symex && frontend_callback_after_symex())
384+
return safety_checkert::resultt::SAFE; // to indicate non-error
385+
380386
// add a partial ordering, if required
381387
if(equation.has_threads())
382388
{
@@ -623,7 +629,8 @@ int bmct::do_language_agnostic_bmc(
623629
abstract_goto_modelt &model,
624630
const ui_message_handlert::uit &ui,
625631
messaget &message,
626-
std::function<void(bmct &, const symbol_tablet &)> frontend_configure_bmc)
632+
std::function<void(bmct &, const symbol_tablet &)> frontend_configure_bmc,
633+
std::function<bool(void)> callback_after_symex)
627634
{
628635
const symbol_tablet &symbol_table = model.get_symbol_table();
629636
message_handlert &mh = message.get_message_handler();
@@ -637,9 +644,10 @@ int bmct::do_language_agnostic_bmc(
637644
std::unique_ptr<cbmc_solverst::solvert> cbmc_solver;
638645
cbmc_solver = solvers.get_solver();
639646
prop_convt &pc = cbmc_solver->prop_conv();
640-
bmct bmc(opts, symbol_table, mh, pc, worklist);
647+
bmct bmc(opts, symbol_table, mh, pc, worklist, callback_after_symex);
641648
bmc.set_ui(ui);
642-
frontend_configure_bmc(bmc, symbol_table);
649+
if(frontend_configure_bmc)
650+
frontend_configure_bmc(bmc, symbol_table);
643651
result = bmc.run(model);
644652
}
645653
INVARIANT(
@@ -682,8 +690,10 @@ int bmct::do_language_agnostic_bmc(
682690
pc,
683691
resume.equation,
684692
resume.state,
685-
worklist);
686-
frontend_configure_bmc(pe, symbol_table);
693+
worklist,
694+
callback_after_symex);
695+
if(frontend_configure_bmc)
696+
frontend_configure_bmc(pe, symbol_table);
687697
result &= pe.run(model);
688698
worklist.pop_front();
689699
}

src/cbmc/bmc.h

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ class bmct:public safety_checkert
7474
const symbol_tablet &outer_symbol_table,
7575
message_handlert &_message_handler,
7676
prop_convt &_prop_conv,
77-
goto_symext::branch_worklistt &_branch_worklist)
77+
goto_symext::branch_worklistt &_branch_worklist,
78+
std::function<bool(void)> callback_after_symex)
7879
: safety_checkert(ns, _message_handler),
7980
options(_options),
8081
outer_symbol_table(outer_symbol_table),
@@ -83,7 +84,8 @@ class bmct:public safety_checkert
8384
branch_worklist(_branch_worklist),
8485
symex(_message_handler, outer_symbol_table, equation, branch_worklist),
8586
prop_conv(_prop_conv),
86-
ui(ui_message_handlert::uit::PLAIN)
87+
ui(ui_message_handlert::uit::PLAIN),
88+
frontend_callback_after_symex(callback_after_symex)
8789
{
8890
symex.constant_propagation=options.get_bool_option("propagation");
8991
symex.record_coverage=
@@ -128,10 +130,9 @@ class bmct:public safety_checkert
128130
abstract_goto_modelt &goto_model,
129131
const ui_message_handlert::uit &ui,
130132
messaget &message,
131-
std::function<void(bmct &, const symbol_tablet &)> frontend_configure_bmc =
132-
[](bmct &_bmc, const symbol_tablet &) { // NOLINT (*)
133-
// Empty default implementation
134-
});
133+
std::function<void(bmct &, const symbol_tablet &)>
134+
frontend_configure_bmc = nullptr,
135+
std::function<bool(void)> callback_after_symex = nullptr);
135136

136137
protected:
137138
/// \brief Constructor for path exploration from saved state
@@ -147,7 +148,8 @@ class bmct:public safety_checkert
147148
message_handlert &_message_handler,
148149
prop_convt &_prop_conv,
149150
symex_target_equationt &_equation,
150-
goto_symext::branch_worklistt &_branch_worklist)
151+
goto_symext::branch_worklistt &_branch_worklist,
152+
std::function<bool(void)> callback_after_symex)
151153
: safety_checkert(ns, _message_handler),
152154
options(_options),
153155
outer_symbol_table(outer_symbol_table),
@@ -156,7 +158,8 @@ class bmct:public safety_checkert
156158
branch_worklist(_branch_worklist),
157159
symex(_message_handler, outer_symbol_table, equation, branch_worklist),
158160
prop_conv(_prop_conv),
159-
ui(ui_message_handlert::uit::PLAIN)
161+
ui(ui_message_handlert::uit::PLAIN),
162+
frontend_callback_after_symex(callback_after_symex)
160163
{
161164
symex.constant_propagation = options.get_bool_option("propagation");
162165
symex.record_coverage =
@@ -238,6 +241,8 @@ class bmct:public safety_checkert
238241
/// full-program model-checking from the entry point of the program.
239242
virtual void perform_symbolic_execution(
240243
goto_symext::get_goto_functiont get_goto_function);
244+
245+
std::function<bool(void)> frontend_callback_after_symex;
241246
};
242247

243248
/// \brief Symbolic execution from a saved branch point
@@ -260,14 +265,16 @@ class path_explorert : public bmct
260265
prop_convt &_prop_conv,
261266
symex_target_equationt &saved_equation,
262267
const goto_symex_statet &saved_state,
263-
goto_symext::branch_worklistt &branch_worklist)
268+
goto_symext::branch_worklistt &branch_worklist,
269+
std::function<bool(void)> callback_after_symex)
264270
: bmct(
265271
_options,
266272
outer_symbol_table,
267273
_message_handler,
268274
_prop_conv,
269275
saved_equation,
270-
branch_worklist),
276+
branch_worklist,
277+
callback_after_symex),
271278
saved_state(saved_state)
272279
{
273280
}

0 commit comments

Comments
 (0)