Skip to content

Commit dfa5a33

Browse files
committed
add option to show code in CBMC trace
1 parent f56c47f commit dfa5a33

File tree

4 files changed

+73
-9
lines changed

4 files changed

+73
-9
lines changed
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
int function_to_call(int a)
2+
{
3+
int local = 1;
4+
return a+local;
5+
}
6+
7+
8+
int main()
9+
{
10+
int a, c;
11+
unsigned int b;
12+
a = 0;
13+
c = -100;
14+
a = function_to_call(a) + function_to_call(c);
15+
if(a < 0)
16+
b = function_to_call(b);
17+
18+
if(c < 0)
19+
b = -function_to_call(b);
20+
21+
__CPROVER_assert(0,"");
22+
23+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CORE
2+
main.c
3+
--trace --trace-show-code
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
7+
local = 1
8+
int a
9+
int c
10+
unsigned int b
11+
a = 0;
12+
c = -100;
13+
function_to_call\(a\)
14+
function_to_call\(c\)
15+
a = return_value_function_to_call \+ return_value_function_to_call
16+
function_to_call\(\(signed int\)b\)
17+
b = \(unsigned int\)return_value_function_to_call
18+
^VERIFICATION FAILED$
19+
--
20+
^warning: ignoring

src/goto-programs/goto_trace.cpp

+23-9
Original file line numberDiff line numberDiff line change
@@ -247,20 +247,30 @@ void trace_value(
247247

248248
void show_state_header(
249249
std::ostream &out,
250+
const namespacet &ns,
250251
const goto_trace_stept &state,
251252
const source_locationt &source_location,
252-
unsigned step_nr)
253+
unsigned step_nr,
254+
const trace_optionst &options)
253255
{
254256
out << "\n";
255257

256-
if(step_nr==0)
258+
if(step_nr == 0)
257259
out << "Initial State";
258260
else
259261
out << "State " << step_nr;
260262

261-
out << " " << source_location
262-
<< " thread " << state.thread_nr << "\n";
263-
out << "----------------------------------------------------" << "\n";
263+
out << " " << source_location << " thread " << state.thread_nr << "\n";
264+
out << "----------------------------------------------------"
265+
<< "\n";
266+
267+
if(options.show_code)
268+
{
269+
out << as_string(ns, *state.pc)
270+
<< "\n";
271+
out << "----------------------------------------------------"
272+
<< "\n";
273+
}
264274
}
265275

266276
bool is_index_member_symbol(const exprt &src)
@@ -342,7 +352,8 @@ void show_goto_trace(
342352
{
343353
first_step=false;
344354
prev_step_nr=step.step_nr;
345-
show_state_header(out, step, step.pc->source_location, step.step_nr);
355+
show_state_header(
356+
out, ns, step, step.pc->source_location, step.step_nr, options);
346357
}
347358

348359
// see if the full lhs is something clean
@@ -370,7 +381,8 @@ void show_goto_trace(
370381
{
371382
first_step=false;
372383
prev_step_nr=step.step_nr;
373-
show_state_header(out, step, step.pc->source_location, step.step_nr);
384+
show_state_header(
385+
out, ns, step, step.pc->source_location, step.step_nr, options);
374386
}
375387

376388
trace_value(
@@ -387,7 +399,8 @@ void show_goto_trace(
387399
}
388400
else
389401
{
390-
show_state_header(out, step, step.pc->source_location, step.step_nr);
402+
show_state_header(
403+
out, ns, step, step.pc->source_location, step.step_nr, options);
391404
out << " OUTPUT " << step.io_id << ":";
392405

393406
for(std::list<exprt>::const_iterator
@@ -408,7 +421,8 @@ void show_goto_trace(
408421
break;
409422

410423
case goto_trace_stept::typet::INPUT:
411-
show_state_header(out, step, step.pc->source_location, step.step_nr);
424+
show_state_header(
425+
out, ns, step, step.pc->source_location, step.step_nr, options);
412426
out << " INPUT " << step.io_id << ":";
413427

414428
for(std::list<exprt>::const_iterator

src/goto-programs/goto_trace.h

+7
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ struct trace_optionst
201201
bool hex_representation;
202202
bool base_prefix;
203203
bool show_function_calls;
204+
bool show_code;
204205

205206
static const trace_optionst default_options;
206207

@@ -210,6 +211,7 @@ struct trace_optionst
210211
hex_representation = options.get_bool_option("trace-hex");
211212
base_prefix = hex_representation;
212213
show_function_calls = options.get_bool_option("trace-show-function-calls");
214+
show_code = options.get_bool_option("trace-show-code");
213215
};
214216

215217
private:
@@ -219,6 +221,7 @@ struct trace_optionst
219221
hex_representation = false;
220222
base_prefix = false;
221223
show_function_calls = false;
224+
show_code = false;
222225
};
223226
};
224227

@@ -243,18 +246,22 @@ void trace_value(
243246

244247
#define OPT_GOTO_TRACE "(trace-json-extended)" \
245248
"(trace-show-function-calls)" \
249+
"(trace-show-code)" \
246250
"(trace-hex)"
247251

248252
#define HELP_GOTO_TRACE \
249253
" --trace-json-extended add rawLhs property to trace\n" \
250254
" --trace-show-function-calls show function calls in plain trace\n" \
255+
" --trace-show-code show original code in plain trace\n" \
251256
" --trace-hex represent plain trace values in hex\n"
252257

253258
#define PARSE_OPTIONS_GOTO_TRACE(cmdline, options) \
254259
if(cmdline.isset("trace-json-extended")) \
255260
options.set_option("trace-json-extended", true); \
256261
if(cmdline.isset("trace-show-function-calls")) \
257262
options.set_option("trace-show-function-calls", true); \
263+
if(cmdline.isset("trace-show-code")) \
264+
options.set_option("trace-show-code", true); \
258265
if(cmdline.isset("trace-hex")) \
259266
options.set_option("trace-hex", true);
260267

0 commit comments

Comments
 (0)