Skip to content

Commit 79a5907

Browse files
committed
Add option to stre and rerun execution states during run
1 parent 4f237af commit 79a5907

21 files changed

+749
-433
lines changed

include/klee/ADT/KTest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ int kTest_toFile(const KTest *, const char *path);
6565
unsigned kTest_numBytes(KTest *);
6666

6767
void kTest_free(KTest *);
68+
void test_kTest_free(KTest *);
6869

6970
#ifdef __cplusplus
7071
}

include/klee/Core/BranchTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
BTYPE(Realloc, 8U) \
2626
BTYPE(Free, 9U) \
2727
BTYPE(GetVal, 10U) \
28-
BMARK(END, 10U)
28+
BTYPE(InitialBranch, 11U) \
29+
BMARK(END, 11U)
2930
/// \endcond
3031

3132
/** @enum BranchType

include/klee/Core/Interpreter.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "TerminationTypes.h"
1313
#include "klee/Module/Annotation.h"
1414

15+
#include "klee/ADT/KTest.h"
1516
#include "klee/Module/SarifReport.h"
1617

1718
#include <cstdint>
@@ -58,8 +59,11 @@ class InterpreterHandler {
5859

5960
virtual void processTestCase(const ExecutionState &state, const char *message,
6061
const char *suffix, bool isError = false) = 0;
61-
6262
virtual ToolJson info() const = 0;
63+
64+
// used for writing .ktest files
65+
virtual int argc() = 0;
66+
virtual char **argv() = 0;
6367
};
6468

6569
/// [File][Line][Column] -> Opcode
@@ -209,10 +213,6 @@ class Interpreter {
209213
// a user specified path. use null to reset.
210214
virtual void setReplayPath(const std::vector<bool> *path) = 0;
211215

212-
// supply a set of symbolic bindings that will be used as "seeds"
213-
// for the search. use null to reset.
214-
virtual void useSeeds(const std::vector<struct KTest *> *seeds) = 0;
215-
216216
virtual void runFunctionAsMain(llvm::Function *f, int argc, char **argv,
217217
char **envp) = 0;
218218

@@ -237,7 +237,10 @@ class Interpreter {
237237
virtual void getConstraintLog(const ExecutionState &state, std::string &res,
238238
LogType logFormat = STP) = 0;
239239

240-
virtual bool getSymbolicSolution(const ExecutionState &state, KTest &res) = 0;
240+
virtual void getSteppedInstructions(const ExecutionState &state,
241+
unsigned &res) = 0;
242+
243+
virtual bool getSymbolicSolution(const ExecutionState &state, KTest *res) = 0;
241244

242245
virtual void addSARIFReport(const ExecutionState &state) = 0;
243246

json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 6af826d0bdb55e4b69e3ad817576745335f243ca

lib/Basic/KTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99

1010
#include "klee/ADT/KTest.h"
1111

12+
#include <cassert>
13+
#include <fstream>
1214
#include <stdint.h>
1315
#include <stdio.h>
1416
#include <stdlib.h>
1517
#include <string.h>
18+
#include <string>
1619

1720
#define KTEST_VERSION 4
1821
#define KTEST_MAGIC_SIZE 5
@@ -295,3 +298,14 @@ void kTest_free(KTest *bo) {
295298
free(bo->objects);
296299
free(bo);
297300
}
301+
302+
void test_kTest_free(KTest *bo) {
303+
unsigned i;
304+
for (i = 0; i < bo->numObjects; i++) {
305+
free(bo->objects[i].name);
306+
free(bo->objects[i].bytes);
307+
free(bo->objects[i].pointers);
308+
}
309+
free(bo->objects);
310+
free(bo);
311+
}

lib/Core/ExecutionState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ExecutionState::ExecutionState(const ExecutionState &state)
178178
gepExprBases(state.gepExprBases), multiplexKF(state.multiplexKF),
179179
prevTargets_(state.prevTargets_), targets_(state.targets_),
180180
prevHistory_(state.prevHistory_), history_(state.history_),
181-
isTargeted_(state.isTargeted_) {
181+
isTargeted_(state.isTargeted_), isSeeded(state.isSeeded) {
182182
queryMetaData.id = state.id;
183183
}
184184

lib/Core/ExecutionState.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ struct ExecutionStack {
151151
inline const call_stack_ty &uniqueFrames() const { return uniqueFrames_; }
152152

153153
void forceReturnLocation(const ref<CodeLocation> &location) {
154+
if (callStack_.empty()) {
155+
llvm::errs() << callStack_.size() << "\n";
156+
}
154157
assert(!callStack_.empty() && "Call stack should contain at least one "
155158
"stack frame to force return location");
156159
std::optional<ref<CodeLocation>> &callStackReturnLocation =
@@ -300,6 +303,7 @@ class ExecutionState {
300303
public:
301304
using stack_ty = ExecutionStack;
302305

306+
bool isSeeded = false;
303307
// Execution - Control Flow specific
304308

305309
/// @brief Pointer to initial instruction

0 commit comments

Comments
 (0)