24#include "llvm/Support/Casting.h"
25#include "llvm/Support/ErrorExtras.h"
42 *s <<
", name = \"" <<
m_name <<
"\"";
67 llvm::StringRef mangled,
105 return m_mangled.GetDisplayDemangledName();
140 if (!caller_module_sp) {
141 LLDB_LOG(log,
"GetLoadAddress: cannot get Module for caller");
145 SectionList *section_list = caller_module_sp->GetSectionList();
147 LLDB_LOG(log,
"GetLoadAddress: cannot get SectionList for Module");
166 LLDB_LOG(log,
"DirectCallEdge: Lazily parsing the call graph for {0}",
169 auto resolve_lazy_callee = [&]() ->
Function * {
173 size_t num_matches = sc_list.
GetSize();
174 if (num_matches == 0 || !sc_list[0].symbol) {
176 "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
180 Address callee_addr = sc_list[0].symbol->GetAddress();
182 LLDB_LOG(log,
"DirectCallEdge: Invalid symbol address");
187 LLDB_LOG(log,
"DirectCallEdge: Could not find complete function");
207 assert(
resolved &&
"Did not resolve lazy callee");
224 llvm::Expected<Value> callee_addr_val =
call_target.Evaluate(
228 if (!callee_addr_val) {
230 "IndirectCallEdge: Could not evaluate expression: {0}");
237 LLDB_LOG(log,
"IndirectCallEdge: Could not extract address from scalar");
243 LLDB_LOG(log,
"IndirectCallEdge: Could not resolve callee's load address");
249 LLDB_LOG(log,
"IndirectCallEdge: Could not find complete function");
265 assert(comp_unit !=
nullptr);
269 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
270 range.GetByteSize()));
279 source_file_sp = std::make_shared<SupportFile>();
287 if (
m_type !=
nullptr &&
m_type->GetDeclaration().GetLine() != 0) {
289 std::make_shared<SupportFile>(
m_type->GetDeclaration().GetFile());
290 line_no =
m_type->GetDeclaration().GetLine();
293 if (line_table ==
nullptr)
298 line_no = line_entry.
line;
299 source_file_sp = line_entry.
file_sp;
304llvm::Expected<std::pair<SupportFileNSP, Function::SourceRange>>
310 if (start_line == 0 || !line_table) {
311 return llvm::createStringErrorV(
312 "Could not find line information for function \"{0}\".",
GetName());
315 uint32_t end_line = start_line;
322 source_file_sp->Equal(*entry.
file_sp,
324 end_line = std::max(end_line, entry.
line);
327 return std::make_pair(std::move(source_file_sp),
338 LLDB_LOG(log,
"GetCallEdges: Attempting to parse call site info for {0}",
353 llvm::sort(
m_call_edges, [](
const std::unique_ptr<CallEdge> &LHS,
354 const std::unique_ptr<CallEdge> &RHS) {
355 return LHS->GetSortKey() < RHS->GetSortKey();
365 [](
const std::unique_ptr<CallEdge> &edge) {
return edge->IsTailCall(); });
372 llvm::partition_point(edges, [&](
const std::unique_ptr<CallEdge> &edge) {
373 return std::make_pair(edge->IsTailCall(),
374 edge->GetReturnPCAddress(*
this, target)) <
375 std::make_pair(
false, return_pc);
377 if (edge_it == edges.end() ||
378 edge_it->get()->GetReturnPCAddress(*
this, target) != return_pc)
380 return edge_it->get();
384 if (!
m_block.BlockInfoHasBeenParsed() && can_create) {
387 module_sp->GetSymbolFile()->ParseBlocksRecursive(*
this);
390 "unable to find module shared pointer for function '{0}' in {1}",
393 m_block.SetBlockInfoHasBeenParsed(
true,
true);
407 *s <<
"id = " << (
const UserID &)*
this;
411 s->
AsRawOstream() <<
", mangled = \"" << mangled <<
'"';
413 *s <<
", decl_context = {";
416 if (decl_context.size())
417 decl_context.pop_back();
418 llvm::interleaveComma(decl_context, *s, [&](
auto &ctx) { ctx.Dump(*s); });
421 *s <<
", range" << (
m_block.GetNumRanges() > 1 ?
"s" :
"") <<
" = ";
426 for (
unsigned idx = 0; idx <
m_block.GetNumRanges(); ++idx) {
428 m_block.GetRangeAtIndex(idx, range);
434 s->
Printf(
"%p: ",
static_cast<const void *
>(
this));
436 *s <<
"Function" <<
static_cast<const UserID &
>(*this);
447 if (
m_block.BlockInfoHasBeenParsed())
458 return section_sp->GetModule();
471 bool prefer_file_cache) {
475 module_sp->GetArchitecture(),
nullptr,
nullptr,
nullptr, flavor,
482 const char *flavor,
Stream &strm,
483 bool prefer_file_cache) {
486 if (disassembler_sp) {
487 const bool show_address =
true;
488 const bool show_bytes =
false;
489 const bool show_control_flow_kind =
false;
490 disassembler_sp->GetInstructionList().Dump(
491 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
505 s->
Printf(
", Function{0x%8.8" PRIx64
"}",
GetID());
528 result = language->IsTopLevelFunction(*
this);
534 return m_mangled.GetDisplayDemangledName();
539 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
540 return sym_file->GetDeclContextForUID(
GetID());
546 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
547 return sym_file->GetCompilerContextForUID(
GetID());
562 if (sym_file ==
nullptr)
584 uint32_t prologue_end_line_idx = 0;
590 &first_line_entry_idx)) {
596 prologue_end_file_addr =
598 prologue_end_line_idx = first_line_entry_idx;
602 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
603 for (uint32_t idx = first_line_entry_idx + 1;
604 idx < last_line_entry_idx; ++idx) {
608 prologue_end_file_addr =
610 prologue_end_line_idx = idx;
622 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
623 for (uint32_t idx = first_line_entry_idx + 1;
624 idx < last_line_entry_idx; ++idx) {
627 if (line_entry.
line != first_line_entry.
line) {
628 prologue_end_file_addr =
630 prologue_end_line_idx = idx;
637 prologue_end_file_addr =
640 prologue_end_line_idx = first_line_entry_idx;
650 const addr_t range_end_file_addr =
655 uint32_t first_non_zero_line = prologue_end_line_idx;
660 if (line_entry.
line != 0)
667 first_non_zero_line++;
670 if (first_non_zero_line > prologue_end_line_idx) {
673 first_non_zero_entry)) {
674 line_zero_end_file_addr =
681 if (func_start_file_addr < prologue_end_file_addr &&
682 prologue_end_file_addr < range_end_file_addr) {
686 if (prologue_end_file_addr < line_zero_end_file_addr &&
687 line_zero_end_file_addr < range_end_file_addr) {
689 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.
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)
union lldb_private::DirectCallEdge::@004246155320214161241340150105105336006135126301 lazy_callee
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.
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
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)
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,...
void GetStartLineSourceInfo(SupportFileNSP &source_file_sp, uint32_t &line_no)
Find the file and line number of the source location of the start 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 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.
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
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
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.
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
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.
SupportFileNSP file_sp
The source file, possibly mapped by the target.source-map setting.
uint16_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
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.