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 SymbolContext sc;
155 addr.CalculateSymbolContext(&sc, eSymbolContextFunction);
156 if (!sc.function) {
158 "CallEdge: Could not find complete function");
159 return SymbolContext();
160 }
161 return sc;
162}
163
165 if (!m_symbol_name)
166 return Address();
167
168 Log *log = GetLog(LLDBLog::Step);
169 LLDB_LOG(log, "DirectCallEdge: Parsing the call graph for {0}",
171
172 SymbolContextList sc_list;
173 images.FindFunctionSymbols(ConstString(m_symbol_name), eFunctionNameTypeAuto,
174 sc_list);
175 size_t num_matches = sc_list.GetSize();
176 if (num_matches == 0 || !sc_list[0].symbol) {
177 LLDB_LOG(log, "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
179 return Address();
180 }
181
182 Address callee_addr = sc_list[0].symbol->GetAddress();
183 if (!callee_addr.IsValid()) {
184 LLDB_LOG(log, "DirectCallEdge: Invalid symbol address");
185 return Address();
186 }
187
188 return callee_addr;
189}
190
198
203
212
214 ExecutionContext &exe_ctx) {
215 Log *log = GetLog(LLDBLog::Step);
217 llvm::Expected<Value> callee_addr_val = call_target.Evaluate(
218 &exe_ctx, exe_ctx.GetRegisterContext(), LLDB_INVALID_ADDRESS,
219 /*initial_value_ptr=*/nullptr,
220 /*object_address_ptr=*/nullptr);
221 if (!callee_addr_val) {
222 LLDB_LOG_ERROR(log, callee_addr_val.takeError(),
223 "IndirectCallEdge: Could not evaluate expression: {0}");
224 return SymbolContext();
225 }
226
227 addr_t raw_addr =
228 callee_addr_val->GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
229 if (raw_addr == LLDB_INVALID_ADDRESS) {
230 LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar");
231 return SymbolContext();
232 }
233
234 if (auto *process = exe_ctx.GetProcessPtr()) {
235 raw_addr = process->FixCodeAddress(raw_addr);
236 } else {
237 LLDB_LOG(log, "IndirectCallEdge: No Process available, unable to call "
238 "FixCodeAddress on function pointer");
239 }
240
241 Address callee_addr;
242 if (!exe_ctx.GetTargetPtr()->ResolveLoadAddress(raw_addr, callee_addr)) {
243 LLDB_LOG(log, "IndirectCallEdge: Could not resolve callee's load address");
244 return SymbolContext();
245 }
246
247 return ResolveCallee(callee_addr);
248}
249
250/// @}
251
252//
254 lldb::user_id_t type_uid, const Mangled &mangled, Type *type,
255 Address address, AddressRanges ranges)
256 : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
257 m_type(type), m_mangled(mangled), m_block(*this, func_uid),
258 m_address(std::move(address)), m_prologue_byte_size(0) {
259 assert(comp_unit != nullptr);
260 lldb::addr_t base_file_addr = m_address.GetFileAddress();
261 for (const AddressRange &range : ranges)
262 m_block.AddRange(
263 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
264 range.GetByteSize()));
265 m_block.FinalizeRanges();
266}
267
268Function::~Function() = default;
269
270bool Function::GetStartLineTableEntry(LineEntry &line_entry, uint32_t *index) {
271 LineTable *line_table = m_comp_unit ? m_comp_unit->GetLineTable() : nullptr;
272 if (line_table == nullptr)
273 return false;
274
275 uint32_t line_entry_idx = UINT32_MAX;
276 if (line_table->FindLineEntryByAddress(GetAddress(), line_entry,
277 &line_entry_idx)) {
278 if (index)
279 *index = line_entry_idx;
280 return true;
281 }
282
283 // The entry point has no line row (e.g. a WebAssembly function's
284 // locals-declaration header), so take the first row inside the function.
285 AddressRange entry_range;
286 if (!m_block.GetRangeContainingAddress(m_address, entry_range))
287 return false;
288 auto [first, last] = line_table->GetLineEntryIndexRange(entry_range);
289 if (first == last)
290 return false;
291 if (!line_table->GetLineEntryAtIndex(first, line_entry))
292 return false;
293 if (index)
294 *index = first;
295 return true;
296}
297
299 uint32_t &line_no) {
300 line_no = 0;
301 source_file_sp = std::make_shared<SupportFile>();
302
303 if (m_comp_unit == nullptr)
304 return;
305
306 // Initialize m_type if it hasn't been initialized already
307 GetType();
308
309 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
310 source_file_sp =
311 std::make_shared<SupportFile>(m_type->GetDeclaration().GetFile());
312 line_no = m_type->GetDeclaration().GetLine();
313 } else {
314 LineEntry line_entry;
315 if (GetStartLineTableEntry(line_entry)) {
316 line_no = line_entry.line;
317 source_file_sp = line_entry.file_sp;
318 }
319 }
320}
321
322llvm::Expected<std::pair<SupportFileNSP, Function::SourceRange>>
324 SupportFileNSP source_file_sp = std::make_shared<SupportFile>();
325 uint32_t start_line;
326 GetStartLineSourceInfo(source_file_sp, start_line);
327 LineTable *line_table = m_comp_unit->GetLineTable();
328 if (start_line == 0 || !line_table) {
329 return llvm::createStringErrorV(
330 "Could not find line information for function \"{0}\".", GetName());
331 }
332
333 uint32_t end_line = start_line;
334 for (const AddressRange &range : GetAddressRanges()) {
335 for (auto [idx, end] = line_table->GetLineEntryIndexRange(range); idx < end;
336 ++idx) {
337 LineEntry entry;
338 // Ignore entries belonging to inlined functions or #included files.
339 if (line_table->GetLineEntryAtIndex(idx, entry) &&
340 source_file_sp->Equal(*entry.file_sp,
342 end_line = std::max(end_line, entry.line);
343 }
344 }
345 return std::make_pair(std::move(source_file_sp),
346 SourceRange(start_line, end_line - start_line));
347}
348
349llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
350 std::lock_guard<std::mutex> guard(m_call_edges_lock);
351
353 return m_call_edges;
354
355 Log *log = GetLog(LLDBLog::Step);
356 LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
358
360
361 // Find the SymbolFile which provided this function's definition.
362 Block &block = GetBlock(/*can_create*/true);
363 SymbolFile *sym_file = block.GetSymbolFile();
364 if (!sym_file)
365 return {};
366
367 // Lazily read call site information from the SymbolFile.
369
370 // Sort the call edges to speed up return_pc lookups.
371 llvm::sort(m_call_edges, [](const std::unique_ptr<CallEdge> &LHS,
372 const std::unique_ptr<CallEdge> &RHS) {
373 return LHS->GetSortKey() < RHS->GetSortKey();
374 });
375
376 return m_call_edges;
377}
378
379llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
380 // Tail calling edges are sorted at the end of the list. Find them by dropping
381 // all non-tail-calls.
382 return GetCallEdges().drop_until(
383 [](const std::unique_ptr<CallEdge> &edge) { return edge->IsTailCall(); });
384}
385
387 Target &target) {
388 auto edges = GetCallEdges();
389 auto edge_it =
390 llvm::partition_point(edges, [&](const std::unique_ptr<CallEdge> &edge) {
391 return std::make_pair(edge->IsTailCall(),
392 edge->GetReturnPCAddress(*this, target)) <
393 std::make_pair(false, return_pc);
394 });
395 if (edge_it == edges.end() ||
396 edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
397 return nullptr;
398 return edge_it->get();
399}
400
401Block &Function::GetBlock(bool can_create) {
402 if (!m_block.BlockInfoHasBeenParsed() && can_create) {
404 if (module_sp) {
405 module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
406 } else {
407 Debugger::ReportError(llvm::formatv(
408 "unable to find module shared pointer for function '{0}' in {1}",
409 GetName().GetCString(), m_comp_unit->GetPrimaryFile().GetPath()));
410 }
411 m_block.SetBlockInfoHasBeenParsed(true, true);
412 }
413 return m_block;
414}
415
417
419
421 Target *target) {
422 ConstString name = GetName();
423 ConstString mangled = m_mangled.GetMangledName();
424
425 *s << "id = " << (const UserID &)*this;
426 if (name)
427 s->AsRawOstream() << ", name = \"" << name << '"';
428 if (mangled)
429 s->AsRawOstream() << ", mangled = \"" << mangled << '"';
430 if (level == eDescriptionLevelVerbose) {
431 *s << ", decl_context = {";
432 auto decl_context = GetCompilerContext();
433 // Drop the function itself from the context chain.
434 if (decl_context.size())
435 decl_context.pop_back();
436 llvm::interleaveComma(decl_context, *s, [&](auto &ctx) { ctx.Dump(*s); });
437 *s << "}";
438 }
439 *s << ", range" << (m_block.GetNumRanges() > 1 ? "s" : "") << " = ";
440 Address::DumpStyle fallback_style =
444 for (unsigned idx = 0; idx < m_block.GetNumRanges(); ++idx) {
445 AddressRange range;
446 m_block.GetRangeAtIndex(idx, range);
447 range.Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
448 }
449}
450
451void Function::Dump(Stream *s, bool show_context) const {
452 s->Printf("%p: ", static_cast<const void *>(this));
453 s->Indent();
454 *s << "Function" << static_cast<const UserID &>(*this);
455
456 m_mangled.Dump(s);
457
458 if (m_type)
459 s->Printf(", type = %p", static_cast<void *>(m_type));
460 else if (m_type_uid != LLDB_INVALID_UID)
461 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
462
463 s->EOL();
464 // Dump the root object
465 if (m_block.BlockInfoHasBeenParsed())
466 m_block.Dump(s, m_address.GetFileAddress(), INT_MAX, show_context);
467}
468
470 sc->function = this;
471 m_comp_unit->CalculateSymbolContext(sc);
472}
473
475 if (SectionSP section_sp = m_address.GetSection())
476 return section_sp->GetModule();
477
478 return this->GetCompileUnit()->GetModule();
479}
480
484
486
488 const char *flavor,
489 bool prefer_file_cache) {
490 ModuleSP module_sp = GetAddress().GetModule();
491 if (module_sp && exe_ctx.HasTargetScope()) {
493 module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
494 exe_ctx.GetTargetRef(), GetAddressRanges(), !prefer_file_cache);
495 }
496 return lldb::DisassemblerSP();
497}
498
500 const char *flavor, Stream &strm,
501 bool prefer_file_cache) {
502 lldb::DisassemblerSP disassembler_sp =
503 GetInstructions(exe_ctx, flavor, prefer_file_cache);
504 if (disassembler_sp) {
505 const bool show_address = true;
506 const bool show_bytes = false;
507 const bool show_control_flow_kind = false;
508 disassembler_sp->GetInstructionList().Dump(
509 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
510 return true;
511 }
512 return false;
513}
514
515// Symbol *
516// Function::CalculateSymbolContextSymbol ()
517//{
518// return // TODO: find the symbol for the function???
519//}
520
522 m_comp_unit->DumpSymbolContext(s);
523 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
524}
525
527 bool result = false;
528
529 // Currently optimization is only indicted by the vendor extension
530 // DW_AT_APPLE_optimized which is set on a compile unit level.
531 if (m_comp_unit) {
532 result = m_comp_unit->GetIsOptimized();
533 }
534 return result;
535}
536
538 bool result = false;
539
540 if (Language *language = Language::FindPlugin(GetLanguage()))
541 result = language->IsTopLevelFunction(*this);
542
543 return result;
544}
545
547 return m_mangled.GetDisplayDemangledName();
548}
549
551 if (ModuleSP module_sp = CalculateSymbolContextModule())
552 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
553 return sym_file->GetDeclContextForUID(GetID());
554 return {};
555}
556
557std::vector<CompilerContext> Function::GetCompilerContext() {
558 if (ModuleSP module_sp = CalculateSymbolContextModule())
559 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
560 return sym_file->GetCompilerContextForUID(GetID());
561 return {};
562}
563
565 if (m_type == nullptr) {
566 SymbolContext sc;
567
569
570 if (!sc.module_sp)
571 return nullptr;
572
573 SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
574
575 if (sym_file == nullptr)
576 return nullptr;
577
578 m_type = sym_file->ResolveTypeUID(m_type_uid);
579 }
580 return m_type;
581}
582
583const Type *Function::GetType() const { return m_type; }
584
586 Type *function_type = GetType();
587 if (function_type)
588 return function_type->GetFullCompilerType();
589 return CompilerType();
590}
591
593 if (m_prologue_byte_size == 0 &&
596 LineTable *line_table = m_comp_unit->GetLineTable();
597 uint32_t prologue_end_line_idx = 0;
598
599 if (line_table) {
600 LineEntry first_line_entry;
601 uint32_t first_line_entry_idx = UINT32_MAX;
602 bool found_first_line_entry =
603 GetStartLineTableEntry(first_line_entry, &first_line_entry_idx);
604
605 if (found_first_line_entry) {
606 // Make sure the first line entry isn't already the end of the prologue
607 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
608 addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
609
610 if (first_line_entry.is_prologue_end) {
611 prologue_end_file_addr =
612 first_line_entry.range.GetBaseAddress().GetFileAddress();
613 prologue_end_line_idx = first_line_entry_idx;
614 } else {
615 // Check the first few instructions and look for one that has
616 // is_prologue_end set to true.
617 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
618 for (uint32_t idx = first_line_entry_idx + 1;
619 idx < last_line_entry_idx; ++idx) {
620 LineEntry line_entry;
621 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
622 if (line_entry.is_prologue_end) {
623 prologue_end_file_addr =
624 line_entry.range.GetBaseAddress().GetFileAddress();
625 prologue_end_line_idx = idx;
626 break;
627 }
628 }
629 }
630 }
631
632 // If we didn't find the end of the prologue in the line tables, then
633 // just use the end address of the first line table entry
634 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
635 // Check the first few instructions and look for one that has a line
636 // number that's different than the first entry.
637 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
638 for (uint32_t idx = first_line_entry_idx + 1;
639 idx < last_line_entry_idx; ++idx) {
640 LineEntry line_entry;
641 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
642 if (line_entry.line != first_line_entry.line) {
643 prologue_end_file_addr =
644 line_entry.range.GetBaseAddress().GetFileAddress();
645 prologue_end_line_idx = idx;
646 break;
647 }
648 }
649 }
650
651 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
652 prologue_end_file_addr =
653 first_line_entry.range.GetBaseAddress().GetFileAddress() +
654 first_line_entry.range.GetByteSize();
655 prologue_end_line_idx = first_line_entry_idx;
656 }
657 }
658
659 AddressRange entry_range;
660 m_block.GetRangeContainingAddress(m_address, entry_range);
661
662 // Deliberately not starting at entry_range.GetBaseAddress() because the
663 // function entry point need not be the first address in the range.
664 const addr_t func_start_file_addr = m_address.GetFileAddress();
665 const addr_t range_end_file_addr =
666 entry_range.GetBaseAddress().GetFileAddress() +
667 entry_range.GetByteSize();
668
669 // Now calculate the offset to pass the subsequent line 0 entries.
670 uint32_t first_non_zero_line = prologue_end_line_idx;
671 while (true) {
672 LineEntry line_entry;
673 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
674 line_entry)) {
675 if (line_entry.line != 0)
676 break;
677 }
678 if (line_entry.range.GetBaseAddress().GetFileAddress() >=
679 range_end_file_addr)
680 break;
681
682 first_non_zero_line++;
683 }
684
685 if (first_non_zero_line > prologue_end_line_idx) {
686 LineEntry first_non_zero_entry;
687 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
688 first_non_zero_entry)) {
689 line_zero_end_file_addr =
690 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
691 }
692 }
693
694 // Verify that this prologue end file address inside the function just
695 // to be sure
696 if (func_start_file_addr < prologue_end_file_addr &&
697 prologue_end_file_addr < range_end_file_addr) {
698 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
699 }
700
701 if (prologue_end_file_addr < line_zero_end_file_addr &&
702 line_zero_end_file_addr < range_end_file_addr) {
704 line_zero_end_file_addr - prologue_end_file_addr;
705 }
706 }
707 }
708 }
709
711}
712
714 lldb::LanguageType lang = m_mangled.GuessLanguage();
715 if (lang != lldb::eLanguageTypeUnknown)
716 return lang;
717
718 if (m_comp_unit)
719 return m_comp_unit->GetLanguage();
720
722}
723
725 return m_mangled.GetName();
726}
727
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:303
uint32_t CalculateSymbolContext(SymbolContext *sc, lldb::SymbolContextItem resolve_scope=lldb::eSymbolContextEverything) const
Reconstruct a symbol context from an address.
Definition Address.cpp:820
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:275
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
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:254
AddrType caller_address_type
Definition Function.h:319
static SymbolContext ResolveCallee(const Address &addr)
Find the function containing addr.
Definition Function.cpp:153
CallSiteParameterArray parameters
Definition Function.h:322
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:318
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:311
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.
SymbolContext GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition, resolved against images.
Definition Function.cpp:199
Address ResolveCalleeAddress(ModuleList &images) const
Definition Function.cpp:164
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:191
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:112
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:115
A class that describes a function.
Definition Function.h:386
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
Definition Function.h:677
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
Definition Function.h:667
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
Definition Function.cpp:526
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
Definition Function.h:644
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:439
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition Function.cpp:420
CompilerType GetCompilerType()
Definition Function.cpp:585
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Definition Function.cpp:537
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Function.cpp:474
CompileUnit * m_comp_unit
The compile unit that owns this function.
Definition Function.h:641
ConstString GetName() const
Definition Function.cpp:724
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:386
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:298
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:349
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Definition Function.cpp:451
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
Definition Function.h:637
Block m_block
All lexical blocks contained in this function.
Definition Function.h:655
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
Definition Function.h:648
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Function.cpp:469
Address m_address
The address (entry point) of the function.
Definition Function.h:658
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Function.cpp:521
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:379
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Definition Function.cpp:499
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition Function.cpp:564
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:671
lldb::LanguageType GetLanguage() const
Definition Function.cpp:713
bool GetStartLineTableEntry(LineEntry &line_entry, uint32_t *index=nullptr)
Get the line table entry for the function's entry point.
Definition Function.cpp:270
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:253
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition Function.cpp:592
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition Function.cpp:550
AddressRanges GetAddressRanges()
Definition Function.h:434
CompileUnit * CalculateSymbolContextCompileUnit() override
Definition Function.cpp:481
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:323
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:416
~Function() override
Destructor.
bool m_call_edges_resolved
Whether call site info has been parsed.
Definition Function.h:674
ConstString GetDisplayName() const
Definition Function.cpp:546
ConstString GetNameNoArguments() const
Definition Function.cpp:728
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Definition Function.cpp:487
Function * CalculateSymbolContextFunction() override
Definition Function.cpp:485
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Definition Function.cpp:557
Range< uint32_t, uint32_t > SourceRange
Definition Function.h:482
Mangled m_mangled
The mangled function name if any.
Definition Function.h:652
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:401
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:204
SymbolContext GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition, resolved against images.
Definition Function.cpp:213
DWARFExpressionList call_target
Definition Function.h:363
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:231
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:3495
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:248
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:83
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