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
26using namespace lldb;
27using namespace lldb_private;
28
29// Basic function information is contained in the FunctionInfo class. It is
30// designed to contain the name, linkage name, and declaration location.
31FunctionInfo::FunctionInfo(const char *name, const Declaration *decl_ptr)
32 : m_name(name), m_declaration(decl_ptr) {}
33
35 : m_name(name), m_declaration(decl_ptr) {}
36
38
39void FunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
40 if (m_name)
41 *s << ", name = \"" << m_name << "\"";
42 m_declaration.Dump(s, show_fullpaths);
43}
44
46 int result = ConstString::Compare(a.GetName(), b.GetName());
47 if (result)
48 return result;
49
51}
52
54
56 return m_declaration;
57}
58
60
63}
64
66 llvm::StringRef mangled,
67 const Declaration *decl_ptr,
68 const Declaration *call_decl_ptr)
69 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
70 m_call_decl(call_decl_ptr) {}
71
73 const Mangled &mangled,
74 const Declaration *decl_ptr,
75 const Declaration *call_decl_ptr)
76 : FunctionInfo(name, decl_ptr), m_mangled(mangled),
77 m_call_decl(call_decl_ptr) {}
78
80
81void InlineFunctionInfo::Dump(Stream *s, bool show_fullpaths) const {
82 FunctionInfo::Dump(s, show_fullpaths);
83 if (m_mangled)
84 m_mangled.Dump(s);
85}
86
88 // s->Indent("[inlined] ");
89 s->Indent();
90 if (m_mangled)
92 else
94}
95
97 if (m_mangled)
98 return m_mangled.GetName();
99 return m_name;
100}
101
103 if (m_mangled)
105 return m_name;
106}
107
109
111 return m_call_decl;
112}
113
115
117
120}
121
122/// @name Call site related structures
123/// @{
124
125CallEdge::~CallEdge() = default;
126
127CallEdge::CallEdge(AddrType caller_address_type, lldb::addr_t caller_address,
128 bool is_tail_call, CallSiteParameterArray &&parameters)
129 : caller_address(caller_address), caller_address_type(caller_address_type),
130 is_tail_call(is_tail_call), parameters(std::move(parameters)) {}
131
133 Function &caller, Target &target) {
134 Log *log = GetLog(LLDBLog::Step);
135
136 const Address &caller_start_addr = caller.GetAddressRange().GetBaseAddress();
137
138 ModuleSP caller_module_sp = caller_start_addr.GetModule();
139 if (!caller_module_sp) {
140 LLDB_LOG(log, "GetLoadAddress: cannot get Module for caller");
142 }
143
144 SectionList *section_list = caller_module_sp->GetSectionList();
145 if (!section_list) {
146 LLDB_LOG(log, "GetLoadAddress: cannot get SectionList for Module");
148 }
149
150 Address the_addr = Address(unresolved_pc, section_list);
151 lldb::addr_t load_addr = the_addr.GetLoadAddress(&target);
152 return load_addr;
153}
154
156 Target &target) const {
157 return GetLoadAddress(GetUnresolvedReturnPCAddress(), caller, target);
158}
159
161 if (resolved)
162 return;
163
164 Log *log = GetLog(LLDBLog::Step);
165 LLDB_LOG(log, "DirectCallEdge: Lazily parsing the call graph for {0}",
166 lazy_callee.symbol_name);
167
168 auto resolve_lazy_callee = [&]() -> Function * {
169 ConstString callee_name{lazy_callee.symbol_name};
170 SymbolContextList sc_list;
171 images.FindFunctionSymbols(callee_name, eFunctionNameTypeAuto, sc_list);
172 size_t num_matches = sc_list.GetSize();
173 if (num_matches == 0 || !sc_list[0].symbol) {
174 LLDB_LOG(log,
175 "DirectCallEdge: Found no symbols for {0}, cannot resolve it",
176 callee_name);
177 return nullptr;
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 Function *f = callee_addr.CalculateSymbolContextFunction();
185 if (!f) {
186 LLDB_LOG(log, "DirectCallEdge: Could not find complete function");
187 return nullptr;
188 }
189 return f;
190 };
191 lazy_callee.def = resolve_lazy_callee();
192 resolved = true;
193}
194
195DirectCallEdge::DirectCallEdge(const char *symbol_name,
196 AddrType caller_address_type,
197 lldb::addr_t caller_address, bool is_tail_call,
198 CallSiteParameterArray &&parameters)
199 : CallEdge(caller_address_type, caller_address, is_tail_call,
200 std::move(parameters)) {
201 lazy_callee.symbol_name = symbol_name;
202}
203
206 assert(resolved && "Did not resolve lazy callee");
207 return lazy_callee.def;
208}
209
211 AddrType caller_address_type,
212 lldb::addr_t caller_address,
213 bool is_tail_call,
214 CallSiteParameterArray &&parameters)
215 : CallEdge(caller_address_type, caller_address, is_tail_call,
216 std::move(parameters)),
217 call_target(std::move(call_target)) {}
218
220 ExecutionContext &exe_ctx) {
221 Log *log = GetLog(LLDBLog::Step);
223 llvm::Expected<Value> callee_addr_val = call_target.Evaluate(
224 &exe_ctx, exe_ctx.GetRegisterContext(), LLDB_INVALID_ADDRESS,
225 /*initial_value_ptr=*/nullptr,
226 /*object_address_ptr=*/nullptr);
227 if (!callee_addr_val) {
228 LLDB_LOG_ERROR(log, callee_addr_val.takeError(),
229 "IndirectCallEdge: Could not evaluate expression: {0}");
230 return nullptr;
231 }
232
233 addr_t raw_addr =
234 callee_addr_val->GetScalar().ULongLong(LLDB_INVALID_ADDRESS);
235 if (raw_addr == LLDB_INVALID_ADDRESS) {
236 LLDB_LOG(log, "IndirectCallEdge: Could not extract address from scalar");
237 return nullptr;
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 nullptr;
244 }
245
246 Function *f = callee_addr.CalculateSymbolContextFunction();
247 if (!f) {
248 LLDB_LOG(log, "IndirectCallEdge: Could not find complete function");
249 return nullptr;
250 }
251
252 return f;
253}
254
255/// @}
256
257AddressRange CollapseRanges(llvm::ArrayRef<AddressRange> ranges) {
258 if (ranges.empty())
259 return AddressRange();
260 if (ranges.size() == 1)
261 return ranges[0];
262
263 Address lowest_addr = ranges[0].GetBaseAddress();
264 addr_t highest_addr = lowest_addr.GetFileAddress() + ranges[0].GetByteSize();
265 for (const AddressRange &range : ranges.drop_front()) {
266 Address range_begin = range.GetBaseAddress();
267 addr_t range_end = range_begin.GetFileAddress() + range.GetByteSize();
268 if (range_begin.GetFileAddress() < lowest_addr.GetFileAddress())
269 lowest_addr = range_begin;
270 if (range_end > highest_addr)
271 highest_addr = range_end;
272 }
273 return AddressRange(lowest_addr, highest_addr - lowest_addr.GetFileAddress());
274}
275
276//
278 lldb::user_id_t type_uid, const Mangled &mangled, Type *type,
279 AddressRanges ranges)
280 : UserID(func_uid), m_comp_unit(comp_unit), m_type_uid(type_uid),
281 m_type(type), m_mangled(mangled), m_block(*this, func_uid),
282 m_range(CollapseRanges(ranges)), m_prologue_byte_size(0) {
283 assert(comp_unit != nullptr);
285 for (const AddressRange &range : ranges)
287 Block::Range(range.GetBaseAddress().GetFileAddress() - base_file_addr,
288 range.GetByteSize()));
290}
291
292Function::~Function() = default;
293
295 uint32_t &line_no) {
296 line_no = 0;
297 source_file_sp.reset();
298
299 if (m_comp_unit == nullptr)
300 return;
301
302 // Initialize m_type if it hasn't been initialized already
303 GetType();
304
305 if (m_type != nullptr && m_type->GetDeclaration().GetLine() != 0) {
306 source_file_sp =
307 std::make_shared<SupportFile>(m_type->GetDeclaration().GetFile());
308 line_no = m_type->GetDeclaration().GetLine();
309 } else {
310 LineTable *line_table = m_comp_unit->GetLineTable();
311 if (line_table == nullptr)
312 return;
313
314 LineEntry line_entry;
315 if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
316 line_entry, nullptr)) {
317 line_no = line_entry.line;
318 source_file_sp = line_entry.file_sp;
319 }
320 }
321}
322
323void Function::GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no) {
324 line_no = 0;
325 source_file.Clear();
326
327 // The -1 is kind of cheesy, but I want to get the last line entry for the
328 // given function, not the first entry of the next.
329 Address scratch_addr(GetAddressRange().GetBaseAddress());
330 scratch_addr.SetOffset(scratch_addr.GetOffset() +
331 GetAddressRange().GetByteSize() - 1);
332
333 LineTable *line_table = m_comp_unit->GetLineTable();
334 if (line_table == nullptr)
335 return;
336
337 LineEntry line_entry;
338 if (line_table->FindLineEntryByAddress(scratch_addr, line_entry, nullptr)) {
339 line_no = line_entry.line;
340 source_file = line_entry.GetFile();
341 }
342}
343
344llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetCallEdges() {
345 std::lock_guard<std::mutex> guard(m_call_edges_lock);
346
348 return m_call_edges;
349
350 Log *log = GetLog(LLDBLog::Step);
351 LLDB_LOG(log, "GetCallEdges: Attempting to parse call site info for {0}",
353
355
356 // Find the SymbolFile which provided this function's definition.
357 Block &block = GetBlock(/*can_create*/true);
358 SymbolFile *sym_file = block.GetSymbolFile();
359 if (!sym_file)
360 return std::nullopt;
361
362 // Lazily read call site information from the SymbolFile.
364
365 // Sort the call edges to speed up return_pc lookups.
366 llvm::sort(m_call_edges, [](const std::unique_ptr<CallEdge> &LHS,
367 const std::unique_ptr<CallEdge> &RHS) {
368 return LHS->GetSortKey() < RHS->GetSortKey();
369 });
370
371 return m_call_edges;
372}
373
374llvm::ArrayRef<std::unique_ptr<CallEdge>> Function::GetTailCallingEdges() {
375 // Tail calling edges are sorted at the end of the list. Find them by dropping
376 // all non-tail-calls.
377 return GetCallEdges().drop_until(
378 [](const std::unique_ptr<CallEdge> &edge) { return edge->IsTailCall(); });
379}
380
382 Target &target) {
383 auto edges = GetCallEdges();
384 auto edge_it =
385 llvm::partition_point(edges, [&](const std::unique_ptr<CallEdge> &edge) {
386 return std::make_pair(edge->IsTailCall(),
387 edge->GetReturnPCAddress(*this, target)) <
388 std::make_pair(false, return_pc);
389 });
390 if (edge_it == edges.end() ||
391 edge_it->get()->GetReturnPCAddress(*this, target) != return_pc)
392 return nullptr;
393 return edge_it->get();
394}
395
396Block &Function::GetBlock(bool can_create) {
397 if (!m_block.BlockInfoHasBeenParsed() && can_create) {
399 if (module_sp) {
400 module_sp->GetSymbolFile()->ParseBlocksRecursive(*this);
401 } else {
402 Debugger::ReportError(llvm::formatv(
403 "unable to find module shared pointer for function '{0}' in {1}",
404 GetName().GetCString(), m_comp_unit->GetPrimaryFile().GetPath()));
405 }
407 }
408 return m_block;
409}
410
412
414
416 Target *target) {
417 ConstString name = GetName();
419
420 *s << "id = " << (const UserID &)*this;
421 if (name)
422 s->AsRawOstream() << ", name = \"" << name << '"';
423 if (mangled)
424 s->AsRawOstream() << ", mangled = \"" << mangled << '"';
425 if (level == eDescriptionLevelVerbose) {
426 *s << ", decl_context = {";
427 auto decl_context = GetCompilerContext();
428 // Drop the function itself from the context chain.
429 if (decl_context.size())
430 decl_context.pop_back();
431 llvm::interleaveComma(decl_context, *s, [&](auto &ctx) { ctx.Dump(*s); });
432 *s << "}";
433 }
434 *s << ", range" << (m_block.GetNumRanges() > 1 ? "s" : "") << " = ";
435 Address::DumpStyle fallback_style =
439 for (unsigned idx = 0; idx < m_block.GetNumRanges(); ++idx) {
440 AddressRange range;
441 m_block.GetRangeAtIndex(idx, range);
442 range.Dump(s, target, Address::DumpStyleLoadAddress, fallback_style);
443 }
444}
445
446void Function::Dump(Stream *s, bool show_context) const {
447 s->Printf("%p: ", static_cast<const void *>(this));
448 s->Indent();
449 *s << "Function" << static_cast<const UserID &>(*this);
450
451 m_mangled.Dump(s);
452
453 if (m_type)
454 s->Printf(", type = %p", static_cast<void *>(m_type));
455 else if (m_type_uid != LLDB_INVALID_UID)
456 s->Printf(", type_uid = 0x%8.8" PRIx64, m_type_uid);
457
458 s->EOL();
459 // Dump the root object
462 show_context);
463}
464
466 sc->function = this;
468}
469
472 if (section_sp)
473 return section_sp->GetModule();
474
475 return this->GetCompileUnit()->GetModule();
476}
477
479 return this->GetCompileUnit();
480}
481
483
485 const char *flavor,
486 bool prefer_file_cache) {
487 ModuleSP module_sp(GetAddressRange().GetBaseAddress().GetModule());
488 if (module_sp && exe_ctx.HasTargetScope()) {
490 module_sp->GetArchitecture(), nullptr, nullptr, nullptr, flavor,
491 exe_ctx.GetTargetRef(), GetAddressRange(), !prefer_file_cache);
492 }
493 return lldb::DisassemblerSP();
494}
495
497 const char *flavor, Stream &strm,
498 bool prefer_file_cache) {
499 lldb::DisassemblerSP disassembler_sp =
500 GetInstructions(exe_ctx, flavor, prefer_file_cache);
501 if (disassembler_sp) {
502 const bool show_address = true;
503 const bool show_bytes = false;
504 const bool show_control_flow_kind = false;
505 disassembler_sp->GetInstructionList().Dump(
506 &strm, show_address, show_bytes, show_control_flow_kind, &exe_ctx);
507 return true;
508 }
509 return false;
510}
511
512// Symbol *
513// Function::CalculateSymbolContextSymbol ()
514//{
515// return // TODO: find the symbol for the function???
516//}
517
520 s->Printf(", Function{0x%8.8" PRIx64 "}", GetID());
521}
522
523size_t Function::MemorySize() const {
524 size_t mem_size = sizeof(Function) + m_block.MemorySize();
525 return mem_size;
526}
527
529 bool result = false;
530
531 // Currently optimization is only indicted by the vendor extension
532 // DW_AT_APPLE_optimized which is set on a compile unit level.
533 if (m_comp_unit) {
534 result = m_comp_unit->GetIsOptimized();
535 }
536 return result;
537}
538
540 bool result = false;
541
542 if (Language *language = Language::FindPlugin(GetLanguage()))
543 result = language->IsTopLevelFunction(*this);
544
545 return result;
546}
547
550}
551
553 if (ModuleSP module_sp = CalculateSymbolContextModule())
554 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
555 return sym_file->GetDeclContextForUID(GetID());
556 return {};
557}
558
559std::vector<CompilerContext> Function::GetCompilerContext() {
560 if (ModuleSP module_sp = CalculateSymbolContextModule())
561 if (SymbolFile *sym_file = module_sp->GetSymbolFile())
562 return sym_file->GetCompilerContextForUID(GetID());
563 return {};
564}
565
567 if (m_type == nullptr) {
568 SymbolContext sc;
569
571
572 if (!sc.module_sp)
573 return nullptr;
574
575 SymbolFile *sym_file = sc.module_sp->GetSymbolFile();
576
577 if (sym_file == nullptr)
578 return nullptr;
579
580 m_type = sym_file->ResolveTypeUID(m_type_uid);
581 }
582 return m_type;
583}
584
585const Type *Function::GetType() const { return m_type; }
586
588 Type *function_type = GetType();
589 if (function_type)
590 return function_type->GetFullCompilerType();
591 return CompilerType();
592}
593
595 if (m_prologue_byte_size == 0 &&
598 LineTable *line_table = m_comp_unit->GetLineTable();
599 uint32_t prologue_end_line_idx = 0;
600
601 if (line_table) {
602 LineEntry first_line_entry;
603 uint32_t first_line_entry_idx = UINT32_MAX;
604 if (line_table->FindLineEntryByAddress(GetAddressRange().GetBaseAddress(),
605 first_line_entry,
606 &first_line_entry_idx)) {
607 // Make sure the first line entry isn't already the end of the prologue
608 addr_t prologue_end_file_addr = LLDB_INVALID_ADDRESS;
609 addr_t line_zero_end_file_addr = LLDB_INVALID_ADDRESS;
610
611 if (first_line_entry.is_prologue_end) {
612 prologue_end_file_addr =
613 first_line_entry.range.GetBaseAddress().GetFileAddress();
614 prologue_end_line_idx = first_line_entry_idx;
615 } else {
616 // Check the first few instructions and look for one that has
617 // is_prologue_end set to true.
618 const uint32_t last_line_entry_idx = first_line_entry_idx + 6;
619 for (uint32_t idx = first_line_entry_idx + 1;
620 idx < last_line_entry_idx; ++idx) {
621 LineEntry line_entry;
622 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
623 if (line_entry.is_prologue_end) {
624 prologue_end_file_addr =
625 line_entry.range.GetBaseAddress().GetFileAddress();
626 prologue_end_line_idx = idx;
627 break;
628 }
629 }
630 }
631 }
632
633 // If we didn't find the end of the prologue in the line tables, then
634 // just use the end address of the first line table entry
635 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
636 // Check the first few instructions and look for one that has a line
637 // number that's different than the first entry.
638 uint32_t last_line_entry_idx = first_line_entry_idx + 6;
639 for (uint32_t idx = first_line_entry_idx + 1;
640 idx < last_line_entry_idx; ++idx) {
641 LineEntry line_entry;
642 if (line_table->GetLineEntryAtIndex(idx, line_entry)) {
643 if (line_entry.line != first_line_entry.line) {
644 prologue_end_file_addr =
645 line_entry.range.GetBaseAddress().GetFileAddress();
646 prologue_end_line_idx = idx;
647 break;
648 }
649 }
650 }
651
652 if (prologue_end_file_addr == LLDB_INVALID_ADDRESS) {
653 prologue_end_file_addr =
654 first_line_entry.range.GetBaseAddress().GetFileAddress() +
655 first_line_entry.range.GetByteSize();
656 prologue_end_line_idx = first_line_entry_idx;
657 }
658 }
659
660 const addr_t func_start_file_addr =
662 const addr_t func_end_file_addr =
663 func_start_file_addr + m_range.GetByteSize();
664
665 // Now calculate the offset to pass the subsequent line 0 entries.
666 uint32_t first_non_zero_line = prologue_end_line_idx;
667 while (true) {
668 LineEntry line_entry;
669 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
670 line_entry)) {
671 if (line_entry.line != 0)
672 break;
673 }
674 if (line_entry.range.GetBaseAddress().GetFileAddress() >=
675 func_end_file_addr)
676 break;
677
678 first_non_zero_line++;
679 }
680
681 if (first_non_zero_line > prologue_end_line_idx) {
682 LineEntry first_non_zero_entry;
683 if (line_table->GetLineEntryAtIndex(first_non_zero_line,
684 first_non_zero_entry)) {
685 line_zero_end_file_addr =
686 first_non_zero_entry.range.GetBaseAddress().GetFileAddress();
687 }
688 }
689
690 // Verify that this prologue end file address in the function's address
691 // range just to be sure
692 if (func_start_file_addr < prologue_end_file_addr &&
693 prologue_end_file_addr < func_end_file_addr) {
694 m_prologue_byte_size = prologue_end_file_addr - func_start_file_addr;
695 }
696
697 if (prologue_end_file_addr < line_zero_end_file_addr &&
698 line_zero_end_file_addr < func_end_file_addr) {
700 line_zero_end_file_addr - prologue_end_file_addr;
701 }
702 }
703 }
704 }
705
707}
708
711 if (lang != lldb::eLanguageTypeUnknown)
712 return lang;
713
714 if (m_comp_unit)
715 return m_comp_unit->GetLanguage();
716
718}
719
721 return m_mangled.GetName();
722}
723
726}
static llvm::raw_ostream & error(Stream &strm)
AddressRange CollapseRanges(llvm::ArrayRef< AddressRange > ranges)
Definition: Function.cpp:257
#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.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
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.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
lldb::SectionSP GetSection() const
Get const accessor for the section.
Definition: Address.h:439
Function * CalculateSymbolContextFunction() const
Definition: Address.cpp:872
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:285
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:329
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:448
A class that describes a single lexical block.
Definition: Block.h:41
bool BlockInfoHasBeenParsed() const
Definition: Block.h:321
void SetBlockInfoHasBeenParsed(bool b, bool set_children)
Definition: Block.cpp:494
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
Definition: Block.cpp:297
size_t GetNumRanges() const
Definition: Block.h:329
SymbolFile * GetSymbolFile()
Get the symbol file which contains debug info for this block's symbol context module.
Definition: Block.cpp:482
void Dump(Stream *s, lldb::addr_t base_addr, int32_t depth, bool show_context) const
Dump the block contents.
Definition: Block.cpp:61
void AddRange(const Range &range)
Add a new offset range to this block.
Definition: Block.cpp:345
void FinalizeRanges()
Definition: Block.cpp:340
size_t MemorySize() const
Get the memory cost of this object.
Definition: Block.cpp:386
Represent a call made within a Function.
Definition: Function.h:267
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:155
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:132
CallEdge(AddrType caller_address_type, lldb::addr_t caller_address, bool is_tail_call, CallSiteParameterArray &&parameters)
Definition: Function.cpp:127
lldb::addr_t GetUnresolvedReturnPCAddress() const
Like GetReturnPCAddress, but returns an unresolved file address.
Definition: Function.h:316
A class that describes a compilation unit.
Definition: CompileUnit.h:43
const FileSpec & GetPrimaryFile() const
Return the primary source spec associated with this compile unit.
Definition: CompileUnit.h:232
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this compile unit.
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: CompileUnit.cpp:44
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition: CompileUnit.cpp:53
lldb::LanguageType GetLanguage()
LineTable * GetLineTable()
Get the line table for the compile unit.
Represents a generic declaration context in a program.
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A uniqued constant string class.
Definition: ConstString.h:40
size_t MemorySize() const
Get the memory cost of this object.
Definition: ConstString.h:397
static int Compare(ConstString lhs, ConstString rhs, const bool case_sensitive=true)
Compare two string objects.
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
static void ReportError(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report error events.
Definition: Debugger.cpp:1628
A class that describes the declaration location of a lldb object.
Definition: Declaration.h:24
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:124
size_t MemorySize() const
Get the memory cost of this object.
Definition: Declaration.cpp:56
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Declaration.cpp:14
static int Compare(const Declaration &lhs, const Declaration &rhs)
Compare two declaration objects.
Definition: Declaration.cpp:58
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:111
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
Definition: Function.cpp:204
bool resolved
Whether or not an attempt was made to find the callee's definition.
Definition: Function.h:356
void ParseSymbolFileAndResolve(ModuleList &images)
Definition: Function.cpp:160
union lldb_private::DirectCallEdge::@22 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:195
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, const AddressRange &disasm_range, 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
A file utility class.
Definition: FileSpec.h:56
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
void Clear()
Clears the object state.
Definition: FileSpec.cpp:259
bool IsClear(ValueType bit) const
Test a single flag bit to see if it is clear (zero).
Definition: Flags.h:111
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
A class that contains generic function information.
Definition: Function.h:31
Declaration & GetDeclaration()
Get accessor for the declaration information.
Definition: Function.cpp:53
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Function.cpp:39
virtual ~FunctionInfo()
Destructor.
ConstString GetName() const
Get accessor for the method name.
Definition: Function.cpp:59
FunctionInfo(const char *name, const Declaration *decl_ptr)
Construct with the function method name and optional declaration information.
Definition: Function.cpp:31
ConstString m_name
Function method name (not a mangled name).
Definition: Function.h:117
virtual size_t MemorySize() const
Get the memory cost of this object.
Definition: Function.cpp:61
static int Compare(const FunctionInfo &lhs, const FunctionInfo &rhs)
Compare two function information objects.
Definition: Function.cpp:45
Declaration m_declaration
Information describing where this function information was defined.
Definition: Function.h:120
A class that describes a function.
Definition: Function.h:399
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:528
lldb::user_id_t m_type_uid
The user ID of for the prototype Type for this function.
Definition: Function.h:643
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition: Function.cpp:415
void GetStartLineSourceInfo(lldb::SupportFileSP &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:294
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
CompilerType GetCompilerType()
Definition: Function.cpp:587
bool IsTopLevelFunction()
Get whether this function represents a 'top-level' function.
Definition: Function.cpp:539
lldb::ModuleSP CalculateSymbolContextModule() override
Definition: Function.cpp:470
CompileUnit * m_comp_unit
The compile unit that owns this function.
Definition: Function.h:640
ConstString GetName() const
Definition: Function.cpp:720
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:381
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:344
void Dump(Stream *s, bool show_context) const
Dump a description of this object to a Stream.
Definition: Function.cpp:446
Block m_block
All lexical blocks contained in this function.
Definition: Function.h:654
Type * m_type
The function prototype type for this function that includes the function info (FunctionInfo),...
Definition: Function.h:647
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: Function.cpp:465
void DumpSymbolContext(Stream *s) override
Dump the object's symbol context to the stream s.
Definition: Function.cpp:518
@ flagsCalculatedPrologueSize
Whether we already tried to calculate the prologue size.
Definition: Function.h:636
llvm::ArrayRef< std::unique_ptr< CallEdge > > GetTailCallingEdges()
Get the outgoing tail-calling edges from this function.
Definition: Function.cpp:374
bool GetDisassembly(const ExecutionContext &exe_ctx, const char *flavor, Stream &strm, bool force_live_memory=false)
Definition: Function.cpp:496
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:566
AddressRange m_range
The function address range that covers the widest range needed to contain all blocks.
Definition: Function.h:659
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:709
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition: Function.cpp:594
CompilerDeclContext GetDeclContext()
Get the DeclContext for this function, if available.
Definition: Function.cpp:552
Function(CompileUnit *comp_unit, lldb::user_id_t func_uid, lldb::user_id_t func_type_uid, const Mangled &mangled, Type *func_type, AddressRanges ranges)
Construct with a compile unit, function UID, function type UID, optional mangled name,...
Definition: Function.cpp:277
void GetEndLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the end of the function.
Definition: Function.cpp:323
CompileUnit * CalculateSymbolContextCompileUnit() override
Definition: Function.cpp:478
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:411
~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:548
ConstString GetNameNoArguments() const
Definition: Function.cpp:724
lldb::DisassemblerSP GetInstructions(const ExecutionContext &exe_ctx, const char *flavor, bool force_live_memory=false)
Definition: Function.cpp:484
Function * CalculateSymbolContextFunction() override
Definition: Function.cpp:482
std::vector< CompilerContext > GetCompilerContext()
Get the CompilerContext for this function, if available.
Definition: Function.cpp:559
size_t MemorySize() const
Get the memory cost of this object.
Definition: Function.cpp:523
Mangled m_mangled
The mangled function name if any.
Definition: Function.h:651
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
Function * GetCallee(ModuleList &images, ExecutionContext &exe_ctx) override
Get the callee's definition.
Definition: Function.cpp:219
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:210
DWARFExpressionList call_target
Definition: Function.h:376
size_t MemorySize() const override
Get the memory cost of this object.
Definition: Function.cpp:118
void DumpStopContext(Stream *s) const
Definition: Function.cpp:87
ConstString GetDisplayName() const
Definition: Function.cpp:102
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition: Function.cpp:108
ConstString GetName() const
Definition: Function.cpp:96
~InlineFunctionInfo() override
Destructor.
Mangled m_mangled
Mangled inlined function name (can be empty if there is no mangled information).
Definition: Function.h:244
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:65
void Dump(Stream *s, bool show_fullpaths) const
Dump a description of this object to a Stream.
Definition: Function.cpp:81
Mangled & GetMangled()
Get accessor for the mangled name object.
Definition: Function.cpp:114
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:84
A line table class.
Definition: LineTable.h:40
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.
Definition: LineTable.cpp:188
bool GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry)
Get the line entry from the line table at index idx.
Definition: LineTable.cpp:179
A class that handles mangled names.
Definition: Mangled.h:33
@ ePreferDemangledWithoutArguments
Definition: Mangled.h:38
size_t MemorySize() const
Get the memory cost of this object.
Definition: Mangled.cpp:381
lldb::LanguageType GuessLanguage() const
Try to guess the language from the mangling.
Definition: Mangled.cpp:391
ConstString & GetMangledName()
Mangled name get accessor.
Definition: Mangled.h:145
ConstString GetName(NamePreference preference=ePreferDemangled) const
Best name get accessor.
Definition: Mangled.cpp:335
ConstString GetDisplayDemangledName() const
Display demangled name get accessor.
Definition: Mangled.cpp:320
void Dump(Stream *s) const
Dump a description of this object to a Stream s.
Definition: Mangled.cpp:358
lldb::ModuleSP GetModule() const
Get const accessor for the module pointer.
Definition: ModuleChild.cpp:24
A collection class for Module objects.
Definition: ModuleList.h:103
void FindFunctionSymbols(ConstString name, lldb::FunctionNameType name_type_mask, SymbolContextList &sc_list)
Definition: ModuleList.cpp:469
An error handling class.
Definition: Status.h:115
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:401
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.
Definition: SymbolContext.h:34
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:50
virtual Type * ResolveTypeUID(lldb::user_id_t type_uid)=0
virtual std::vector< std::unique_ptr< CallEdge > > ParseCallEdgesInFunction(UserID func_id)
Definition: SymbolFile.h:359
bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, uint32_t stop_id=SectionLoadHistory::eStopIDNow)
Definition: Target.cpp:3219
const lldb_private::Declaration & GetDeclaration() const
Definition: Type.cpp:576
CompilerType GetFullCompilerType()
Definition: Type.cpp:764
#define LLDB_INVALID_UID
Definition: lldb-defines.h:88
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
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
llvm::SmallVector< CallSiteParameter, 0 > CallSiteParameterArray
A vector of CallSiteParameter.
Definition: Function.h:261
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelVerbose
std::shared_ptr< lldb_private::SupportFile > SupportFileSP
Definition: lldb-forward.h:479
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
Definition: lldb-forward.h:341
uint64_t user_id_t
Definition: lldb-types.h:82
std::shared_ptr< lldb_private::Section > SectionSP
Definition: lldb-forward.h:418
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
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:147
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
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:161
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
A mix in class that contains a generic user ID.
Definition: UserID.h:31
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47