Skip to content

Commit 4d32f96

Browse files
committed
add option to show code in CBMC trace
1 parent 6083743 commit 4d32f96

File tree

4 files changed

+74
-9
lines changed

4 files changed

+74
-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+
}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
19+
^VERIFICATION FAILED$
20+
--
21+
^warning: ignoring

src/goto-programs/goto_trace.cpp

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

241241
void show_state_header(
242242
std::ostream &out,
243+
const namespacet &ns,
243244
const goto_trace_stept &state,
244245
const source_locationt &source_location,
245-
unsigned step_nr)
246+
unsigned step_nr,
247+
const trace_optionst &options)
246248
{
247249
out << "\n";
248250

249-
if(step_nr==0)
251+
if(step_nr == 0)
250252
out << "Initial State";
251253
else
252254
out << "State " << step_nr;
253255

254-
out << " " << source_location
255-
<< " thread " << state.thread_nr << "\n";
256-
out << "----------------------------------------------------" << "\n";
256+
out << " " << source_location << " thread " << state.thread_nr << "\n";
257+
out << "----------------------------------------------------"
258+
<< "\n";
259+
260+
if(options.show_code)
261+
{
262+
out << as_string(ns, *state.pc)
263+
<< "\n";
264+
out << "----------------------------------------------------"
265+
<< "\n";
266+
}
257267
}
258268

259269
bool is_index_member_symbol(const exprt &src)
@@ -334,7 +344,8 @@ void show_goto_trace(
334344
{
335345
first_step=false;
336346
prev_step_nr=step.step_nr;
337-
show_state_header(out, step, step.pc->source_location, step.step_nr);
347+
show_state_header(
348+
out, ns, step, step.pc->source_location, step.step_nr, options);
338349
}
339350

340351
// see if the full lhs is something clean
@@ -362,7 +373,8 @@ void show_goto_trace(
362373
{
363374
first_step=false;
364375
prev_step_nr=step.step_nr;
365-
show_state_header(out, step, step.pc->source_location, step.step_nr);
376+
show_state_header(
377+
out, ns, step, step.pc->source_location, step.step_nr, options);
366378
}
367379

368380
trace_value(
@@ -379,7 +391,8 @@ void show_goto_trace(
379391
}
380392
else
381393
{
382-
show_state_header(out, step, step.pc->source_location, step.step_nr);
394+
show_state_header(
395+
out, ns, step, step.pc->source_location, step.step_nr, options);
383396
out << " OUTPUT " << step.io_id << ":";
384397

385398
for(std::list<exprt>::const_iterator
@@ -400,7 +413,8 @@ void show_goto_trace(
400413
break;
401414

402415
case goto_trace_stept::typet::INPUT:
403-
show_state_header(out, step, step.pc->source_location, step.step_nr);
416+
show_state_header(
417+
out, ns, step, step.pc->source_location, step.step_nr, options);
404418
out << " INPUT " << step.io_id << ":";
405419

406420
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)