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