1 /* Copyright (c) 2014-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "src/mc/mc_private.hpp"
12 #include "src/mc/inspect/ObjectInformation.hpp"
13 #include "src/mc/inspect/Type.hpp"
14 #include "src/mc/inspect/Variable.hpp"
15 #include "src/mc/remote/RemoteClient.hpp"
22 static std::default_random_engine rnd_engine;
24 static simgrid::mc::RemoteClient* process;
26 static uintptr_t eval_binary_operation(simgrid::dwarf::ExpressionContext const& state, int op, uintptr_t a, uintptr_t b)
29 ops[0].atom = DW_OP_const8u;
31 ops[1].atom = DW_OP_const8u;
35 simgrid::dwarf::ExpressionStack stack;
37 simgrid::dwarf::execute(ops, 3, state, stack);
38 } catch (const simgrid::dwarf::evaluation_error&) {
39 fprintf(stderr,"Expression evaluation error");
42 assert(stack.size() == 1);
46 static void basic_test(simgrid::dwarf::ExpressionContext const& state)
51 uintptr_t a = rnd_engine();
52 uintptr_t b = rnd_engine();
54 simgrid::dwarf::ExpressionStack stack;
56 bool caught_ex = false;
58 ops[0].atom = DW_OP_drop;
59 simgrid::dwarf::execute(ops, 1, state, stack);
60 } catch (const simgrid::dwarf::evaluation_error&) {
64 fprintf(stderr, "Exception expected");
66 ops[0].atom = DW_OP_lit21;
67 simgrid::dwarf::execute(ops, 1, state, stack);
68 assert(stack.size() == 1);
69 assert(stack.top() == 21);
71 ops[0].atom = DW_OP_const8u;
73 simgrid::dwarf::execute(ops, 1, state, stack);
74 assert(stack.size() == 2);
75 assert(stack.top() == a);
77 ops[0].atom = DW_OP_drop;
78 ops[1].atom = DW_OP_drop;
79 simgrid::dwarf::execute(ops, 2, state, stack);
80 assert(stack.empty());
83 ops[0].atom = DW_OP_lit21;
84 ops[1].atom = DW_OP_plus_uconst;
86 simgrid::dwarf::execute(ops, 2, state, stack);
87 assert(stack.size() == 1);
88 assert(stack.top() == a + 21);
91 ops[0].atom = DW_OP_const8u;
93 ops[1].atom = DW_OP_dup;
94 ops[2].atom = DW_OP_plus;
95 simgrid::dwarf::execute(ops, 3, state, stack);
96 assert(stack.size() == 1);
97 assert(stack.top() == a + a);
100 ops[0].atom = DW_OP_const8u;
102 ops[1].atom = DW_OP_const8u;
104 ops[2].atom = DW_OP_over;
105 simgrid::dwarf::execute(ops, 3, state, stack);
106 assert(stack.size() == 3);
107 assert(stack.top() == a);
108 assert(stack.top(1) == b);
109 assert(stack.top(2) == a);
112 ops[0].atom = DW_OP_const8u;
114 ops[1].atom = DW_OP_const8u;
116 ops[2].atom = DW_OP_swap;
117 simgrid::dwarf::execute(ops, 3, state, stack);
118 assert(stack.size() == 2);
119 assert(stack.top() == a);
120 assert(stack.top(1) == b);
121 } catch (const simgrid::dwarf::evaluation_error&) {
122 fprintf(stderr,"Expression evaluation error");
126 static void test_deref(simgrid::dwarf::ExpressionContext const& state)
132 ops[0].atom = DW_OP_const8u;
133 ops[0].number = (uintptr_t)&foo;
134 ops[1].atom = DW_OP_deref;
136 simgrid::dwarf::ExpressionStack stack;
138 simgrid::dwarf::execute(ops, 2, state, stack);
139 assert(stack.size() == 1);
140 assert(stack.top() == foo);
141 } catch (const simgrid::dwarf::evaluation_error&) {
142 fprintf(stderr,"Expression evaluation error");
148 process = new simgrid::mc::RemoteClient(getpid(), -1);
151 simgrid::dwarf::ExpressionContext state;
152 state.address_space = (simgrid::mc::AddressSpace*) process;
156 for(int i=0; i!=100; ++i) {
157 uintptr_t a = rnd_engine();
158 uintptr_t b = rnd_engine();
159 assert(eval_binary_operation(state, DW_OP_plus, a, b) == (a + b));
162 for(int i=0; i!=100; ++i) {
163 uintptr_t a = rnd_engine();
164 uintptr_t b = rnd_engine();
165 assert(eval_binary_operation(state, DW_OP_or, a, b) == (a | b));
168 for(int i=0; i!=100; ++i) {
169 uintptr_t a = rnd_engine();
170 uintptr_t b = rnd_engine();
171 assert(eval_binary_operation(state, DW_OP_and, a, b) == (a & b));
174 for(int i=0; i!=100; ++i) {
175 uintptr_t a = rnd_engine();
176 uintptr_t b = rnd_engine();
177 assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));