LLDB mainline
Function.cpp
Go to the documentation of this file.
1//===-- Function.cpp ------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Debugger.h"
12#include "lldb/Core/Module.h"
14#include "lldb/Core/Section.h"
15#include "lldb/Host/Host.h"
21#include "lldb/Target/Target.h"
23#include "lldb/Utility/Log.h"
24#include "llvm/Support/Casting.h"
25
26using namespace lldb;
27using namespace lldb_private;
28
29// Basic function information is contained in the FunctionInfo class. It is
30// designed to contain the name, linkage name, and declaration location.
31FunctionInfo::FunctionInfo(const char *name, const Declaration *decl_ptr)
32 : m_name(name), m_declaration(decl_ptr) {}
33
35 : m_name(name), m_declaration(decl_ptr) {}
36
38
39void FunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
40 if (m_name)
41 *s << ", name = \"" << m_name << "\"";
42 m_declaration.Dump(s, show_fullpaths);
43}
44
46 int result = ConstString::Compare(a.GetName(), b.GetName());
47 if (result)
48 return result;
49
51}
52
54
58
60
62 return m_name.MemorySize() + m_declaration.MemorySize();
63}
64
66 llvm::StringRef mangled,
67 const Declaration *decl_ptr,
68 const Declaration *call_decl_ptr)
69 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
70 m_call_decl(call_decl_ptr) {}
71
73 const Mangled &mangled,
74 const Declaration *decl_ptr,
75 const Declaration *call_decl_ptr)
76 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
77 m_call_decl(call_decl_ptr) {}
78
80
81void InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
82 FunctionInfo::Dump(s, show_fullpaths);
83 if (m_mangled)
84 m_mangled.Dump(s);
85}
86
88 // s->Indent("[inlined] ");
89 s->Indent();
90 if (m_mangled)
91 s->PutCString(m_mangled.GetName().AsCString());
92 else
93 s->PutCString(m_name.AsCString());
94}
95
97 if (m_mangled)
98 return m_mangled.GetName();
99 return m_name;
100}
101
103 if (m_mangled)
104 return m_mangled.GetDisplayDemangledName();
105 return m_name;
106}
107
109
113
115
117
119 return FunctionInfo::MemorySize() + m_mangled.MemorySize();
120}
121
122/// @name Call site related structures
123/// @{
124
125CallEdge::~CallEdge() = default;
126
131
133 Function &caller, Target &target) {
134 Log *log = GetLog(LLDBLog::Step);
135
136 const Address &caller_start_addr = caller.GetAddress();
137
138 ModuleSP caller_module_sp = caller_start_addr.GetModule();
139 if (!caller_module_sp) {
140 LLDB_LOG(log, "GetLoadAddress: cannot get Module for caller");
142 }
143
144 SectionList *section_list = caller_module_sp->GetSectionList();
145 if (!section_list) {
146 LLDB_LOG(log, "GetLoadAddress: cannot get SectionList for Module");
148 }
149
150 Address the_addr = Address(unresolved_pc, section_list);
151 lldb::addr_t load_addr = the_addr.GetLoadAddress(&target);
152 return load_addr;
153}
154
156 Target &target) const {
157 return GetLoadAddress(GetUnresolvedReturnPCAddress(), caller, target);
158}
159
161 if (resolved)
162 return;
163
164 Log *log = GetLog(LLDBLog::Step);
165 LLDB_LOG(log, "DirectCallEdge: Lazily parsing the call graph for {0}",
166 lazy_callee.symbol_name);
167
168 auto resolve_lazy_callee = [&]() -> Function * {
169 ConstString callee_name{lazy_callee.symbol_name};
170 SymbolContextList sc_list;
171 images.FindFunctionSymbols(callee_name, eFunctionNameTypeAuto, sc_list);
172 size_t num_matches = sc_list.GetSize();
173 if (num_matches == 0 || !sc_list[0].symbol) {
174 LLDB_LOG(log,
175 "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
176 callee_name);
177 return nullptr;
178 }
179 Address callee_addr = sc_list[0].symbol->GetAddress();
180 if (!callee_addr.IsValid()) {
181 LLDB_LOG(log, "DirectCallEdge: Invalid symbol address");
182 return nullptr;
183 }
184 Function *f = callee_addr.CalculateSymbolContextFunction();
185 if (!f) {
186 LLDB_LOG(log, "DirectCallEdge: Could not find complete function");
187 return nullptr;
188 }
189 return f;
190 };
191 lazy_callee.def = resolve_lazy_callee();
192 resolved = true;
193}
194
203
206 assert(resolved && "Did not resolve lazy callee");
207 return lazy_callee.def;
208}
209
218
220 ExecutionContext &exe_ctx) {
221 Log *log = GetLog(LLDBLog::Step);
223 llvm::Expected<Value> callee_addr_val = call_target.Evaluate(
224 &exe_ctx, exe_ctx.GetRegisterContext(), LLDB_INVALID_ADDRESS,
225 /*initial_value_ptr=*/nullptr,
226 /*object_address_ptr=*/nullptr);
227 if (!callee_addr_val) {
228 LLDB_LOG_ERROR(log, callee_addr_val.takeError(),
229 "IndirectCallEdge: Could not evaluate expression: {0}");
230 return nullptr;
231 }
232
233 addr_t raw_addr =
234 callee_addr_val->GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
235 if (raw_addr == LLDB_INVALID_ADDRESS) {
236 LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar");
237 return nullptr;
238 }
239
240 Address callee_addr;
241 if (!exe_ctx.GetTargetPtr()->ResolveLoadAddress(raw_addr, callee_addr)) {
242 LLDB_LOG(log, "IndirectCallEdge: Could not resolve callee's load address");
243 return nullptr;
244 }
245
246 Function *f = callee_addr.CalculateSymbolContextFunction();
247 if (!f) {
248 LLDB_LOG(log, "IndirectCallEdge: Could not find complete function");
249 return nullptr;
250 }
251
252 return f;
253}
254
255/// @}
256
257//
259 lldb::user_id_t type_uid, const Mangled &mangled, Type *type,
260 Address address, AddressRanges ranges)
261 : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
262 m_type(type), m_mangled(mangled), m_block(*this, func_uid),
263 m_address(std::move(address)), m_prologue_byte_size(0) {
264 assert(comp_unit != nullptr);
265 lldb::addr_t base_file_addr = m_address.GetFileAddress();
266 for (const AddressRange &range : ranges)
267 m_block.AddRange(
268 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
269 range.GetByteSize()));
270 m_block.FinalizeRanges();
271}
272
273Function::~Function() = default;
274
276 uint32_t &line_no) {
277 line_no = 0;
278 source_file_sp.reset();
279
280 if (m_comp_unit == nullptr)
281 return;
282
283 // Initialize m_type if it hasn't been initialized already
284 GetType();
285
286 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
287 source_file_sp =
288 std::make_shared<SupportFile>(m_type->GetDeclaration().GetFile());
289 line_no = m_type->GetDeclaration().GetLine();
290 } else {
291 LineTable *line_table = m_comp_unit->GetLineTable();
292 if (line_table == nullptr)
293 return;
294
295 LineEntry line_entry;
296 if (line_table->FindLineEntryByAddress(GetAddress(), line_entry, nullptr)) {
297 line_no = line_entry.line;
298 source_file_sp = line_entry.file_sp;
299 }
300 }
301}
302
303llvm::Expected<std::pair<SupportFileSP, Function::SourceRange>>
305 SupportFileSP source_file_sp;
306 uint32_t start_line;
307 GetStartLineSourceInfo(source_file_sp, start_line);
308 LineTable *line_table = m_comp_unit->GetLineTable();
309 if (start_line == 0 || !line_table) {
310 return llvm::createStringError(llvm::formatv(
311 "Could not find line information for function \"{0}\".", GetName()));
312 }
313
314 uint32_t end_line = start_line;
315 for (const AddressRange &range : GetAddressRanges()) {
316 for (auto [idx, end] = line_table->GetLineEntryIndexRange(range); idx < end;
317 ++idx) {
318 LineEntry entry;
319 // Ignore entries belonging to inlined functions or #included files.
320 if (line_table->GetLineEntryAtIndex(idx, entry) &&
321 source_file_sp->Equal(*entry.file_sp,
323 end_line = std::max(end_line, entry.line);
324 }
325 }
326 return std::make_pair(std::move(source_file_sp),
327 SourceRange(start_line, end_line - start_line));
328}
329
330llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
331 std::lock_guard<std::mutex> guard(m_call_edges_lock);
332
334 return m_call_edges;
335
336 Log *log = GetLog(LLDBLog::Step);
337 LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
339
341
342 // Find the SymbolFile which provided this function's definition.
343 Block &block = GetBlock(/*can_create*/true);
344 SymbolFile *sym_file = block.GetSymbolFile();
345 if (!sym_file)
346 return {};
347
348 // Lazily read call site information from the SymbolFile.
350
351 // Sort the call edges to speed up return_pc lookups.
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();
355 });
356
357 return m_call_edges;
358}
359
360llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
361 // Tail calling edges are sorted at the end of the list. Find them by dropping
362 // all non-tail-calls.
363 return GetCallEdges().drop_until(
364 [](const std::unique_ptr<CallEdge> &edge) { return edge->IsTailCall(); });
365}
366
368 Target &target) {
369 auto edges = GetCallEdges();
370 auto edge_it =
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);
375 });
376 if (edge_it == edges.end() ||
377 edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
378 return nullptr;
379 return edge_it->get();
380}
381
382Block &Function::GetBlock(bool can_create) {
383 if (!m_block.BlockInfoHasBeenParsed() && can_create) {
385 if (module_sp) {
386 module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
387 } else {
388 Debugger::ReportError(llvm::formatv(
389 "unable to find module shared pointer for function '{0}' in {1}",
390 GetName().GetCString(), m_comp_unit->GetPrimaryFile().GetPath()));
391 }
392 m_block.SetBlockInfoHasBeenParsed(true, true);
393 }
394 return m_block;
395}
396
398
400
402 Target *target) {
403 ConstString name = GetName();
404 ConstString mangled = m_mangled.GetMangledName();
405
406 *s << "id = " << (const UserID &)*this;
407 if (name)
408 s->AsRawOstream() << ", name = \"" << name << '"';
409 if (mangled)
410 s->AsRawOstream() << ", mangled = \"" << mangled << '"';
411 if (level == eDescriptionLevelVerbose) {
412 *s << ", decl_context = {";
413 auto decl_context = GetCompilerContext();
414 // Drop the function itself from the context chain.
415 if (decl_context.size())
416 decl_context.pop_back();
417 llvm::interleaveComma(decl_context, *s, [&](auto &ctx) { ctx.Dump(*s); });
418 *s << "}";
419 }
420 *s << ", range" << (m_block.GetNumRanges() > 1 ? "s" : "") << " = ";
421 Address::DumpStyle fallback_style =
425 for (unsigned idx = 0; idx < m_block.GetNumRanges(); ++idx) {
426 AddressRange range;
427 m_block.GetRangeAtIndex(idx, range);
428 range.Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
429 }
430}
431
432void Function::Dump(Stream *s, bool show_context) const {
433 s->Printf("%p: ", static_cast<const void *>(this));
434 s->Indent();
435 *s << "Function" << static_cast<const UserID &>(*this);
436
437 m_mangled.Dump(s);
438
439 if (m_type)
440 s->Printf(", type = %p", static_cast<void *>(m_type));
441 else if (m_type_uid != LLDB_INVALID_UID)
442 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
443
444 s->EOL();
445 // Dump the root object
446 if (m_block.BlockInfoHasBeenParsed())
447 m_block.Dump(s, m_address.GetFileAddress(), INT_MAX, show_context);
448}
449
451 sc->function = this;
452 m_comp_unit->CalculateSymbolContext(sc);
453}
454
456 if (SectionSP section_sp = m_address.GetSection())
457 return section_sp->GetModule();
458
459 return this->GetCompileUnit()->GetModule();
460}
461
465
467
469 const char *flavor,
470 bool prefer_file_cache) {
471 ModuleSP module_sp = GetAddress().GetModule();
472 if (module_sp && exe_ctx.HasTargetScope()) {
474 module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
475 exe_ctx.GetTargetRef(), GetAddressRanges(), !prefer_file_cache);
476 }
477 return lldb::DisassemblerSP();
478}
479
481 const char *flavor, Stream &strm,
482 bool prefer_file_cache) {
483 lldb::DisassemblerSP disassembler_sp =
484 GetInstructions(exe_ctx, flavor, 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);
491 return true;
492 }
493 return false;
494}
495
496// Symbol *
497// Function::CalculateSymbolContextSymbol ()
498//{
499// return // TODO: find the symbol for the function???
500//}
501
503 m_comp_unit->DumpSymbolContext(s);
504 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
505}
506
507size_t Function::MemorySize() const {
508 size_t mem_size = sizeof(Function) + m_block.MemorySize();
509 return mem_size;
510}
511
513 bool result = false;
514
515 // Currently optimization is only indicted by the vendor extension
516 // DW_AT_APPLE_optimized which is set on a compile unit level.
517 if (m_comp_unit) {
518 result = m_comp_unit->GetIsOptimized();
519 }
520 return result;
521}
522
524 bool result = false;
525
526 if (Language *language = Language::FindPlugin(GetLanguage()))
527 result = language->IsTopLevelFunction(*this);
528
529 return result;
530}
531
533 return m_mangled.GetDisplayDemangledName();
534}
535
537 if (ModuleSP module_sp = CalculateSymbolContextModule())
538 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
539 return sym_file->GetDeclContextForUID(GetID());
540 return {};
541}
542
543std::vector<CompilerContext> Function::GetCompilerContext() {
544 if (ModuleSP module_sp = CalculateSymbolContextModule())
545 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
546 return sym_file->GetCompilerContextForUID(GetID());
547 return {};
548}
549
551 if (m_type == nullptr) {
552 SymbolContext sc;
553
555
556 if (!sc.module_sp)
557 return nullptr;
558
559 SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
560
561 if (sym_file == nullptr)
562 return nullptr;
563
564 m_type = sym_file->ResolveTypeUID(m_type_uid);
565 }
566 return m_type;
567}
568
569const Type *Function::GetType() const { return m_type; }
570
572 Type *function_type = GetType();
573 if (function_type)
574 return function_type->GetFullCompilerType();
575 return CompilerType();
576}
577
579 if (m_prologue_byte_size == 0 &&
582 LineTable *line_table = m_comp_unit->GetLineTable();
583 uint32_t prologue_end_line_idx = 0;
584
585 if (line_table) {
586 LineEntry first_line_entry;
587 uint32_t first_line_entry_idx = UINT32_MAX;
588 if (line_table->FindLineEntryByAddress(GetAddress(), first_line_entry,
589 &first_line_entry_idx)) {
590 // Make sure the first line entry isn't already the end of the prologue
591 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
592 addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
593
594 if (first_line_entry.is_prologue_end) {
595 prologue_end_file_addr =
596 first_line_entry.range.GetBaseAddress().GetFileAddress();
597 prologue_end_line_idx = first_line_entry_idx;
598 } else {
599 // Check the first few instructions and look for one that has
600 // is_prologue_end set to true.
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) {
604 LineEntry line_entry;
605 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
606 if (line_entry.is_prologue_end) {
607 prologue_end_file_addr =
608 line_entry.range.GetBaseAddress().GetFileAddress();
609 prologue_end_line_idx = idx;
610 break;
611 }
612 }
613 }
614 }
615
616 // If we didn't find the end of the prologue in the line tables, then
617 // just use the end address of the first line table entry
618 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
619 // Check the first few instructions and look for one that has a line
620 // number that's different than the first entry.
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) {
624 LineEntry line_entry;
625 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
626 if (line_entry.line != first_line_entry.line) {
627 prologue_end_file_addr =
628 line_entry.range.GetBaseAddress().GetFileAddress();
629 prologue_end_line_idx = idx;
630 break;
631 }
632 }
633 }
634
635 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
636 prologue_end_file_addr =
637 first_line_entry.range.GetBaseAddress().GetFileAddress() +
638 first_line_entry.range.GetByteSize();
639 prologue_end_line_idx = first_line_entry_idx;
640 }
641 }
642
643 AddressRange entry_range;
644 m_block.GetRangeContainingAddress(m_address, entry_range);
645
646 // Deliberately not starting at entry_range.GetBaseAddress() because the
647 // function entry point need not be the first address in the range.
648 const addr_t func_start_file_addr = m_address.GetFileAddress();
649 const addr_t range_end_file_addr =
650 entry_range.GetBaseAddress().GetFileAddress() +
651 entry_range.GetByteSize();
652
653 // Now calculate the offset to pass the subsequent line 0 entries.
654 uint32_t first_non_zero_line = prologue_end_line_idx;
655 while (true) {
656 LineEntry line_entry;
657 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
658 line_entry)) {
659 if (line_entry.line != 0)
660 break;
661 }
662 if (line_entry.range.GetBaseAddress().GetFileAddress() >=
663 range_end_file_addr)
664 break;
665
666 first_non_zero_line++;
667 }
668
669 if (first_non_zero_line > prologue_end_line_idx) {
670 LineEntry first_non_zero_entry;
671 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
672 first_non_zero_entry)) {
673 line_zero_end_file_addr =
674 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
675 }
676 }
677
678 // Verify that this prologue end file address inside the function just
679 // to be sure
680 if (func_start_file_addr < prologue_end_file_addr &&
681 prologue_end_file_addr < range_end_file_addr) {
682 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
683 }
684
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;
689 }
690 }
691 }
692 }
693
695}
696
698 lldb::LanguageType lang = m_mangled.GuessLanguage();
699 if (lang != lldb::eLanguageTypeUnknown)
700 return lang;
701
702 if (m_comp_unit)
703 return m_comp_unit->GetLanguage();
704
706}
707
709 return m_mangled.GetName();
710}
711
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:392
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.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:301
Function * CalculateSymbolContextFunction() const
Definition Address.cpp:860
DumpStyle
Dump styles allow the Address::Dump(Stream *,DumpStyle) const function to display Address contents in...
Definition Address.h:66
@ DumpStyleFileAddress
Display as the file address (if any).
Definition Address.h:87
@ DumpStyleModuleWithFileAddress
Display as the file address with the module name prepended (if any).
Definition Address.h:93
@ DumpStyleLoadAddress
Display as the load address (if resolved).
Definition Address.h:99
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:273
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:281
bool IsValid() const
Check if the object state is valid.
Definition Address.h:355
A class that describes a single lexical block.
Definition Block.h:41
RangeList::Entry Range
Definition Block.h:44
SymbolFile * GetSymbolFile()
Get the symbol file which contains debug info for this block's symbol context module.
Definition Block.cpp:467
Represent a call made within a Function.
Definition Function.h:268
AddrType caller_address_type
Definition Function.h:325
CallSiteParameterArray parameters
Definition Function.h:328
lldb::addr_t GetReturnPCAddress(Function &caller, Target &target) const
Get the load PC address of the instruction which executes after the call returns.
Definition Function.cpp:155
lldb::addr_t caller_address
Definition Function.h:324
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...
Definition Function.cpp:132
CallEdge(AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &&parameters)
Definition Function.cpp:127
lldb::addr_t GetUnresolvedReturnPCAddress() const
Like GetReturnPCAddress, but returns an unresolved file address.
Definition Function.h:317
A class that describes a compilation unit.
Definition CompileUnit.h:43
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
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.
Definition Declaration.h:24
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.
Definition Function.cpp:204
bool resolved
Whether or not an attempt was made to find the callee's definition.
Definition Function.h:357
void ParseSymbolFileAndResolve(ModuleList &images)
Definition Function.cpp:160
DirectCallEdge(const char *symbol_name, AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &&parameters)
Construct a call edge using a symbol name to identify the callee, and a return PC within the calling ...
Definition Function.cpp:195
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.
Definition Function.cpp:53
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition Function.cpp:39
virtual ~FunctionInfo()
Destructor.
ConstString GetName() const
Get accessor for the method name.
Definition Function.cpp:59
FunctionInfo(const char *name, const Declaration *decl_ptr)
Construct with the function method name and optional declaration information.
Definition Function.cpp:31
ConstString m_name
Function method name (not a mangled name).
Definition Function.h:118
virtual size_t MemorySize() const
Get the memory cost of this object.
Definition Function.cpp:61
static int Compare(const FunctionInfo &lhs, const FunctionInfo &rhs)
Compare two function information objects.
Definition Function.cpp:45
Declaration m_declaration
Information describing where this function information was defined.
Definition Function.h:121
A class that describes a function.
Definition Function.h:400
llvm::Expected< std::pair< lldb::SupportFileSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:304
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
Definition Function.h:678
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
Definition Function.h:668
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
Definition Function.cpp:512
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
Definition Function.h:645
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:453
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition Function.cpp:401
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.
Definition Function.cpp:275
CompilerType GetCompilerType()
Definition Function.cpp:571
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Definition Function.cpp:523
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Function.cpp:455
CompileUnit * m_comp_unit
The compile unit that owns this function.
Definition Function.h:642
ConstString GetName() const
Definition Function.cpp:708
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,...
Definition Function.cpp:367
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetCallEdges()
Get the outgoing call edges from this function, sorted by their return PC addresses (in increasing or...
Definition Function.cpp:330
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Definition Function.cpp:432
Block m_block
All lexical blocks contained in this function.
Definition Function.h:656
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
Definition Function.h:638
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
Definition Function.h:649
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Function.cpp:450
Address m_address
The address (entry point) of the function.
Definition Function.h:659
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Function.cpp:502
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:360
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Definition Function.cpp:480
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition Function.cpp:550
std::mutex m_call_edges_lock
Exclusive lock that controls read/write access to m_call_edges and m_call_edges_resolved.
Definition Function.h:672
lldb::LanguageType GetLanguage() const
Definition Function.cpp:697
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,...
Definition Function.cpp:258
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition Function.cpp:578
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition Function.cpp:536
AddressRanges GetAddressRanges()
Definition Function.h:448
CompileUnit * CalculateSymbolContextCompileUnit() override
Definition Function.cpp:462
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:397
~Function() override
Destructor.
bool m_call_edges_resolved
Whether call site info has been parsed.
Definition Function.h:675
ConstString GetDisplayName() const
Definition Function.cpp:532
ConstString GetNameNoArguments() const
Definition Function.cpp:712
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Definition Function.cpp:468
Function * CalculateSymbolContextFunction() override
Definition Function.cpp:466
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Definition Function.cpp:543
Range< uint32_t, uint32_t > SourceRange
Definition Function.h:475
size_t MemorySize() const
Get the memory cost of this object.
Definition Function.cpp:507
Mangled m_mangled
The mangled function name if any.
Definition Function.h:653
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:382
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
Definition Function.cpp:219
IndirectCallEdge(DWARFExpressionList call_target, AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &&parameters)
Construct a call edge using a DWARFExpression to identify the callee, and a return PC within the call...
Definition Function.cpp:210
DWARFExpressionList call_target
Definition Function.h:377
size_t MemorySize() const override
Get the memory cost of this object.
Definition Function.cpp:118
void DumpStopContext(Stream *s) const
Definition Function.cpp:87
ConstString GetDisplayName() const
Definition Function.cpp:102
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition Function.cpp:108
ConstString GetName() const
Definition Function.cpp:96
~InlineFunctionInfo() override
Destructor.
Mangled m_mangled
Mangled inlined function name (can be empty if there is no mangled information).
Definition Function.h:245
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.
Definition Function.cpp:65
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition Function.cpp:81
Mangled & GetMangled()
Get accessor for the mangled name object.
Definition Function.cpp:114
static Language * FindPlugin(lldb::LanguageType language)
Definition Language.cpp:84
A line table class.
Definition LineTable.h:25
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.
Definition Mangled.h:34
@ ePreferDemangledWithoutArguments
Definition Mangled.h:39
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
A collection class for Module objects.
Definition ModuleList.h:104
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
An error handling class.
Definition Status.h:118
A stream class that can stream formatted output to a file.
Definition Stream.h:28
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:400
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:65
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
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.
Definition SymbolFile.h:51
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
virtual std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id)
Definition SymbolFile.h:373
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3285
CompilerType GetFullCompilerType()
Definition Type.cpp:772
#define LLDB_INVALID_UID
#define LLDB_INVALID_ADDRESS
#define UINT32_MAX
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.
Definition Log.h:332
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
Definition Function.h:262
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
uint64_t user_id_t
Definition lldb-types.h:82
std::shared_ptr< lldb_private::Section > SectionSP
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
A line table entry class.
Definition LineEntry.h:21
AddressRange range
The section offset address range for this line entry.
Definition LineEntry.h:137
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition LineEntry.h:147
uint16_t is_prologue_end
Indicates this entry is one (of possibly many) where execution should be suspended for an entry break...
Definition LineEntry.h:161
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition LineEntry.h:140
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47