LLDB mainline
lldb_private::Function Class Reference

A class that describes a function. More...

#include "lldb/Symbol/Function.h"

Inheritance diagram for lldb_private::Function:
[legend]

Public Types

using SourceRange = Range<uint32_t, uint32_t>

Public Member Functions

 Function (CompileUnit *comp_unit, lldb::user_id_t func_uid, lldb::user_id_t func_type_uid, const Mangled &mangled, Type *func_type, Address address, AddressRanges ranges)
 Construct with a compile unit, function UID, function type UID, optional mangled name, function type, and a section offset based address range.
 ~Function () override
 Destructor.
void CalculateSymbolContext (SymbolContext *sc) override
 Reconstruct the object's symbol context into sc.
lldb::ModuleSP CalculateSymbolContextModule () override
CompileUnitCalculateSymbolContextCompileUnit () override
FunctionCalculateSymbolContextFunction () override
AddressRanges GetAddressRanges ()
const AddressGetAddress () const
 Return the address of the function (its entry point).
bool GetRangeContainingLoadAddress (lldb::addr_t load_addr, Target &target, AddressRange &range)
lldb::LanguageType GetLanguage () const
void GetStartLineSourceInfo (lldb::SupportFileSP &source_file_sp, uint32_t &line_no)
 Find the file and line number of the source location of the start of the function.
llvm::Expected< std::pair< lldb::SupportFileSP, SourceRange > > GetSourceInfo ()
 Find the file and line number range of the function.
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetCallEdges ()
 Get the outgoing call edges from this function, sorted by their return PC addresses (in increasing order).
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges ()
 Get the outgoing tail-calling edges from this function.
CallEdgeGetCallEdgeForReturnAddress (lldb::addr_t return_pc, Target &target)
 Get the outgoing call edge from this function which has the given return address return_pc, or return nullptr.
BlockGetBlock (bool can_create)
 Get accessor for the block list.
CompileUnitGetCompileUnit ()
 Get accessor for the compile unit that owns this function.
const CompileUnitGetCompileUnit () const
 Get const accessor for the compile unit that owns this function.
void GetDescription (Stream *s, lldb::DescriptionLevel level, Target *target)
DWARFExpressionListGetFrameBaseExpression ()
 Get accessor for the frame base location.
const DWARFExpressionListGetFrameBaseExpression () const
 Get const accessor for the frame base location.
ConstString GetName () const
ConstString GetNameNoArguments () const
ConstString GetDisplayName () const
const MangledGetMangled () const
CompilerDeclContext GetDeclContext ()
 Get the DeclContext for this function, if available.
std::vector< CompilerContextGetCompilerContext ()
 Get the CompilerContext for this function, if available.
TypeGetType ()
 Get accessor for the type that describes the function return value type, and parameter types.
const TypeGetType () const
 Get const accessor for the type that describes the function return value type, and parameter types.
CompilerType GetCompilerType ()
uint32_t GetPrologueByteSize ()
 Get the size of the prologue instructions for this function.
void Dump (Stream *s, bool show_context) const
 Dump a description of this object to a Stream.
void DumpSymbolContext (Stream *s) override
 Dump the object's symbol context to the stream s.
size_t MemorySize () const
 Get the memory cost of this object.
bool GetIsOptimized ()
 Get whether compiler optimizations were enabled for this function.
bool IsTopLevelFunction ()
 Get whether this function represents a 'top-level' function.
lldb::DisassemblerSP GetInstructions (const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
bool GetDisassembly (const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Public Member Functions inherited from lldb_private::UserID
 UserID (lldb::user_id_t uid=LLDB_INVALID_UID)
 Construct with optional user ID.
 ~UserID ()=default
 Destructor.
void Clear ()
 Clears the object state.
lldb::user_id_t GetID () const
 Get accessor for the user ID.
void SetID (lldb::user_id_t uid)
 Set accessor for the user ID.
Public Member Functions inherited from lldb_private::SymbolContextScope
virtual ~SymbolContextScope ()=default
virtual BlockCalculateSymbolContextBlock ()
virtual SymbolCalculateSymbolContextSymbol ()

Protected Types

enum  { flagsCalculatedPrologueSize = (1 << 0) }

Protected Attributes

CompileUnitm_comp_unit
 The compile unit that owns this function.
lldb::user_id_t m_type_uid
 The user ID of for the prototype Type for this function.
Typem_type
 The function prototype type for this function that includes the function info (FunctionInfo), return type and parameters.
Mangled m_mangled
 The mangled function name if any.
Block m_block
 All lexical blocks contained in this function.
Address m_address
 The address (entry point) of the function.
DWARFExpressionList m_frame_base
 The frame base expression for variables that are relative to the frame pointer.
Flags m_flags
uint32_t m_prologue_byte_size
 Compute the prologue size once and cache it.
std::mutex m_call_edges_lock
 Exclusive lock that controls read/write access to m_call_edges and m_call_edges_resolved.
bool m_call_edges_resolved = false
 Whether call site info has been parsed.
std::vector< std::unique_ptr< CallEdge > > m_call_edges
 Outgoing call edges.
Protected Attributes inherited from lldb_private::UserID
lldb::user_id_t m_uid
 The user ID that uniquely identifies an object.

Private Member Functions

 Function (const Function &)=delete
const Functionoperator= (const Function &)=delete

Detailed Description

A class that describes a function.

Functions belong to CompileUnit objects (Function::m_comp_unit), have unique user IDs (Function::UserID), know how to reconstruct their symbol context (Function::SymbolContextScope), have a specific function type (Function::m_type_uid), have a simple method name (FunctionInfo::m_name), be declared at a specific location (FunctionInfo::m_declaration), possibly have mangled names (Function::m_mangled), an optional return type (Function::m_type), and contains lexical blocks (Function::m_blocks).

The function information is split into a few pieces:

  • The concrete instance information
  • The abstract information

The abstract information is found in the function type (Type) that describes a function information, return type and parameter types.

The concrete information is the address range information and specific locations for an instance of this function.

Definition at line 400 of file Function.h.

Member Typedef Documentation

◆ SourceRange

using lldb_private::Function::SourceRange = Range<uint32_t, uint32_t>

Definition at line 475 of file Function.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
protected
Enumerator
flagsCalculatedPrologueSize 

Whether we already tried to calculate the prologue size.

Definition at line 636 of file Function.h.

Constructor & Destructor Documentation

◆ Function() [1/2]

Function::Function ( CompileUnit * comp_unit,
lldb::user_id_t func_uid,
lldb::user_id_t func_type_uid,
const Mangled & mangled,
Type * func_type,
Address address,
AddressRanges ranges )

Construct with a compile unit, function UID, function type UID, optional mangled name, function type, and a section offset based address range.

Parameters
[in]comp_unitThe compile unit to which this function belongs.
[in]func_uidThe UID for this function. This value is provided by the SymbolFile plug-in and can be any value that allows the plug-in to quickly find and parse more detailed information when and if more information is needed.
[in]func_type_uidThe type UID for the function Type to allow for lazy type parsing from the debug information.
[in]mangledThe optional mangled name for this function. If empty, there is no mangled information.
[in]func_typeThe optional function type. If NULL, the function type will be parsed on demand when accessed using the Function::GetType() function by asking the SymbolFile plug-in to get the type for func_type_uid.
[in]rangeThe section offset based address for this function.

Definition at line 258 of file Function.cpp.

References m_address, m_block, m_comp_unit, m_mangled, m_prologue_byte_size, m_type, m_type_uid, and lldb_private::UserID::UserID().

Referenced by CalculateSymbolContextFunction(), Function(), MemorySize(), operator=(), and ~Function().

◆ ~Function()

Function::~Function ( )
overridedefault

Destructor.

References Function().

◆ Function() [2/2]

lldb_private::Function::Function ( const Function & )
privatedelete

References Function().

Member Function Documentation

◆ CalculateSymbolContext()

void Function::CalculateSymbolContext ( SymbolContext * sc)
overridevirtual

Reconstruct the object's symbol context into sc.

The object should fill in as much of the SymbolContext as it can so function calls that require a symbol context can be made for the given object.

Parameters
[out]scA symbol context object pointer that gets filled in.
See also
SymbolContextScope

Implements lldb_private::SymbolContextScope.

Definition at line 450 of file Function.cpp.

References lldb_private::SymbolContext::function, and m_comp_unit.

Referenced by GetType(), and lldb_private::StackFrameList::SynthesizeTailCallFrames().

◆ CalculateSymbolContextCompileUnit()

CompileUnit * Function::CalculateSymbolContextCompileUnit ( )
overridevirtual

Reimplemented from lldb_private::SymbolContextScope.

Definition at line 462 of file Function.cpp.

References GetCompileUnit().

◆ CalculateSymbolContextFunction()

Function * Function::CalculateSymbolContextFunction ( )
overridevirtual

Reimplemented from lldb_private::SymbolContextScope.

Definition at line 466 of file Function.cpp.

References Function().

◆ CalculateSymbolContextModule()

ModuleSP Function::CalculateSymbolContextModule ( )
overridevirtual

◆ Dump()

void Function::Dump ( Stream * s,
bool show_context ) const

Dump a description of this object to a Stream.

Dump a description of the contents of this object to the supplied stream s.

Parameters
[in]sThe stream to which to dump the object description.
[in]show_contextIf true, variables will dump their symbol context information.

Definition at line 432 of file Function.cpp.

References lldb_private::Stream::EOL(), lldb_private::Stream::Indent(), LLDB_INVALID_UID, m_address, m_block, m_mangled, m_type, m_type_uid, lldb_private::Stream::Printf(), and lldb_private::UserID::UserID().

◆ DumpSymbolContext()

void Function::DumpSymbolContext ( Stream * s)
overridevirtual

Dump the object's symbol context to the stream s.

The object should dump its symbol context to the stream s. This function is widely used in the DumpDebug and verbose output for lldb objects.

Parameters
[in]sThe stream to which to dump the object's symbol context.
See also
SymbolContextScope

Implements lldb_private::SymbolContextScope.

Definition at line 502 of file Function.cpp.

References lldb_private::UserID::GetID(), m_comp_unit, and lldb_private::Stream::Printf().

Referenced by lldb_private::ClangExpressionDeclMap::AddOneFunction(), and lldb_private::Block::DumpSymbolContext().

◆ GetAddress()

const Address & lldb_private::Function::GetAddress ( ) const
inline

Return the address of the function (its entry point).

This address is also used as a base address for relocation of function-scope entities (blocks and variables).

Definition at line 453 of file Function.h.

References m_address.

Referenced by lldb_private::BreakpointResolver::AddLocation(), lldb_private::ClangExpressionDeclMap::AddOneFunction(), lldb_private::Block::AddRange(), DynamicLoaderPOSIXDYLD::AlwaysRelyOnEHUnwindInfo(), lldb_private::DynamicLoaderDarwin::AlwaysRelyOnEHUnwindInfo(), lldb_private::VariableAnnotator::annotate(), lldb_private::npdb::SymbolFileNativePDB::CreateBlock(), lldb_private::npdb::SymbolFileNativePDB::CreateLocalVariable(), DumpAddressOffsetFromFunction(), lldb_private::Variable::DumpLocations(), lldb_private::Module::FindFunctions(), lldb_private::SearchFilter::FunctionPasses(), lldb_private::ArchitectureMips::GetBreakableLoadAddress(), lldb::SBBlock::GetDescription(), lldb_private::Block::GetDescription(), GetInstructions(), lldb_private::CallEdge::GetLoadAddress(), GetPrologueByteSize(), lldb_private::Block::GetRangeAtIndex(), lldb_private::Block::GetRangeContainingAddress(), lldb_private::Block::GetRangeIndexContainingAddress(), lldb_private::Block::GetRanges(), lldb_private::Block::GetStartAddress(), GetStartLineSourceInfo(), lldb_private::Variable::LocationIsValidForAddress(), lldb_private::Variable::LocationIsValidForFrame(), lldb_private::DWARFExpressionList::MatchesOperand(), lldb_private::breakpad::SymbolFileBreakpad::ParseBlocksRecursive(), RemoveFunctionsWithModuleNotEqualTo(), lldb_private::ThreadPlanStepInRange::ShouldStop(), and lldb_private::ValueObjectVariable::UpdateValue().

◆ GetAddressRanges()

◆ GetBlock()

◆ GetCallEdgeForReturnAddress()

CallEdge * Function::GetCallEdgeForReturnAddress ( lldb::addr_t return_pc,
Target & target )

Get the outgoing call edge from this function which has the given return address return_pc, or return nullptr.

Note that this will not return a tail-calling edge.

Definition at line 367 of file Function.cpp.

References GetCallEdges().

Referenced by Evaluate_DW_OP_entry_value(), and FindInterveningFrames().

◆ GetCallEdges()

llvm::ArrayRef< std::unique_ptr< CallEdge > > Function::GetCallEdges ( )

◆ GetCompilerContext()

std::vector< CompilerContext > Function::GetCompilerContext ( )

Get the CompilerContext for this function, if available.

Returns
The CompilerContext, or an empty vector if none is available.

Definition at line 543 of file Function.cpp.

References CalculateSymbolContextModule(), and lldb_private::UserID::GetID().

Referenced by GetDescription().

◆ GetCompilerType()

CompilerType Function::GetCompilerType ( )

◆ GetCompileUnit() [1/2]

◆ GetCompileUnit() [2/2]

const CompileUnit * Function::GetCompileUnit ( ) const

Get const accessor for the compile unit that owns this function.

Returns
A const compile unit object pointer.

Definition at line 399 of file Function.cpp.

References m_comp_unit.

◆ GetDeclContext()

CompilerDeclContext Function::GetDeclContext ( )

Get the DeclContext for this function, if available.

Returns
The DeclContext, or NULL if none exists.

Definition at line 536 of file Function.cpp.

References CalculateSymbolContextModule(), and lldb_private::UserID::GetID().

Referenced by lldb_private::ClangExpressionDeclMap::AddOneFunction(), and lldb_private::ClangExpressionDeclMap::SearchFunctionsInSymbolContexts().

◆ GetDescription()

◆ GetDisassembly()

bool Function::GetDisassembly ( const ExecutionContext & exe_ctx,
const char * flavor,
Stream & strm,
bool force_live_memory = false )

Definition at line 480 of file Function.cpp.

References GetInstructions().

◆ GetDisplayName()

◆ GetFrameBaseExpression() [1/2]

DWARFExpressionList & lldb_private::Function::GetFrameBaseExpression ( )
inline

Get accessor for the frame base location.

Returns
A location expression that describes the function frame base.

Definition at line 520 of file Function.h.

References m_frame_base.

◆ GetFrameBaseExpression() [2/2]

const DWARFExpressionList & lldb_private::Function::GetFrameBaseExpression ( ) const
inline

Get const accessor for the frame base location.

Returns
A const compile unit object pointer.

Definition at line 526 of file Function.h.

References m_frame_base.

◆ GetInstructions()

◆ GetIsOptimized()

bool Function::GetIsOptimized ( )

Get whether compiler optimizations were enabled for this function.

The debug information may provide information about whether this function was compiled with optimization or not. In this case, "optimized" means that the debug experience may be difficult for the user to understand. Variables may not be available when the developer would expect them, stepping through the source lines in the function may appear strange, etc.

Returns
Returns 'true' if this function was compiled with optimization. 'false' indicates that either the optimization is unknown, or this function was built without optimization.

Definition at line 512 of file Function.cpp.

References m_comp_unit.

Referenced by lldb_private::FormatEntity::Format(), and lldb_private::Process::PrintWarningOptimization().

◆ GetLanguage()

◆ GetMangled()

◆ GetName()

◆ GetNameNoArguments()

ConstString Function::GetNameNoArguments ( ) const

◆ GetPrologueByteSize()

◆ GetRangeContainingLoadAddress()

bool lldb_private::Function::GetRangeContainingLoadAddress ( lldb::addr_t load_addr,
Target & target,
AddressRange & range )
inline

◆ GetSourceInfo()

◆ GetStartLineSourceInfo()

void Function::GetStartLineSourceInfo ( lldb::SupportFileSP & source_file_sp,
uint32_t & line_no )

Find the file and line number of the source location of the start of the function.

This will use the declaration if present and fall back on the line table if that fails. So there may NOT be a line table entry for this source file/line combo.

Parameters
[out]source_fileThe source file.
[out]line_noThe line number.

Definition at line 275 of file Function.cpp.

References lldb_private::LineEntry::file_sp, lldb_private::LineTable::FindLineEntryByAddress(), GetAddress(), GetType(), lldb_private::LineEntry::line, m_comp_unit, and m_type.

Referenced by lldb_private::BreakpointResolverFileLine::FilterContexts(), lldb_private::Disassembler::GetFunctionDeclLineEntry(), GetSourceInfo(), and lldb_private::Disassembler::PrintInstructions().

◆ GetTailCallingEdges()

llvm::ArrayRef< std::unique_ptr< CallEdge > > Function::GetTailCallingEdges ( )

Get the outgoing tail-calling edges from this function.

If none exist, return std::nullopt.

Definition at line 360 of file Function.cpp.

References GetCallEdges().

Referenced by Evaluate_DW_OP_entry_value(), and FindInterveningFrames().

◆ GetType() [1/2]

◆ GetType() [2/2]

const Type * Function::GetType ( ) const

Get const accessor for the type that describes the function return value type, and parameter types.

Returns
A const type object pointer.

Definition at line 569 of file Function.cpp.

References m_type.

◆ IsTopLevelFunction()

bool Function::IsTopLevelFunction ( )

Get whether this function represents a 'top-level' function.

The concept of a top-level function is language-specific, mostly meant to represent the notion of scripting-style code that has global visibility of the variables/symbols/functions/... defined within the containing file/module

If stopped in a top-level function, LLDB will expose global variables as-if locals in the 'frame variable' command

Returns
Returns 'true' if this function is a top-level function, 'false' otherwise.

Definition at line 523 of file Function.cpp.

References lldb_private::Language::FindPlugin(), and GetLanguage().

◆ MemorySize()

size_t Function::MemorySize ( ) const

Get the memory cost of this object.

Returns
The number of bytes that this object occupies in memory. The returned value does not include the bytes for any shared string values.

Definition at line 507 of file Function.cpp.

References Function(), and m_block.

◆ operator=()

const Function & lldb_private::Function::operator= ( const Function & )
privatedelete

References Function().

Member Data Documentation

◆ m_address

Address lldb_private::Function::m_address
protected

The address (entry point) of the function.

Definition at line 659 of file Function.h.

Referenced by CalculateSymbolContextModule(), Dump(), Function(), GetAddress(), and GetPrologueByteSize().

◆ m_block

Block lldb_private::Function::m_block
protected

All lexical blocks contained in this function.

Definition at line 656 of file Function.h.

Referenced by Dump(), Function(), GetAddressRanges(), GetBlock(), GetDescription(), GetPrologueByteSize(), GetRangeContainingLoadAddress(), and MemorySize().

◆ m_call_edges

std::vector<std::unique_ptr<CallEdge> > lldb_private::Function::m_call_edges
protected

Outgoing call edges.

Definition at line 678 of file Function.h.

Referenced by GetCallEdges().

◆ m_call_edges_lock

std::mutex lldb_private::Function::m_call_edges_lock
protected

Exclusive lock that controls read/write access to m_call_edges and m_call_edges_resolved.

Definition at line 672 of file Function.h.

Referenced by GetCallEdges().

◆ m_call_edges_resolved

bool lldb_private::Function::m_call_edges_resolved = false
protected

Whether call site info has been parsed.

Definition at line 675 of file Function.h.

Referenced by GetCallEdges().

◆ m_comp_unit

CompileUnit* lldb_private::Function::m_comp_unit
protected

◆ m_flags

Flags lldb_private::Function::m_flags
protected

Definition at line 665 of file Function.h.

Referenced by GetPrologueByteSize().

◆ m_frame_base

DWARFExpressionList lldb_private::Function::m_frame_base
protected

The frame base expression for variables that are relative to the frame pointer.

Definition at line 663 of file Function.h.

Referenced by GetFrameBaseExpression(), and GetFrameBaseExpression().

◆ m_mangled

Mangled lldb_private::Function::m_mangled
protected

The mangled function name if any.

If empty, there is no mangled information.

Definition at line 653 of file Function.h.

Referenced by Dump(), Function(), GetDescription(), GetDisplayName(), GetLanguage(), GetMangled(), GetName(), and GetNameNoArguments().

◆ m_prologue_byte_size

uint32_t lldb_private::Function::m_prologue_byte_size
protected

Compute the prologue size once and cache it.

Definition at line 668 of file Function.h.

Referenced by Function(), and GetPrologueByteSize().

◆ m_type

Type* lldb_private::Function::m_type
protected

The function prototype type for this function that includes the function info (FunctionInfo), return type and parameters.

Definition at line 649 of file Function.h.

Referenced by Dump(), Function(), GetStartLineSourceInfo(), GetType(), and GetType().

◆ m_type_uid

lldb::user_id_t lldb_private::Function::m_type_uid
protected

The user ID of for the prototype Type for this function.

Definition at line 645 of file Function.h.

Referenced by Dump(), Function(), and GetType().


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