Go to the documentation of this file.
24 #include "llvm/Support/Casting.h"
31 FunctionInfo::FunctionInfo(
const char *name,
const Declaration *decl_ptr)
32 : m_name(name), m_declaration(decl_ptr) {}
35 : m_name(name), m_declaration(decl_ptr) {}
41 *s <<
", name = \"" <<
m_name <<
"\"";
66 llvm::StringRef mangled,
70 m_call_decl(call_decl_ptr) {}
73 const Mangled &mangled,
77 m_call_decl(call_decl_ptr) {}
104 return m_mangled.GetDisplayDemangledName();
131 ModuleSP caller_module_sp = caller_start_addr.
GetModule();
132 if (!caller_module_sp) {
133 LLDB_LOG(log,
"GetLoadAddress: cannot get Module for caller");
137 SectionList *section_list = caller_module_sp->GetSectionList();
139 LLDB_LOG(log,
"GetLoadAddress: cannot get SectionList for Module");
158 LLDB_LOG(log,
"DirectCallEdge: Lazily parsing the call graph for {0}",
161 auto resolve_lazy_callee = [&]() ->
Function * {
165 size_t num_matches = sc_list.
GetSize();
166 if (num_matches == 0 || !sc_list[0].symbol) {
168 "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
172 Address callee_addr = sc_list[0].symbol->GetAddress();
174 LLDB_LOG(log,
"DirectCallEdge: Invalid symbol address");
179 LLDB_LOG(log,
"DirectCallEdge: Could not find complete function");
190 assert(
resolved &&
"Did not resolve lazy callee");
198 Value callee_addr_val;
202 nullptr, callee_addr_val, &
error)) {
203 LLDB_LOGF(log,
"IndirectCallEdge: Could not evaluate expression: %s",
210 LLDB_LOG(log,
"IndirectCallEdge: Could not extract address from scalar");
216 LLDB_LOG(log,
"IndirectCallEdge: Could not resolve callee's load address");
222 LLDB_LOG(log,
"IndirectCallEdge: Could not find complete function");
235 :
UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
236 m_type(type), m_mangled(mangled), m_block(func_uid), m_range(range),
237 m_frame_base(), m_flags(), m_prologue_byte_size(0) {
239 assert(comp_unit !=
nullptr);
260 if (line_table ==
nullptr)
265 line_entry,
nullptr)) {
266 line_no = line_entry.
line;
267 source_file = line_entry.
file;
283 if (line_table ==
nullptr)
288 line_no = line_entry.
line;
289 source_file = line_entry.
file;
300 LLDB_LOG(log,
"GetCallEdges: Attempting to parse call site info for {0}",
315 llvm::sort(
m_call_edges, [](
const std::unique_ptr<CallEdge> &LHS,
316 const std::unique_ptr<CallEdge> &RHS) {
317 return LHS->GetSortKey() < RHS->GetSortKey();
327 [](
const std::unique_ptr<CallEdge> &edge) {
return edge->IsTailCall(); });
334 llvm::partition_point(edges, [&](
const std::unique_ptr<CallEdge> &edge) {
335 return std::make_pair(edge->IsTailCall(),
336 edge->GetReturnPCAddress(*
this, target)) <
337 std::make_pair(
false, return_pc);
339 if (edge_it == edges.end() ||
340 edge_it->get()->GetReturnPCAddress(*
this, target) != return_pc)
342 return edge_it->get();
349 module_sp->GetSymbolFile()->ParseBlocksRecursive(*
this);
352 "unable to find module shared pointer for function '{0}' in {1}",
369 *s <<
"id = " << (
const UserID &)*
this;
373 s->
AsRawOstream() <<
", mangled = \"" << mangled <<
'"';
385 s->
Printf(
"%p: ",
static_cast<const void *
>(
this));
387 *s <<
"Function" <<
static_cast<const UserID &
>(*this);
411 return section_sp->GetModule();
424 bool prefer_file_cache) {
431 return lldb::DisassemblerSP();
435 const char *flavor,
Stream &strm,
436 bool prefer_file_cache) {
437 lldb::DisassemblerSP disassembler_sp =
439 if (disassembler_sp) {
440 const bool show_address =
true;
441 const bool show_bytes =
false;
442 const bool show_control_flow_kind =
false;
443 disassembler_sp->GetInstructionList().Dump(
444 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
458 s->
Printf(
", Function{0x%8.8" PRIx64
"}",
GetID());
481 result = language->IsTopLevelFunction(*
this);
487 return m_mangled.GetDisplayDemangledName();
494 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
495 return sym_file->GetDeclContextForUID(
GetID());
511 if (sym_file ==
nullptr)
540 &first_line_entry_idx)) {
546 prologue_end_file_addr =
548 prologue_end_line_idx = first_line_entry_idx;
552 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
553 for (
uint32_t idx = first_line_entry_idx + 1;
554 idx < last_line_entry_idx; ++idx) {
558 prologue_end_file_addr =
560 prologue_end_line_idx = idx;
572 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
573 for (
uint32_t idx = first_line_entry_idx + 1;
574 idx < last_line_entry_idx; ++idx) {
577 if (line_entry.
line != first_line_entry.
line) {
578 prologue_end_file_addr =
580 prologue_end_line_idx = idx;
587 prologue_end_file_addr =
590 prologue_end_line_idx = first_line_entry_idx;
594 const addr_t func_start_file_addr =
596 const addr_t func_end_file_addr =
600 uint32_t first_non_zero_line = prologue_end_line_idx;
605 if (line_entry.
line != 0)
612 first_non_zero_line++;
615 if (first_non_zero_line > prologue_end_line_idx) {
618 first_non_zero_entry)) {
619 line_zero_end_file_addr =
626 if (func_start_file_addr < prologue_end_file_addr &&
627 prologue_end_file_addr < func_end_file_addr) {
631 if (prologue_end_file_addr < line_zero_end_file_addr &&
632 line_zero_end_file_addr < func_end_file_addr) {
634 line_zero_end_file_addr - prologue_end_file_addr;
659 return m_mangled.GetName(Mangled::ePreferDemangledWithoutArguments);
size_t MemorySize() const
Get the memory cost of this object.
bool FindLineEntryByAddress(const Address &so_addr, LineEntry &line_entry, uint32_t *index_ptr=nullptr)
Find a line entry that contains the section offset address so_addr.
Address & GetBaseAddress()
Get accessor for the base address of the range.
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
ConstString m_name
Function method name (not a mangled name).
Provides public interface for all SymbolFiles.
bool m_call_edges_resolved
Whether call site info has been parsed.
virtual size_t MemorySize() const
Get the memory cost of this object.
virtual std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id)
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
FileSpec file
The source file, possibly mapped by the target.source-map setting.
lldb::ModuleSP CalculateSymbolContextModule() override
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
~Function() override
Destructor.
void SetBlockInfoHasBeenParsed(bool b, bool set_children)
bool IsValid() const
Check if the object state is valid.
AddressRange m_range
The function address range that covers the widest range needed to contain all blocks.
Function * CalculateSymbolContextFunction() const
const AddressRange & GetAddressRange()
std::mutex m_call_edges_lock
Exclusive lock that controls read/write access to m_call_edges and m_call_edges_resolved.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
static int Compare(ConstString lhs, ConstString rhs, const bool case_sensitive=true)
Compare two string objects.
void SetParentScope(SymbolContextScope *parent_scope)
@ DumpStyleFileAddress
Display as the file address (if any).
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
uint16_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
ConstString GetDisplayName() const
#define LLDB_LOGF(log,...)
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry)
Get the line entry from the line table at index idx.
Mangled m_mangled
Mangled inlined function name (can be empty if there is no mangled information).
virtual ~FunctionInfo()
Destructor.
Declaration & GetCallSite()
Get accessor for the call site declaration information.
LanguageType
Programming language type.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
SymbolFile * GetSymbolFile()
Get the symbol file which contains debug info for this block's symbol context module.
FileSpec & GetFile()
Get accessor for file specification.
Block m_block
All lexical blocks contained in this function.
ConstString GetNameNoArguments() const
lldb::addr_t GetUnresolvedReturnPCAddress() const
Like GetReturnPCAddress, but returns an unresolved file address.
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
bool BlockInfoHasBeenParsed() const
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
const Scalar & GetScalar() const
static int Compare(const FunctionInfo &lhs, const FunctionInfo &rhs)
Compare two function information objects.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
static llvm::raw_ostream & error(Stream &strm)
RegisterContext * GetRegisterContext() const
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
@ DumpStyleLoadAddress
Display as the load address (if resolved).
ConstString GetName() const
unsigned long long ULongLong(unsigned long long fail_value=0) const
Block & GetBlock(bool can_create)
Get accessor for the block list.
Mangled m_mangled
The mangled function name if any.
Function * function
The Function for a given query.
size_t MemorySize() const
Get the memory cost of this object.
lldb::addr_t GetFileAddress() const
Get the file address.
Mangled & GetMangled()
Get accessor for the mangled name object.
InlineFunctionInfo(const char *name, llvm::StringRef mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr)
Construct with the function method name, mangled name, and optional declaration information.
uint32_t GetSize() const
Get accessor for a symbol context list size.
Function(CompileUnit *comp_unit, lldb::user_id_t func_uid, lldb::user_id_t func_type_uid, const Mangled &mangled, Type *func_type, const AddressRange &range)
Construct with a compile unit, function UID, function type UID, optional mangled name,...
const lldb_private::Declaration & GetDeclaration() const
size_t MemorySize() const
Get the memory cost of this object.
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
ConstString GetName() const
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this compile unit.
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
const FileSpec & GetPrimaryFile() const
Return the primary source file associated with this compile unit.
lldb::SectionSP GetSection() const
Get const accessor for the section.
LineTable * GetLineTable()
Get the line table for the compile unit.
lldb::LanguageType GetLanguage()
void DumpStopContext(Stream *s) const
union lldb_private::DirectCallEdge::@23 lazy_callee
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Represents a generic declaration context in a program.
static Language * FindPlugin(lldb::LanguageType language)
CallEdge * GetCallEdgeForReturnAddress(lldb::addr_t return_pc, Target &target)
Get the outgoing call edge from this function which has the given return address return_pc,...
uint32_t line
The source line number, or zero if there is no line number information.
lldb::user_id_t GetID() const
Get accessor for the user ID.
Declaration & GetDeclaration()
Get accessor for the declaration information.
bool Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr, Value &result, Status *error_ptr) const
void GetStartLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
void Clear()
Clears the object state.
Function * CalculateSymbolContextFunction() override
uint32_t GetLine() const
Get accessor for the declaration line number.
ConstString GetDisplayName() const
~InlineFunctionInfo() override
Destructor.
@ eLanguageTypeUnknown
Unknown or invalid language value.
bool Dump(Stream *s, Target *target, Address::DumpStyle style, Address::DumpStyle fallback_style=Address::DumpStyleInvalid) const
Dump a description of this object to a Stream.
DWARFExpressionList call_target
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
size_t EOL()
Output and End of Line character to the stream.
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
lldb::addr_t GetReturnPCAddress(Function &caller, Target &target) const
Get the load PC address of the instruction which executes after the call returns.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t MemorySize() const
Get the memory cost of this object.
AddressRange range
The section offset address range for this line entry.
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
CompileUnit * m_comp_unit
The compile unit that owns this function.
lldb::ModuleSP module_sp
The Module for a given query.
ConstString GetName() const
Get accessor for the method name.
Declaration m_declaration
Information describing where this function information was defined.
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
#define LLDB_INVALID_ADDRESS
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
CompileUnit * CalculateSymbolContextCompileUnit() override
size_t MemorySize() const override
Get the memory cost of this object.
Generic representation of a type in a programming language.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Target & GetTargetRef() const
Returns a reference to the target object.
A class that represents a running process on the host machine.
@ eDescriptionLevelVerbose
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetCallEdges()
Get the outgoing call edges from this function, sorted by their return PC addresses (in increasing or...
bool resolved
Whether or not an attempt was made to find the callee's definition.
CompilerType GetCompilerType()
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
lldb::addr_t GetOffset() const
Get the section relative offset value.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the end of the function.
void ParseSymbolFileAndResolve(ModuleList &images)
static lldb::addr_t GetLoadAddress(lldb::addr_t unresolved_pc, Function &caller, Target &target)
Helper that finds the load address of unresolved_pc, a file address which refers to an instruction wi...
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
FunctionInfo(const char *name, const Declaration *decl_ptr)
Construct with the function method name and optional declaration information.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
lldb::LanguageType GetLanguage() const
bool IsClear(ValueType bit) const
Test a single flag bit to see if it is clear (zero).
CompilerType GetFullCompilerType()
Target * GetTargetPtr() const
Returns a pointer to the target object.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
void Dump(Stream *s, lldb::addr_t base_addr, int32_t depth, bool show_context) const
Dump the block contents.
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.