retdec
|
#include <llvmir_emul.h>
Classes | |
struct | CallEntry |
Public Member Functions | |
LlvmIrEmulator (llvm::Module *m) | |
~LlvmIrEmulator () | |
llvm::GenericValue | runFunction (llvm::Function *f, const llvm::ArrayRef< llvm::GenericValue > argVals={}) |
const std::list< llvm::Instruction * > & | getVisitedInstructions () const |
const std::list< llvm::BasicBlock * > & | getVisitedBasicBlocks () const |
bool | wasInstructionVisited (llvm::Instruction *i) const |
bool | wasBasicBlockVisited (llvm::BasicBlock *bb) const |
llvm::GenericValue | getExitValue () const |
const std::list< CallEntry > & | getCallEntries () const |
std::list< llvm::Value * > | getCalledValues () const |
std::set< llvm::Value * > | getCalledValuesSet () const |
bool | wasValueCalled (llvm::Value *v) const |
const CallEntry * | getCallEntry (llvm::Value *v, unsigned n=0) const |
bool | wasGlobalVariableLoaded (llvm::GlobalVariable *gv) |
bool | wasGlobalVariableStored (llvm::GlobalVariable *gv) |
std::list< llvm::GlobalVariable * > | getLoadedGlobalVariables () |
std::set< llvm::GlobalVariable * > | getLoadedGlobalVariablesSet () |
std::list< llvm::GlobalVariable * > | getStoredGlobalVariables () |
std::set< llvm::GlobalVariable * > | getStoredGlobalVariablesSet () |
llvm::GenericValue | getGlobalVariableValue (llvm::GlobalVariable *gv) |
void | setGlobalVariableValue (llvm::GlobalVariable *gv, llvm::GenericValue val) |
bool | wasMemoryLoaded (uint64_t addr) |
bool | wasMemoryStored (uint64_t addr) |
std::list< uint64_t > | getLoadedMemory () |
std::set< uint64_t > | getLoadedMemorySet () |
std::list< uint64_t > | getStoredMemory () |
std::set< uint64_t > | getStoredMemorySet () |
llvm::GenericValue | getMemoryValue (uint64_t addr) |
void | setMemoryValue (uint64_t addr, llvm::GenericValue val) |
llvm::GenericValue | getValueValue (llvm::Value *val) |
void | visitReturnInst (llvm::ReturnInst &I) |
void | visitBranchInst (llvm::BranchInst &I) |
void | visitSwitchInst (llvm::SwitchInst &I) |
void | visitIndirectBrInst (llvm::IndirectBrInst &I) |
void | visitBinaryOperator (llvm::BinaryOperator &I) |
void | visitICmpInst (llvm::ICmpInst &I) |
void | visitFCmpInst (llvm::FCmpInst &I) |
void | visitAllocaInst (llvm::AllocaInst &I) |
void | visitLoadInst (llvm::LoadInst &I) |
void | visitStoreInst (llvm::StoreInst &I) |
void | visitGetElementPtrInst (llvm::GetElementPtrInst &I) |
void | visitPHINode (llvm::PHINode &PN) |
void | visitTruncInst (llvm::TruncInst &I) |
void | visitZExtInst (llvm::ZExtInst &I) |
void | visitSExtInst (llvm::SExtInst &I) |
void | visitFPTruncInst (llvm::FPTruncInst &I) |
void | visitFPExtInst (llvm::FPExtInst &I) |
void | visitUIToFPInst (llvm::UIToFPInst &I) |
void | visitSIToFPInst (llvm::SIToFPInst &I) |
void | visitFPToUIInst (llvm::FPToUIInst &I) |
void | visitFPToSIInst (llvm::FPToSIInst &I) |
void | visitPtrToIntInst (llvm::PtrToIntInst &I) |
void | visitIntToPtrInst (llvm::IntToPtrInst &I) |
void | visitBitCastInst (llvm::BitCastInst &I) |
void | visitSelectInst (llvm::SelectInst &I) |
void | visitCallInst (llvm::CallInst &I) |
void | visitInvokeInst (llvm::InvokeInst &I) |
void | visitUnreachableInst (llvm::UnreachableInst &I) |
void | visitShl (llvm::BinaryOperator &I) |
void | visitLShr (llvm::BinaryOperator &I) |
void | visitAShr (llvm::BinaryOperator &I) |
void | visitVAArgInst (llvm::VAArgInst &I) |
void | visitExtractElementInst (llvm::ExtractElementInst &I) |
void | visitInsertElementInst (llvm::InsertElementInst &I) |
void | visitShuffleVectorInst (llvm::ShuffleVectorInst &I) |
void | visitExtractValueInst (llvm::ExtractValueInst &I) |
void | visitInsertValueInst (llvm::InsertValueInst &I) |
void | visitInstruction (llvm::Instruction &I) |
Public Attributes | |
std::vector< LocalExecutionContext > | _ecStackRetired |
Private Member Functions | |
void | run () |
void | callFunction (llvm::Function *f, llvm::ArrayRef< llvm::GenericValue > argVals) |
void | logInstruction (llvm::Instruction *i) |
void | popStackAndReturnValueToCaller (llvm::Type *retT, llvm::GenericValue res) |
Private Attributes | |
llvm::IntrinsicLowering * | IL = nullptr |
llvm::Module * | _module = nullptr |
llvm::GenericValue | _exitValue |
std::vector< LocalExecutionContext > | _ecStack |
GlobalExecutionContext | _globalEc |
std::list< llvm::Instruction * > | _visitedInsns |
std::list< llvm::BasicBlock * > | _visitedBbs |
std::list< CallEntry > | _calls |
Intrinsic calls are lowered and not logged here. More... | |
retdec::llvmir_emul::LlvmIrEmulator::LlvmIrEmulator | ( | llvm::Module * | m | ) |
retdec::llvmir_emul::LlvmIrEmulator::~LlvmIrEmulator | ( | ) |
|
private |
Right now, this can not handle variadic functions. We probably will not need them anyway, but if we did, it is handled in the LLVM interpreter.
std::list< llvm::Value * > retdec::llvmir_emul::LlvmIrEmulator::getCalledValues | ( | ) | const |
std::set< llvm::Value * > retdec::llvmir_emul::LlvmIrEmulator::getCalledValuesSet | ( | ) | const |
const std::list< LlvmIrEmulator::CallEntry > & retdec::llvmir_emul::LlvmIrEmulator::getCallEntries | ( | ) | const |
const LlvmIrEmulator::CallEntry * retdec::llvmir_emul::LlvmIrEmulator::getCallEntry | ( | llvm::Value * | v, |
unsigned | n = 0 |
||
) | const |
n-th
call entry calling v
value, or nullptr
if such entry does not exist. llvm::GenericValue retdec::llvmir_emul::LlvmIrEmulator::getExitValue | ( | ) | const |
llvm::GenericValue retdec::llvmir_emul::LlvmIrEmulator::getGlobalVariableValue | ( | llvm::GlobalVariable * | gv | ) |
std::list< llvm::GlobalVariable * > retdec::llvmir_emul::LlvmIrEmulator::getLoadedGlobalVariables | ( | ) |
std::set< llvm::GlobalVariable * > retdec::llvmir_emul::LlvmIrEmulator::getLoadedGlobalVariablesSet | ( | ) |
std::list< uint64_t > retdec::llvmir_emul::LlvmIrEmulator::getLoadedMemory | ( | ) |
std::set< uint64_t > retdec::llvmir_emul::LlvmIrEmulator::getLoadedMemorySet | ( | ) |
llvm::GenericValue retdec::llvmir_emul::LlvmIrEmulator::getMemoryValue | ( | uint64_t | addr | ) |
std::list< llvm::GlobalVariable * > retdec::llvmir_emul::LlvmIrEmulator::getStoredGlobalVariables | ( | ) |
std::set< llvm::GlobalVariable * > retdec::llvmir_emul::LlvmIrEmulator::getStoredGlobalVariablesSet | ( | ) |
std::list< uint64_t > retdec::llvmir_emul::LlvmIrEmulator::getStoredMemory | ( | ) |
std::set< uint64_t > retdec::llvmir_emul::LlvmIrEmulator::getStoredMemorySet | ( | ) |
llvm::GenericValue retdec::llvmir_emul::LlvmIrEmulator::getValueValue | ( | llvm::Value * | val | ) |
Get generic value for the passed LLVM value val. If val
is a global variable, result of getGlobalVariableValue()
is returned. Otherwise, LLVM value to generic value map in global context is used.
const std::list< llvm::BasicBlock * > & retdec::llvmir_emul::LlvmIrEmulator::getVisitedBasicBlocks | ( | ) | const |
const std::list< llvm::Instruction * > & retdec::llvmir_emul::LlvmIrEmulator::getVisitedInstructions | ( | ) | const |
|
private |
|
private |
|
private |
llvm::GenericValue retdec::llvmir_emul::LlvmIrEmulator::runFunction | ( | llvm::Function * | f, |
const llvm::ArrayRef< llvm::GenericValue > | argVals = {} |
||
) |
void retdec::llvmir_emul::LlvmIrEmulator::setGlobalVariableValue | ( | llvm::GlobalVariable * | gv, |
llvm::GenericValue | val | ||
) |
void retdec::llvmir_emul::LlvmIrEmulator::setMemoryValue | ( | uint64_t | addr, |
llvm::GenericValue | val | ||
) |
void retdec::llvmir_emul::LlvmIrEmulator::visitAllocaInst | ( | llvm::AllocaInst & | I | ) |
Matula: Right now, we do the same thing as LLVM's interpreter – really allocate memory and keed track of it via ExecutionContext::allocas. Maybe this is not needed at all, or it would be better to solve it in a different way without memory allocation.
void retdec::llvmir_emul::LlvmIrEmulator::visitAShr | ( | llvm::BinaryOperator & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitBinaryOperator | ( | llvm::BinaryOperator & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitBitCastInst | ( | llvm::BitCastInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitBranchInst | ( | llvm::BranchInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitCallInst | ( | llvm::CallInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitExtractElementInst | ( | llvm::ExtractElementInst & | I | ) |
This is not really getting the value. It just sets ExtractValueInst's result to uninitialized GenericValue.
void retdec::llvmir_emul::LlvmIrEmulator::visitExtractValueInst | ( | llvm::ExtractValueInst & | I | ) |
This is not really getting the value. It just sets ExtractValueInst's result to uninitialized GenericValue.
void retdec::llvmir_emul::LlvmIrEmulator::visitFCmpInst | ( | llvm::FCmpInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitFPExtInst | ( | llvm::FPExtInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitFPToSIInst | ( | llvm::FPToSIInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitFPToUIInst | ( | llvm::FPToUIInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitFPTruncInst | ( | llvm::FPTruncInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitGetElementPtrInst | ( | llvm::GetElementPtrInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitICmpInst | ( | llvm::ICmpInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitIndirectBrInst | ( | llvm::IndirectBrInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitInsertElementInst | ( | llvm::InsertElementInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitInsertValueInst | ( | llvm::InsertValueInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitInstruction | ( | llvm::Instruction & | I | ) |
When visitor does not find visit method for a particular child class, it uses visit method for the parent class. This is a visit for the super parent class for all LLVM instructions. If visitor gets here, it means the current instruction is not handled – it should have its own specialized visit method, no instruction should be handled by this super visit method.
void retdec::llvmir_emul::LlvmIrEmulator::visitIntToPtrInst | ( | llvm::IntToPtrInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitInvokeInst | ( | llvm::InvokeInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitLoadInst | ( | llvm::LoadInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitLShr | ( | llvm::BinaryOperator & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitPHINode | ( | llvm::PHINode & | PN | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitPtrToIntInst | ( | llvm::PtrToIntInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitReturnInst | ( | llvm::ReturnInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitSelectInst | ( | llvm::SelectInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitSExtInst | ( | llvm::SExtInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitShl | ( | llvm::BinaryOperator & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitShuffleVectorInst | ( | llvm::ShuffleVectorInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitSIToFPInst | ( | llvm::SIToFPInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitStoreInst | ( | llvm::StoreInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitSwitchInst | ( | llvm::SwitchInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitTruncInst | ( | llvm::TruncInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitUIToFPInst | ( | llvm::UIToFPInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitUnreachableInst | ( | llvm::UnreachableInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitVAArgInst | ( | llvm::VAArgInst & | I | ) |
void retdec::llvmir_emul::LlvmIrEmulator::visitZExtInst | ( | llvm::ZExtInst & | I | ) |
bool retdec::llvmir_emul::LlvmIrEmulator::wasBasicBlockVisited | ( | llvm::BasicBlock * | bb | ) | const |
bool retdec::llvmir_emul::LlvmIrEmulator::wasGlobalVariableLoaded | ( | llvm::GlobalVariable * | gv | ) |
bool retdec::llvmir_emul::LlvmIrEmulator::wasGlobalVariableStored | ( | llvm::GlobalVariable * | gv | ) |
bool retdec::llvmir_emul::LlvmIrEmulator::wasInstructionVisited | ( | llvm::Instruction * | i | ) | const |
bool retdec::llvmir_emul::LlvmIrEmulator::wasMemoryLoaded | ( | uint64_t | addr | ) |
bool retdec::llvmir_emul::LlvmIrEmulator::wasMemoryStored | ( | uint64_t | addr | ) |
bool retdec::llvmir_emul::LlvmIrEmulator::wasValueCalled | ( | llvm::Value * | v | ) | const |
True
if value v is called at least once.
|
private |
Intrinsic calls are lowered and not logged here.
|
private |
std::vector<LocalExecutionContext> retdec::llvmir_emul::LlvmIrEmulator::_ecStackRetired |
|
private |
|
private |
|
private |
|
private |
All visited basic blocks in order of their visitation. No cycling checks are performed at the moment – one basic block might be visited multiple times.
|
private |
All visited instruction in order of their visitation. No cycling checks are performed at the moment – one instruction might be visited multiple times.
|
private |