LLDB  mainline
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
Instrumenter Class Referenceabstract

Finds and instruments individual LLVM IR instructions. More...

#include <IRDynamicChecks.cpp>

Inheritance diagram for Instrumenter:
Inheritance graph
[legend]
Collaboration diagram for Instrumenter:
Collaboration graph
[legend]

Public Member Functions

 Instrumenter (llvm::Module &module, std::shared_ptr< UtilityFunction > checker_function)
 Constructor. More...
 
virtual ~Instrumenter ()=default
 
bool Inspect (llvm::Function &function)
 Inspect a function to find instructions to instrument. More...
 
bool Instrument ()
 Instrument all the instructions found by Inspect() More...
 

Protected Types

typedef std::vector< llvm::Instruction * > InstVector
 
typedef InstVector::iterator InstIterator
 

Protected Member Functions

virtual bool InstrumentInstruction (llvm::Instruction *inst)=0
 Add instrumentation to a single instruction. More...
 
void RegisterInstruction (llvm::Instruction &inst)
 Register a single instruction to be instrumented. More...
 
virtual bool InspectInstruction (llvm::Instruction &i)
 Determine whether a single instruction is interesting to instrument, and, if so, call RegisterInstruction. More...
 
virtual bool InspectBasicBlock (llvm::BasicBlock &bb)
 Scan a basic block to see if any instructions are interesting. More...
 
virtual bool InspectFunction (llvm::Function &f)
 Scan a function to see if any instructions are interesting. More...
 
llvm::FunctionCallee BuildPointerValidatorFunc (lldb::addr_t start_address)
 Build a function pointer for a function with signature void (*)(uint8_t*) with a given address. More...
 
llvm::FunctionCallee BuildObjectCheckerFunc (lldb::addr_t start_address)
 Build a function pointer for a function with signature void (*)(uint8_t*, uint8_t*) with a given address. More...
 
PointerType * GetI8PtrTy ()
 
IntegerType * GetIntptrTy ()
 

Protected Attributes

InstVector m_to_instrument
 List of instructions the inspector found. More...
 
llvm::Module & m_module
 The module which is being instrumented. More...
 
std::shared_ptr< UtilityFunctionm_checker_function
 The dynamic checker function for the process. More...
 

Private Attributes

PointerType * m_i8ptr_ty
 
IntegerType * m_intptr_ty
 

Detailed Description

Finds and instruments individual LLVM IR instructions.

When instrumenting LLVM IR, it is frequently desirable to first search for instructions, and then later modify them. This way iterators remain intact, and multiple passes can look at the same code base without treading on each other's toes.

The Instrumenter class implements this functionality. A client first calls Inspect on a function, which populates a list of instructions to be instrumented. Then, later, when all passes' Inspect functions have been called, the client calls Instrument, which adds the desired instrumentation.

A subclass of Instrumenter must override InstrumentInstruction, which is responsible for adding whatever instrumentation is necessary.

A subclass of Instrumenter may override:

Definition at line 133 of file IRDynamicChecks.cpp.

Member Typedef Documentation

◆ InstIterator

typedef InstVector::iterator Instrumenter::InstIterator
protected

Definition at line 298 of file IRDynamicChecks.cpp.

◆ InstVector

typedef std::vector<llvm::Instruction *> Instrumenter::InstVector
protected

Definition at line 297 of file IRDynamicChecks.cpp.

Constructor & Destructor Documentation

◆ Instrumenter()

Instrumenter::Instrumenter ( llvm::Module &  module,
std::shared_ptr< UtilityFunction checker_function 
)
inline

Constructor.

Parameters
[in]moduleThe module being instrumented.

Definition at line 139 of file IRDynamicChecks.cpp.

◆ ~Instrumenter()

virtual Instrumenter::~Instrumenter ( )
virtualdefault

Member Function Documentation

◆ BuildObjectCheckerFunc()

llvm::FunctionCallee Instrumenter::BuildObjectCheckerFunc ( lldb::addr_t  start_address)
inlineprotected

Build a function pointer for a function with signature void (*)(uint8_t*, uint8_t*) with a given address.

Parameters
[in]start_addressThe address of the function.
Returns
The function pointer, for use in a CallInst.

Definition at line 263 of file IRDynamicChecks.cpp.

◆ BuildPointerValidatorFunc()

llvm::FunctionCallee Instrumenter::BuildPointerValidatorFunc ( lldb::addr_t  start_address)
inlineprotected

Build a function pointer for a function with signature void (*)(uint8_t*) with a given address.

Parameters
[in]start_addressThe address of the function.
Returns
The function pointer, for use in a CallInst.

Definition at line 240 of file IRDynamicChecks.cpp.

◆ GetI8PtrTy()

PointerType* Instrumenter::GetI8PtrTy ( )
inlineprotected

Definition at line 279 of file IRDynamicChecks.cpp.

◆ GetIntptrTy()

IntegerType* Instrumenter::GetIntptrTy ( )
inlineprotected

Definition at line 286 of file IRDynamicChecks.cpp.

◆ Inspect()

bool Instrumenter::Inspect ( llvm::Function &  function)
inline

Inspect a function to find instructions to instrument.

Parameters
[in]functionThe function to inspect.
Returns
True on success; false on error.

Definition at line 153 of file IRDynamicChecks.cpp.

Referenced by lldb_private::IRDynamicChecks::runOnModule().

◆ InspectBasicBlock()

virtual bool Instrumenter::InspectBasicBlock ( llvm::BasicBlock &  bb)
inlineprotectedvirtual

Scan a basic block to see if any instructions are interesting.

Parameters
[in]bbThe basic block to be inspected.
Returns
False if there was an error scanning; true otherwise.

Definition at line 205 of file IRDynamicChecks.cpp.

◆ InspectFunction()

virtual bool Instrumenter::InspectFunction ( llvm::Function &  f)
inlineprotectedvirtual

Scan a function to see if any instructions are interesting.

Parameters
[in]fThe function to be inspected.
Returns
False if there was an error scanning; true otherwise.

Definition at line 222 of file IRDynamicChecks.cpp.

◆ InspectInstruction()

virtual bool Instrumenter::InspectInstruction ( llvm::Instruction &  i)
inlineprotectedvirtual

Determine whether a single instruction is interesting to instrument, and, if so, call RegisterInstruction.

Parameters
[in]iThe instruction to be inspected.
Returns
False if there was an error scanning; true otherwise.

Reimplemented in ObjcObjectChecker, and ValidPointerChecker.

Definition at line 196 of file IRDynamicChecks.cpp.

◆ Instrument()

bool Instrumenter::Instrument ( )
inline

Instrument all the instructions found by Inspect()

Returns
True on success; false on error.

Definition at line 159 of file IRDynamicChecks.cpp.

Referenced by lldb_private::IRDynamicChecks::runOnModule().

◆ InstrumentInstruction()

virtual bool Instrumenter::InstrumentInstruction ( llvm::Instruction *  inst)
protectedpure virtual

Add instrumentation to a single instruction.

Parameters
[in]instThe instruction to be instrumented.
Returns
True on success; false otherwise.

Implemented in ObjcObjectChecker, and ValidPointerChecker.

◆ RegisterInstruction()

void Instrumenter::RegisterInstruction ( llvm::Instruction &  inst)
inlineprotected

Register a single instruction to be instrumented.

Parameters
[in]instThe instruction to be instrumented.

Definition at line 184 of file IRDynamicChecks.cpp.

Member Data Documentation

◆ m_checker_function

std::shared_ptr<UtilityFunction> Instrumenter::m_checker_function
protected

The dynamic checker function for the process.

Definition at line 303 of file IRDynamicChecks.cpp.

◆ m_i8ptr_ty

PointerType* Instrumenter::m_i8ptr_ty
private

Definition at line 306 of file IRDynamicChecks.cpp.

◆ m_intptr_ty

IntegerType* Instrumenter::m_intptr_ty
private

Definition at line 307 of file IRDynamicChecks.cpp.

◆ m_module

llvm::Module& Instrumenter::m_module
protected

The module which is being instrumented.

Definition at line 301 of file IRDynamicChecks.cpp.

◆ m_to_instrument

InstVector Instrumenter::m_to_instrument
protected

List of instructions the inspector found.

Definition at line 300 of file IRDynamicChecks.cpp.


The documentation for this class was generated from the following file: