LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
llvm::MCObjectDisassembler Class Reference

Disassemble an ObjectFile to an MCModule and MCFunctions. This class builds on MCDisassembler to disassemble whole sections, creating MCAtom (MCTextAtom for disassembled sections and MCDataAtom for raw data). It can also be used to create a control flow graph consisting of MCFunctions and MCBasicBlocks. More...

#include <MCObjectDisassembler.h>

Inheritance diagram for llvm::MCObjectDisassembler:
Inheritance graph
[legend]
Collaboration diagram for llvm::MCObjectDisassembler:
Collaboration graph
[legend]

Public Types

typedef std::vector< uint64_t > AddressSetTy
 

Public Member Functions

 MCObjectDisassembler (const object::ObjectFile &Obj, const MCDisassembler &Dis, const MCInstrAnalysis &MIA)
 
virtual ~MCObjectDisassembler ()
 
MCModulebuildModule (bool withCFG=false)
 Build an MCModule, creating atoms and optionally functions. More...
 
MCModulebuildEmptyModule ()
 
Create a new MCFunction.
MCFunctioncreateFunction (MCModule *Module, uint64_t BeginAddr, AddressSetTy &CallTargets, AddressSetTy &TailCallTargets)
 
void setFallbackRegion (OwningPtr< MemoryObject > &Region)
 Set the region on which to fallback if disassembly was requested somewhere not accessible in the object file. This is used for dynamic disassembly (see RawMemoryObject). More...
 
void setSymbolizer (MCObjectSymbolizer *ObjectSymbolizer)
 Set the symbolizer to use to get information on external functions. Note that this isn't used to do instruction-level symbolization (that is, plugged into MCDisassembler), but to symbolize function call targets. More...
 
virtual uint64_t getEntrypoint ()
 Get the effective address of the entrypoint, or 0 if there is none. More...
 
Get the addresses of static constructors/destructors in the object.

The caller is expected to know how to interpret the addresses; for example, Mach-O init functions expect 5 arguments, not for ELF. The addresses are original object file load addresses, not effective.

virtual ArrayRef< uint64_t > getStaticInitFunctions ()
 
virtual ArrayRef< uint64_t > getStaticExitFunctions ()
 
Translation between effective and objectfile load address.

Compute the effective load address, from an objectfile virtual address. This is implemented in a format-specific way, to take into account things like PIE/ASLR when doing dynamic disassembly. For example, on Mach-O this would be done by adding the VM addr slide, on glibc ELF by keeping a map between segment load addresses, filled using dl_iterate_phdr, etc.. In most static situations and in the default impl., this returns Addr.

virtual uint64_t getEffectiveLoadAddr (uint64_t Addr)
 
virtual uint64_t getOriginalLoadAddr (uint64_t EffectiveAddr)
 Compute the original load address, as specified in the objectfile. This is the inverse of getEffectiveLoadAddr. More...
 

Protected Member Functions

MemoryObjectgetRegionFor (uint64_t Addr)
 Return a memory region suitable for reading starting at Addr. In most cases, this returns a StringRefMemoryObject backed by the containing section. When no section was found, this returns the FallbackRegion, if it is suitable. If it is not, or if there is no fallback region, this returns 0. More...
 

Protected Attributes

const object::ObjectFileObj
 
const MCDisassemblerDis
 
const MCInstrAnalysisMIA
 
MCObjectSymbolizerMOS
 
OwningPtr< MemoryObjectFallbackRegion
 The fallback memory region, outside the object file. More...
 

Detailed Description

Disassemble an ObjectFile to an MCModule and MCFunctions. This class builds on MCDisassembler to disassemble whole sections, creating MCAtom (MCTextAtom for disassembled sections and MCDataAtom for raw data). It can also be used to create a control flow graph consisting of MCFunctions and MCBasicBlocks.

Definition at line 44 of file MCObjectDisassembler.h.

Member Typedef Documentation

typedef std::vector<uint64_t> llvm::MCObjectDisassembler::AddressSetTy

Definition at line 61 of file MCObjectDisassembler.h.

Constructor & Destructor Documentation

MCObjectDisassembler::MCObjectDisassembler ( const object::ObjectFile Obj,
const MCDisassembler Dis,
const MCInstrAnalysis MIA 
)

Definition at line 34 of file MCObjectDisassembler.cpp.

virtual llvm::MCObjectDisassembler::~MCObjectDisassembler ( )
inlinevirtual

Definition at line 49 of file MCObjectDisassembler.h.

Member Function Documentation

MCModule * MCObjectDisassembler::buildEmptyModule ( )

Definition at line 77 of file MCObjectDisassembler.cpp.

References getEntrypoint().

Referenced by buildModule().

MCModule * MCObjectDisassembler::buildModule ( bool  withCFG = false)

Build an MCModule, creating atoms and optionally functions.

Parameters
withCFGAlso build a CFG by adding MCFunctions to the Module. If withCFG is false, the MCModule built only contains atoms, representing what was found in the object file. If withCFG is true, MCFunctions are created, containing MCBasicBlocks. All text atoms are split to form basic block atoms, which then each back an MCBasicBlock.

Definition at line 83 of file MCObjectDisassembler.cpp.

References buildEmptyModule().

MCFunction * MCObjectDisassembler::createFunction ( MCModule Module,
uint64_t  BeginAddr,
AddressSetTy CallTargets,
AddressSetTy TailCallTargets 
)
uint64_t MCObjectDisassembler::getEffectiveLoadAddr ( uint64_t  Addr)
virtual

Reimplemented in llvm::MCMachOObjectDisassembler.

Definition at line 69 of file MCObjectDisassembler.cpp.

Referenced by getEntrypoint().

uint64_t MCObjectDisassembler::getEntrypoint ( )
virtual
uint64_t MCObjectDisassembler::getOriginalLoadAddr ( uint64_t  EffectiveAddr)
virtual

Compute the original load address, as specified in the objectfile. This is the inverse of getEffectiveLoadAddr.

Reimplemented in llvm::MCMachOObjectDisassembler.

Definition at line 73 of file MCObjectDisassembler.cpp.

Referenced by createFunction().

MemoryObject * MCObjectDisassembler::getRegionFor ( uint64_t  Addr)
protected

Return a memory region suitable for reading starting at Addr. In most cases, this returns a StringRefMemoryObject backed by the containing section. When no section was found, this returns the FallbackRegion, if it is suitable. If it is not, or if there is no fallback region, this returns 0.

Definition at line 64 of file MCObjectDisassembler.cpp.

References FallbackRegion.

ArrayRef< uint64_t > MCObjectDisassembler::getStaticExitFunctions ( )
virtual

Reimplemented in llvm::MCMachOObjectDisassembler.

Definition at line 60 of file MCObjectDisassembler.cpp.

ArrayRef< uint64_t > MCObjectDisassembler::getStaticInitFunctions ( )
virtual

Reimplemented in llvm::MCMachOObjectDisassembler.

Definition at line 56 of file MCObjectDisassembler.cpp.

void llvm::MCObjectDisassembler::setFallbackRegion ( OwningPtr< MemoryObject > &  Region)
inline

Set the region on which to fallback if disassembly was requested somewhere not accessible in the object file. This is used for dynamic disassembly (see RawMemoryObject).

Definition at line 70 of file MCObjectDisassembler.h.

References FallbackRegion, and llvm::OwningPtr< T >::take().

void llvm::MCObjectDisassembler::setSymbolizer ( MCObjectSymbolizer ObjectSymbolizer)
inline

Set the symbolizer to use to get information on external functions. Note that this isn't used to do instruction-level symbolization (that is, plugged into MCDisassembler), but to symbolize function call targets.

Definition at line 77 of file MCObjectDisassembler.h.

References MOS.

Member Data Documentation

const MCDisassembler& llvm::MCObjectDisassembler::Dis
protected

Definition at line 111 of file MCObjectDisassembler.h.

OwningPtr<MemoryObject> llvm::MCObjectDisassembler::FallbackRegion
protected

The fallback memory region, outside the object file.

Definition at line 116 of file MCObjectDisassembler.h.

Referenced by getRegionFor(), and setFallbackRegion().

const MCInstrAnalysis& llvm::MCObjectDisassembler::MIA
protected

Definition at line 112 of file MCObjectDisassembler.h.

MCObjectSymbolizer* llvm::MCObjectDisassembler::MOS
protected

Definition at line 113 of file MCObjectDisassembler.h.

Referenced by createFunction(), and setSymbolizer().

const object::ObjectFile& llvm::MCObjectDisassembler::Obj
protected

Definition at line 110 of file MCObjectDisassembler.h.

Referenced by getEntrypoint().


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