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 Jul 11, 2024
1 parent 78f5095 commit e699dd6
Show file tree
Hide file tree
Showing 20 changed files with 729 additions and 450 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 @@ -9,6 +9,7 @@

#include "klee/ADT/KTest.h"

#include <fstream>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
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 += strlen(ktest->objects[i].name) * sizeof(char);
size += ktest->objects[i].numBytes * sizeof(unsigned char);
size += ktest->objects[i].numPointers * sizeof(Pointer);
}
return size;
}
2 changes: 1 addition & 1 deletion lib/Core/ExecutionState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ExecutionState::ExecutionState(const ExecutionState &state)
gepExprBases(state.gepExprBases), multiplexKF(state.multiplexKF),
prevTargets_(state.prevTargets_), targets_(state.targets_),
prevHistory_(state.prevHistory_), history_(state.history_),
isTargeted_(state.isTargeted_) {
isTargeted_(state.isTargeted_), isSeeded(state.isSeeded) {
queryMetaData.id = state.id;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Core/ExecutionState.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ class ExecutionState {
public:
using stack_ty = ExecutionStack;

bool isSeeded = false;
// Execution - Control Flow specific

/// @brief Pointer to initial instruction
Expand Down
Loading

0 comments on commit e699dd6

Please sign in to comment.