LLDB mainline
Variable.cpp
Go to the documentation of this file.
1//===-- Variable.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/Debugger.h"
12#include "lldb/Core/Module.h"
13#include "lldb/Symbol/Block.h"
20#include "lldb/Symbol/Type.h"
23#include "lldb/Target/ABI.h"
25#include "lldb/Target/Process.h"
28#include "lldb/Target/Target.h"
29#include "lldb/Target/Thread.h"
31#include "lldb/Utility/Log.h"
33#include "lldb/Utility/Stream.h"
37
38#include "llvm/ADT/Twine.h"
39
40using namespace lldb;
41using namespace lldb_private;
42
43Variable::Variable(lldb::user_id_t uid, const char *name, const char *mangled,
44 const lldb::SymbolFileTypeSP &symfile_type_sp,
45 ValueType scope, SymbolContextScope *context,
46 const RangeList &scope_range, Declaration *decl_ptr,
47 const DWARFExpressionList &location_list, bool external,
48 bool artificial, bool location_is_constant_data,
49 bool static_member, std::optional<uint64_t> tag_offset)
50 : UserID(uid), m_name(name), m_mangled(ConstString(mangled)),
51 m_symfile_type_sp(symfile_type_sp), m_scope(scope),
52 m_owner_scope(context), m_scope_range(scope_range),
53 m_declaration(decl_ptr), m_location_list(location_list),
54 m_external(external), m_artificial(artificial),
55 m_loc_is_const_data(location_is_constant_data),
56 m_static_member(static_member), m_tag_offset(tag_offset) {
57#ifndef NDEBUG
59 .GetInjectVarLocListError())
60 m_location_list.Clear();
61#endif
62}
63
64Variable::~Variable() = default;
65
67 lldb::LanguageType lang = m_mangled.GuessLanguage();
69 return lang;
70
71 if (auto *func = m_owner_scope->CalculateSymbolContextFunction()) {
72 if ((lang = func->GetLanguage()) != lldb::eLanguageTypeUnknown)
73 return lang;
74 } else if (auto *comp_unit =
75 m_owner_scope->CalculateSymbolContextCompileUnit()) {
76 if ((lang = comp_unit->GetLanguage()) != lldb::eLanguageTypeUnknown)
77 return lang;
78 }
79
81}
82
84 ConstString name = m_mangled.GetName();
85 if (name)
86 return name;
87 return m_name;
88}
89
91
93 if (m_name == name)
94 return true;
95 return m_mangled.NameMatches(name);
96}
97bool Variable::NameMatches(const RegularExpression &regex) const {
98 if (regex.Execute(m_name.AsCString(nullptr)))
99 return true;
100 if (m_mangled)
101 return m_mangled.NameMatches(regex);
102 return false;
103}
104
107 return m_symfile_type_sp->GetType();
108 return nullptr;
109}
110
112 Type *type = GetType();
113 if (type)
115 return nullptr;
116}
117
118void Variable::Dump(Stream *s, bool show_context) const {
119 s->Printf("%p: ", static_cast<const void *>(this));
120 s->Indent();
121 *s << "Variable" << (const UserID &)*this;
122
123 if (m_name)
124 *s << ", name = \"" << m_name << "\"";
125
126 if (m_symfile_type_sp) {
127 Type *type = m_symfile_type_sp->GetType();
128 if (type) {
129 s->Format(", type = {{{0:x-16}} {1} (", type->GetID(), type);
130 type->DumpTypeName(s);
131 s->PutChar(')');
132 }
133 }
134
135 if (m_scope != eValueTypeInvalid) {
136 s->PutCString(", scope = ");
137 switch (m_scope) {
139 s->PutCString(m_external ? "global" : "static");
140 break;
142 s->PutCString("parameter");
143 break;
145 s->PutCString("local");
146 break;
148 s->PutCString("thread local");
149 break;
150 default:
151 s->AsRawOstream() << "??? (" << m_scope << ')';
152 }
153 }
154
155 if (show_context && m_owner_scope != nullptr) {
156 s->PutCString(", context = ( ");
157 m_owner_scope->DumpSymbolContext(s);
158 s->PutCString(" )");
159 }
160
161 bool show_fullpaths = false;
162 m_declaration.Dump(s, show_fullpaths);
163
164 if (m_location_list.IsValid()) {
165 s->PutCString(", location = ");
166 ABISP abi;
167 if (m_owner_scope) {
168 ModuleSP module_sp(m_owner_scope->CalculateSymbolContextModule());
169 if (module_sp)
170 abi = ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
171 }
172 m_location_list.GetDescription(s, lldb::eDescriptionLevelBrief, abi.get());
173 }
174
175 if (m_external)
176 s->PutCString(", external");
177
178 if (m_artificial)
179 s->PutCString(", artificial");
180
181 s->EOL();
182}
183
184bool Variable::DumpDeclaration(Stream *s, bool show_fullpaths,
185 bool show_module) {
186 bool dumped_declaration_info = false;
187 if (m_owner_scope) {
188 SymbolContext sc;
189 m_owner_scope->CalculateSymbolContext(&sc);
190 sc.block = nullptr;
191 sc.line_entry.Clear();
192 bool show_inlined_frames = false;
193 const bool show_function_arguments = true;
194 const bool show_function_name = true;
195
196 dumped_declaration_info = sc.DumpStopContext(
197 s, nullptr, Address(), show_fullpaths, show_module, show_inlined_frames,
198 show_function_arguments, show_function_name);
199
200 if (sc.function)
201 s->PutChar(':');
202 }
203 if (m_declaration.DumpStopContext(s, false))
204 dumped_declaration_info = true;
205 return dumped_declaration_info;
206}
207
209 Type *type = GetType();
210 if (type)
212 return CompilerDeclContext();
213}
214
216 Type *type = GetType();
217 return type ? type->GetSymbolFile()->GetDeclForUID(GetID()) : CompilerDecl();
218}
219
221 if (m_owner_scope) {
222 m_owner_scope->CalculateSymbolContext(sc);
223 sc->variable = this;
224 } else
225 sc->Clear(false);
226}
227
229 if (frame) {
230 Function *function =
231 frame->GetSymbolContext(eSymbolContextFunction).function;
232 if (function) {
233 TargetSP target_sp(frame->CalculateTarget());
234
235 addr_t loclist_base_load_addr =
236 function->GetAddress().GetLoadAddress(target_sp.get());
237 if (loclist_base_load_addr == LLDB_INVALID_ADDRESS)
238 return false;
239 // It is a location list. We just need to tell if the location list
240 // contains the current address when converted to a load address
241 return m_location_list.ContainsAddress(
242 loclist_base_load_addr,
244 target_sp.get()));
245 }
246 }
247 return false;
248}
249
251 // Be sure to resolve the address to section offset prior to calling this
252 // function.
253 if (address.IsSectionOffset()) {
254 // We need to check if the address is valid for both scope range and value
255 // range.
256 // Empty scope range means block range.
257 bool valid_in_scope_range =
259 address.GetFileAddress()) != nullptr;
260 if (!valid_in_scope_range)
261 return false;
262 SymbolContext sc;
264 if (sc.module_sp == address.GetModule()) {
265 // Is the variable is described by a single location?
266 if (m_location_list.IsAlwaysValidSingleExpr()) {
267 // Yes it is, the location is valid.
268 return true;
269 }
270
271 if (sc.function) {
272 addr_t loclist_base_file_addr =
274 if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
275 return false;
276 // It is a location list. We just need to tell if the location list
277 // contains the current address when converted to a load address
278 return m_location_list.ContainsAddress(loclist_base_file_addr,
279 address.GetFileAddress());
280 }
281 }
282 }
283 return false;
284}
285
287 // Synthetic values are always in scope.
289 return true;
290
291 switch (m_scope) {
294 return frame != nullptr;
295
300 return true;
301
304 if (frame) {
305 // We don't have a location list, we just need to see if the block that
306 // this variable was defined in is currently
307 Block *deepest_frame_block =
308 frame->GetSymbolContext(eSymbolContextBlock).block;
309 Address frame_addr = frame->GetFrameCodeAddress();
310 if (deepest_frame_block)
311 return IsInScope(*deepest_frame_block, frame_addr);
312 }
313 break;
314
315 default:
316 break;
317 }
318 return false;
319}
320
321bool Variable::IsInScope(const Block &block, const Address &addr) {
322 SymbolContext variable_sc;
323 CalculateSymbolContext(&variable_sc);
324
325 // Check for static or global variable defined at the compile unit
326 // level that wasn't defined in a block
327 if (variable_sc.block == nullptr)
328 return true;
329
330 // Check if the variable is valid in the current block
331 if (variable_sc.block != &block && !variable_sc.block->Contains(&block))
332 return false;
333
334 // If no scope range is specified then it means that the scope is the
335 // same as the scope of the enclosing lexical block.
336 if (m_scope_range.IsEmpty())
337 return true;
338
339 return m_scope_range.FindEntryThatContains(addr.GetFileAddress()) != nullptr;
340}
341
343 llvm::StringRef variable_expr_path, ExecutionContextScope *scope,
344 GetVariableCallback callback, void *baton, VariableList &variable_list,
345 ValueObjectList &valobj_list) {
347 if (!callback || variable_expr_path.empty()) {
348 error = Status::FromErrorString("unknown error");
349 return error;
350 }
351
352 switch (variable_expr_path.front()) {
353 case '*':
355 variable_expr_path.drop_front(), scope, callback, baton, variable_list,
356 valobj_list);
357 if (error.Fail()) {
358 error = Status::FromErrorString("unknown error");
359 return error;
360 }
361 for (uint32_t i = 0; i < valobj_list.GetSize();) {
362 Status tmp_error;
363 ValueObjectSP valobj_sp(
364 valobj_list.GetValueObjectAtIndex(i)->Dereference(tmp_error));
365 if (tmp_error.Fail()) {
366 variable_list.RemoveVariableAtIndex(i);
367 valobj_list.RemoveValueObjectAtIndex(i);
368 } else {
369 valobj_list.SetValueObjectAtIndex(i, valobj_sp);
370 ++i;
371 }
372 }
373 return error;
374 case '&': {
376 variable_expr_path.drop_front(), scope, callback, baton, variable_list,
377 valobj_list);
378 if (error.Success()) {
379 for (uint32_t i = 0; i < valobj_list.GetSize();) {
380 Status tmp_error;
381 ValueObjectSP valobj_sp(
382 valobj_list.GetValueObjectAtIndex(i)->AddressOf(tmp_error));
383 if (tmp_error.Fail()) {
384 variable_list.RemoveVariableAtIndex(i);
385 valobj_list.RemoveValueObjectAtIndex(i);
386 } else {
387 valobj_list.SetValueObjectAtIndex(i, valobj_sp);
388 ++i;
389 }
390 }
391 } else {
392 error = Status::FromErrorString("unknown error");
393 }
394 return error;
395 } break;
396
397 default: {
398 static RegularExpression g_regex(
399 llvm::StringRef("^([A-Za-z_:][A-Za-z_0-9:]*)(.*)"));
400 llvm::SmallVector<llvm::StringRef, 2> matches;
401 variable_list.Clear();
402 if (!g_regex.Execute(variable_expr_path, &matches)) {
404 "unable to extract a variable name from '{0}'", variable_expr_path);
405 return error;
406 }
407 std::string variable_name = matches[1].str();
408 if (!callback(baton, variable_name.c_str(), variable_list)) {
409 error = Status::FromErrorString("unknown error");
410 return error;
411 }
412 uint32_t i = 0;
413 while (i < variable_list.GetSize()) {
414 VariableSP var_sp(variable_list.GetVariableAtIndex(i));
415 ValueObjectSP valobj_sp;
416 if (!var_sp) {
417 variable_list.RemoveVariableAtIndex(i);
418 continue;
419 }
420 ValueObjectSP variable_valobj_sp(
421 ValueObjectVariable::Create(scope, var_sp));
422 if (!variable_valobj_sp) {
423 variable_list.RemoveVariableAtIndex(i);
424 continue;
425 }
426
427 llvm::StringRef variable_sub_expr_path =
428 variable_expr_path.drop_front(variable_name.size());
429 if (!variable_sub_expr_path.empty()) {
430 valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
431 variable_sub_expr_path);
432 if (!valobj_sp) {
434 "invalid expression path '{0}' for variable '{1}'",
435 variable_sub_expr_path, var_sp->GetName().GetCString());
436 variable_list.RemoveVariableAtIndex(i);
437 continue;
438 }
439 } else {
440 // Just the name of a variable with no extras
441 valobj_sp = variable_valobj_sp;
442 }
443
444 valobj_list.Append(valobj_sp);
445 ++i;
446 }
447
448 if (variable_list.GetSize() > 0) {
449 error.Clear();
450 return error;
451 }
452 } break;
453 }
454 error = Status::FromErrorString("unknown error");
455 return error;
456}
457
458bool Variable::DumpLocations(Stream *s, const Address &address) {
459 SymbolContext sc;
461 ABISP abi;
462 if (m_owner_scope) {
463 ModuleSP module_sp(m_owner_scope->CalculateSymbolContextModule());
464 if (module_sp)
465 abi = ABI::FindPlugin(ProcessSP(), module_sp->GetArchitecture());
466 }
467
468 const addr_t file_addr = address.GetFileAddress();
469 if (sc.function) {
470 addr_t loclist_base_file_addr = sc.function->GetAddress().GetFileAddress();
471 if (loclist_base_file_addr == LLDB_INVALID_ADDRESS)
472 return false;
473 return m_location_list.DumpLocations(s, eDescriptionLevelBrief,
474 loclist_base_file_addr, file_addr,
475 abi.get());
476 }
477 return false;
478}
479
480static void PrivateAutoComplete(
481 StackFrame *frame, llvm::StringRef partial_path,
482 const llvm::Twine
483 &prefix_path, // Anything that has been resolved already will be in here
484 const CompilerType &compiler_type, CompletionRequest &request);
485
486/// Get the CompilerType of the current instance (this/self) for direct ivar
487/// completion. Returns an invalid CompilerType if the frame is not for an
488/// instance method.
490 VariableList &variable_list) {
491 SymbolContext sc =
492 frame.GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
493 llvm::StringRef instance_name = sc.GetInstanceName();
494 if (instance_name.empty())
495 return {};
496 VariableSP var_sp = variable_list.FindVariable(ConstString(instance_name));
497 if (!var_sp)
498 return {};
499 Type *var_type = var_sp->GetType();
500 if (!var_type)
501 return {};
502 CompilerType compiler_type = var_type->GetForwardCompilerType();
503 if (compiler_type.IsPointerType())
504 compiler_type = compiler_type.GetPointeeType();
505 return compiler_type.GetCanonicalType();
506}
507
509 StackFrame *frame, const std::string &partial_member_name,
510 llvm::StringRef partial_path,
511 const llvm::Twine
512 &prefix_path, // Anything that has been resolved already will be in here
513 const CompilerType &compiler_type, CompletionRequest &request) {
514
515 // We are in a type parsing child members
516 const uint32_t num_bases = compiler_type.GetNumDirectBaseClasses();
517
518 if (num_bases > 0) {
519 for (uint32_t i = 0; i < num_bases; ++i) {
520 CompilerType base_class_type =
521 compiler_type.GetDirectBaseClassAtIndex(i, nullptr);
522
523 PrivateAutoCompleteMembers(frame, partial_member_name, partial_path,
524 prefix_path,
525 base_class_type.GetCanonicalType(), request);
526 }
527 }
528
529 const uint32_t num_vbases = compiler_type.GetNumVirtualBaseClasses();
530
531 if (num_vbases > 0) {
532 for (uint32_t i = 0; i < num_vbases; ++i) {
533 CompilerType vbase_class_type =
534 compiler_type.GetVirtualBaseClassAtIndex(i, nullptr);
535
536 PrivateAutoCompleteMembers(frame, partial_member_name, partial_path,
537 prefix_path,
538 vbase_class_type.GetCanonicalType(), request);
539 }
540 }
541
542 // We are in a type parsing child members
543 const uint32_t num_fields = compiler_type.GetNumFields();
544
545 if (num_fields > 0) {
546 for (uint32_t i = 0; i < num_fields; ++i) {
547 std::string member_name;
548
549 CompilerType member_compiler_type = compiler_type.GetFieldAtIndex(
550 i, member_name, nullptr, nullptr, nullptr);
551
552 if (partial_member_name.empty()) {
553 request.AddCompletion((prefix_path + member_name).str());
554 } else if (llvm::StringRef(member_name)
555 .starts_with(partial_member_name)) {
556 if (member_name == partial_member_name) {
558 frame, partial_path,
559 prefix_path + member_name, // Anything that has been resolved
560 // already will be in here
561 member_compiler_type.GetCanonicalType(), request);
562 } else if (partial_path.empty()) {
563 request.AddCompletion((prefix_path + member_name).str());
564 }
565 }
566 }
567 }
568}
569
571 StackFrame *frame, llvm::StringRef partial_path,
572 const llvm::Twine
573 &prefix_path, // Anything that has been resolved already will be in here
574 const CompilerType &compiler_type, CompletionRequest &request) {
575 // printf ("\nPrivateAutoComplete()\n\tprefix_path = '%s'\n\tpartial_path =
576 // '%s'\n", prefix_path.c_str(), partial_path.c_str());
577 std::string remaining_partial_path;
578
579 const lldb::TypeClass type_class = compiler_type.GetTypeClass();
580 if (partial_path.empty()) {
581 if (compiler_type.IsValid()) {
582 switch (type_class) {
583 default:
584 case eTypeClassArray:
585 case eTypeClassBlockPointer:
586 case eTypeClassBuiltin:
587 case eTypeClassComplexFloat:
588 case eTypeClassComplexInteger:
589 case eTypeClassEnumeration:
590 case eTypeClassFunction:
591 case eTypeClassMemberPointer:
592 case eTypeClassReference:
593 case eTypeClassTypedef:
594 case eTypeClassVector: {
595 request.AddCompletion(prefix_path.str());
596 } break;
597
598 case eTypeClassClass:
599 case eTypeClassStruct:
600 case eTypeClassUnion:
601 if (prefix_path.str().back() != '.')
602 request.AddCompletion((prefix_path + ".").str());
603 break;
604
605 case eTypeClassObjCObject:
606 case eTypeClassObjCInterface:
607 break;
608 case eTypeClassObjCObjectPointer:
609 case eTypeClassPointer: {
610 bool omit_empty_base_classes = true;
611 if (llvm::expectedToOptional(
612 compiler_type.GetNumChildren(omit_empty_base_classes, nullptr))
613 .value_or(0))
614 request.AddCompletion((prefix_path + "->").str());
615 else {
616 request.AddCompletion(prefix_path.str());
617 }
618 } break;
619 }
620 } else {
621 if (frame) {
622 const bool get_file_globals = true;
623 const bool include_synthetic_vars = true;
624
625 VariableList *variable_list = frame->GetVariableList(
626 get_file_globals, include_synthetic_vars, nullptr);
627
628 if (variable_list) {
629 for (const VariableSP &var_sp : *variable_list)
630 request.AddCompletion(var_sp->GetName());
631
632 // Offer members of this/self so that direct ivar access can be
633 // completed (eg "frame variable member" for "this->member").
634 CompilerType instance_type = GetInstanceType(*frame, *variable_list);
635 if (instance_type.IsValid())
636 PrivateAutoCompleteMembers(frame, "", "", "", instance_type,
637 request);
638 }
639 }
640 }
641 } else {
642 const char ch = partial_path[0];
643 switch (ch) {
644 case '*':
645 if (prefix_path.str().empty()) {
646 PrivateAutoComplete(frame, partial_path.substr(1), "*", compiler_type,
647 request);
648 }
649 break;
650
651 case '&':
652 if (prefix_path.isTriviallyEmpty()) {
653 PrivateAutoComplete(frame, partial_path.substr(1), std::string("&"),
654 compiler_type, request);
655 }
656 break;
657
658 case '-':
659 if (partial_path.size() > 1 && partial_path[1] == '>' &&
660 !prefix_path.str().empty()) {
661 switch (type_class) {
662 case lldb::eTypeClassPointer: {
663 CompilerType pointee_type(compiler_type.GetPointeeType());
664 if (partial_path.size() > 2 && partial_path[2]) {
665 // If there is more after the "->", then search deeper
666 PrivateAutoComplete(frame, partial_path.substr(2),
667 prefix_path + "->",
668 pointee_type.GetCanonicalType(), request);
669 } else {
670 // Nothing after the "->", so list all members
672 frame, std::string(), std::string(), prefix_path + "->",
673 pointee_type.GetCanonicalType(), request);
674 }
675 } break;
676 default:
677 break;
678 }
679 }
680 break;
681
682 case '.':
683 if (compiler_type.IsValid()) {
684 switch (type_class) {
685 case lldb::eTypeClassUnion:
686 case lldb::eTypeClassStruct:
687 case lldb::eTypeClassClass:
688 if (partial_path.size() > 1 && partial_path[1]) {
689 // If there is more after the ".", then search deeper
690 PrivateAutoComplete(frame, partial_path.substr(1),
691 prefix_path + ".", compiler_type, request);
692
693 } else {
694 // Nothing after the ".", so list all members
695 PrivateAutoCompleteMembers(frame, std::string(), partial_path,
696 prefix_path + ".", compiler_type,
697 request);
698 }
699 break;
700 default:
701 break;
702 }
703 }
704 break;
705 default:
706 if (isalpha(ch) || ch == '_' || ch == '$') {
707 const size_t partial_path_len = partial_path.size();
708 size_t pos = 1;
709 while (pos < partial_path_len) {
710 const char curr_ch = partial_path[pos];
711 if (isalnum(curr_ch) || curr_ch == '_' || curr_ch == '$') {
712 ++pos;
713 continue;
714 }
715 break;
716 }
717
718 std::string token(std::string(partial_path), 0, pos);
719 remaining_partial_path = std::string(partial_path.substr(pos));
720
721 if (compiler_type.IsValid()) {
722 PrivateAutoCompleteMembers(frame, token, remaining_partial_path,
723 prefix_path, compiler_type, request);
724 } else if (frame) {
725 // We haven't found our variable yet
726 const bool get_file_globals = true;
727 const bool include_synthetic_vars = true;
728
729 VariableList *variable_list = frame->GetVariableList(
730 get_file_globals, include_synthetic_vars, nullptr);
731
732 if (!variable_list)
733 break;
734
735 for (VariableSP var_sp : *variable_list) {
736
737 if (!var_sp)
738 continue;
739
740 llvm::StringRef variable_name = var_sp->GetName().GetStringRef();
741 if (variable_name.starts_with(token)) {
742 if (variable_name == token) {
743 Type *variable_type = var_sp->GetType();
744 if (variable_type) {
745 CompilerType variable_compiler_type(
746 variable_type->GetForwardCompilerType());
748 frame, remaining_partial_path,
749 prefix_path + token, // Anything that has been resolved
750 // already will be in here
751 variable_compiler_type.GetCanonicalType(), request);
752 } else {
753 request.AddCompletion((prefix_path + variable_name).str());
754 }
755 } else if (remaining_partial_path.empty()) {
756 request.AddCompletion((prefix_path + variable_name).str());
757 }
758 }
759 }
760
761 // Try also completing the token as a member of this/self (direct ivar
762 // access).
763 CompilerType instance_type = GetInstanceType(*frame, *variable_list);
764 if (instance_type.IsValid())
765 PrivateAutoCompleteMembers(frame, token, remaining_partial_path,
766 prefix_path, instance_type, request);
767 }
768 }
769 break;
770 }
771 }
772}
773
775 CompletionRequest &request) {
776 CompilerType compiler_type;
777
779 "", compiler_type, request);
780}
static llvm::raw_ostream & error(Stream &strm)
static void PrivateAutoCompleteMembers(StackFrame *frame, const std::string &partial_member_name, llvm::StringRef partial_path, const llvm::Twine &prefix_path, const CompilerType &compiler_type, CompletionRequest &request)
Definition Variable.cpp:508
static CompilerType GetInstanceType(StackFrame &frame, VariableList &variable_list)
Get the CompilerType of the current instance (this/self) for direct ivar completion.
Definition Variable.cpp:489
static void PrivateAutoComplete(StackFrame *frame, llvm::StringRef partial_path, const llvm::Twine &prefix_path, const CompilerType &compiler_type, CompletionRequest &request)
Definition Variable.cpp:570
static lldb::ABISP FindPlugin(lldb::ProcessSP process_sp, const ArchSpec &arch)
Definition ABI.cpp:27
A section + offset based address class.
Definition Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition Address.cpp:303
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition Address.cpp:275
lldb::addr_t GetFileAddress() const
Get the file address.
Definition Address.cpp:283
bool IsSectionOffset() const
Check if an address is section offset.
Definition Address.h:342
A class that describes a single lexical block.
Definition Block.h:41
bool Contains(lldb::addr_t range_offset) const
Check if an offset is in one of the block offset ranges.
Definition Block.cpp:180
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
CompilerType GetVirtualBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
CompilerType GetFieldAtIndex(size_t idx, std::string &name, uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr, bool *is_bitfield_ptr) const
lldb::TypeClass GetTypeClass() const
uint32_t GetNumVirtualBaseClasses() const
uint32_t GetNumFields() const
uint32_t GetNumDirectBaseClasses() const
CompilerType GetDirectBaseClassAtIndex(size_t idx, uint32_t *bit_offset_ptr) const
CompilerType GetPointeeType() const
If this type is a pointer type, return the type that the pointer points to, else return an invalid ty...
llvm::Expected< uint32_t > GetNumChildren(bool omit_empty_base_classes, const ExecutionContext *exe_ctx) const
CompilerType GetCanonicalType() const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
"lldb/Utility/ArgCompletionRequest.h"
void AddCompletion(llvm::StringRef completion, llvm::StringRef description="", CompletionMode mode=CompletionMode::Normal)
Adds a possible completion string.
llvm::StringRef GetCursorArgumentPrefix() const
A uniqued constant string class.
Definition ConstString.h:40
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
A class that describes the declaration location of a lldb object.
Definition Declaration.h:24
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
StackFrame * GetFramePtr() const
Returns a pointer to the frame object.
A class that describes a function.
Definition Function.h:377
const Address & GetAddress() const
Return the address of the function (its entry point).
Definition Function.h:430
const Entry * FindEntryThatContains(B addr) const
Definition RangeMap.h:338
bool Execute(llvm::StringRef string, llvm::SmallVectorImpl< llvm::StringRef > *matches=nullptr) const
Execute a regular expression match using the compiled regular expression that is already in this obje...
This base class provides an interface to stack frames.
Definition StackFrame.h:44
virtual Address GetFrameCodeAddressForSymbolication()
Get the current code Address suitable for symbolication, may not be the same as GetFrameCodeAddress()...
virtual VariableList * GetVariableList(bool get_file_globals, bool include_synthetic_vars, Status *error_ptr)
Retrieve the list of variables whose scope either:
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
lldb::TargetSP CalculateTarget() override
An error handling class.
Definition Status.h:118
static Status FromErrorString(const char *str)
Definition Status.h:141
bool Fail() const
Test for error condition.
Definition Status.cpp:293
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
A stream class that can stream formatted output to a file.
Definition Stream.h:28
void Format(const char *format, Args &&... args)
Forwards the arguments to llvm::formatv and writes to the stream.
Definition Stream.h:370
llvm::raw_ostream & AsRawOstream()
Returns a raw_ostream that forwards the data to this Stream object.
Definition Stream.h:405
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition Stream.cpp:63
size_t PutChar(char ch)
Definition Stream.cpp:131
size_t EOL()
Output and End of Line character to the stream.
Definition Stream.cpp:155
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
llvm::StringRef GetInstanceName()
Determines the name of the instance for this decl context.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module 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.
void Clear(bool clear_target)
Clear the object's state.
Variable * variable
The global variable matching the given query.
LineEntry line_entry
The LineEntry for a given query.
virtual CompilerDeclContext GetDeclContextContainingUID(lldb::user_id_t uid)
Definition SymbolFile.h:241
virtual CompilerDecl GetDeclForUID(lldb::user_id_t uid)
Definition SymbolFile.h:237
virtual lldb::TypeSP GetTypeEnclosingVariableUID(lldb::user_id_t uid)
Get the semantically innermost non-function type that encloses the provided variable.
Definition SymbolFile.h:542
CompilerType GetForwardCompilerType()
Definition Type.cpp:791
SymbolFile * GetSymbolFile()
Definition Type.h:476
void DumpTypeName(Stream *s)
Definition Type.cpp:452
A collection of ValueObject values that.
void SetValueObjectAtIndex(size_t idx, const lldb::ValueObjectSP &valobj_sp)
void Append(const lldb::ValueObjectSP &val_obj_sp)
lldb::ValueObjectSP GetValueObjectAtIndex(size_t idx)
lldb::ValueObjectSP RemoveValueObjectAtIndex(size_t idx)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
lldb::VariableSP GetVariableAtIndex(size_t idx) const
lldb::VariableSP RemoveVariableAtIndex(size_t idx)
lldb::VariableSP FindVariable(ConstString name, bool include_static_members=true) const
bool DumpDeclaration(Stream *s, bool show_fullpaths, bool show_module)
Definition Variable.cpp:184
const RangeList & GetScopeRange() const
Definition Variable.h:71
unsigned m_static_member
Non-zero if variable is static member of a class or struct.
Definition Variable.h:150
bool IsInScope(StackFrame *frame)
Definition Variable.cpp:286
static void AutoComplete(const ExecutionContext &exe_ctx, CompletionRequest &request)
Definition Variable.cpp:774
CompilerDeclContext GetDeclContext()
Definition Variable.cpp:208
unsigned m_artificial
Non-zero if the variable is not explicitly declared in source.
Definition Variable.h:145
unsigned m_external
Visible outside the containing compile unit?
Definition Variable.h:143
bool LocationIsValidForAddress(const Address &address)
Definition Variable.cpp:250
unsigned m_loc_is_const_data
The m_location expression contains the constant variable value data, not a DWARF location.
Definition Variable.h:148
lldb::SymbolFileTypeSP m_symfile_type_sp
The type pointer of the variable (int, struct, class, etc) global, parameter, local.
Definition Variable.h:130
RangeList m_scope_range
The list of ranges inside the owner's scope where this variable is valid.
Definition Variable.h:136
ConstString GetUnqualifiedName() const
Definition Variable.cpp:90
static Status GetValuesForVariableExpressionPath(llvm::StringRef variable_expr_path, ExecutionContextScope *scope, GetVariableCallback callback, void *baton, VariableList &variable_list, ValueObjectList &valobj_list)
Definition Variable.cpp:342
Mangled m_mangled
The mangled name of the variable.
Definition Variable.h:127
bool NameMatches(ConstString name) const
Since a variable can have a basename "i" and also a mangled named "_ZN12_GLOBAL__N_11iE" and a demang...
Definition Variable.cpp:92
void Dump(Stream *s, bool show_context) const
Definition Variable.cpp:118
std::optional< uint64_t > m_tag_offset
The value of DW_AT_LLVM_tag_offset if present.
Definition Variable.h:152
lldb::ValueType m_scope
Definition Variable.h:131
SymbolContextScope * m_owner_scope
The symbol file scope that this variable was defined in.
Definition Variable.h:133
ConstString GetName() const
Definition Variable.cpp:83
CompilerDecl GetDecl()
Definition Variable.cpp:215
ConstString m_name
The basename of the variable (no namespaces).
Definition Variable.h:125
RangeVector< lldb::addr_t, lldb::addr_t > RangeList
Definition Variable.h:27
Declaration m_declaration
Declaration location for this item.
Definition Variable.h:138
void CalculateSymbolContext(SymbolContext *sc)
Definition Variable.cpp:220
lldb::TypeSP GetEnclosingType()
Definition Variable.cpp:111
bool DumpLocations(Stream *s, const Address &address)
Definition Variable.cpp:458
lldb::LanguageType GetLanguage() const
Definition Variable.cpp:66
bool LocationIsValidForFrame(StackFrame *frame)
Definition Variable.cpp:228
Variable(lldb::user_id_t uid, const char *name, const char *mangled, const lldb::SymbolFileTypeSP &symfile_type_sp, lldb::ValueType scope, SymbolContextScope *owner_scope, const RangeList &scope_range, Declaration *decl, const DWARFExpressionList &location, bool external, bool artificial, bool location_is_constant_data, bool static_member=false, std::optional< uint64_t > tag_offset=std::nullopt)
Constructors and Destructors.
Definition Variable.cpp:43
size_t(* GetVariableCallback)(void *baton, const char *name, VariableList &var_list)
Definition Variable.h:108
DWARFExpressionList m_location_list
The location of this variable that can be fed to DWARFExpression::Evaluate().
Definition Variable.h:141
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
constexpr bool IsSyntheticValueType(lldb::ValueType vt)
Return true if vt represents a synthetic value, false if not.
Definition ValueType.h:27
std::shared_ptr< lldb_private::ABI > ABISP
@ eDescriptionLevelBrief
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
std::shared_ptr< lldb_private::Type > TypeSP
std::shared_ptr< lldb_private::Process > ProcessSP
std::shared_ptr< lldb_private::SymbolFileType > SymbolFileTypeSP
std::shared_ptr< lldb_private::Variable > VariableSP
@ eValueTypeVariableGlobal
globals variable
@ eValueTypeConstResult
constant result variables
@ eValueTypeVariableLocal
function local variables
@ eValueTypeVariableArgument
function argument variables
@ eValueTypeRegister
stack frame register value
@ eValueTypeVariableStatic
static variable
@ eValueTypeRegisterSet
A collection of stack frame register values.
@ eValueTypeVariableThreadLocal
thread local storage variable
uint64_t user_id_t
Definition lldb-types.h:83
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::Module > ModuleSP
void Clear()
Clear the object's state.
Definition LineEntry.cpp:22
static TestingProperties & GetGlobalTestingProperties()
Definition Debugger.cpp:270
UserID(lldb::user_id_t uid=LLDB_INVALID_UID)
Construct with optional user ID.
Definition UserID.h:33
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47