24#include "llvm/Support/Casting.h"
41 *s <<
", name = \"" <<
m_name <<
"\"";
66 llvm::StringRef mangled,
104 return m_mangled.GetDisplayDemangledName();
139 if (!caller_module_sp) {
140 LLDB_LOG(log,
"GetLoadAddress: cannot get Module for caller");
144 SectionList *section_list = caller_module_sp->GetSectionList();
146 LLDB_LOG(log,
"GetLoadAddress: cannot get SectionList for Module");
165 LLDB_LOG(log,
"DirectCallEdge: Lazily parsing the call graph for {0}",
168 auto resolve_lazy_callee = [&]() ->
Function * {
172 size_t num_matches = sc_list.
GetSize();
173 if (num_matches == 0 || !sc_list[0].symbol) {
175 "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
179 Address callee_addr = sc_list[0].symbol->GetAddress();
181 LLDB_LOG(log,
"DirectCallEdge: Invalid symbol address");
186 LLDB_LOG(log,
"DirectCallEdge: Could not find complete function");
206 assert(
resolved &&
"Did not resolve lazy callee");
223 llvm::Expected<Value> callee_addr_val =
call_target.Evaluate(
227 if (!callee_addr_val) {
229 "IndirectCallEdge: Could not evaluate expression: {0}");
236 LLDB_LOG(log,
"IndirectCallEdge: Could not extract address from scalar");
242 LLDB_LOG(log,
"IndirectCallEdge: Could not resolve callee's load address");
248 LLDB_LOG(log,
"IndirectCallEdge: Could not find complete function");
264 assert(comp_unit !=
nullptr);
268 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
269 range.GetByteSize()));
278 source_file_sp.reset();
286 if (
m_type !=
nullptr &&
m_type->GetDeclaration().GetLine() != 0) {
288 std::make_shared<SupportFile>(
m_type->GetDeclaration().GetFile());
289 line_no =
m_type->GetDeclaration().GetLine();
292 if (line_table ==
nullptr)
297 line_no = line_entry.
line;
298 source_file_sp = line_entry.
file_sp;
303llvm::Expected<std::pair<SupportFileSP, Function::SourceRange>>
309 if (start_line == 0 || !line_table) {
310 return llvm::createStringError(llvm::formatv(
311 "Could not find line information for function \"{0}\".",
GetName()));
314 uint32_t end_line = start_line;
321 source_file_sp->Equal(*entry.
file_sp,
323 end_line = std::max(end_line, entry.
line);
326 return std::make_pair(std::move(source_file_sp),
337 LLDB_LOG(log,
"GetCallEdges: Attempting to parse call site info for {0}",
352 llvm::sort(
m_call_edges, [](
const std::unique_ptr<CallEdge> &LHS,
353 const std::unique_ptr<CallEdge> &RHS) {
354 return LHS->GetSortKey() < RHS->GetSortKey();
364 [](
const std::unique_ptr<CallEdge> &edge) {
return edge->IsTailCall(); });
371 llvm::partition_point(edges, [&](
const std::unique_ptr<CallEdge> &edge) {
372 return std::make_pair(edge->IsTailCall(),
373 edge->GetReturnPCAddress(*
this, target)) <
374 std::make_pair(
false, return_pc);
376 if (edge_it == edges.end() ||
377 edge_it->get()->GetReturnPCAddress(*
this, target) != return_pc)
379 return edge_it->get();
383 if (!
m_block.BlockInfoHasBeenParsed() && can_create) {
386 module_sp->GetSymbolFile()->ParseBlocksRecursive(*
this);
389 "unable to find module shared pointer for function '{0}' in {1}",
392 m_block.SetBlockInfoHasBeenParsed(
true,
true);
406 *s <<
"id = " << (
const UserID &)*
this;
410 s->
AsRawOstream() <<
", mangled = \"" << mangled <<
'"';
412 *s <<
", decl_context = {";
415 if (decl_context.size())
416 decl_context.pop_back();
417 llvm::interleaveComma(decl_context, *s, [&](
auto &ctx) { ctx.Dump(*s); });
420 *s <<
", range" << (
m_block.GetNumRanges() > 1 ?
"s" :
"") <<
" = ";
425 for (
unsigned idx = 0; idx <
m_block.GetNumRanges(); ++idx) {
427 m_block.GetRangeAtIndex(idx, range);
433 s->
Printf(
"%p: ",
static_cast<const void *
>(
this));
435 *s <<
"Function" <<
static_cast<const UserID &
>(*this);
446 if (
m_block.BlockInfoHasBeenParsed())
457 return section_sp->GetModule();
470 bool prefer_file_cache) {
474 module_sp->GetArchitecture(),
nullptr,
nullptr,
nullptr, flavor,
481 const char *flavor,
Stream &strm,
482 bool prefer_file_cache) {
485 if (disassembler_sp) {
486 const bool show_address =
true;
487 const bool show_bytes =
false;
488 const bool show_control_flow_kind =
false;
489 disassembler_sp->GetInstructionList().Dump(
490 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
504 s->
Printf(
", Function{0x%8.8" PRIx64
"}",
GetID());
527 result = language->IsTopLevelFunction(*
this);
533 return m_mangled.GetDisplayDemangledName();
538 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
539 return sym_file->GetDeclContextForUID(
GetID());
545 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
546 return sym_file->GetCompilerContextForUID(
GetID());
561 if (sym_file ==
nullptr)
583 uint32_t prologue_end_line_idx = 0;
589 &first_line_entry_idx)) {
595 prologue_end_file_addr =
597 prologue_end_line_idx = first_line_entry_idx;
601 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
602 for (uint32_t idx = first_line_entry_idx + 1;
603 idx < last_line_entry_idx; ++idx) {
607 prologue_end_file_addr =
609 prologue_end_line_idx = idx;
621 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
622 for (uint32_t idx = first_line_entry_idx + 1;
623 idx < last_line_entry_idx; ++idx) {
626 if (line_entry.
line != first_line_entry.
line) {
627 prologue_end_file_addr =
629 prologue_end_line_idx = idx;
636 prologue_end_file_addr =
639 prologue_end_line_idx = first_line_entry_idx;
649 const addr_t range_end_file_addr =
654 uint32_t first_non_zero_line = prologue_end_line_idx;
659 if (line_entry.
line != 0)
666 first_non_zero_line++;
669 if (first_non_zero_line > prologue_end_line_idx) {
672 first_non_zero_entry)) {
673 line_zero_end_file_addr =
680 if (func_start_file_addr < prologue_end_file_addr &&
681 prologue_end_file_addr < range_end_file_addr) {
685 if (prologue_end_file_addr < line_zero_end_file_addr &&
686 line_zero_end_file_addr < range_end_file_addr) {
688 line_zero_end_file_addr - prologue_end_file_addr;
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_LOG_ERROR(log, error,...)
A section + offset based address range class.
Address & GetBaseAddress()
Get accessor for the base address of the range.
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.
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
A section + offset based address class.
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Function * CalculateSymbolContextFunction() const
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
@ DumpStyleFileAddress
Display as the file address (if any).
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
@ DumpStyleLoadAddress
Display as the load address (if resolved).
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
lldb::addr_t GetFileAddress() const
Get the file address.
bool IsValid() const
Check if the object state is valid.
A class that describes a single lexical block.
SymbolFile * GetSymbolFile()
Get the symbol file which contains debug info for this block's symbol context module.
Represent a call made within a Function.
AddrType caller_address_type
CallSiteParameterArray parameters
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 caller_address
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...
CallEdge(AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &¶meters)
lldb::addr_t GetUnresolvedReturnPCAddress() const
Like GetReturnPCAddress, but returns an unresolved file address.
A class that describes a compilation unit.
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
A uniqued constant string class.
static int Compare(ConstString lhs, ConstString rhs, const bool case_sensitive=true)
Compare two string objects.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
A class that describes the declaration location of a lldb object.
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
union lldb_private::DirectCallEdge::@365073217334004215133022257144172244077326052052 lazy_callee
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
bool resolved
Whether or not an attempt was made to find the callee's definition.
void ParseSymbolFileAndResolve(ModuleList &images)
DirectCallEdge(const char *symbol_name, AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &¶meters)
Construct a call edge using a symbol name to identify the callee, and a return PC within the calling ...
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, llvm::ArrayRef< AddressRange > disasm_ranges, bool force_live_memory=false)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
Target * GetTargetPtr() const
Returns a pointer to the target object.
bool HasTargetScope() const
Returns true the ExecutionContext object contains a valid target.
Target & GetTargetRef() const
Returns a reference to the target object.
RegisterContext * GetRegisterContext() const
Declaration & GetDeclaration()
Get accessor for the declaration information.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
virtual ~FunctionInfo()
Destructor.
ConstString GetName() const
Get accessor for the method name.
FunctionInfo(const char *name, const Declaration *decl_ptr)
Construct with the function method name and optional declaration information.
ConstString m_name
Function method name (not a mangled name).
virtual size_t MemorySize() const
Get the memory cost of this object.
static int Compare(const FunctionInfo &lhs, const FunctionInfo &rhs)
Compare two function information objects.
Declaration m_declaration
Information describing where this function information was defined.
A class that describes a function.
llvm::Expected< std::pair< lldb::SupportFileSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
const Address & GetAddress() const
Return the address of the function (its entry point).
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
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.
CompilerType GetCompilerType()
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
lldb::ModuleSP CalculateSymbolContextModule() override
CompileUnit * m_comp_unit
The compile unit that owns this function.
ConstString GetName() const
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,...
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetCallEdges()
Get the outgoing call edges from this function, sorted by their return PC addresses (in increasing or...
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Block m_block
All lexical blocks contained in this function.
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
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.
Address m_address
The address (entry point) of the function.
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
std::mutex m_call_edges_lock
Exclusive lock that controls read/write access to m_call_edges and m_call_edges_resolved.
lldb::LanguageType GetLanguage() const
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,...
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
AddressRanges GetAddressRanges()
CompileUnit * CalculateSymbolContextCompileUnit() override
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
~Function() override
Destructor.
bool m_call_edges_resolved
Whether call site info has been parsed.
ConstString GetDisplayName() const
ConstString GetNameNoArguments() const
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Function * CalculateSymbolContextFunction() override
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Range< uint32_t, uint32_t > SourceRange
size_t MemorySize() const
Get the memory cost of this object.
Mangled m_mangled
The mangled function name if any.
Block & GetBlock(bool can_create)
Get accessor for the block list.
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
IndirectCallEdge(DWARFExpressionList call_target, AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &¶meters)
Construct a call edge using a DWARFExpression to identify the callee, and a return PC within the call...
DWARFExpressionList call_target
size_t MemorySize() const override
Get the memory cost of this object.
void DumpStopContext(Stream *s) const
ConstString GetDisplayName() const
Declaration & GetCallSite()
Get accessor for the call site declaration information.
ConstString GetName() const
~InlineFunctionInfo() override
Destructor.
Mangled m_mangled
Mangled inlined function name (can be empty if there is no mangled information).
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.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Mangled & GetMangled()
Get accessor for the mangled name object.
static Language * FindPlugin(lldb::LanguageType language)
std::pair< uint32_t, uint32_t > GetLineEntryIndexRange(const AddressRange &range) const
Returns the (half-open) range of line entry indexes which overlap the given address range.
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.
bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry)
Get the line entry from the line table at index idx.
A class that handles mangled names.
@ ePreferDemangledWithoutArguments
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
A stream class that can stream formatted output to a file.
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
size_t EOL()
Output and End of Line character to the stream.
@ eEqualFileSpecAndChecksumIfSet
Defines a list of symbol context objects.
uint32_t GetSize() const
Get accessor for a symbol context list size.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
Provides public interface for all SymbolFiles.
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
virtual std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id)
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
CompilerType GetFullCompilerType()
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::SupportFile > SupportFileSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
std::shared_ptr< lldb_private::Section > SectionSP
std::shared_ptr< lldb_private::Module > ModuleSP
A line table entry class.
AddressRange range
The section offset address range for this line entry.
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
uint16_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
lldb::user_id_t GetID() const
Get accessor for the user ID.