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