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
273 uint32_t &line_no) {
274 line_no = 0;
275 source_file_sp = std::make_shared<SupportFile>();
276
277 if (m_comp_unit == nullptr)
278 return;
279
280 // Initialize m_type if it hasn't been initialized already
281 GetType();
282
283 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
284 source_file_sp =
285 std::make_shared<SupportFile>(m_type->GetDeclaration().GetFile());
286 line_no = m_type->GetDeclaration().GetLine();
287 } else {
288 LineTable *line_table = m_comp_unit->GetLineTable();
289 if (line_table == nullptr)
290 return;
291
292 LineEntry line_entry;
293 if (line_table->FindLineEntryByAddress(GetAddress(), line_entry, nullptr)) {
294 line_no = line_entry.line;
295 source_file_sp = line_entry.file_sp;
296 }
297 }
298}
299
300llvm::Expected<std::pair<SupportFileNSP, Function::SourceRange>>
302 SupportFileNSP source_file_sp = std::make_shared<SupportFile>();
303 uint32_t start_line;
304 GetStartLineSourceInfo(source_file_sp, start_line);
305 LineTable *line_table = m_comp_unit->GetLineTable();
306 if (start_line == 0 || !line_table) {
307 return llvm::createStringErrorV(
308 "Could not find line information for function \"{0}\".", GetName());
309 }
310
311 uint32_t end_line = start_line;
312 for (const AddressRange &range : GetAddressRanges()) {
313 for (auto [idx, end] = line_table->GetLineEntryIndexRange(range); idx < end;
314 ++idx) {
315 LineEntry entry;
316 // Ignore entries belonging to inlined functions or #included files.
317 if (line_table->GetLineEntryAtIndex(idx, entry) &&
318 source_file_sp->Equal(*entry.file_sp,
320 end_line = std::max(end_line, entry.line);
321 }
322 }
323 return std::make_pair(std::move(source_file_sp),
324 SourceRange(start_line, end_line - start_line));
325}
326
327llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
328 std::lock_guard<std::mutex> guard(m_call_edges_lock);
329
331 return m_call_edges;
332
333 Log *log = GetLog(LLDBLog::Step);
334 LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
336
338
339 // Find the SymbolFile which provided this function's definition.
340 Block &block = GetBlock(/*can_create*/true);
341 SymbolFile *sym_file = block.GetSymbolFile();
342 if (!sym_file)
343 return {};
344
345 // Lazily read call site information from the SymbolFile.
347
348 // Sort the call edges to speed up return_pc lookups.
349 llvm::sort(m_call_edges, [](const std::unique_ptr<CallEdge> &LHS,
350 const std::unique_ptr<CallEdge> &RHS) {
351 return LHS->GetSortKey() < RHS->GetSortKey();
352 });
353
354 return m_call_edges;
355}
356
357llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
358 // Tail calling edges are sorted at the end of the list. Find them by dropping
359 // all non-tail-calls.
360 return GetCallEdges().drop_until(
361 [](const std::unique_ptr<CallEdge> &edge) { return edge->IsTailCall(); });
362}
363
365 Target &target) {
366 auto edges = GetCallEdges();
367 auto edge_it =
368 llvm::partition_point(edges, [&](const std::unique_ptr<CallEdge> &edge) {
369 return std::make_pair(edge->IsTailCall(),
370 edge->GetReturnPCAddress(*this, target)) <
371 std::make_pair(false, return_pc);
372 });
373 if (edge_it == edges.end() ||
374 edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
375 return nullptr;
376 return edge_it->get();
377}
378
379Block &Function::GetBlock(bool can_create) {
380 if (!m_block.BlockInfoHasBeenParsed() && can_create) {
382 if (module_sp) {
383 module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
384 } else {
385 Debugger::ReportError(llvm::formatv(
386 "unable to find module shared pointer for function '{0}' in {1}",
387 GetName().GetCString(), m_comp_unit->GetPrimaryFile().GetPath()));
388 }
389 m_block.SetBlockInfoHasBeenParsed(true, true);
390 }
391 return m_block;
392}
393
395
397
399 Target *target) {
400 ConstString name = GetName();
401 ConstString mangled = m_mangled.GetMangledName();
402
403 *s << "id = " << (const UserID &)*this;
404 if (name)
405 s->AsRawOstream() << ", name = \"" << name << '"';
406 if (mangled)
407 s->AsRawOstream() << ", mangled = \"" << mangled << '"';
408 if (level == eDescriptionLevelVerbose) {
409 *s << ", decl_context = {";
410 auto decl_context = GetCompilerContext();
411 // Drop the function itself from the context chain.
412 if (decl_context.size())
413 decl_context.pop_back();
414 llvm::interleaveComma(decl_context, *s, [&](auto &ctx) { ctx.Dump(*s); });
415 *s << "}";
416 }
417 *s << ", range" << (m_block.GetNumRanges() > 1 ? "s" : "") << " = ";
418 Address::DumpStyle fallback_style =
422 for (unsigned idx = 0; idx < m_block.GetNumRanges(); ++idx) {
423 AddressRange range;
424 m_block.GetRangeAtIndex(idx, range);
425 range.Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
426 }
427}
428
429void Function::Dump(Stream *s, bool show_context) const {
430 s->Printf("%p: ", static_cast<const void *>(this));
431 s->Indent();
432 *s << "Function" << static_cast<const UserID &>(*this);
433
434 m_mangled.Dump(s);
435
436 if (m_type)
437 s->Printf(", type = %p", static_cast<void *>(m_type));
438 else if (m_type_uid != LLDB_INVALID_UID)
439 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
440
441 s->EOL();
442 // Dump the root object
443 if (m_block.BlockInfoHasBeenParsed())
444 m_block.Dump(s, m_address.GetFileAddress(), INT_MAX, show_context);
445}
446
448 sc->function = this;
449 m_comp_unit->CalculateSymbolContext(sc);
450}
451
453 if (SectionSP section_sp = m_address.GetSection())
454 return section_sp->GetModule();
455
456 return this->GetCompileUnit()->GetModule();
457}
458
462
464
466 const char *flavor,
467 bool prefer_file_cache) {
468 ModuleSP module_sp = GetAddress().GetModule();
469 if (module_sp && exe_ctx.HasTargetScope()) {
471 module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
472 exe_ctx.GetTargetRef(), GetAddressRanges(), !prefer_file_cache);
473 }
474 return lldb::DisassemblerSP();
475}
476
478 const char *flavor, Stream &strm,
479 bool prefer_file_cache) {
480 lldb::DisassemblerSP disassembler_sp =
481 GetInstructions(exe_ctx, flavor, prefer_file_cache);
482 if (disassembler_sp) {
483 const bool show_address = true;
484 const bool show_bytes = false;
485 const bool show_control_flow_kind = false;
486 disassembler_sp->GetInstructionList().Dump(
487 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
488 return true;
489 }
490 return false;
491}
492
493// Symbol *
494// Function::CalculateSymbolContextSymbol ()
495//{
496// return // TODO: find the symbol for the function???
497//}
498
500 m_comp_unit->DumpSymbolContext(s);
501 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
502}
503
505 bool result = false;
506
507 // Currently optimization is only indicted by the vendor extension
508 // DW_AT_APPLE_optimized which is set on a compile unit level.
509 if (m_comp_unit) {
510 result = m_comp_unit->GetIsOptimized();
511 }
512 return result;
513}
514
516 bool result = false;
517
518 if (Language *language = Language::FindPlugin(GetLanguage()))
519 result = language->IsTopLevelFunction(*this);
520
521 return result;
522}
523
525 return m_mangled.GetDisplayDemangledName();
526}
527
529 if (ModuleSP module_sp = CalculateSymbolContextModule())
530 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
531 return sym_file->GetDeclContextForUID(GetID());
532 return {};
533}
534
535std::vector<CompilerContext> Function::GetCompilerContext() {
536 if (ModuleSP module_sp = CalculateSymbolContextModule())
537 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
538 return sym_file->GetCompilerContextForUID(GetID());
539 return {};
540}
541
543 if (m_type == nullptr) {
544 SymbolContext sc;
545
547
548 if (!sc.module_sp)
549 return nullptr;
550
551 SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
552
553 if (sym_file == nullptr)
554 return nullptr;
555
556 m_type = sym_file->ResolveTypeUID(m_type_uid);
557 }
558 return m_type;
559}
560
561const Type *Function::GetType() const { return m_type; }
562
564 Type *function_type = GetType();
565 if (function_type)
566 return function_type->GetFullCompilerType();
567 return CompilerType();
568}
569
571 if (m_prologue_byte_size == 0 &&
574 LineTable *line_table = m_comp_unit->GetLineTable();
575 uint32_t prologue_end_line_idx = 0;
576
577 if (line_table) {
578 LineEntry first_line_entry;
579 uint32_t first_line_entry_idx = UINT32_MAX;
580 bool found_first_line_entry = line_table->FindLineEntryByAddress(
581 GetAddress(), first_line_entry, &first_line_entry_idx);
582
583 // When the entry point isn't covered (e.g. WebAssembly), fall back to the
584 // first line entry that begins within the function so the prologue is
585 // still skipped to a real instruction instead of leaving the breakpoint
586 // on the (unexecutable) entry address.
587 if (!found_first_line_entry) {
588 AddressRange entry_range;
589 if (m_block.GetRangeContainingAddress(m_address, entry_range)) {
590 const addr_t func_start_addr = m_address.GetFileAddress();
591 const addr_t func_end_addr =
592 entry_range.GetBaseAddress().GetFileAddress() +
593 entry_range.GetByteSize();
594 const uint32_t line_table_size = line_table->GetSize();
595 for (uint32_t idx = 0; idx < line_table_size; ++idx) {
596 LineEntry line_entry;
597 bool success = line_table->GetLineEntryAtIndex(idx, line_entry);
598 assert(success && "idx is within the line table size");
600 const addr_t entry_addr =
601 line_entry.range.GetBaseAddress().GetFileAddress();
602 if (entry_addr >= func_start_addr && entry_addr < func_end_addr) {
603 first_line_entry = line_entry;
604 first_line_entry_idx = idx;
605 found_first_line_entry = true;
606 break;
607 }
608 }
609 }
610 }
611
612 if (found_first_line_entry) {
613 // Make sure the first line entry isn't already the end of the prologue
614 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
615 addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
616
617 if (first_line_entry.is_prologue_end) {
618 prologue_end_file_addr =
619 first_line_entry.range.GetBaseAddress().GetFileAddress();
620 prologue_end_line_idx = first_line_entry_idx;
621 } else {
622 // Check the first few instructions and look for one that has
623 // is_prologue_end set to true.
624 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
625 for (uint32_t idx = first_line_entry_idx + 1;
626 idx < last_line_entry_idx; ++idx) {
627 LineEntry line_entry;
628 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
629 if (line_entry.is_prologue_end) {
630 prologue_end_file_addr =
631 line_entry.range.GetBaseAddress().GetFileAddress();
632 prologue_end_line_idx = idx;
633 break;
634 }
635 }
636 }
637 }
638
639 // If we didn't find the end of the prologue in the line tables, then
640 // just use the end address of the first line table entry
641 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
642 // Check the first few instructions and look for one that has a line
643 // number that's different than the first entry.
644 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
645 for (uint32_t idx = first_line_entry_idx + 1;
646 idx < last_line_entry_idx; ++idx) {
647 LineEntry line_entry;
648 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
649 if (line_entry.line != first_line_entry.line) {
650 prologue_end_file_addr =
651 line_entry.range.GetBaseAddress().GetFileAddress();
652 prologue_end_line_idx = idx;
653 break;
654 }
655 }
656 }
657
658 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
659 prologue_end_file_addr =
660 first_line_entry.range.GetBaseAddress().GetFileAddress() +
661 first_line_entry.range.GetByteSize();
662 prologue_end_line_idx = first_line_entry_idx;
663 }
664 }
665
666 AddressRange entry_range;
667 m_block.GetRangeContainingAddress(m_address, entry_range);
668
669 // Deliberately not starting at entry_range.GetBaseAddress() because the
670 // function entry point need not be the first address in the range.
671 const addr_t func_start_file_addr = m_address.GetFileAddress();
672 const addr_t range_end_file_addr =
673 entry_range.GetBaseAddress().GetFileAddress() +
674 entry_range.GetByteSize();
675
676 // Now calculate the offset to pass the subsequent line 0 entries.
677 uint32_t first_non_zero_line = prologue_end_line_idx;
678 while (true) {
679 LineEntry line_entry;
680 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
681 line_entry)) {
682 if (line_entry.line != 0)
683 break;
684 }
685 if (line_entry.range.GetBaseAddress().GetFileAddress() >=
686 range_end_file_addr)
687 break;
688
689 first_non_zero_line++;
690 }
691
692 if (first_non_zero_line > prologue_end_line_idx) {
693 LineEntry first_non_zero_entry;
694 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
695 first_non_zero_entry)) {
696 line_zero_end_file_addr =
697 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
698 }
699 }
700
701 // Verify that this prologue end file address inside the function just
702 // to be sure
703 if (func_start_file_addr < prologue_end_file_addr &&
704 prologue_end_file_addr < range_end_file_addr) {
705 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
706 }
707
708 if (prologue_end_file_addr < line_zero_end_file_addr &&
709 line_zero_end_file_addr < range_end_file_addr) {
711 line_zero_end_file_addr - prologue_end_file_addr;
712 }
713 }
714 }
715 }
716
718}
719
721 lldb::LanguageType lang = m_mangled.GuessLanguage();
722 if (lang != lldb::eLanguageTypeUnknown)
723 return lang;
724
725 if (m_comp_unit)
726 return m_comp_unit->GetLanguage();
727
729}
730
732 return m_mangled.GetName();
733}
734
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:376
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:406
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:252
AddrType caller_address_type
Definition Function.h:309
CallSiteParameterArray parameters
Definition Function.h:312
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:308
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:301
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:332
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:110
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:113
A class that describes a function.
Definition Function.h:376
std::vector< std::unique_ptr< CallEdge > > m_call_edges
Outgoing call edges.
Definition Function.h:646
uint32_t m_prologue_byte_size
Compute the prologue size once and cache it.
Definition Function.h:636
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this function.
Definition Function.cpp:504
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
Definition Function.h:613
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:429
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition Function.cpp:398
CompilerType GetCompilerType()
Definition Function.cpp:563
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Definition Function.cpp:515
lldb::ModuleSP CalculateSymbolContextModule() override
Definition Function.cpp:452
CompileUnit * m_comp_unit
The compile unit that owns this function.
Definition Function.h:610
ConstString GetName() const
Definition Function.cpp:731
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:364
void GetStartLineSourceInfo(SupportFileNSP &source_file_sp, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
Definition Function.cpp:272
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:327
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Definition Function.cpp:429
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
Definition Function.h:606
Block m_block
All lexical blocks contained in this function.
Definition Function.h:624
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
Definition Function.h:617
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition Function.cpp:447
Address m_address
The address (entry point) of the function.
Definition Function.h:627
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition Function.cpp:499
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition Function.cpp:357
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Definition Function.cpp:477
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition Function.cpp:542
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:640
lldb::LanguageType GetLanguage() const
Definition Function.cpp:720
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:570
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition Function.cpp:528
AddressRanges GetAddressRanges()
Definition Function.h:424
CompileUnit * CalculateSymbolContextCompileUnit() override
Definition Function.cpp:459
llvm::Expected< std::pair< SupportFileNSP, SourceRange > > GetSourceInfo()
Find the file and line number range of the function.
Definition Function.cpp:301
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition Function.cpp:394
~Function() override
Destructor.
bool m_call_edges_resolved
Whether call site info has been parsed.
Definition Function.h:643
ConstString GetDisplayName() const
Definition Function.cpp:524
ConstString GetNameNoArguments() const
Definition Function.cpp:735
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Definition Function.cpp:465
Function * CalculateSymbolContextFunction() override
Definition Function.cpp:463
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Definition Function.cpp:535
Range< uint32_t, uint32_t > SourceRange
Definition Function.h:451
Mangled m_mangled
The mangled function name if any.
Definition Function.h:621
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition Function.cpp:379
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:353
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:229
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.
uint32_t GetSize() const
Gets the size of the line table in number of line table entries.
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 UNUSED_IF_ASSERT_DISABLED(x)
#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:339
NonNullSharedPtr< lldb_private::SupportFile > SupportFileNSP
Definition SupportFile.h:80
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
Definition Function.h:246
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