LLDB mainline
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
lldb_private::IRExecutionUnit Class Reference

"lldb/Expression/IRExecutionUnit.h" Contains the IR and, optionally, JIT- compiled code for a module. More...

#include <IRExecutionUnit.h>

Inheritance diagram for lldb_private::IRExecutionUnit:
Inheritance graph
[legend]

Classes

struct  AllocationRecord
 Encapsulates a single allocation request made by the JIT. More...
 
struct  JittedEntity
 
class  JittedFunction
 "lldb/Expression/IRExecutionUnit.h" Encapsulates a single function that has been generated by the JIT. More...
 
struct  JittedGlobalVariable
 
class  MemoryManager
 

Public Member Functions

 IRExecutionUnit (std::unique_ptr< llvm::LLVMContext > &context_up, std::unique_ptr< llvm::Module > &module_up, ConstString &name, const lldb::TargetSP &target_sp, const SymbolContext &sym_ctx, std::vector< std::string > &cpu_features)
 Constructor.
 
 ~IRExecutionUnit () override
 Destructor.
 
ConstString GetFunctionName ()
 
llvm::Module * GetModule ()
 
llvm::Function * GetFunction ()
 
void GetRunnableInfo (Status &error, lldb::addr_t &func_addr, lldb::addr_t &func_end)
 
lldb::addr_t WriteNow (const uint8_t *bytes, size_t size, Status &error)
 Accessors for IRForTarget and other clients that may want binary data placed on their behalf.
 
void FreeNow (lldb::addr_t allocation)
 
lldb::ByteOrder GetByteOrder () const override
 ObjectFileJITDelegate overrides.
 
uint32_t GetAddressByteSize () const override
 
void PopulateSymtab (lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab) override
 
void PopulateSectionList (lldb_private::ObjectFile *obj_file, lldb_private::SectionList &section_list) override
 
ArchSpec GetArchitecture () override
 
lldb::ModuleSP GetJITModule ()
 
lldb::addr_t FindSymbol (ConstString name, bool &missing_weak)
 
void GetStaticInitializers (std::vector< lldb::addr_t > &static_initializers)
 
const std::vector< JittedFunction > & GetJittedFunctions ()
 
const std::vector< JittedGlobalVariable > & GetJittedGlobalVariables ()
 
- Public Member Functions inherited from lldb_private::IRMemoryMap
 IRMemoryMap (lldb::TargetSP target_sp)
 
 ~IRMemoryMap ()
 
lldb::addr_t Malloc (size_t size, uint8_t alignment, uint32_t permissions, AllocationPolicy policy, bool zero_memory, Status &error)
 
void Leak (lldb::addr_t process_address, Status &error)
 
void Free (lldb::addr_t process_address, Status &error)
 
void WriteMemory (lldb::addr_t process_address, const uint8_t *bytes, size_t size, Status &error)
 
void WriteScalarToMemory (lldb::addr_t process_address, Scalar &scalar, size_t size, Status &error)
 
void WritePointerToMemory (lldb::addr_t process_address, lldb::addr_t address, Status &error)
 
void ReadMemory (uint8_t *bytes, lldb::addr_t process_address, size_t size, Status &error)
 
void ReadScalarFromMemory (Scalar &scalar, lldb::addr_t process_address, size_t size, Status &error)
 
void ReadPointerFromMemory (lldb::addr_t *address, lldb::addr_t process_address, Status &error)
 
bool GetAllocSize (lldb::addr_t address, size_t &size)
 
void GetMemoryData (DataExtractor &extractor, lldb::addr_t process_address, size_t size, Status &error)
 
lldb::ByteOrder GetByteOrder ()
 
uint32_t GetAddressByteSize ()
 
ExecutionContextScopeGetBestExecutionContextScope () const
 
lldb::TargetSP GetTarget ()
 
- Public Member Functions inherited from lldb_private::ObjectFileJITDelegate
 ObjectFileJITDelegate ()=default
 
virtual ~ObjectFileJITDelegate ()=default
 
virtual lldb::ByteOrder GetByteOrder () const =0
 
virtual uint32_t GetAddressByteSize () const =0
 
virtual void PopulateSymtab (lldb_private::ObjectFile *obj_file, lldb_private::Symtab &symtab)=0
 
virtual void PopulateSectionList (lldb_private::ObjectFile *obj_file, lldb_private::SectionList &section_list)=0
 
virtual ArchSpec GetArchitecture ()=0
 

Private Types

enum class  AllocationKind {
  Stub , Code , Data , Global ,
  Bytes
}
 
typedef std::pair< lldb::addr_t, uintptr_t > AddrRange
 
typedef std::vector< AllocationRecordRecordVector
 

Private Member Functions

lldb::addr_t GetRemoteAddressForLocal (lldb::addr_t local_address)
 Look up the object in m_address_map that contains a given address, find where it was copied to, and return the remote address at the same offset into the copied entity.
 
AddrRange GetRemoteRangeForLocal (lldb::addr_t local_address)
 Look up the object in m_address_map that contains a given address, find where it was copied to, and return its address range in the target process.
 
bool CommitAllocations (lldb::ProcessSP &process_sp)
 Commit all allocations to the process and record where they were stored.
 
void ReportAllocations (llvm::ExecutionEngine &engine)
 Report all committed allocations to the execution engine.
 
bool WriteData (lldb::ProcessSP &process_sp)
 Write the contents of all allocations to the process.
 
Status DisassembleFunction (Stream &stream, lldb::ProcessSP &process_sp)
 
void CollectCandidateCNames (std::vector< ConstString > &C_names, ConstString name)
 
void CollectCandidateCPlusPlusNames (std::vector< ConstString > &CPP_names, const std::vector< ConstString > &C_names, const SymbolContext &sc)
 
lldb::addr_t FindInSymbols (const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc, bool &symbol_was_missing_weak)
 
lldb::addr_t FindInRuntimes (const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
 
lldb::addr_t FindInUserDefinedSymbols (const std::vector< ConstString > &names, const lldb_private::SymbolContext &sc)
 
void ReportSymbolLookupError (ConstString name)
 
bool CommitOneAllocation (lldb::ProcessSP &process_sp, Status &error, AllocationRecord &record)
 

Static Private Member Functions

static lldb::SectionType GetSectionTypeFromSectionName (const llvm::StringRef &name, AllocationKind alloc_kind)
 

Private Attributes

RecordVector m_records
 
std::unique_ptr< llvm::LLVMContext > m_context_up
 
std::unique_ptr< llvm::ExecutionEngine > m_execution_engine_up
 
std::unique_ptr< llvm::ObjectCache > m_object_cache_up
 
std::unique_ptr< llvm::Module > m_module_up
 Holder for the module until it's been handed off.
 
llvm::Module * m_module
 Owned by the execution engine.
 
std::vector< std::string > m_cpu_features
 
std::vector< JittedFunctionm_jitted_functions
 A vector of all functions that have been JITted into machine code.
 
std::vector< JittedGlobalVariablem_jitted_global_variables
 A vector of all functions that have been JITted into machine code.
 
const ConstString m_name
 
SymbolContext m_sym_ctx
 Used for symbol lookups.
 
std::vector< ConstStringm_failed_lookups
 
std::atomic< bool > m_did_jit
 
lldb::addr_t m_function_load_addr
 
lldb::addr_t m_function_end_load_addr
 
bool m_strip_underscore = true
 True for platforms where global symbols have a _ prefix.
 
bool m_reported_allocations
 True after allocations have been reported.
 

Static Private Attributes

static const unsigned eSectionIDInvalid = (unsigned)-1
 

Additional Inherited Members

- Public Types inherited from lldb_private::IRMemoryMap
enum  AllocationPolicy : uint8_t { eAllocationPolicyInvalid , eAllocationPolicyHostOnly , eAllocationPolicyMirror , eAllocationPolicyProcessOnly }
 
- Protected Member Functions inherited from lldb_private::IRMemoryMap
lldb::ProcessWPGetProcessWP ()
 

Detailed Description

"lldb/Expression/IRExecutionUnit.h" Contains the IR and, optionally, JIT- compiled code for a module.

This class encapsulates the compiled version of an expression, in IR form (for interpretation purposes) and in raw machine code form (for execution in the target).

This object wraps an IR module that comes from the expression parser, and knows how to use the JIT to make it into executable code. It can then be used as input to the IR interpreter, or the address of the executable code can be passed to a thread plan to run in the target.

This class creates a subclass of LLVM's SectionMemoryManager, because that is how the JIT emits code. Because LLDB needs to move JIT-compiled code into the target process, the IRExecutionUnit knows how to copy the emitted code into the target process.

Definition at line 56 of file IRExecutionUnit.h.

Member Typedef Documentation

◆ AddrRange

typedef std::pair<lldb::addr_t, uintptr_t> lldb_private::IRExecutionUnit::AddrRange
private

Definition at line 176 of file IRExecutionUnit.h.

◆ RecordVector

Definition at line 363 of file IRExecutionUnit.h.

Member Enumeration Documentation

◆ AllocationKind

Enumerator
Stub 
Code 
Data 
Global 
Bytes 

Definition at line 327 of file IRExecutionUnit.h.

Constructor & Destructor Documentation

◆ IRExecutionUnit()

IRExecutionUnit::IRExecutionUnit ( std::unique_ptr< llvm::LLVMContext > &  context_up,
std::unique_ptr< llvm::Module > &  module_up,
ConstString name,
const lldb::TargetSP target_sp,
const SymbolContext sym_ctx,
std::vector< std::string > &  cpu_features 
)

Constructor.

Definition at line 44 of file IRExecutionUnit.cpp.

◆ ~IRExecutionUnit()

IRExecutionUnit::~IRExecutionUnit ( )
override

Destructor.

Definition at line 501 of file IRExecutionUnit.cpp.

References m_context_up, m_execution_engine_up, and m_module_up.

Member Function Documentation

◆ CollectCandidateCNames()

void IRExecutionUnit::CollectCandidateCNames ( std::vector< ConstString > &  C_names,
ConstString  name 
)
private

Definition at line 666 of file IRExecutionUnit.cpp.

References lldb_private::ConstString::AsCString(), and m_strip_underscore.

Referenced by FindSymbol().

◆ CollectCandidateCPlusPlusNames()

void IRExecutionUnit::CollectCandidateCPlusPlusNames ( std::vector< ConstString > &  CPP_names,
const std::vector< ConstString > &  C_names,
const SymbolContext sc 
)
private

◆ CommitAllocations()

bool IRExecutionUnit::CommitAllocations ( lldb::ProcessSP process_sp)
private

Commit all allocations to the process and record where they were stored.

Parameters
[in]process_spThe process to allocate memory in.
Returns
True <=> all allocations were performed successfully. This method will attempt to free allocated memory if the operation fails.

Definition at line 1094 of file IRExecutionUnit.cpp.

References CommitOneAllocation(), lldb_private::IRMemoryMap::Free(), LLDB_INVALID_ADDRESS, and m_records.

Referenced by GetRunnableInfo().

◆ CommitOneAllocation()

bool IRExecutionUnit::CommitOneAllocation ( lldb::ProcessSP process_sp,
Status error,
AllocationRecord record 
)
private

◆ DisassembleFunction()

Status IRExecutionUnit::DisassembleFunction ( Stream stream,
lldb::ProcessSP process_sp 
)
private

◆ FindInRuntimes()

lldb::addr_t IRExecutionUnit::FindInRuntimes ( const std::vector< ConstString > &  names,
const lldb_private::SymbolContext sc 
)
private

Definition at line 844 of file IRExecutionUnit.cpp.

References LLDB_INVALID_ADDRESS, and lldb_private::SymbolContext::target_sp.

Referenced by FindSymbol().

◆ FindInSymbols()

lldb::addr_t IRExecutionUnit::FindInSymbols ( const std::vector< ConstString > &  names,
const lldb_private::SymbolContext sc,
bool &  symbol_was_missing_weak 
)
private

◆ FindInUserDefinedSymbols()

lldb::addr_t IRExecutionUnit::FindInUserDefinedSymbols ( const std::vector< ConstString > &  names,
const lldb_private::SymbolContext sc 
)
private

Definition at line 870 of file IRExecutionUnit.cpp.

References LLDB_INVALID_ADDRESS, and lldb_private::SymbolContext::target_sp.

Referenced by FindSymbol().

◆ FindSymbol()

lldb::addr_t IRExecutionUnit::FindSymbol ( lldb_private::ConstString  name,
bool &  missing_weak 
)

◆ FreeNow()

void IRExecutionUnit::FreeNow ( lldb::addr_t  allocation)

Definition at line 93 of file IRExecutionUnit.cpp.

References lldb_private::IRMemoryMap::Free(), and LLDB_INVALID_ADDRESS.

◆ GetAddressByteSize()

uint32_t IRExecutionUnit::GetAddressByteSize ( ) const
overridevirtual

◆ GetArchitecture()

ArchSpec IRExecutionUnit::GetArchitecture ( )
overridevirtual

◆ GetByteOrder()

lldb::ByteOrder IRExecutionUnit::GetByteOrder ( ) const
overridevirtual

◆ GetFunction()

llvm::Function * lldb_private::IRExecutionUnit::GetFunction ( )
inline

Definition at line 73 of file IRExecutionUnit.h.

References lldb_private::ConstString::GetStringRef(), m_module, and m_name.

◆ GetFunctionName()

ConstString lldb_private::IRExecutionUnit::GetFunctionName ( )
inline

Definition at line 69 of file IRExecutionUnit.h.

References m_name.

◆ GetJITModule()

lldb::ModuleSP IRExecutionUnit::GetJITModule ( )

◆ GetJittedFunctions()

const std::vector< JittedFunction > & lldb_private::IRExecutionUnit::GetJittedFunctions ( )
inline

Definition at line 156 of file IRExecutionUnit.h.

References m_jitted_functions.

◆ GetJittedGlobalVariables()

const std::vector< JittedGlobalVariable > & lldb_private::IRExecutionUnit::GetJittedGlobalVariables ( )
inline

Definition at line 160 of file IRExecutionUnit.h.

References m_jitted_global_variables.

◆ GetModule()

llvm::Module * lldb_private::IRExecutionUnit::GetModule ( )
inline

Definition at line 71 of file IRExecutionUnit.h.

References m_module.

◆ GetRemoteAddressForLocal()

lldb::addr_t IRExecutionUnit::GetRemoteAddressForLocal ( lldb::addr_t  local_address)
private

Look up the object in m_address_map that contains a given address, find where it was copied to, and return the remote address at the same offset into the copied entity.

Parameters
[in]local_addressThe address in the debugger.
Returns
The address in the target process.

Definition at line 1009 of file IRExecutionUnit.cpp.

References lldb_private::Expressions, lldb_private::GetLog(), LLDB_INVALID_ADDRESS, LLDB_LOGF, and m_records.

Referenced by GetRunnableInfo().

◆ GetRemoteRangeForLocal()

IRExecutionUnit::AddrRange IRExecutionUnit::GetRemoteRangeForLocal ( lldb::addr_t  local_address)
private

Look up the object in m_address_map that contains a given address, find where it was copied to, and return its address range in the target process.

Parameters
[in]local_addressThe address in the debugger.
Returns
The range of the containing object in the target process.

Definition at line 1038 of file IRExecutionUnit.cpp.

References LLDB_INVALID_ADDRESS, and m_records.

Referenced by DisassembleFunction(), and GetRunnableInfo().

◆ GetRunnableInfo()

void IRExecutionUnit::GetRunnableInfo ( Status error,
lldb::addr_t func_addr,
lldb::addr_t func_end 
)

◆ GetSectionTypeFromSectionName()

lldb::SectionType IRExecutionUnit::GetSectionTypeFromSectionName ( const llvm::StringRef &  name,
IRExecutionUnit::AllocationKind  alloc_kind 
)
staticprivate

◆ GetStaticInitializers()

void IRExecutionUnit::GetStaticInitializers ( std::vector< lldb::addr_t > &  static_initializers)

◆ PopulateSectionList()

void IRExecutionUnit::PopulateSectionList ( lldb_private::ObjectFile obj_file,
lldb_private::SectionList section_list 
)
overridevirtual

◆ PopulateSymtab()

void IRExecutionUnit::PopulateSymtab ( lldb_private::ObjectFile obj_file,
lldb_private::Symtab symtab 
)
overridevirtual

Implements lldb_private::ObjectFileJITDelegate.

Definition at line 1172 of file IRExecutionUnit.cpp.

◆ ReportAllocations()

void IRExecutionUnit::ReportAllocations ( llvm::ExecutionEngine &  engine)
private

Report all committed allocations to the execution engine.

Parameters
[in]engineThe execution engine to notify.

Definition at line 1119 of file IRExecutionUnit.cpp.

References eSectionIDInvalid, LLDB_INVALID_ADDRESS, m_records, and m_reported_allocations.

Referenced by GetRunnableInfo().

◆ ReportSymbolLookupError()

void IRExecutionUnit::ReportSymbolLookupError ( ConstString  name)
private

Definition at line 225 of file IRExecutionUnit.cpp.

References m_failed_lookups.

◆ WriteData()

bool IRExecutionUnit::WriteData ( lldb::ProcessSP process_sp)
private

Write the contents of all allocations to the process.

Parameters
[in]process_spThe process containing the allocations.
Returns
True <=> all allocations were performed successfully.

Definition at line 1137 of file IRExecutionUnit.cpp.

References LLDB_INVALID_ADDRESS, m_records, lldb_private::Status::Success(), and lldb_private::IRMemoryMap::WriteMemory().

Referenced by GetRunnableInfo().

◆ WriteNow()

lldb::addr_t IRExecutionUnit::WriteNow ( const uint8_t *  bytes,
size_t  size,
Status error 
)

Member Data Documentation

◆ eSectionIDInvalid

const unsigned lldb_private::IRExecutionUnit::eSectionIDInvalid = (unsigned)-1
staticprivate

Definition at line 325 of file IRExecutionUnit.h.

Referenced by ReportAllocations().

◆ m_context_up

std::unique_ptr<llvm::LLVMContext> lldb_private::IRExecutionUnit::m_context_up
private

Definition at line 366 of file IRExecutionUnit.h.

Referenced by ~IRExecutionUnit().

◆ m_cpu_features

std::vector<std::string> lldb_private::IRExecutionUnit::m_cpu_features
private

Definition at line 372 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo().

◆ m_did_jit

std::atomic<bool> lldb_private::IRExecutionUnit::m_did_jit
private

Definition at line 385 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo().

◆ m_execution_engine_up

std::unique_ptr<llvm::ExecutionEngine> lldb_private::IRExecutionUnit::m_execution_engine_up
private

Definition at line 367 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo(), and ~IRExecutionUnit().

◆ m_failed_lookups

std::vector<ConstString> lldb_private::IRExecutionUnit::m_failed_lookups
private

Definition at line 383 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo(), and ReportSymbolLookupError().

◆ m_function_end_load_addr

lldb::addr_t lldb_private::IRExecutionUnit::m_function_end_load_addr
private

Definition at line 388 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo().

◆ m_function_load_addr

lldb::addr_t lldb_private::IRExecutionUnit::m_function_load_addr
private

Definition at line 387 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo().

◆ m_jitted_functions

std::vector<JittedFunction> lldb_private::IRExecutionUnit::m_jitted_functions
private

A vector of all functions that have been JITted into machine code.

Definition at line 373 of file IRExecutionUnit.h.

Referenced by DisassembleFunction(), GetJittedFunctions(), GetRunnableInfo(), and GetStaticInitializers().

◆ m_jitted_global_variables

std::vector<JittedGlobalVariable> lldb_private::IRExecutionUnit::m_jitted_global_variables
private

A vector of all functions that have been JITted into machine code.

Definition at line 376 of file IRExecutionUnit.h.

Referenced by GetJittedGlobalVariables(), and GetRunnableInfo().

◆ m_module

llvm::Module* lldb_private::IRExecutionUnit::m_module
private

Owned by the execution engine.

Definition at line 371 of file IRExecutionUnit.h.

Referenced by GetFunction(), GetModule(), GetRunnableInfo(), and GetStaticInitializers().

◆ m_module_up

std::unique_ptr<llvm::Module> lldb_private::IRExecutionUnit::m_module_up
private

Holder for the module until it's been handed off.

Definition at line 370 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo(), and ~IRExecutionUnit().

◆ m_name

const ConstString lldb_private::IRExecutionUnit::m_name
private

◆ m_object_cache_up

std::unique_ptr<llvm::ObjectCache> lldb_private::IRExecutionUnit::m_object_cache_up
private

Definition at line 368 of file IRExecutionUnit.h.

Referenced by GetRunnableInfo().

◆ m_records

RecordVector lldb_private::IRExecutionUnit::m_records
private

◆ m_reported_allocations

bool lldb_private::IRExecutionUnit::m_reported_allocations
private

True after allocations have been reported.

It is possible that sections will be allocated when this is true, in which case they weren't depended on by any function. (Top-level code defining a variable, but defining no functions using that variable, would do this.) If this is true, any allocations need to be committed immediately – no opportunity for relocation.

Definition at line 392 of file IRExecutionUnit.h.

Referenced by ReportAllocations().

◆ m_strip_underscore

bool lldb_private::IRExecutionUnit::m_strip_underscore = true
private

True for platforms where global symbols have a _ prefix.

Definition at line 390 of file IRExecutionUnit.h.

Referenced by CollectCandidateCNames(), and GetRunnableInfo().

◆ m_sym_ctx

SymbolContext lldb_private::IRExecutionUnit::m_sym_ctx
private

Used for symbol lookups.

Definition at line 382 of file IRExecutionUnit.h.

Referenced by FindSymbol().


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