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