24#include "llvm/Support/Casting.h"
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) {}
77 m_call_decl(call_decl_ptr) {}
129 : caller_address(caller_address), caller_address_type(caller_address_type),
130 is_tail_call(is_tail_call), parameters(std::move(parameters)) {}
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");
199 :
CallEdge(caller_address_type, caller_address, is_tail_call,
200 std::move(parameters)) {
206 assert(
resolved &&
"Did not resolve lazy callee");
215 :
CallEdge(caller_address_type, caller_address, is_tail_call,
216 std::move(parameters)),
217 call_target(std::move(call_target)) {}
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");
260 if (ranges.size() == 1)
263 Address lowest_addr = ranges[0].GetBaseAddress();
266 Address range_begin = range.GetBaseAddress();
269 lowest_addr = range_begin;
270 if (range_end > highest_addr)
271 highest_addr = range_end;
280 :
UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
281 m_type(type), m_mangled(mangled), m_block(*this, func_uid),
283 assert(comp_unit !=
nullptr);
287 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
288 range.GetByteSize()));
297 source_file_sp.reset();
311 if (line_table ==
nullptr)
316 line_entry,
nullptr)) {
317 line_no = line_entry.
line;
318 source_file_sp = line_entry.
file_sp;
334 if (line_table ==
nullptr)
339 line_no = line_entry.
line;
340 source_file = line_entry.
GetFile();
351 LLDB_LOG(log,
"GetCallEdges: Attempting to parse call site info for {0}",
366 llvm::sort(
m_call_edges, [](
const std::unique_ptr<CallEdge> &LHS,
367 const std::unique_ptr<CallEdge> &RHS) {
368 return LHS->GetSortKey() < RHS->GetSortKey();
378 [](
const std::unique_ptr<CallEdge> &edge) {
return edge->IsTailCall(); });
385 llvm::partition_point(edges, [&](
const std::unique_ptr<CallEdge> &edge) {
386 return std::make_pair(edge->IsTailCall(),
387 edge->GetReturnPCAddress(*
this, target)) <
388 std::make_pair(
false, return_pc);
390 if (edge_it == edges.end() ||
391 edge_it->get()->GetReturnPCAddress(*
this, target) != return_pc)
393 return edge_it->get();
400 module_sp->GetSymbolFile()->ParseBlocksRecursive(*
this);
403 "unable to find module shared pointer for function '{0}' in {1}",
420 *s <<
"id = " << (
const UserID &)*
this;
424 s->
AsRawOstream() <<
", mangled = \"" << mangled <<
'"';
426 *s <<
", decl_context = {";
429 if (decl_context.size())
430 decl_context.pop_back();
431 llvm::interleaveComma(decl_context, *s, [&](
auto &ctx) { ctx.Dump(*s); });
447 s->
Printf(
"%p: ",
static_cast<const void *
>(
this));
449 *s <<
"Function" <<
static_cast<const UserID &
>(*this);
473 return section_sp->GetModule();
486 bool prefer_file_cache) {
490 module_sp->GetArchitecture(),
nullptr,
nullptr,
nullptr, flavor,
497 const char *flavor,
Stream &strm,
498 bool prefer_file_cache) {
501 if (disassembler_sp) {
502 const bool show_address =
true;
503 const bool show_bytes =
false;
504 const bool show_control_flow_kind =
false;
505 disassembler_sp->GetInstructionList().Dump(
506 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
520 s->
Printf(
", Function{0x%8.8" PRIx64
"}",
GetID());
543 result = language->IsTopLevelFunction(*
this);
554 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
555 return sym_file->GetDeclContextForUID(
GetID());
561 if (
SymbolFile *sym_file = module_sp->GetSymbolFile())
562 return sym_file->GetCompilerContextForUID(
GetID());
577 if (sym_file ==
nullptr)
599 uint32_t prologue_end_line_idx = 0;
606 &first_line_entry_idx)) {
612 prologue_end_file_addr =
614 prologue_end_line_idx = first_line_entry_idx;
618 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
619 for (uint32_t idx = first_line_entry_idx + 1;
620 idx < last_line_entry_idx; ++idx) {
624 prologue_end_file_addr =
626 prologue_end_line_idx = idx;
638 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
639 for (uint32_t idx = first_line_entry_idx + 1;
640 idx < last_line_entry_idx; ++idx) {
643 if (line_entry.
line != first_line_entry.
line) {
644 prologue_end_file_addr =
646 prologue_end_line_idx = idx;
653 prologue_end_file_addr =
656 prologue_end_line_idx = first_line_entry_idx;
660 const addr_t func_start_file_addr =
662 const addr_t func_end_file_addr =
666 uint32_t first_non_zero_line = prologue_end_line_idx;
671 if (line_entry.
line != 0)
678 first_non_zero_line++;
681 if (first_non_zero_line > prologue_end_line_idx) {
684 first_non_zero_entry)) {
685 line_zero_end_file_addr =
692 if (func_start_file_addr < prologue_end_file_addr &&
693 prologue_end_file_addr < func_end_file_addr) {
697 if (prologue_end_file_addr < line_zero_end_file_addr &&
698 line_zero_end_file_addr < func_end_file_addr) {
700 line_zero_end_file_addr - prologue_end_file_addr;
static llvm::raw_ostream & error(Stream &strm)
AddressRange CollapseRanges(llvm::ArrayRef< AddressRange > ranges)
#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.
lldb::SectionSP GetSection() const
Get const accessor for the section.
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.
lldb::addr_t GetOffset() const
Get the section relative offset value.
bool IsValid() const
Check if the object state is valid.
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
A class that describes a single lexical block.
bool BlockInfoHasBeenParsed() const
void SetBlockInfoHasBeenParsed(bool b, bool set_children)
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
size_t GetNumRanges() const
SymbolFile * GetSymbolFile()
Get the symbol file which contains debug info for this block's symbol context module.
void Dump(Stream *s, lldb::addr_t base_addr, int32_t depth, bool show_context) const
Dump the block contents.
void AddRange(const Range &range)
Add a new offset range to this block.
size_t MemorySize() const
Get the memory cost of this object.
Represent a call made within a Function.
lldb::addr_t GetReturnPCAddress(Function &caller, Target &target) const
Get the load PC address of the instruction which executes after the call returns.
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.
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this compile unit.
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
lldb::LanguageType GetLanguage()
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
A uniqued constant string class.
size_t MemorySize() const
Get the memory cost of this object.
static int Compare(ConstString lhs, ConstString rhs, const bool case_sensitive=true)
Compare two string objects.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
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.
uint32_t GetLine() const
Get accessor for the declaration line number.
size_t MemorySize() const
Get the memory cost of this object.
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
FileSpec & GetFile()
Get accessor for file specification.
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::@22 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, const AddressRange &disasm_range, 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
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
void Clear()
Clears the object state.
bool IsClear(ValueType bit) const
Test a single flag bit to see if it is clear (zero).
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
A class that contains generic function information.
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.
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.
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
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.
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.
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
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.
AddressRange m_range
The function address range that covers the widest range needed to contain all blocks.
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
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Function(CompileUnit *comp_unit, lldb::user_id_t func_uid, lldb::user_id_t func_type_uid, const Mangled &mangled, Type *func_type, AddressRanges ranges)
Construct with a compile unit, function UID, function type UID, optional mangled name,...
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.
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.
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)
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
size_t MemorySize() const
Get the memory cost of this object.
lldb::LanguageType GuessLanguage() const
Try to guess the language from the mangling.
ConstString & GetMangledName()
Mangled name get accessor.
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
void Dump(Stream *s) const
Dump a description of this object to a Stream s.
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.
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)
const lldb_private::Declaration & GetDeclaration() const
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.
const FileSpec & GetFile() const
Helper to access the file.
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.
A mix in class that contains a generic user ID.
lldb::user_id_t GetID() const
Get accessor for the user ID.