Skip to content

Commit

Permalink
add option to show code in CBMC trace
Browse files Browse the repository at this point in the history
  • Loading branch information
polgreen committed Jul 4, 2018
1 parent 207110e commit 47fd446
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
23 changes: 23 additions & 0 deletions regression/cbmc/trace_show_code/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
int function_to_call(int a)
{
int local = 1;
return a+local;
}


int main()
{
int a, c;
unsigned int b;
a = 0;
c = -100;
a = function_to_call(a) + function_to_call(c);
if(a < 0)
b = function_to_call(b);

if(c < 0)
b = -function_to_call(b);

__CPROVER_assert(0,"");

}
21 changes: 21 additions & 0 deletions regression/cbmc/trace_show_code/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
CORE
main.c
--trace --trace-show-code
^EXIT=10$
^SIGNAL=0$

local = 1
int a
int c
unsigned int b
a = 0;
c = -100;
function_to_call\(a\)
function_to_call\(c\)
a = return_value_function_to_call \+ return_value_function_to_call
function_to_call\(\(signed int\)b\)
b = \(unsigned int\)return_value_function_to_call

^VERIFICATION FAILED$
--
^warning: ignoring
32 changes: 23 additions & 9 deletions src/goto-programs/goto_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,30 @@ void trace_value(

void show_state_header(
std::ostream &out,
const namespacet &ns,
const goto_trace_stept &state,
const source_locationt &source_location,
unsigned step_nr)
unsigned step_nr,
const trace_optionst &options)
{
out << "\n";

if(step_nr==0)
if(step_nr == 0)
out << "Initial State";
else
out << "State " << step_nr;

out << " " << source_location
<< " thread " << state.thread_nr << "\n";
out << "----------------------------------------------------" << "\n";
out << " " << source_location << " thread " << state.thread_nr << "\n";
out << "----------------------------------------------------"
<< "\n";

if(options.show_code)
{
out << as_string(ns, *state.pc)
<< "\n";
out << "----------------------------------------------------"
<< "\n";
}
}

bool is_index_member_symbol(const exprt &src)
Expand Down Expand Up @@ -335,7 +345,8 @@ void show_goto_trace(
{
first_step=false;
prev_step_nr=step.step_nr;
show_state_header(out, step, step.pc->source_location, step.step_nr);
show_state_header(
out, ns, step, step.pc->source_location, step.step_nr, options);
}

// see if the full lhs is something clean
Expand Down Expand Up @@ -363,7 +374,8 @@ void show_goto_trace(
{
first_step=false;
prev_step_nr=step.step_nr;
show_state_header(out, step, step.pc->source_location, step.step_nr);
show_state_header(
out, ns, step, step.pc->source_location, step.step_nr, options);
}

trace_value(
Expand All @@ -380,7 +392,8 @@ void show_goto_trace(
}
else
{
show_state_header(out, step, step.pc->source_location, step.step_nr);
show_state_header(
out, ns, step, step.pc->source_location, step.step_nr, options);
out << " OUTPUT " << step.io_id << ":";

for(std::list<exprt>::const_iterator
Expand All @@ -401,7 +414,8 @@ void show_goto_trace(
break;

case goto_trace_stept::typet::INPUT:
show_state_header(out, step, step.pc->source_location, step.step_nr);
show_state_header(
out, ns, step, step.pc->source_location, step.step_nr, options);
out << " INPUT " << step.io_id << ":";

for(std::list<exprt>::const_iterator
Expand Down
7 changes: 7 additions & 0 deletions src/goto-programs/goto_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ struct trace_optionst
bool hex_representation;
bool base_prefix;
bool show_function_calls;
bool show_code;

static const trace_optionst default_options;

Expand All @@ -210,6 +211,7 @@ struct trace_optionst
hex_representation = options.get_bool_option("trace-hex");
base_prefix = hex_representation;
show_function_calls = options.get_bool_option("trace-show-function-calls");
show_code = options.get_bool_option("trace-show-code");
};

private:
Expand All @@ -219,6 +221,7 @@ struct trace_optionst
hex_representation = false;
base_prefix = false;
show_function_calls = false;
show_code = false;
};
};

Expand All @@ -243,18 +246,22 @@ void trace_value(

#define OPT_GOTO_TRACE "(trace-json-extended)" \
"(trace-show-function-calls)" \
"(trace-show-code)" \
"(trace-hex)"

#define HELP_GOTO_TRACE \
" --trace-json-extended add rawLhs property to trace\n" \
" --trace-show-function-calls show function calls in plain trace\n" \
" --trace-show-code show original code in plain trace\n" \
" --trace-hex represent plain trace values in hex\n"

#define PARSE_OPTIONS_GOTO_TRACE(cmdline, options) \
if(cmdline.isset("trace-json-extended")) \
options.set_option("trace-json-extended", true); \
if(cmdline.isset("trace-show-function-calls")) \
options.set_option("trace-show-function-calls", true); \
if(cmdline.isset("trace-show-code")) \
options.set_option("trace-show-code", true); \
if(cmdline.isset("trace-hex")) \
options.set_option("trace-hex", true);

Expand Down

0 comments on commit 47fd446

Please sign in to comment.