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#include "llvm/Support/ErrorExtras.h"
26
27using namespace lldb;
28using namespace lldb_private;
29
30// Basic function information is contained in the FunctionInfo class. It is
31// designed to contain the name, linkage name, and declaration location.
32FunctionInfo::FunctionInfo(const char *name, const Declaration *decl_ptr)
33 : m_name(name), m_declaration(decl_ptr) {}
34
36 : m_name(name), m_declaration(decl_ptr) {}
37
39
40void FunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
41 if (m_name)
42 *s << ", name = \"" << m_name << "\"";
43 m_declaration.Dump(s, show_fullpaths);
44}
45
47 int result = ConstString::Compare(a.GetName(), b.GetName());
48 if (result)
49 return result;
50
52}
53
55
59
61
63 llvm::StringRef mangled,
64 const Declaration *decl_ptr,
65 const Declaration *call_decl_ptr)
66 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
67 m_call_decl(call_decl_ptr) {}
68
70 const Mangled &mangled,
71 const Declaration *decl_ptr,
72 const Declaration *call_decl_ptr)
73 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
74 m_call_decl(call_decl_ptr) {}
75
77
78void InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
79 FunctionInfo::Dump(s, show_fullpaths);
80 if (m_mangled)
81 m_mangled.Dump(s);
82}
83
85 // s->Indent("[inlined] ");
86 s->Indent();
87 if (m_mangled)
88 s->PutCString(m_mangled.GetName());
89 else
91}
92
94 if (m_mangled)
95 return m_mangled.GetName();
96 return m_name;
97}
98
100 if (m_mangled)
101 return m_mangled.GetDisplayDemangledName();
102 return m_name;
103}
104
106
110
112
114
115/// @name Call site related structures
116/// @{
117
118CallEdge::~CallEdge() = default;
119
124
126 Function &caller, Target &target) {
127 Log *log = GetLog(LLDBLog::Step);
128
129 const Address &caller_start_addr = caller.GetAddress();
130
131 ModuleSP caller_module_sp = caller_start_addr.GetModule();
132 if (!caller_module_sp) {
133 LLDB_LOG(log, "GetLoadAddress: cannot get Module for caller");
135 }
136
137 SectionList *section_list = caller_module_sp->GetSectionList();
138 if (!section_list) {
139 LLDB_LOG(log, "GetLoadAddress: cannot get SectionList for Module");
141 }
142
143 Address the_addr = Address(unresolved_pc, section_list);
144 lldb::addr_t load_addr = the_addr.GetLoadAddress(&target);
145 return load_addr;
146}
147
149 Target &target) const {
150 return GetLoadAddress(GetUnresolvedReturnPCAddress(), caller, target);
151}
152
154 if (!m_symbol_name)
155 return nullptr;
156
157 Log *log = GetLog(LLDBLog::Step);
158 LLDB_LOG(log, "DirectCallEdge: Lazily parsing the call graph for {0}",
160
161 SymbolContextList sc_list;
162 images.FindFunctionSymbols(ConstString(m_symbol_name), eFunctionNameTypeAuto,
163 sc_list);
164 size_t num_matches = sc_list.GetSize();
165 if (num_matches == 0 || !sc_list[0].symbol) {
166 LLDB_LOG(log, "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
168 return nullptr;
169 }
170
171 Address callee_addr = sc_list[0].symbol->GetAddress();
172 if (!callee_addr.IsValid()) {
173 LLDB_LOG(log, "DirectCallEdge: Invalid symbol address");
174 return nullptr;
175 }
176
177 Function *f = callee_addr.CalculateSymbolContextFunction();
178 if (!f) {
179 LLDB_LOG(log, "DirectCallEdge: Could not find complete function");
180 return nullptr;
181 }
182
183 return f;
184}
185
193
195 std::call_once(m_resolved_flag,
196 [&] { m_callee_def = ResolveCallee(images); });
197 return m_callee_def;
198}
199
208
210 ExecutionContext &exe_ctx) {
211 Log *log = GetLog(LLDBLog::Step);
213 llvm::Expected<Value> callee_addr_val = call_target.Evaluate(
214 &exe_ctx, exe_ctx.GetRegisterContext(), LLDB_INVALID_ADDRESS,
215 /*initial_value_ptr=*/nullptr,
216 /*object_address_ptr=*/nullptr);
217 if (!callee_addr_val) {
218 LLDB_LOG_ERROR(log, callee_addr_val.takeError(),
219 "IndirectCallEdge: Could not evaluate expression: {0}");
220 return nullptr;
221 }
222
223 addr_t raw_addr =
224 callee_addr_val->GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
225 if (raw_addr == LLDB_INVALID_ADDRESS) {
226 LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar");
227 return nullptr;
228 }
229
230 if (auto *process = exe_ctx.GetProcessPtr()) {
231 raw_addr = process->FixCodeAddress(raw_addr);
232 } else {
233 LLDB_LOG(log, "IndirectCallEdge: No Process available, unable to call "
234 "FixCodeAddress on function pointer");
235 }
236
237 Address callee_addr;
238 if (!exe_ctx.GetTargetPtr()->ResolveLoadAddress(raw_addr, callee_addr)) {
239 LLDB_LOG(log, "IndirectCallEdge: Could not resolve callee's load address");
240 return nullptr;
241 }
242
243 Function *f = callee_addr.CalculateSymbolContextFunction();
244 if (!f) {
245 LLDB_LOG(log, "IndirectCallEdge: Could not find complete function");
246 return nullptr;
247 }
248
249 return f;
250}
251
252/// @}
253
254//
256 lldb::user_id_t type_uid, const Mangled &mangled, Type *type,
257 Address address, AddressRanges ranges)
258 : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
259 m_type(type), m_mangled(mangled), m_block(*this, func_uid),
260 m_address(std::move(address)), m_prologue_byte_size(0) {
261 assert(comp_unit != nullptr);
262 lldb::addr_t base_file_addr = m_address.GetFileAddress();
263 for (const AddressRange &range : ranges)
264 m_block.AddRange(
265 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
266 range.GetByteSize()));
267 m_block.FinalizeRanges();
268}
269
270Function::~Function() = default;
271
272bool Function::GetStartLineTableEntry(LineEntry &line_entry, uint32_t *index) {
273 LineTable *line_table = m_comp_unit ? m_comp_unit->GetLineTable() : nullptr;
274 if (line_table == nullptr)
275 return false;
276
277 uint32_t line_entry_idx = UINT32_MAX;
278 if (line_table->FindLineEntryByAddress(GetAddress(), line_entry,
279 &line_entry_idx)) {
280 if (index)
281 *index = line_entry_idx;
282 return true;
283 }
284
285 // The entry point has no line row (e.g. a WebAssembly function's
286 // locals-declaration header), so take the first row inside the function.
287 AddressRange entry_range;
288 if (!m_block.GetRangeContainingAddress(m_address, entry_range))
289 return false;
290 auto [first, last] = line_table->GetLineEntryIndexRange(entry_range);
291 if (first == last)
292 return false;
293 if (!line_table->GetLineEntryAtIndex(first, line_entry))
294 return false;
295 if (index)
296 *index = first;
297 return true;
298}
299
301 uint32_t &line_no) {
302 line_no = 0;
303 source_file_sp = std::make_shared<SupportFile>();
304
305 if (m_comp_unit == nullptr)
306 return;
307
308 // Initialize m_type if it hasn't been initialized already
309 GetType();
310
311 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
312 source_file_sp =
313 std::make_shared<SupportFile>(m_type->GetDeclaration().GetFile());
314 line_no = m_type->GetDeclaration().GetLine();
315 } else {
316 LineEntry line_entry;
317 if (GetStartLineTableEntry(line_entry)) {
318 line_no = line_entry.line;
319 source_file_sp = line_entry.file_sp;
320 }
321 }
322}
323
324llvm::Expected<std::pair<SupportFileNSP, Function::SourceRange>>
326 SupportFileNSP source_file_sp = std::make_shared<SupportFile>();
327 uint32_t start_line;
328 GetStartLineSourceInfo(source_file_sp, start_line);
329 LineTable *line_table = m_comp_unit->GetLineTable();
330 if (start_line == 0 || !line_table) {
331 return llvm::createStringErrorV(
332 "Could not find line information for function \"{0}\".", GetName());
333 }
334
335 uint32_t end_line = start_line;
336 for (const AddressRange &range : GetAddressRanges()) {
337 for (auto [idx, end] = line_table->GetLineEntryIndexRange(range); idx < end;
338 ++idx) {
339 LineEntry entry;
340 // Ignore entries belonging to inlined functions or #included files.
341 if (line_table->GetLineEntryAtIndex(idx, entry) &&
342 source_file_sp->Equal(*entry.file_sp,
344 end_line = std::max(end_line, entry.line);
345 }
346 }
347 return std::make_pair(std::move(source_file_sp),
348 SourceRange(start_line, end_line - start_line));
349}
350
351llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
352 std::lock_guard<std::mutex> guard(m_call_edges_lock);
353
355 return m_call_edges;
356
357 Log *log = GetLog(LLDBLog::Step);
358 LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
360
362
363 // Find the SymbolFile which provided this function's definition.
364 Block &block = GetBlock(/*can_create*/true);
365 SymbolFile *sym_file = block.GetSymbolFile();
366 if (!sym_file)
367 return {};
368
369 // Lazily read call site information from the SymbolFile.
371
372 // Sort the call edges to speed up return_pc lookups.
373 llvm::sort(m_call_edges, [](const std::unique_ptr<CallEdge> &LHS,
374 const std::unique_ptr<CallEdge> &RHS) {
375 return LHS->GetSortKey() < RHS->GetSortKey();
376 });
377
378 return m_call_edges;
379}
380
381llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
382 // Tail calling edges are sorted at the end of the list. Find them by dropping
383 // all non-tail-calls.
384 return GetCallEdges().drop_until(
385 [](const std::unique_ptr<CallEdge> &edge) { return edge->IsTailCall(); });
386}
387
389 Target &target) {
390 auto edges = GetCallEdges();
391 auto edge_it =
392 llvm::partition_point(edges, [&](const std::unique_ptr<CallEdge> &edge) {
393 return std::make_pair(edge->IsTailCall(),
394 edge->GetReturnPCAddress(*this, target)) <
395 std::make_pair(false, return_pc);
396 });
397 if (edge_it == edges.end() ||
398 edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
399 return nullptr;
400 return edge_it->get();
401}
402
403Block &Function::GetBlock(bool can_create) {
404 if (!m_block.BlockInfoHasBeenParsed() && can_create) {
406 if (module_sp) {
407 module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
408 } else {
409 Debugger::ReportError(llvm::formatv(
410 "unable to find module shared pointer for function '{0}' in {1}",
411 GetName().GetCString(), m_comp_unit->GetPrimaryFile().GetPath()));
412 }
413 m_block.SetBlockInfoHasBeenParsed(true, true);
414 }
415 return m_block;
416}
417
419
421
423 Target *target) {
424 ConstString name = GetName();
425 ConstString mangled = m_mangled.GetMangledName();
426
427 *s << "id = " << (const UserID &)*this;
428 if (name)
429 s->AsRawOstream() << ", name = \"" << name << '"';
430 if (mangled)
431 s->AsRawOstream() << ", mangled = \"" << mangled << '"';
432 if (level == eDescriptionLevelVerbose) {
433 *s << ", decl_context = {";
434 auto decl_context = GetCompilerContext();
435 // Drop the function itself from the context chain.
436 if (decl_context.size())
437 decl_context.pop_back();
438 llvm::interleaveComma(decl_context, *s, [&](auto &ctx) { ctx.Dump(*s); });
439 *s << "}";
440 }
441 *s << ", range" << (m_block.GetNumRanges() > 1 ? "s" : "") << " = ";
442 Address::DumpStyle fallback_style =
446 for (unsigned idx = 0; idx < m_block.GetNumRanges(); ++idx) {
447 AddressRange range;
448 m_block.GetRangeAtIndex(idx, range);
449 range.Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
450 }
451}
452
453void Function::Dump(Stream *s, bool show_context) const {
454 s->Printf("%p: ", static_cast<const void *>(this));
455 s->Indent();
456 *s << "Function" << static_cast<const UserID &>(*this);
457
458 m_mangled.Dump(s);
459
460 if (m_type)
461 s->Printf(", type = %p", static_cast<void *>(m_type));
462 else if (m_type_uid != LLDB_INVALID_UID)
463 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
464
465 s->EOL();
466 // Dump the root object
467 if (m_block.BlockInfoHasBeenParsed())
468 m_block.Dump(s, m_address.GetFileAddress(), INT_MAX, show_context);
469}
470
472 sc->function = this;
473 m_comp_unit->CalculateSymbolContext(sc);
474}
475
477 if (SectionSP section_sp = m_address.GetSection())
478 return section_sp->GetModule();
479
480 return this->GetCompileUnit()->GetModule();
481}
482
486
488
490 const char *flavor,
491 bool prefer_file_cache) {
492 ModuleSP module_sp = GetAddress().GetModule();
493 if (module_sp && exe_ctx.HasTargetScope()) {
495 module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
496 exe_ctx.GetTargetRef(), GetAddressRanges(), !prefer_file_cache);
497 }
498 return lldb::DisassemblerSP();
499}
500
502 const char *flavor, Stream &strm,
503 bool prefer_file_cache) {
504 lldb::DisassemblerSP disassembler_sp =
505 GetInstructions(exe_ctx, flavor, prefer_file_cache);
506 if (disassembler_sp) {
507 const bool show_address = true;
508 const bool show_bytes = false;
509 const bool show_control_flow_kind = false;
510 disassembler_sp->GetInstructionList().Dump(
511 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
512 return true;
513 }
514 return false;
515}
516
517// Symbol *
518// Function::CalculateSymbolContextSymbol ()
519//{
520// return // TODO: find the symbol for the function???
521//}
522
524 m_comp_unit->DumpSymbolContext(s);
525 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
526}
527
529 bool result = false;
530
531 // Currently optimization is only indicted by the vendor extension
532 // DW_AT_APPLE_optimized which is set on a compile unit level.
533 if (m_comp_unit) {
534 result = m_comp_unit->GetIsOptimized();
535 }
536 return result;
537}
538
540 bool result = false;
541
542 if (Language *language = Language::FindPlugin(GetLanguage()))
543 result = language->IsTopLevelFunction(*this);
544
545 return result;
546}
547
549 return m_mangled.GetDisplayDemangledName();
550}
551
553 if (ModuleSP module_sp = CalculateSymbolContextModule())
554 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
555 return sym_file->GetDeclContextForUID(GetID());
556 return {};
557}
558
559std::vector<CompilerContext> Function::GetCompilerContext() {
560 if (ModuleSP module_sp = CalculateSymbolContextModule())
561 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
562 return sym_file->GetCompilerContextForUID(GetID());
563 return {};
564}
565
567 if (m_type == nullptr) {
568 SymbolContext sc;
569
571
572 if (!sc.module_sp)
573 return nullptr;
574
575 SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
576
577 if (sym_file == nullptr)
578 return nullptr;
579
580 m_type = sym_file->ResolveTypeUID(m_type_uid);
581 }
582 return m_type;
583}
584
585const Type *Function::GetType() const { return m_type; }
586
588 Type *function_type = GetType();
589 if (function_type)
590 return function_type->GetFullCompilerType();
591 return CompilerType();
592}
593
595 if (m_prologue_byte_size == 0 &&
598 LineTable *line_table = m_comp_unit->GetLineTable();
599 uint32_t prologue_end_line_idx = 0;
600
601 if (line_table) {
602 LineEntry first_line_entry;
603 uint32_t first_line_entry_idx = UINT32_MAX;
604 bool found_first_line_entry =
605 GetStartLineTableEntry(first_line_entry, &first_line_entry_idx);
606
607 if (found_first_line_entry) {
608 // Make sure the first line entry isn't already the end of the prologue
609 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
610 addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
611
612 if (first_line_entry.is_prologue_end) {
613 prologue_end_file_addr =
614 first_line_entry.range.GetBaseAddress().GetFileAddress();
615 prologue_end_line_idx = first_line_entry_idx;
616 } else {
617 // Check the first few instructions and look for one that has
618 // is_prologue_end set to true.
619 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
620 for (uint32_t idx = first_line_entry_idx + 1;
621 idx < last_line_entry_idx; ++idx) {
622 LineEntry line_entry;
623 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
624 if (line_entry.is_prologue_end) {
625 prologue_end_file_addr =
626 line_entry.range.GetBaseAddress().GetFileAddress();
627 prologue_end_line_idx = idx;
628 break;
629 }
630 }
631 }
632 }
633
634 // If we didn't find the end of the prologue in the line tables, then
635 // just use the end address of the first line table entry
636 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
637 // Check the first few instructions and look for one that has a line
638 // number that's different than the first entry.
639 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
640 for (uint32_t idx = first_line_entry_idx + 1;
641 idx < last_line_entry_idx; ++idx) {
642 LineEntry line_entry;
643 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
644 if (line_entry.line != first_line_entry.line) {
645 prologue_end_file_addr =
646 line_entry.range.GetBaseAddress().GetFileAddress();
647 prologue_end_line_idx = idx;
648 break;
649 }
650 }
651 }
652
653 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
654 prologue_end_file_addr =
655 first_line_entry.range.GetBaseAddress().GetFileAddress() +
656 first_line_entry.range.GetByteSize();
657 prologue_end_line_idx = first_line_entry_idx;
658 }
659 }
660
661 AddressRange entry_range;
662 m_block.GetRangeContainingAddress(m_address, entry_range);
663
664 // Deliberately not starting at entry_range.GetBaseAddress() because the
665 // function entry point need not be the first address in the range.
666 const addr_t func_start_file_addr = m_address.GetFileAddress();
667 const addr_t range_end_file_addr =
668 entry_range.GetBaseAddress().GetFileAddress() +
669 entry_range.GetByteSize();
670
671 // Now calculate the offset to pass the subsequent line 0 entries.
672 uint32_t first_non_zero_line = prologue_end_line_idx;
673 while (true) {
674 LineEntry line_entry;
675 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
676 line_entry)) {
677 if (line_entry.line != 0)
678 break;
679 }
680 if (line_entry.range.GetBaseAddress().GetFileAddress() >=
681 range_end_file_addr)
682 break;
683
684 first_non_zero_line++;
685 }
686
687 if (first_non_zero_line > prologue_end_line_idx) {
688 LineEntry first_non_zero_entry;
689 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
690 first_non_zero_entry)) {
691 line_zero_end_file_addr =
692 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
693 }
694 }
695
696 // Verify that this prologue end file address inside the function just
697 // to be sure
698 if (func_start_file_addr < prologue_end_file_addr &&
699 prologue_end_file_addr < range_end_file_addr) {
700 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
701 }
702
703 if (prologue_end_file_addr < line_zero_end_file_addr &&
704 line_zero_end_file_addr < range_end_file_addr) {
706 line_zero_end_file_addr - prologue_end_file_addr;
707 }
708 }
709 }
710 }
711
713}
714
716 lldb::LanguageType lang = m_mangled.GuessLanguage();
717 if (lang != lldb::eLanguageTypeUnknown)
718 return lang;
719
720 if (m_comp_unit)
721 return m_comp_unit->GetLanguage();
722
724}
725
727 return m_mangled.GetName();
728}
729
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:375
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
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:859
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:457
Represent a call made within a Function.
Definition Function.h:253
AddrType caller_address_type
Definition Function.h:310
CallSiteParameterArray parameters
Definition Function.h:313
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:148
lldb::addr_t caller_address
Definition Function.h:309
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:125
CallEdge(AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &&parameters)
Definition Function.cpp:120
lldb::addr_t GetUnresolvedReturnPCAddress() const
Like GetReturnPCAddress, but returns an unresolved file address.
Definition Function.h:302
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.
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
Definition Function.cpp:194
std::once_flag m_resolved_flag
Definition Function.h:333
Function * ResolveCallee(ModuleList &images)
Definition Function.cpp:153
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:186
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.
Definition Function.cpp:54
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition Function.cpp:40
virtual ~FunctionInfo()
Destructor.
ConstString GetName() const
Get accessor for the method name.
Definition Function.cpp:60
FunctionInfo(const char *name, const Declaration *decl_ptr)
Construct with the function method name and optional declaration information.
Definition Function.cpp:32
ConstString m_name
Function method name (not a mangled name).
Definition Function.h:111
static int Compare(const FunctionInfo &lhs, const FunctionInfo &rhs)
Compare two function information objects.
Definition Function.cpp:46
Declaration m_declaration
Information describing where this function information was defined.
Definition Function.h:114
A class that describes a function.
Definition Function.h:377
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
Definition Function.h:668
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
Definition Function.h:658
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
Definition Function.cpp:528
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
Definition Function.h:635
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:430
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition Function.cpp:422
CompilerType GetCompilerType()
Definition Function.cpp:587
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Definition Function.cpp:539
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Function.cpp:476
CompileUnit * m_comp_unit
The compile unit that owns this function.
Definition Function.h:632
ConstString GetName() const
Definition Function.cpp:726
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:388
void GetStartLineSourceInfo(SupportFileNSP &source_file_sp, uint32_t &line_no)
Find the source file and line number for the start of the function.
Definition Function.cpp:300
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:351
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Definition Function.cpp:453
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
Definition Function.h:628
Block m_block
All lexical blocks contained in this function.
Definition Function.h:646
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
Definition Function.h:639
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Function.cpp:471
Address m_address
The address (entry point) of the function.
Definition Function.h:649
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Function.cpp:523
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:381
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Definition Function.cpp:501
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition Function.cpp:566
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:662
lldb::LanguageType GetLanguage() const
Definition Function.cpp:715
bool GetStartLineTableEntry(LineEntry &line_entry, uint32_t *index=nullptr)
Get the line table entry for the function's entry point.
Definition Function.cpp:272
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:255
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition Function.cpp:594
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition Function.cpp:552
AddressRanges GetAddressRanges()
Definition Function.h:425
CompileUnit * CalculateSymbolContextCompileUnit() override
Definition Function.cpp:483
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:325
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:418
~Function() override
Destructor.
bool m_call_edges_resolved
Whether call site info has been parsed.
Definition Function.h:665
ConstString GetDisplayName() const
Definition Function.cpp:548
ConstString GetNameNoArguments() const
Definition Function.cpp:730
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Definition Function.cpp:489
Function * CalculateSymbolContextFunction() override
Definition Function.cpp:487
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Definition Function.cpp:559
Range< uint32_t, uint32_t > SourceRange
Definition Function.h:473
Mangled m_mangled
The mangled function name if any.
Definition Function.h:643
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:403
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
Definition Function.cpp:209
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:200
DWARFExpressionList call_target
Definition Function.h:354
void DumpStopContext(Stream *s) const
Definition Function.cpp:84
ConstString GetDisplayName() const
Definition Function.cpp:99
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition Function.cpp:105
ConstString GetName() const
Definition Function.cpp:93
~InlineFunctionInfo() override
Destructor.
Mangled m_mangled
Mangled inlined function name (can be empty if there is no mangled information).
Definition Function.h:230
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:62
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition Function.cpp:78
Mangled & GetMangled()
Get accessor for the mangled name object.
Definition Function.cpp:111
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:125
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:405
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:63
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:376
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow, bool allow_section_end=false)
Definition Target.cpp:3484
CompilerType GetFullCompilerType()
Definition Type.cpp:781
#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:338
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
Definition SupportFile.h:80
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
Definition Function.h:247
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
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:151
SupportFileNSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition LineEntry.h:144
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:165
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