LLDB mainline
SymbolContext.cpp
Go to the documentation of this file.
1//===-- SymbolContext.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
11#include "lldb/Core/Address.h"
12#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Module.h"
15#include "lldb/Host/Host.h"
16#include "lldb/Symbol/Block.h"
19#include "lldb/Symbol/Symbol.h"
24#include "lldb/Target/Target.h"
26#include "lldb/Utility/Log.h"
27#include "lldb/Utility/Stream.h"
30
31using namespace lldb;
32using namespace lldb_private;
33
34SymbolContext::SymbolContext() : target_sp(), module_sp(), line_entry() {}
35
37 Block *b, LineEntry *le, Symbol *s)
38 : target_sp(), module_sp(m), comp_unit(cu), function(f), block(b),
39 line_entry(), symbol(s) {
40 if (le)
41 line_entry = *le;
42}
43
45 CompileUnit *cu, Function *f, Block *b,
46 LineEntry *le, Symbol *s)
47 : target_sp(t), module_sp(m), comp_unit(cu), function(f), block(b),
48 line_entry(), symbol(s) {
49 if (le)
50 line_entry = *le;
51}
52
54 : target_sp(), module_sp(), line_entry() {
55 sc_scope->CalculateSymbolContext(this);
56}
57
59
60void SymbolContext::Clear(bool clear_target) {
61 if (clear_target)
62 target_sp.reset();
63 module_sp.reset();
64 comp_unit = nullptr;
65 function = nullptr;
66 block = nullptr;
68 symbol = nullptr;
69 variable = nullptr;
70}
71
73 Stream *s, ExecutionContextScope *exe_scope, const Address &addr,
74 bool show_fullpaths, bool show_module, bool show_inlined_frames,
75 bool show_function_arguments, bool show_function_name,
76 bool show_function_display_name,
77 std::optional<Stream::HighlightSettings> settings) const {
78 bool dumped_something = false;
79 if (show_module && module_sp) {
80 if (show_fullpaths)
81 *s << module_sp->GetFileSpec();
82 else
83 *s << module_sp->GetFileSpec().GetFilename();
84 s->PutChar('`');
85 dumped_something = true;
86 }
87 if (function != nullptr) {
88 SymbolContext inline_parent_sc;
89 Address inline_parent_addr;
90 if (!show_function_name) {
91 s->Printf("<");
92 dumped_something = true;
93 } else {
94 ConstString name;
95 if (!show_function_arguments)
97 if (!name && show_function_display_name)
98 name = function->GetDisplayName();
99 if (!name)
100 name = function->GetName();
101 if (name)
102 s->PutCStringColorHighlighted(name.GetStringRef(), settings);
103 }
104
105 if (addr_t file_addr = addr.GetFileAddress();
106 file_addr != LLDB_INVALID_ADDRESS) {
107 const addr_t function_offset =
108 file_addr - function->GetAddress().GetFileAddress();
109 if (!show_function_name) {
110 // Print +offset even if offset is 0
111 dumped_something = true;
112 s->Printf("+%" PRIu64 ">", function_offset);
113 } else if (function_offset) {
114 dumped_something = true;
115 s->Printf(" + %" PRIu64, function_offset);
116 }
117 }
118
119 if (GetParentOfInlinedScope(addr, inline_parent_sc, inline_parent_addr)) {
120 dumped_something = true;
121 Block *inlined_block = block->GetContainingInlinedBlock();
122 const InlineFunctionInfo *inlined_block_info =
123 inlined_block->GetInlinedFunctionInfo();
124 s->Printf(" [inlined] %s", inlined_block_info->GetName().GetCString());
125
126 lldb_private::AddressRange block_range;
127 if (inlined_block->GetRangeContainingAddress(addr, block_range)) {
128 const addr_t inlined_function_offset =
129 addr.GetFileAddress() -
130 block_range.GetBaseAddress().GetFileAddress();
131 if (inlined_function_offset) {
132 s->Printf(" + %" PRIu64, inlined_function_offset);
133 }
134 }
135 // "line_entry" will always be valid as GetParentOfInlinedScope(...) will
136 // fill it in correctly with the calling file and line. Previous code
137 // was extracting the calling file and line from inlined_block_info and
138 // using it right away which is not correct. On the first call to this
139 // function "line_entry" will contain the actual line table entry. On
140 // susequent calls "line_entry" will contain the calling file and line
141 // from the previous inline info.
142 if (line_entry.IsValid()) {
143 s->PutCString(" at ");
144 line_entry.DumpStopContext(s, show_fullpaths);
145 }
146
147 if (show_inlined_frames) {
148 s->EOL();
149 s->Indent();
150 const bool show_function_name = true;
151 return inline_parent_sc.DumpStopContext(
152 s, exe_scope, inline_parent_addr, show_fullpaths, show_module,
153 show_inlined_frames, show_function_arguments, show_function_name,
154 show_function_display_name);
155 }
156 } else {
157 if (line_entry.IsValid()) {
158 dumped_something = true;
159 s->PutCString(" at ");
160 if (line_entry.DumpStopContext(s, show_fullpaths))
161 dumped_something = true;
162 }
163 }
164 } else if (symbol != nullptr) {
165 if (!show_function_name) {
166 s->Printf("<");
167 dumped_something = true;
168 } else if (symbol->GetName()) {
169 dumped_something = true;
171 s->PutCString("symbol stub for: ");
172 ConstString name;
173 if (show_function_display_name)
174 name = symbol->GetDisplayName();
175 if (!name)
176 name = symbol->GetName();
177 s->PutCStringColorHighlighted(name.GetStringRef(), settings);
178 }
179
180 if (addr.IsValid() && symbol->ValueIsAddress()) {
181 const addr_t symbol_offset =
183 if (!show_function_name) {
184 // Print +offset even if offset is 0
185 dumped_something = true;
186 s->Printf("+%" PRIu64 ">", symbol_offset);
187 } else if (symbol_offset) {
188 dumped_something = true;
189 s->Printf(" + %" PRIu64, symbol_offset);
190 }
191 }
192 } else if (addr.IsValid()) {
194 dumped_something = true;
195 }
196 return dumped_something;
197}
198
200 Stream *s, lldb::DescriptionLevel level, Target *target,
201 std::optional<Stream::HighlightSettings> settings) const {
202 if (module_sp) {
203 s->Indent(" Module: file = \"");
204 module_sp->GetFileSpec().Dump(s->AsRawOstream());
205 *s << '"';
206 if (module_sp->GetArchitecture().IsValid())
207 s->Printf(", arch = \"%s\"",
208 module_sp->GetArchitecture().GetArchitectureName());
209 s->EOL();
210 }
211
212 if (comp_unit != nullptr) {
213 s->Indent("CompileUnit: ");
214 comp_unit->GetDescription(s, level);
215 s->EOL();
216 }
217
218 if (function != nullptr) {
219 s->Indent(" Function: ");
220 function->GetDescription(s, level, target);
221 s->EOL();
222
223 Type *func_type = function->GetType();
224 if (func_type) {
225 s->Indent(" FuncType: ");
226 func_type->GetDescription(s, level, false, target);
227 s->EOL();
228 }
229 }
230
231 if (block != nullptr) {
232 std::vector<Block *> blocks;
233 blocks.push_back(block);
234 Block *parent_block = block->GetParent();
235
236 while (parent_block) {
237 blocks.push_back(parent_block);
238 parent_block = parent_block->GetParent();
239 }
240 std::vector<Block *>::reverse_iterator pos;
241 std::vector<Block *>::reverse_iterator begin = blocks.rbegin();
242 std::vector<Block *>::reverse_iterator end = blocks.rend();
243 for (pos = begin; pos != end; ++pos) {
244 if (pos == begin)
245 s->Indent(" Blocks: ");
246 else
247 s->Indent(" ");
248 (*pos)->GetDescription(s, function, level, target);
249 s->EOL();
250 }
251 }
252
253 if (line_entry.IsValid()) {
254 s->Indent(" LineEntry: ");
255 line_entry.GetDescription(s, level, comp_unit, target, false);
256 s->EOL();
257 }
258
259 if (symbol != nullptr) {
260 s->Indent(" Symbol: ");
261 symbol->GetDescription(s, level, target, settings);
262 s->EOL();
263 }
264
265 if (variable != nullptr) {
266 s->Indent(" Variable: ");
267
268 s->Printf("id = {0x%8.8" PRIx64 "}, ", variable->GetID());
269
270 switch (variable->GetScope()) {
272 s->PutCString("kind = global, ");
273 break;
274
276 s->PutCString("kind = static, ");
277 break;
278
280 s->PutCString("kind = argument, ");
281 break;
282
284 s->PutCString("kind = local, ");
285 break;
286
288 s->PutCString("kind = thread local, ");
289 break;
290
291 default:
292 break;
293 }
294
295 s->Printf("name = \"%s\"\n", variable->GetName().GetCString());
296 }
297}
298
300 uint32_t resolved_mask = 0;
301 if (target_sp)
302 resolved_mask |= eSymbolContextTarget;
303 if (module_sp)
304 resolved_mask |= eSymbolContextModule;
305 if (comp_unit)
306 resolved_mask |= eSymbolContextCompUnit;
307 if (function)
308 resolved_mask |= eSymbolContextFunction;
309 if (block)
310 resolved_mask |= eSymbolContextBlock;
311 if (line_entry.IsValid())
312 resolved_mask |= eSymbolContextLineEntry;
313 if (symbol)
314 resolved_mask |= eSymbolContextSymbol;
315 if (variable)
316 resolved_mask |= eSymbolContextVariable;
317 return resolved_mask;
318}
319
320void SymbolContext::Dump(Stream *s, Target *target) const {
321 *s << this << ": ";
322 s->Indent();
323 s->PutCString("SymbolContext");
324 s->IndentMore();
325 s->EOL();
326 s->IndentMore();
327 s->Indent();
328 *s << "Module = " << module_sp.get() << ' ';
329 if (module_sp)
330 module_sp->GetFileSpec().Dump(s->AsRawOstream());
331 s->EOL();
332 s->Indent();
333 *s << "CompileUnit = " << comp_unit;
334 if (comp_unit != nullptr)
335 s->Format(" {{{0:x-16}} {1}", comp_unit->GetID(),
337 s->EOL();
338 s->Indent();
339 *s << "Function = " << function;
340 if (function != nullptr) {
341 s->Format(" {{{0:x-16}} {1}, address-range = ", function->GetID(),
342 function->GetType()->GetName());
345 s->EOL();
346 s->Indent();
347 Type *func_type = function->GetType();
348 if (func_type) {
349 *s << " Type = ";
350 func_type->Dump(s, false);
351 }
352 }
353 s->EOL();
354 s->Indent();
355 *s << "Block = " << block;
356 if (block != nullptr)
357 s->Format(" {{{0:x-16}}", block->GetID());
358 s->EOL();
359 s->Indent();
360 *s << "LineEntry = ";
363 s->EOL();
364 s->Indent();
365 *s << "Symbol = " << symbol;
366 if (symbol != nullptr && symbol->GetMangled())
367 *s << ' ' << symbol->GetName().AsCString();
368 s->EOL();
369 *s << "Variable = " << variable;
370 if (variable != nullptr) {
371 s->Format(" {{{0:x-16}} {1}", variable->GetID(),
372 variable->GetType()->GetName());
373 s->EOL();
374 }
375 s->IndentLess();
376 s->IndentLess();
377}
378
380 const SymbolContext &rhs) {
381 return lhs.function == rhs.function && lhs.symbol == rhs.symbol &&
382 lhs.module_sp.get() == rhs.module_sp.get() &&
383 lhs.comp_unit == rhs.comp_unit &&
384 lhs.target_sp.get() == rhs.target_sp.get() &&
386 lhs.variable == rhs.variable;
387}
388
390 const SymbolContext &rhs) {
391 return !(lhs == rhs);
392}
393
394bool SymbolContext::GetAddressRange(uint32_t scope, uint32_t range_idx,
395 bool use_inline_block_range,
396 AddressRange &range) const {
397 if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) {
398 range = line_entry.range;
399 return true;
400 }
401
402 if ((scope & eSymbolContextBlock) && (block != nullptr)) {
403 if (use_inline_block_range) {
404 Block *inline_block = block->GetContainingInlinedBlock();
405 if (inline_block)
406 return inline_block->GetRangeAtIndex(range_idx, range);
407 } else {
408 return block->GetRangeAtIndex(range_idx, range);
409 }
410 }
411
412 if ((scope & eSymbolContextFunction) && (function != nullptr)) {
413 if (range_idx == 0) {
414 range = function->GetAddressRange();
415 return true;
416 }
417 }
418
419 if ((scope & eSymbolContextSymbol) && (symbol != nullptr)) {
420 if (range_idx == 0) {
421 if (symbol->ValueIsAddress()) {
424 return true;
425 }
426 }
427 }
428 range.Clear();
429 return false;
430}
431
433 LanguageType lang;
434 if (function && (lang = function->GetLanguage()) != eLanguageTypeUnknown) {
435 return lang;
436 } else if (variable &&
438 return lang;
439 } else if (symbol && (lang = symbol->GetLanguage()) != eLanguageTypeUnknown) {
440 return lang;
441 } else if (comp_unit &&
443 return lang;
444 } else if (symbol) {
445 // If all else fails, try to guess the language from the name.
446 return symbol->GetMangled().GuessLanguage();
447 }
449}
450
452 SymbolContext &next_frame_sc,
453 Address &next_frame_pc) const {
454 next_frame_sc.Clear(false);
455 next_frame_pc.Clear();
456
457 if (block) {
458 // const addr_t curr_frame_file_addr = curr_frame_pc.GetFileAddress();
459
460 // In order to get the parent of an inlined function we first need to see
461 // if we are in an inlined block as "this->block" could be an inlined
462 // block, or a parent of "block" could be. So lets check if this block or
463 // one of this blocks parents is an inlined function.
464 Block *curr_inlined_block = block->GetContainingInlinedBlock();
465 if (curr_inlined_block) {
466 // "this->block" is contained in an inline function block, so to get the
467 // scope above the inlined block, we get the parent of the inlined block
468 // itself
469 Block *next_frame_block = curr_inlined_block->GetParent();
470 // Now calculate the symbol context of the containing block
471 next_frame_block->CalculateSymbolContext(&next_frame_sc);
472
473 // If we get here we weren't able to find the return line entry using the
474 // nesting of the blocks and the line table. So just use the call site
475 // info from our inlined block.
476
477 AddressRange range;
478 if (curr_inlined_block->GetRangeContainingAddress(curr_frame_pc, range)) {
479 // To see there this new frame block it, we need to look at the call
480 // site information from
481 const InlineFunctionInfo *curr_inlined_block_inlined_info =
482 curr_inlined_block->GetInlinedFunctionInfo();
483 next_frame_pc = range.GetBaseAddress();
484 next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc;
485 next_frame_sc.line_entry.file_sp = std::make_shared<SupportFile>(
486 curr_inlined_block_inlined_info->GetCallSite().GetFile());
487 next_frame_sc.line_entry.original_file_sp =
488 std::make_shared<SupportFile>(
489 curr_inlined_block_inlined_info->GetCallSite().GetFile());
490 next_frame_sc.line_entry.line =
491 curr_inlined_block_inlined_info->GetCallSite().GetLine();
492 next_frame_sc.line_entry.column =
493 curr_inlined_block_inlined_info->GetCallSite().GetColumn();
494 return true;
495 } else {
497
498 if (log) {
499 LLDB_LOGF(
500 log,
501 "warning: inlined block 0x%8.8" PRIx64
502 " doesn't have a range that contains file address 0x%" PRIx64,
503 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress());
504 }
505#ifdef LLDB_CONFIGURATION_DEBUG
506 else {
507 ObjectFile *objfile = nullptr;
508 if (module_sp) {
509 if (SymbolFile *symbol_file = module_sp->GetSymbolFile())
510 objfile = symbol_file->GetObjectFile();
511 }
512 if (objfile) {
513 Debugger::ReportWarning(llvm::formatv(
514 "inlined block {0:x} doesn't have a range that contains file "
515 "address {1:x} in {2}",
516 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress(),
517 objfile->GetFileSpec().GetPath()));
518 } else {
519 Debugger::ReportWarning(llvm::formatv(
520 "inlined block {0:x} doesn't have a range that contains file "
521 "address {1:x}",
522 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress()));
523 }
524 }
525#endif
526 }
527 }
528 }
529
530 return false;
531}
532
534 if (function) {
535 if (block) {
536 // If this symbol context has a block, check to see if this block is
537 // itself, or is contained within a block with inlined function
538 // information. If so, then the inlined block is the block that defines
539 // the function.
540 Block *inlined_block = block->GetContainingInlinedBlock();
541 if (inlined_block)
542 return inlined_block;
543
544 // The block in this symbol context is not inside an inlined block, so
545 // the block that defines the function is the function's top level block,
546 // which is returned below.
547 }
548
549 // There is no block information in this symbol context, so we must assume
550 // that the block that is desired is the top level block of the function
551 // itself.
552 return &function->GetBlock(true);
553 }
554 return nullptr;
555}
556
559
560 if (Block *function_block = GetFunctionBlock())
561 if (CompilerDeclContext decl_ctx = function_block->GetDeclContext())
562 lang_type = decl_ctx.GetLanguage();
563
564 if (lang_type == eLanguageTypeUnknown)
565 lang_type = GetLanguage();
566
567 if (auto *lang = Language::FindPlugin(lang_type))
568 return lang->GetInstanceVariableName();
569
570 return {};
571}
572
573void SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list) const {
574 Block *curr_block = block;
575 bool isInlinedblock = false;
576 if (curr_block != nullptr &&
577 curr_block->GetContainingInlinedBlock() != nullptr)
578 isInlinedblock = true;
579
580 // Find all types that match the current block if we have one and put them
581 // first in the list. Keep iterating up through all blocks.
582 while (curr_block != nullptr && !isInlinedblock) {
583 type_map.ForEach(
584 [curr_block, &type_list](const lldb::TypeSP &type_sp) -> bool {
585 SymbolContextScope *scs = type_sp->GetSymbolContextScope();
586 if (scs && curr_block == scs->CalculateSymbolContextBlock())
587 type_list.Insert(type_sp);
588 return true; // Keep iterating
589 });
590
591 // Remove any entries that are now in "type_list" from "type_map" since we
592 // can't remove from type_map while iterating
593 type_list.ForEach([&type_map](const lldb::TypeSP &type_sp) -> bool {
594 type_map.Remove(type_sp);
595 return true; // Keep iterating
596 });
597 curr_block = curr_block->GetParent();
598 }
599 // Find all types that match the current function, if we have onem, and put
600 // them next in the list.
601 if (function != nullptr && !type_map.Empty()) {
602 const size_t old_type_list_size = type_list.GetSize();
603 type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
604 SymbolContextScope *scs = type_sp->GetSymbolContextScope();
605 if (scs && function == scs->CalculateSymbolContextFunction())
606 type_list.Insert(type_sp);
607 return true; // Keep iterating
608 });
609
610 // Remove any entries that are now in "type_list" from "type_map" since we
611 // can't remove from type_map while iterating
612 const size_t new_type_list_size = type_list.GetSize();
613 if (new_type_list_size > old_type_list_size) {
614 for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
615 type_map.Remove(type_list.GetTypeAtIndex(i));
616 }
617 }
618 // Find all types that match the current compile unit, if we have one, and
619 // put them next in the list.
620 if (comp_unit != nullptr && !type_map.Empty()) {
621 const size_t old_type_list_size = type_list.GetSize();
622
623 type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
624 SymbolContextScope *scs = type_sp->GetSymbolContextScope();
625 if (scs && comp_unit == scs->CalculateSymbolContextCompileUnit())
626 type_list.Insert(type_sp);
627 return true; // Keep iterating
628 });
629
630 // Remove any entries that are now in "type_list" from "type_map" since we
631 // can't remove from type_map while iterating
632 const size_t new_type_list_size = type_list.GetSize();
633 if (new_type_list_size > old_type_list_size) {
634 for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
635 type_map.Remove(type_list.GetTypeAtIndex(i));
636 }
637 }
638 // Find all types that match the current module, if we have one, and put them
639 // next in the list.
640 if (module_sp && !type_map.Empty()) {
641 const size_t old_type_list_size = type_list.GetSize();
642 type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
643 SymbolContextScope *scs = type_sp->GetSymbolContextScope();
644 if (scs && module_sp == scs->CalculateSymbolContextModule())
645 type_list.Insert(type_sp);
646 return true; // Keep iterating
647 });
648 // Remove any entries that are now in "type_list" from "type_map" since we
649 // can't remove from type_map while iterating
650 const size_t new_type_list_size = type_list.GetSize();
651 if (new_type_list_size > old_type_list_size) {
652 for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
653 type_map.Remove(type_list.GetTypeAtIndex(i));
654 }
655 }
656 // Any types that are left get copied into the list an any order.
657 if (!type_map.Empty()) {
658 type_map.ForEach([&type_list](const lldb::TypeSP &type_sp) -> bool {
659 type_list.Insert(type_sp);
660 return true; // Keep iterating
661 });
662 }
663}
664
667 if (function) {
668 if (block) {
669 Block *inlined_block = block->GetContainingInlinedBlock();
670
671 if (inlined_block) {
672 const InlineFunctionInfo *inline_info =
673 inlined_block->GetInlinedFunctionInfo();
674 if (inline_info)
675 return inline_info->GetName();
676 }
677 }
678 return function->GetMangled().GetName(preference);
679 } else if (symbol && symbol->ValueIsAddress()) {
680 return symbol->GetMangled().GetName(preference);
681 } else {
682 // No function, return an empty string.
683 return ConstString();
684 }
685}
686
689 Address start_addr;
690 if (block) {
691 Block *inlined_block = block->GetContainingInlinedBlock();
692 if (inlined_block) {
693 if (inlined_block->GetStartAddress(start_addr)) {
695 return line_entry;
696 }
697 return LineEntry();
698 }
699 }
700
701 if (function) {
703 return line_entry;
704 }
705 return LineEntry();
706}
707
708llvm::Error
710 AddressRange &range) {
711 if (!line_entry.IsValid()) {
712 return llvm::createStringError("Symbol context has no line table.");
713 }
714
715 range = line_entry.range;
716 if (line_entry.line > end_line) {
717 return llvm::createStringError(
718 "end line option %d must be after the current line: %d", end_line,
720 }
721
722 uint32_t line_index = 0;
723 bool found = false;
724 while (true) {
725 LineEntry this_line;
726 line_index = comp_unit->FindLineEntry(line_index, line_entry.line, nullptr,
727 false, &this_line);
728 if (line_index == UINT32_MAX)
729 break;
730 if (LineEntry::Compare(this_line, line_entry) == 0) {
731 found = true;
732 break;
733 }
734 }
735
736 LineEntry end_entry;
737 if (!found) {
738 // Can't find the index of the SymbolContext's line entry in the
739 // SymbolContext's CompUnit.
740 return llvm::createStringError(
741 "Can't find the current line entry in the CompUnit - can't process "
742 "the end-line option");
743 }
744
745 line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
746 &end_entry);
747 if (line_index == UINT32_MAX) {
748 return llvm::createStringError(
749 "could not find a line table entry corresponding "
750 "to end line number %d",
751 end_line);
752 }
753
754 Block *func_block = GetFunctionBlock();
755 if (func_block && func_block->GetRangeIndexContainingAddress(
756 end_entry.range.GetBaseAddress()) == UINT32_MAX) {
757 return llvm::createStringError(
758 "end line number %d is not contained within the current function.",
759 end_line);
760 }
761
762 lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -
764 range.SetByteSize(range_size);
765 return llvm::Error::success();
766}
767
769 Status &error) {
770 error.Clear();
771
772 if (!target_sp) {
773 return nullptr;
774 }
775
776 Target &target = *target_sp;
777 Module *module = module_sp.get();
778
779 auto ProcessMatches = [this, &name, &target,
780 module](const SymbolContextList &sc_list,
781 Status &error) -> const Symbol * {
782 llvm::SmallVector<const Symbol *, 1> external_symbols;
783 llvm::SmallVector<const Symbol *, 1> internal_symbols;
784 for (const SymbolContext &sym_ctx : sc_list) {
785 if (sym_ctx.symbol) {
786 const Symbol *symbol = sym_ctx.symbol;
787 const Address sym_address = symbol->GetAddress();
788
789 if (sym_address.IsValid()) {
790 switch (symbol->GetType()) {
791 case eSymbolTypeData:
798 // If the demangled name was synthesized, then don't use it for
799 // expressions. Only let the symbol match if the mangled named
800 // matches for these symbols.
801 if (symbol->GetMangled().GetMangledName() != name)
802 break;
803 }
804 if (symbol->IsExternal()) {
805 external_symbols.push_back(symbol);
806 } else {
807 internal_symbols.push_back(symbol);
808 }
809 break;
811 ConstString reexport_name = symbol->GetReExportedSymbolName();
812 if (reexport_name) {
813 ModuleSP reexport_module_sp;
814 ModuleSpec reexport_module_spec;
815 reexport_module_spec.GetPlatformFileSpec() =
817 if (reexport_module_spec.GetPlatformFileSpec()) {
818 reexport_module_sp =
819 target.GetImages().FindFirstModule(reexport_module_spec);
820 if (!reexport_module_sp) {
821 reexport_module_spec.GetPlatformFileSpec().ClearDirectory();
822 reexport_module_sp =
823 target.GetImages().FindFirstModule(reexport_module_spec);
824 }
825 }
826 // Don't allow us to try and resolve a re-exported symbol if it
827 // is the same as the current symbol
828 if (name == symbol->GetReExportedSymbolName() &&
829 module == reexport_module_sp.get())
830 return nullptr;
831
833 error);
834 }
835 } break;
836
837 case eSymbolTypeCode: // We already lookup functions elsewhere
839 case eSymbolTypeLocal:
840 case eSymbolTypeParam:
848 case eSymbolTypeBlock:
859 break;
860 }
861 }
862 }
863 }
864
865 if (external_symbols.size() > 1) {
866 StreamString ss;
867 ss.Printf("Multiple external symbols found for '%s'\n", name.AsCString());
868 for (const Symbol *symbol : external_symbols) {
870 }
871 ss.PutChar('\n');
873 return nullptr;
874 } else if (external_symbols.size()) {
875 return external_symbols[0];
876 } else if (internal_symbols.size() > 1) {
877 StreamString ss;
878 ss.Printf("Multiple internal symbols found for '%s'\n", name.AsCString());
879 for (const Symbol *symbol : internal_symbols) {
881 ss.PutChar('\n');
882 }
884 return nullptr;
885 } else if (internal_symbols.size()) {
886 return internal_symbols[0];
887 } else {
888 return nullptr;
889 }
890 };
891
892 if (module) {
893 SymbolContextList sc_list;
894 module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
895 const Symbol *const module_symbol = ProcessMatches(sc_list, error);
896
897 if (!error.Success()) {
898 return nullptr;
899 } else if (module_symbol) {
900 return module_symbol;
901 }
902 }
903
904 {
905 SymbolContextList sc_list;
907 sc_list);
908 const Symbol *const target_symbol = ProcessMatches(sc_list, error);
909
910 if (!error.Success()) {
911 return nullptr;
912 } else if (target_symbol) {
913 return target_symbol;
914 }
915 }
916
917 return nullptr; // no error; we just didn't find anything
918}
919
920//
921// SymbolContextSpecifier
922//
923
925 : m_target_sp(target_sp), m_module_spec(), m_module_sp(), m_file_spec_up(),
926 m_start_line(0), m_end_line(0), m_function_spec(), m_class_name(),
927 m_address_range_up(), m_type(eNothingSpecified) {}
928
930
932 SpecificationType type) {
933 bool return_value = true;
934 switch (type) {
936 Clear();
937 break;
939 m_start_line = line_no;
941 break;
943 m_end_line = line_no;
945 break;
946 default:
947 return_value = false;
948 break;
949 }
950 return return_value;
951}
952
953bool SymbolContextSpecifier::AddSpecification(const char *spec_string,
954 SpecificationType type) {
955 bool return_value = true;
956 switch (type) {
958 Clear();
959 break;
960 case eModuleSpecified: {
961 // See if we can find the Module, if so stick it in the SymbolContext.
962 FileSpec module_file_spec(spec_string);
963 ModuleSpec module_spec(module_file_spec);
964 lldb::ModuleSP module_sp =
965 m_target_sp ? m_target_sp->GetImages().FindFirstModule(module_spec)
966 : nullptr;
968 if (module_sp)
969 m_module_sp = module_sp;
970 else
971 m_module_spec.assign(spec_string);
972 } break;
973 case eFileSpecified:
974 // CompUnits can't necessarily be resolved here, since an inlined function
975 // might show up in a number of CompUnits. Instead we just convert to a
976 // FileSpec and store it away.
977 m_file_spec_up = std::make_unique<FileSpec>(spec_string);
979 break;
981 if ((return_value = llvm::to_integer(spec_string, m_start_line)))
983 break;
985 if ((return_value = llvm::to_integer(spec_string, m_end_line)))
987 break;
989 m_function_spec.assign(spec_string);
991 break;
993 Clear();
994 m_class_name.assign(spec_string);
996 break;
998 // Not specified yet...
999 break;
1000 }
1001
1002 return return_value;
1003}
1004
1006 m_module_spec.clear();
1007 m_file_spec_up.reset();
1008 m_function_spec.clear();
1009 m_class_name.clear();
1010 m_start_line = 0;
1011 m_end_line = 0;
1012 m_address_range_up.reset();
1013
1015}
1016
1019 return true;
1020
1021 // Only compare targets if this specifier has one and it's not the Dummy
1022 // target. Otherwise if a specifier gets made in the dummy target and
1023 // copied over we'll artificially fail the comparision.
1024 if (m_target_sp && !m_target_sp->IsDummyTarget() &&
1025 m_target_sp != sc.target_sp)
1026 return false;
1027
1028 if (m_type & eModuleSpecified) {
1029 if (sc.module_sp) {
1030 if (m_module_sp.get() != nullptr) {
1031 if (m_module_sp.get() != sc.module_sp.get())
1032 return false;
1033 } else {
1034 FileSpec module_file_spec(m_module_spec);
1035 if (!FileSpec::Match(module_file_spec, sc.module_sp->GetFileSpec()))
1036 return false;
1037 }
1038 }
1039 }
1040 if (m_type & eFileSpecified) {
1041 if (m_file_spec_up) {
1042 // If we don't have a block or a comp_unit, then we aren't going to match
1043 // a source file.
1044 if (sc.block == nullptr && sc.comp_unit == nullptr)
1045 return false;
1046
1047 // Check if the block is present, and if so is it inlined:
1048 bool was_inlined = false;
1049 if (sc.block != nullptr) {
1050 const InlineFunctionInfo *inline_info =
1052 if (inline_info != nullptr) {
1053 was_inlined = true;
1055 inline_info->GetDeclaration().GetFile()))
1056 return false;
1057 }
1058 }
1059
1060 // Next check the comp unit, but only if the SymbolContext was not
1061 // inlined.
1062 if (!was_inlined && sc.comp_unit != nullptr) {
1064 return false;
1065 }
1066 }
1067 }
1070 return false;
1071 }
1072
1073 if (m_type & eFunctionSpecified) {
1074 // First check the current block, and if it is inlined, get the inlined
1075 // function name:
1076 bool was_inlined = false;
1077 ConstString func_name(m_function_spec.c_str());
1078
1079 if (sc.block != nullptr) {
1080 const InlineFunctionInfo *inline_info =
1082 if (inline_info != nullptr) {
1083 was_inlined = true;
1084 const Mangled &name = inline_info->GetMangled();
1085 if (!name.NameMatches(func_name))
1086 return false;
1087 }
1088 }
1089 // If it wasn't inlined, check the name in the function or symbol:
1090 if (!was_inlined) {
1091 if (sc.function != nullptr) {
1092 if (!sc.function->GetMangled().NameMatches(func_name))
1093 return false;
1094 } else if (sc.symbol != nullptr) {
1095 if (!sc.symbol->GetMangled().NameMatches(func_name))
1096 return false;
1097 }
1098 }
1099 }
1100
1101 return true;
1102}
1103
1106
1107 } else {
1108 Address match_address(addr, nullptr);
1109 SymbolContext sc;
1110 m_target_sp->GetImages().ResolveSymbolContextForAddress(
1111 match_address, eSymbolContextEverything, sc);
1112 return SymbolContextMatches(sc);
1113 }
1114 return true;
1115}
1116
1118 Stream *s, lldb::DescriptionLevel level) const {
1119 char path_str[PATH_MAX + 1];
1120
1121 if (m_type == eNothingSpecified) {
1122 s->Printf("Nothing specified.\n");
1123 }
1124
1125 if (m_type == eModuleSpecified) {
1126 s->Indent();
1127 if (m_module_sp) {
1128 m_module_sp->GetFileSpec().GetPath(path_str, PATH_MAX);
1129 s->Printf("Module: %s\n", path_str);
1130 } else
1131 s->Printf("Module: %s\n", m_module_spec.c_str());
1132 }
1133
1134 if (m_type == eFileSpecified && m_file_spec_up != nullptr) {
1135 m_file_spec_up->GetPath(path_str, PATH_MAX);
1136 s->Indent();
1137 s->Printf("File: %s", path_str);
1138 if (m_type == eLineStartSpecified) {
1139 s->Printf(" from line %" PRIu64 "", (uint64_t)m_start_line);
1141 s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1142 else
1143 s->Printf("to end");
1144 } else if (m_type == eLineEndSpecified) {
1145 s->Printf(" from start to line %" PRIu64 "", (uint64_t)m_end_line);
1146 }
1147 s->Printf(".\n");
1148 }
1149
1150 if (m_type == eLineStartSpecified) {
1151 s->Indent();
1152 s->Printf("From line %" PRIu64 "", (uint64_t)m_start_line);
1154 s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1155 else
1156 s->Printf("to end");
1157 s->Printf(".\n");
1158 } else if (m_type == eLineEndSpecified) {
1159 s->Printf("From start to line %" PRIu64 ".\n", (uint64_t)m_end_line);
1160 }
1161
1162 if (m_type == eFunctionSpecified) {
1163 s->Indent();
1164 s->Printf("Function: %s.\n", m_function_spec.c_str());
1165 }
1166
1168 s->Indent();
1169 s->Printf("Class name: %s.\n", m_class_name.c_str());
1170 }
1171
1172 if (m_type == eAddressRangeSpecified && m_address_range_up != nullptr) {
1173 s->Indent();
1174 s->PutCString("Address range: ");
1175 m_address_range_up->Dump(s, m_target_sp.get(),
1178 s->PutCString("\n");
1179 }
1180}
1181
1182//
1183// SymbolContextList
1184//
1185
1187
1189
1191 m_symbol_contexts.push_back(sc);
1192}
1193
1195 collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1196 for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos)
1197 m_symbol_contexts.push_back(*pos);
1198}
1199
1201 bool merge_symbol_into_function) {
1202 uint32_t unique_sc_add_count = 0;
1203 collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1204 for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) {
1205 if (AppendIfUnique(*pos, merge_symbol_into_function))
1206 ++unique_sc_add_count;
1207 }
1208 return unique_sc_add_count;
1209}
1210
1212 bool merge_symbol_into_function) {
1213 collection::iterator pos, end = m_symbol_contexts.end();
1214 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1215 if (*pos == sc)
1216 return false;
1217 }
1218 if (merge_symbol_into_function && sc.symbol != nullptr &&
1219 sc.comp_unit == nullptr && sc.function == nullptr &&
1220 sc.block == nullptr && !sc.line_entry.IsValid()) {
1221 if (sc.symbol->ValueIsAddress()) {
1222 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1223 // Don't merge symbols into inlined function symbol contexts
1224 if (pos->block && pos->block->GetContainingInlinedBlock())
1225 continue;
1226
1227 if (pos->function) {
1228 if (pos->function->GetAddress() == sc.symbol->GetAddressRef()) {
1229 // Do we already have a function with this symbol?
1230 if (pos->symbol == sc.symbol)
1231 return false;
1232 if (pos->symbol == nullptr) {
1233 pos->symbol = sc.symbol;
1234 return false;
1235 }
1236 }
1237 }
1238 }
1239 }
1240 }
1241 m_symbol_contexts.push_back(sc);
1242 return true;
1243}
1244
1246
1247void SymbolContextList::Dump(Stream *s, Target *target) const {
1248
1249 *s << this << ": ";
1250 s->Indent();
1251 s->PutCString("SymbolContextList");
1252 s->EOL();
1253 s->IndentMore();
1254
1255 collection::const_iterator pos, end = m_symbol_contexts.end();
1256 for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1257 // pos->Dump(s, target);
1258 pos->GetDescription(s, eDescriptionLevelVerbose, target);
1259 }
1260 s->IndentLess();
1261}
1262
1264 if (idx < m_symbol_contexts.size()) {
1265 sc = m_symbol_contexts[idx];
1266 return true;
1267 }
1268 return false;
1269}
1270
1272 if (idx < m_symbol_contexts.size()) {
1273 m_symbol_contexts.erase(m_symbol_contexts.begin() + idx);
1274 return true;
1275 }
1276 return false;
1277}
1278
1279uint32_t SymbolContextList::GetSize() const { return m_symbol_contexts.size(); }
1280
1281bool SymbolContextList::IsEmpty() const { return m_symbol_contexts.empty(); }
1282
1283uint32_t SymbolContextList::NumLineEntriesWithLine(uint32_t line) const {
1284 uint32_t match_count = 0;
1285 const size_t size = m_symbol_contexts.size();
1286 for (size_t idx = 0; idx < size; ++idx) {
1287 if (m_symbol_contexts[idx].line_entry.line == line)
1288 ++match_count;
1289 }
1290 return match_count;
1291}
1292
1294 Target *target) const {
1295 const size_t size = m_symbol_contexts.size();
1296 for (size_t idx = 0; idx < size; ++idx)
1297 m_symbol_contexts[idx].GetDescription(s, level, target);
1298}
1299
1301 const SymbolContextList &rhs) {
1302 const uint32_t size = lhs.GetSize();
1303 if (size != rhs.GetSize())
1304 return false;
1305
1306 SymbolContext lhs_sc;
1307 SymbolContext rhs_sc;
1308 for (uint32_t i = 0; i < size; ++i) {
1309 lhs.GetContextAtIndex(i, lhs_sc);
1310 rhs.GetContextAtIndex(i, rhs_sc);
1311 if (lhs_sc != rhs_sc)
1312 return false;
1313 }
1314 return true;
1315}
1316
1318 const SymbolContextList &rhs) {
1319 return !(lhs == rhs);
1320}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOGF(log,...)
Definition: Log.h:376
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.
void Clear()
Clear the object's state.
void SetByteSize(lldb::addr_t byte_size)
Set accessor for the byte size of this range.
Definition: AddressRange.h:239
A section + offset based address class.
Definition: Address.h:62
void Clear()
Clear the object's state.
Definition: Address.h:181
@ 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
bool Dump(Stream *s, ExecutionContextScope *exe_scope, DumpStyle style, DumpStyle fallback_style=DumpStyleInvalid, uint32_t addr_byte_size=UINT32_MAX, bool all_ranges=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump a description of this object to a Stream.
Definition: Address.cpp:407
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:292
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 CalculateSymbolContextLineEntry(LineEntry &line_entry) const
Definition: Address.cpp:913
A class that describes a single lexical block.
Definition: Block.h:41
void CalculateSymbolContext(SymbolContext *sc) override
Reconstruct the object's symbol context into sc.
Definition: Block.cpp:137
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:200
bool GetRangeAtIndex(uint32_t range_idx, AddressRange &range)
Definition: Block.cpp:296
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:266
bool GetRangeContainingAddress(const Address &addr, AddressRange &range)
Definition: Block.cpp:242
Block * GetParent() const
Get the parent block.
Definition: Block.cpp:196
bool GetStartAddress(Address &addr)
Definition: Block.cpp:326
uint32_t GetRangeIndexContainingAddress(const Address &addr)
Definition: Block.cpp:279
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
uint32_t FindLineEntry(uint32_t start_idx, uint32_t line, const FileSpec *file_spec_ptr, bool exact, LineEntry *line_entry)
Find the line entry by line and optional inlined file spec.
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
Definition: CompileUnit.cpp:58
lldb::LanguageType GetLanguage()
Represents a generic declaration context in a program.
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
Definition: ConstString.h:197
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
static void ReportWarning(std::string message, std::optional< lldb::user_id_t > debugger_id=std::nullopt, std::once_flag *once=nullptr)
Report warning events.
Definition: Debugger.cpp:1622
uint32_t GetLine() const
Get accessor for the declaration line number.
Definition: Declaration.h:124
uint16_t GetColumn() const
Get accessor for the declaration column number.
Definition: Declaration.h:131
FileSpec & GetFile()
Get accessor for file specification.
Definition: Declaration.h:111
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
A file utility class.
Definition: FileSpec.h:56
static bool Match(const FileSpec &pattern, const FileSpec &file)
Match FileSpec pattern against FileSpec file.
Definition: FileSpec.cpp:301
void ClearDirectory()
Clear the directory in this object.
Definition: FileSpec.cpp:360
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
Declaration & GetDeclaration()
Get accessor for the declaration information.
Definition: Function.cpp:53
A class that describes a function.
Definition: Function.h:399
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition: Function.h:455
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target)
Definition: Function.cpp:415
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
ConstString GetName() const
Definition: Function.cpp:719
const Mangled & GetMangled() const
Definition: Function.h:537
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:566
lldb::LanguageType GetLanguage() const
Definition: Function.cpp:708
ConstString GetDisplayName() const
Definition: Function.cpp:548
ConstString GetNameNoArguments() const
Definition: Function.cpp:723
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
A class that describes information for an inlined function.
Definition: Function.h:125
Declaration & GetCallSite()
Get accessor for the call site declaration information.
Definition: Function.cpp:108
ConstString GetName() const
Definition: Function.cpp:96
Mangled & GetMangled()
Get accessor for the mangled name object.
Definition: Function.cpp:114
static Language * FindPlugin(lldb::LanguageType language)
Definition: Language.cpp:84
A class that handles mangled names.
Definition: Mangled.h:33
bool NameMatches(ConstString name) const
Check if "name" matches either the mangled or demangled name.
Definition: Mangled.h:171
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
lldb::ModuleSP FindFirstModule(const ModuleSpec &module_spec) const
Definition: ModuleList.cpp:626
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list) const
Definition: ModuleList.cpp:527
FileSpec & GetPlatformFileSpec()
Definition: ModuleSpec.h:65
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:89
void FindSymbolsWithNameAndType(ConstString name, lldb::SymbolType symbol_type, SymbolContextList &sc_list)
Definition: Module.cpp:1307
A plug-in interface definition class for object file parsers.
Definition: ObjectFile.h:44
virtual FileSpec & GetFileSpec()
Get accessor to the object file specification.
Definition: ObjectFile.h:275
An error handling class.
Definition: Status.h:118
static Status FromErrorString(const char *str)
Definition: Status.h:141
const char * GetData() const
Definition: StreamString.h:45
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
void Format(const char *format, Args &&... args)
Definition: Stream.h:353
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 PutChar(char ch)
Definition: Stream.cpp:131
void PutCStringColorHighlighted(llvm::StringRef text, std::optional< HighlightSettings > settings=std::nullopt)
Output a C string to the stream with color highlighting.
Definition: Stream.cpp:75
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
void IndentLess(unsigned amount=2)
Decrement the current indentation level.
Definition: Stream.cpp:198
void IndentMore(unsigned amount=2)
Increment the current indentation level.
Definition: Stream.cpp:195
Defines a list of symbol context objects.
collection m_symbol_contexts
The list of symbol contexts.
bool GetContextAtIndex(size_t idx, SymbolContext &sc) const
Get accessor for a symbol context at index idx.
uint32_t GetSize() const
Get accessor for a symbol context list size.
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const
const_iterator end() const
bool AppendIfUnique(const SymbolContext &sc, bool merge_symbol_into_function)
void Dump(Stream *s, Target *target) const
Dump a description of this object to a Stream.
uint32_t NumLineEntriesWithLine(uint32_t line) const
void Append(const SymbolContext &sc)
Append a new symbol context to the list.
void Clear()
Clear the object's state.
SymbolContextList()
Default constructor.
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual Function * CalculateSymbolContextFunction()
virtual CompileUnit * CalculateSymbolContextCompileUnit()
virtual void CalculateSymbolContext(SymbolContext *sc)=0
Reconstruct the object's symbol context into sc.
virtual Block * CalculateSymbolContextBlock()
virtual lldb::ModuleSP CalculateSymbolContextModule()
void GetDescription(Stream *s, lldb::DescriptionLevel level) const
bool AddressMatches(lldb::addr_t addr)
std::unique_ptr< AddressRange > m_address_range_up
std::unique_ptr< FileSpec > m_file_spec_up
bool AddLineSpecification(uint32_t line_no, SpecificationType type)
bool AddSpecification(const char *spec_string, SpecificationType type)
bool SymbolContextMatches(const SymbolContext &sc)
SymbolContextSpecifier(const lldb::TargetSP &target_sp)
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
LineEntry GetFunctionStartLineEntry() const
Get the line entry that corresponds to the function.
const Symbol * FindBestGlobalDataSymbol(ConstString name, Status &error)
Find the best global data symbol visible from this context.
lldb::LanguageType GetLanguage() const
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
void Dump(Stream *s, Target *target) const
Dump a description of this object to a Stream.
llvm::Error GetAddressRangeFromHereToEndLine(uint32_t end_line, AddressRange &range)
Function * function
The Function for a given query.
Block * GetFunctionBlock()
Find a block that defines the function represented by this symbol context.
llvm::StringRef GetInstanceVariableName()
Determines the name of the instance variable for the this decl context.
bool GetParentOfInlinedScope(const Address &curr_frame_pc, SymbolContext &next_frame_sc, Address &inlined_frame_addr) const
Find the block containing the inlined block that contains this block.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
void SortTypeList(TypeMap &type_map, TypeList &type_list) const
Sorts the types in TypeMap according to SymbolContext to TypeList.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, bool show_function_display_name=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump the stop context in this object to a Stream.
uint32_t GetResolvedMask() const
void Clear(bool clear_target)
Clear the object's state.
Variable * variable
The global variable matching the given query.
bool GetAddressRange(uint32_t scope, uint32_t range_idx, bool use_inline_block_range, AddressRange &range) const
Get the address range contained within a symbol context.
Symbol * symbol
The Symbol for a given query.
lldb::TargetSP target_sp
The Target for a given query.
LineEntry line_entry
The LineEntry for a given query.
SymbolContext()
Default constructor.
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
bool ValueIsAddress() const
Definition: Symbol.cpp:165
bool IsExternal() const
Definition: Symbol.h:196
bool GetDemangledNameIsSynthesized() const
Definition: Symbol.h:225
Mangled & GetMangled()
Definition: Symbol.h:146
lldb::LanguageType GetLanguage() const
Definition: Symbol.h:138
Address & GetAddressRef()
Definition: Symbol.h:72
ConstString GetReExportedSymbolName() const
Definition: Symbol.cpp:173
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Definition: Symbol.cpp:225
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:468
ConstString GetName() const
Definition: Symbol.cpp:548
lldb::SymbolType GetType() const
Definition: Symbol.h:168
Address GetAddress() const
Definition: Symbol.h:88
FileSpec GetReExportedSymbolSharedLibrary() const
Definition: Symbol.cpp:187
ConstString GetDisplayName() const
Definition: Symbol.cpp:169
const ModuleList & GetImages() const
Get accessor for the images for this process.
Definition: Target.h:997
uint32_t GetSize() const
Definition: TypeList.cpp:60
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition: TypeList.cpp:78
lldb::TypeSP GetTypeAtIndex(uint32_t idx)
Definition: TypeList.cpp:66
void Insert(const lldb::TypeSP &type)
Definition: TypeList.cpp:27
bool Empty() const
Definition: TypeMap.cpp:77
bool Remove(const lldb::TypeSP &type_sp)
Definition: TypeMap.cpp:116
void ForEach(std::function< bool(const lldb::TypeSP &type_sp)> const &callback) const
Definition: TypeMap.cpp:100
ConstString GetName()
Definition: Type.cpp:440
void GetDescription(Stream *s, lldb::DescriptionLevel level, bool show_name, ExecutionContextScope *exe_scope)
Definition: Type.cpp:304
void Dump(Stream *s, bool show_context, lldb::DescriptionLevel level=lldb::eDescriptionLevelFull)
Definition: Type.cpp:372
ConstString GetName() const
Definition: Variable.cpp:73
lldb::LanguageType GetLanguage() const
Definition: Variable.cpp:56
lldb::ValueType GetScope() const
Definition: Variable.h:66
#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
bool operator!=(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1028
bool operator==(const Address &lhs, const Address &rhs)
Definition: Address.cpp:1022
Definition: SBAddress.h:15
DescriptionLevel
Description levels for "void GetDescription(Stream *, DescriptionLevel)" calls.
@ eDescriptionLevelFull
@ eDescriptionLevelVerbose
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
Definition: lldb-forward.h:461
@ eSymbolTypeUndefined
@ eSymbolTypeVariableType
@ eSymbolTypeObjCMetaClass
@ eSymbolTypeReExported
@ eSymbolTypeObjCClass
@ eSymbolTypeObjectFile
@ eSymbolTypeTrampoline
@ eSymbolTypeResolver
@ eSymbolTypeParam
@ eSymbolTypeSourceFile
@ eSymbolTypeException
@ eSymbolTypeInvalid
@ eSymbolTypeVariable
@ eSymbolTypeAbsolute
@ eSymbolTypeAdditional
When symbols take more than one entry, the extra entries get this type.
@ eSymbolTypeInstrumentation
@ eSymbolTypeLocal
@ eSymbolTypeHeaderFile
@ eSymbolTypeBlock
@ eSymbolTypeCommonBlock
@ eSymbolTypeCompiler
@ eSymbolTypeLineHeader
@ eSymbolTypeObjCIVar
@ eSymbolTypeLineEntry
@ eSymbolTypeRuntime
@ eSymbolTypeScopeBegin
@ eSymbolTypeScopeEnd
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:448
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeVariableStatic
static variable
@ eValueTypeVariableThreadLocal
thread local storage variable
A line table entry class.
Definition: LineEntry.h:21
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition: LineEntry.h:151
void Clear()
Clear the object's state.
Definition: LineEntry.cpp:22
bool Dump(Stream *s, Target *target, bool show_file, Address::DumpStyle style, Address::DumpStyle fallback_style, bool show_range) const
Dump a description of this object to a Stream.
Definition: LineEntry.cpp:60
lldb::SupportFileSP original_file_sp
The original source file, from debug info.
Definition: LineEntry.h:143
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:35
static int Compare(const LineEntry &lhs, const LineEntry &rhs)
Compare two LineEntry objects.
Definition: LineEntry.cpp:147
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
bool GetDescription(Stream *s, lldb::DescriptionLevel level, CompileUnit *cu, Target *target, bool show_address_only) const
Definition: LineEntry.cpp:95
bool DumpStopContext(Stream *s, bool show_fullpaths) const
Dumps information specific to a process that stops at this line entry to the supplied stream s.
Definition: LineEntry.cpp:39
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
#define PATH_MAX