Skip to content

Commit

Permalink
Add options to store and rerun execution states during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dim8art committed Aug 7, 2024
1 parent 24156e1 commit d79de72
Show file tree
Hide file tree
Showing 20 changed files with 737 additions and 455 deletions.
1 change: 1 addition & 0 deletions include/klee/ADT/KTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ unsigned kTest_numBytes(KTest *);

void kTest_free(KTest *);

unsigned getkTestMemoryUsage(KTest *ktest);
#ifdef __cplusplus
}
#endif
Expand Down
3 changes: 2 additions & 1 deletion include/klee/Core/BranchTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
BTYPE(Realloc, 8U) \
BTYPE(Free, 9U) \
BTYPE(GetVal, 10U) \
BMARK(END, 10U)
BTYPE(InitialBranch, 11U) \
BMARK(END, 11U)
/// \endcond

/** @enum BranchType
Expand Down
14 changes: 8 additions & 6 deletions include/klee/Core/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ class InterpreterHandler {

virtual void processTestCase(const ExecutionState &state, const char *message,
const char *suffix, bool isError = false) = 0;

virtual ToolJson info() const = 0;

// used for writing .ktest files
virtual int argc() = 0;
virtual char **argv() = 0;
};

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

// supply a set of symbolic bindings that will be used as "seeds"
// for the search. use null to reset.
virtual void useSeeds(const std::vector<struct KTest *> *seeds) = 0;

virtual void runFunctionAsMain(llvm::Function *f, int argc, char **argv,
char **envp) = 0;

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

virtual bool getSymbolicSolution(const ExecutionState &state, KTest &res) = 0;
virtual void getSteppedInstructions(const ExecutionState &state,
unsigned &res) = 0;

virtual bool getSymbolicSolution(const ExecutionState &state, KTest *res) = 0;

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

Expand Down
11 changes: 11 additions & 0 deletions lib/Basic/KTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>

#define KTEST_VERSION 4
#define KTEST_MAGIC_SIZE 5
Expand Down Expand Up @@ -295,3 +296,13 @@ void kTest_free(KTest *bo) {
free(bo->objects);
free(bo);
}

unsigned getkTestMemoryUsage(KTest *ktest) {
size_t size = 0;
for (unsigned i = 0; i < ktest->numObjects; i++) {
size += std::strlen(ktest->objects[i].name) * sizeof(char);
size += ktest->objects[i].numBytes * sizeof(unsigned char);
size += ktest->objects[i].numPointers * sizeof(Pointer);
}
return size;
}
6 changes: 3 additions & 3 deletions lib/Core/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ ExecutionState::ExecutionState(const ExecutionState &state)
coveredNew(state.coveredNew), coveredNewError(state.coveredNewError),
forkDisabled(state.forkDisabled), returnValue(state.returnValue),
gepExprBases(state.gepExprBases), multiplexKF(state.multiplexKF),
prevTargets_(state.prevTargets_), targets_(state.targets_),
prevHistory_(state.prevHistory_), history_(state.history_),
isTargeted_(state.isTargeted_) {
isSeeded(state.isSeeded), prevTargets_(state.prevTargets_),
targets_(state.targets_), prevHistory_(state.prevHistory_),
history_(state.history_), isTargeted_(state.isTargeted_) {
queryMetaData.id = state.id;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Core/ExecutionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ class ExecutionState {
// Temp: to know which multiplex path this state has taken
KFunction *multiplexKF = nullptr;

bool isSeeded = false;

private:
PersistentSet<ref<Target>> prevTargets_;
PersistentSet<ref<Target>> targets_;
Expand Down
Loading

0 comments on commit d79de72

Please sign in to comment.