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}",
172 size_t num_matches = sc_list.
GetSize();
173 if (num_matches == 0 || !sc_list[0].symbol) {
174 LLDB_LOG(log,
"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");
187 LLDB_LOG(log,
"DirectCallEdge: Could not find complete function");
221 llvm::Expected<Value> callee_addr_val =
call_target.Evaluate(
225 if (!callee_addr_val) {
227 "IndirectCallEdge: Could not evaluate expression: {0}");
234 LLDB_LOG(log,
"IndirectCallEdge: Could not extract address from scalar");
239 raw_addr = process->FixCodeAddress(raw_addr);
241 LLDB_LOG(log,
"IndirectCallEdge: No Process available, unable to call "
242 "FixCodeAddress on function pointer");
247 LLDB_LOG(log,
"IndirectCallEdge: Could not resolve callee's load address");
253 LLDB_LOG(log,
"IndirectCallEdge: Could not find complete function");
269 assert(comp_unit !=
nullptr);
273 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
274 range.GetByteSize()));
283 source_file_sp = std::make_shared<SupportFile>();
291 if (
m_type !=
nullptr &&
m_type->GetDeclaration().GetLine() != 0) {
293 std::make_shared<SupportFile>(
m_type->GetDeclaration().GetFile());
294 line_no =
m_type->GetDeclaration().GetLine();
297 if (line_table ==
nullptr)
302 line_no = line_entry.
line;
303 source_file_sp = line_entry.
file_sp;
308llvm::Expected<std::pair<SupportFileNSP, Function::SourceRange>>
314 if (start_line == 0 || !line_table) {
315 return llvm::createStringErrorV(
316 "Could not find line information for function \"{0}\".",
GetName());
319 uint32_t end_line = start_line;
326 source_file_sp->Equal(*entry.
file_sp,
328 end_line = std::max(end_line, entry.
line);
331 return std::make_pair(std::move(source_file_sp),
342 LLDB_LOG(log,
"GetCallEdges: Attempting to parse call site info for {0}",
357 llvm::sort(
m_call_edges, [](
const std::unique_ptr<CallEdge> &LHS,
358 const std::unique_ptr<CallEdge> &RHS) {
359 return LHS->GetSortKey() < RHS->GetSortKey();
369 [](
const std::unique_ptr<CallEdge> &edge) {
return edge->IsTailCall(); });
376 llvm::partition_point(edges, [&](
const std::unique_ptr<CallEdge> &edge) {
377 return std::make_pair(edge->IsTailCall(),
378 edge->GetReturnPCAddress(*
this, target)) <
379 std::make_pair(
false, return_pc);
381 if (edge_it == edges.end() ||
382 edge_it->get()->GetReturnPCAddress(*
this, target) != return_pc)
384 return edge_it->get();
388 if (!
m_block.BlockInfoHasBeenParsed() && can_create) {
391 module_sp->GetSymbolFile()->ParseBlocksRecursive(*
this);
394 "unable to find module shared pointer for function '{0}' in {1}",
397 m_block.SetBlockInfoHasBeenParsed(
true,
true);
411 *s <<
"id = " << (
const UserID &)*
this;
415 s->
AsRawOstream() <<
", mangled = \"" << mangled <<
'"';
417 *s <<
", decl_context = {";
420 if (decl_context.size())
421 decl_context.pop_back();
422 llvm::interleaveComma(decl_context, *s, [&](
auto &ctx) { ctx.Dump(*s); });
425 *s <<
", range" << (
m_block.GetNumRanges() > 1 ?
"s" :
"") <<
" = ";
430 for (
unsigned idx = 0; idx <
m_block.GetNumRanges(); ++idx) {
432 m_block.GetRangeAtIndex(idx, range);
438 s->
Printf(
"%p: ",
static_cast<const void *
>(
this));
440 *s <<
"Function" <<
static_cast<const UserID &
>(*this);
451 if (
m_block.BlockInfoHasBeenParsed())
462 return section_sp->GetModule();
475 bool prefer_file_cache) {
479 module_sp->GetArchitecture(),
nullptr,
nullptr,
nullptr, flavor,
486 const char *flavor,
Stream &strm,
487 bool prefer_file_cache) {
490 if (disassembler_sp) {
491 const bool show_address =
true;
492 const bool show_bytes =
false;
493 const bool show_control_flow_kind =
false;
494 disassembler_sp->GetInstructionList().Dump(
495 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
509 s->
Printf(
", Function{0x%8.8" PRIx64
"}",
GetID());
532 result = language->IsTopLevelFunction(*
this);
538 return m_mangled.GetDisplayDemangledName();
543 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
544 return sym_file->GetDeclContextForUID(
GetID());
550 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
551 return sym_file->GetCompilerContextForUID(
GetID());
566 if (sym_file ==
nullptr)
588 uint32_t prologue_end_line_idx = 0;
594 &first_line_entry_idx)) {
600 prologue_end_file_addr =
602 prologue_end_line_idx = first_line_entry_idx;
606 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
607 for (uint32_t idx = first_line_entry_idx + 1;
608 idx < last_line_entry_idx; ++idx) {
612 prologue_end_file_addr =
614 prologue_end_line_idx = idx;
626 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
627 for (uint32_t idx = first_line_entry_idx + 1;
628 idx < last_line_entry_idx; ++idx) {
631 if (line_entry.
line != first_line_entry.
line) {
632 prologue_end_file_addr =
634 prologue_end_line_idx = idx;
641 prologue_end_file_addr =
644 prologue_end_line_idx = first_line_entry_idx;
654 const addr_t range_end_file_addr =
659 uint32_t first_non_zero_line = prologue_end_line_idx;
664 if (line_entry.
line != 0)
671 first_non_zero_line++;
674 if (first_non_zero_line > prologue_end_line_idx) {
677 first_non_zero_entry)) {
678 line_zero_end_file_addr =
685 if (func_start_file_addr < prologue_end_file_addr &&
686 prologue_end_file_addr < range_end_file_addr) {
690 if (prologue_end_file_addr < line_zero_end_file_addr &&
691 line_zero_end_file_addr < range_end_file_addr) {
693 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.
const char * m_symbol_name
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
std::once_flag m_resolved_flag
Function * ResolveCallee(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.
Process * GetProcessPtr() const
Returns a pointer to the process 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.
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.
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
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.