Skip to content

Commit 80059c5

Browse files
committed
goto-program interpreter: test and fix stepping commands
"s" without a suffix or with a suffix that is not one of [aeo0-9] previously resulted in an invariant violation. Also make "r0" actually work by fixing the assumptions about the structure of the top-level function.
1 parent 9edf8f8 commit 80059c5

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

regression/goto-interpreter/memory-dump/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
main.c
3-
s1,so,m
3+
m
44
^Starting interpreter$
55
^__CPROVER_rounding_mode\[0\]=0$
66
^\d+- Program End\.$

regression/goto-interpreter/step/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
int main()
22
{
3+
__CPROVER_rounding_mode = 1;
4+
// test single stepping
5+
int i = 1;
6+
i = 2;
7+
i = 3;
38
int x;
49
__CPROVER_assert(x == 42, "should fail");
510
return 0;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
CORE
2+
main.c
3+
r0,s,sa,m,s2,m,s2,m,so,m,se
4+
^Starting interpreter$
5+
^__CPROVER_rounding_mode\[0\]=0$
6+
^__CPROVER_rounding_mode\[0\]=1$
7+
^main::1::i\[0\]=1$
8+
^\d+- Program End\.$
9+
^EXIT=0$
10+
^SIGNAL=0$
11+
--
12+
^main::1::i\[0\]=2$
13+
--
14+
Use the various step instructions: restart execution without running
15+
initialization (r0), execute one step (s), step over __CPROVER_initialize (sa),
16+
generate the first memory dump (__CPROVER_rounding_mode set to 0), step into
17+
main and execute the first assignment (__CPROVER_rounding_mode set to 1),
18+
execute two steps (s2) to declare i and assign 1 to i, step to the end of the
19+
function (so) without dumping intermittent values, thus never dumping i==2. The
20+
execute to the end of the program (se).

src/goto-programs/interpreter.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void interpretert::operator()()
6464
void interpretert::initialize(bool init)
6565
{
6666
build_memory_map();
67+
// reset the call stack
68+
call_stack = call_stackt{};
6769

6870
total_steps=0;
6971
const goto_functionst::function_mapt::const_iterator
@@ -83,15 +85,20 @@ void interpretert::initialize(bool init)
8385
done=false;
8486
if(init)
8587
{
86-
stack_depth=call_stack.size()+1;
87-
show_state();
88-
step();
89-
while(!done && (stack_depth<=call_stack.size()) && (stack_depth!=npos))
88+
// execute instructions up to and including __CPROVER_initialize()
89+
while(!done && call_stack.size() == 0)
90+
{
91+
show_state();
92+
step();
93+
}
94+
// initialization
95+
while(!done && call_stack.size() > 0)
9096
{
9197
show_state();
9298
step();
9399
}
94-
while(!done && (call_stack.size()==0))
100+
// invoke the user entry point
101+
while(!done && call_stack.size() == 0)
95102
{
96103
show_state();
97104
step();
@@ -200,7 +207,7 @@ void interpretert::command()
200207
else if((ch=='s') || (ch==0))
201208
{
202209
num_steps=1;
203-
stack_depth=npos;
210+
std::size_t stack_depth = npos;
204211
ch=tolower(command[1]);
205212
if(ch=='e')
206213
num_steps=npos;
@@ -210,7 +217,7 @@ void interpretert::command()
210217
stack_depth=call_stack.size()+1;
211218
else
212219
{
213-
num_steps=safe_string2size_t(command+1);
220+
num_steps = unsafe_string2size_t(command + 1);
214221
if(num_steps==0)
215222
num_steps=1;
216223
}

src/goto-programs/interpreter_class.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ class interpretert:public messaget
274274

275275
dynamic_typest dynamic_types;
276276
int num_dynamic_objects;
277-
mp_integer stack_depth;
278277
unsigned thread_id;
279278

280279
bool evaluate_boolean(const exprt &expr)

0 commit comments

Comments
 (0)