LLDB  mainline
Public Member Functions | Protected Types | Protected Member Functions | Protected 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, DynamicCheckerFunctions &checker_functions)
 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 &i)
 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...
 
DynamicCheckerFunctionsm_checker_functions
 The dynamic checker functions for the process. More...
 

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

Member Typedef Documentation

◆ InstIterator

typedef InstVector::iterator Instrumenter::InstIterator
protected

Definition at line 295 of file IRDynamicChecks.cpp.

◆ InstVector

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

Definition at line 294 of file IRDynamicChecks.cpp.

Constructor & Destructor Documentation

◆ Instrumenter()

Instrumenter::Instrumenter ( llvm::Module &  module,
DynamicCheckerFunctions checker_functions 
)
inline

Constructor.

Parameters
[in]moduleThe module being instrumented.

Definition at line 137 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 260 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 237 of file IRDynamicChecks.cpp.

◆ GetI8PtrTy()

PointerType* Instrumenter::GetI8PtrTy ( )
inlineprotected

Definition at line 276 of file IRDynamicChecks.cpp.

◆ GetIntptrTy()

IntegerType* Instrumenter::GetIntptrTy ( )
inlineprotected

Definition at line 283 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 150 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 202 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 219 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 193 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 156 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 &  i)
inlineprotected

Register a single instruction to be instrumented.

Parameters
[in]instThe instruction to be instrumented.

Definition at line 181 of file IRDynamicChecks.cpp.

Member Data Documentation

◆ m_checker_functions

DynamicCheckerFunctions& Instrumenter::m_checker_functions
protected

The dynamic checker functions for the process.

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

◆ m_to_instrument

InstVector Instrumenter::m_to_instrument
protected

List of instructions the inspector found.

Definition at line 297 of file IRDynamicChecks.cpp.


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