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]

Public Member Functions

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

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

Protected Attributes

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

Private Attributes

PointerType * m_i8ptr_ty = nullptr
 
IntegerType * m_intptr_ty = nullptr
 

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 128 of file IRDynamicChecks.cpp.

Member Typedef Documentation

◆ InstIterator

typedef InstVector::iterator Instrumenter::InstIterator
protected

Definition at line 291 of file IRDynamicChecks.cpp.

◆ InstVector

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

Definition at line 290 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 134 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 257 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 234 of file IRDynamicChecks.cpp.

◆ GetI8PtrTy()

PointerType * Instrumenter::GetI8PtrTy ( )
inlineprotected

Definition at line 273 of file IRDynamicChecks.cpp.

◆ GetIntptrTy()

IntegerType * Instrumenter::GetIntptrTy ( )
inlineprotected

Definition at line 280 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 147 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 199 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 216 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 ValidPointerChecker, and ObjcObjectChecker.

Definition at line 190 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 153 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 ValidPointerChecker, and ObjcObjectChecker.

◆ 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 178 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 296 of file IRDynamicChecks.cpp.

◆ m_i8ptr_ty

PointerType* Instrumenter::m_i8ptr_ty = nullptr
private

Definition at line 299 of file IRDynamicChecks.cpp.

◆ m_intptr_ty

IntegerType* Instrumenter::m_intptr_ty = nullptr
private

Definition at line 300 of file IRDynamicChecks.cpp.

◆ m_module

llvm::Module& Instrumenter::m_module
protected

The module which is being instrumented.

Definition at line 294 of file IRDynamicChecks.cpp.

◆ m_to_instrument

InstVector Instrumenter::m_to_instrument
protected

List of instructions the inspector found.

Definition at line 293 of file IRDynamicChecks.cpp.


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