19#include "llvm/Support/FormatAdapters.h"
27 std::vector<lldb::VariableSP> possible_matches;
30 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
32 str_ref_name.consume_front(
"::");
38 if (var_sp->NameMatches(name))
39 possible_matches.push_back(var_sp);
43 if (possible_matches.size() > 0)
44 return possible_matches[0];
50 llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
54 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
59 name_ref.consume_front(
"::");
66 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
74 target_sp->GetImages().FindGlobalVariables(
75 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
78 if (!modules_var_list.
Empty()) {
91 std::shared_ptr<StackFrame> stack_frame,
95 if (name_ref.consume_front(
"$")) {
100 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
106 if (!name_ref.contains(
"::")) {
110 stack_frame->GetInScopeVariableList(
false));
115 variable_list->FindVariable(
ConstString(name_ref));
118 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
126 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
128 value_sp = stack_frame->FindVariable(
ConstString(ivar_name));
130 value_sp = value_sp->GetChildMemberWithName(name_ref);
139 std::shared_ptr<StackFrame> frame_sp,
141 bool fragile_ivar,
bool check_ptr_vs_member)
149 auto value_or_error = node->
Accept(
this);
152 return value_or_error;
155llvm::Expected<lldb::ValueObjectSP>
167 llvm::formatv(
"use of undeclared identifier '{0}'", node->
GetName());
168 return llvm::make_error<DILDiagnosticError>(
175llvm::Expected<lldb::ValueObjectSP>
194 child_sp = synth_obj_sp->Dereference(
error);
198 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
207 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
215 return llvm::make_error<DILDiagnosticError>(
219llvm::Expected<lldb::ValueObjectSP>
232 const uint32_t pointer_type_flags =
233 base->GetCompilerType().GetTypeInfo(
nullptr);
234 if ((pointer_type_flags & lldb::eTypeIsObjC) &&
235 (pointer_type_flags & lldb::eTypeIsPointer)) {
244 if (!base->IsPointerType() && base->HasSyntheticValue()) {
247 base->GetSyntheticValue()->Dereference(deref_error);
248 synth_deref_sp && deref_error.
Success()) {
249 base = std::move(synth_deref_sp);
251 if (!base || deref_error.
Fail()) {
252 std::string errMsg = llvm::formatv(
253 "Failed to dereference synthetic value: {0}", deref_error);
254 return llvm::make_error<DILDiagnosticError>(
260 std::string errMsg =
"Failed to dereference synthetic value";
261 return llvm::make_error<DILDiagnosticError>(
269 bool base_is_ptr = base->IsPointerType();
271 if (expr_is_ptr != base_is_ptr) {
274 llvm::formatv(
"member reference type {0} is a pointer; "
275 "did you mean to use '->'?",
276 base->GetCompilerType().TypeDescription());
277 return llvm::make_error<DILDiagnosticError>(
281 llvm::formatv(
"member reference type {0} is not a pointer; "
282 "did you mean to use '.'?",
283 base->GetCompilerType().TypeDescription());
284 return llvm::make_error<DILDiagnosticError>(
294 field_obj = base->GetSyntheticValue();
296 field_obj = field_obj->GetChildMemberWithName(node->
GetFieldName());
300 std::string errMsg = llvm::formatv(
301 "\"{0}\" is not a member of \"({1}) {2}\"", node->
GetFieldName(),
302 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
303 return llvm::make_error<DILDiagnosticError>(
313 field_obj = dynamic_val_sp;
319 if (node->
GetIsArrow() && base->IsPointerType())
321 std::string errMsg = llvm::formatv(
322 "\"{0}\" is not a member of \"({1}) {2}\"", node->
GetFieldName(),
323 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
324 return llvm::make_error<DILDiagnosticError>(
328llvm::Expected<lldb::ValueObjectSP>
336 uint64_t child_idx = node->
GetIndex();
339 bool is_incomplete_array =
false;
341 base->GetExpressionPath(var_expr_path_strm);
344 bool is_objc_pointer =
true;
347 is_objc_pointer =
false;
348 else if (!base->GetCompilerType().IsPointerType())
349 is_objc_pointer =
false;
352 std::string err_msg = llvm::formatv(
353 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
354 base->GetTypeName().AsCString(
"<invalid type>"),
356 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
359 if (is_objc_pointer) {
361 if (!synthetic || synthetic == base) {
362 std::string err_msg =
363 llvm::formatv(
"\"({0}) {1}\" is not an array type",
364 base->GetTypeName().AsCString(
"<invalid type>"),
366 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
369 if (
static_cast<uint32_t
>(child_idx) >=
370 synthetic->GetNumChildrenIgnoringErrors()) {
371 std::string err_msg = llvm::formatv(
372 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
373 base->GetTypeName().AsCString(
"<invalid type>"),
375 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
378 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
379 if (!child_valobj_sp) {
380 std::string err_msg = llvm::formatv(
381 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
382 base->GetTypeName().AsCString(
"<invalid type>"),
384 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
388 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
389 child_valobj_sp = std::move(dynamic_sp);
391 return child_valobj_sp;
394 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
395 if (!child_valobj_sp) {
396 std::string err_msg = llvm::formatv(
397 "failed to use pointer as array for index {0} for "
399 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
402 err_msg =
"subscript of pointer to incomplete type 'void'";
403 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
406 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
407 child_valobj_sp = base->GetChildAtIndex(child_idx);
409 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
410 if (!child_valobj_sp) {
411 std::string err_msg = llvm::formatv(
412 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
413 base->GetTypeName().AsCString(
"<invalid type>"),
415 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
420 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
421 if (!child_valobj_sp) {
422 std::string err_msg = llvm::formatv(
423 "bitfield range {0}-{1} is not valid for \"({2}) {3}\"", child_idx,
424 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
426 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
432 std::string err_msg =
433 llvm::formatv(
"\"{0}\" is not an array type",
434 base->GetTypeName().AsCString(
"<invalid type>"));
435 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
438 if (
static_cast<uint32_t
>(child_idx) >=
439 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
440 std::string err_msg = llvm::formatv(
441 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
442 base->GetTypeName().AsCString(
"<invalid type>"),
444 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
447 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
448 if (!child_valobj_sp) {
449 std::string err_msg = llvm::formatv(
450 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
451 base->GetTypeName().AsCString(
"<invalid type>"),
453 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
458 if (child_valobj_sp) {
460 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
461 child_valobj_sp = std::move(dynamic_sp);
463 return child_valobj_sp;
466 int64_t signed_child_idx = node->
GetIndex();
467 return base->GetSyntheticArrayMember(signed_child_idx,
true);
470llvm::Expected<lldb::ValueObjectSP>
480 if (first_index > last_index)
481 std::swap(first_index, last_index);
484 if (base->GetCompilerType().IsReferenceType()) {
485 base = base->Dereference(
error);
487 return error.ToError();
490 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
491 if (!child_valobj_sp) {
492 std::string message = llvm::formatv(
493 "bitfield range {0}-{1} is not valid for \"({2}) {3}\"", first_index,
494 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
495 base->GetName().AsCString());
496 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
499 return child_valobj_sp;
502static llvm::Expected<lldb::TypeSystemSP>
505 ctx->GetSymbolContext(lldb::eSymbolContextCompUnit);
508 symbol_context = ctx->GetSymbolContext(lldb::eSymbolContextModule);
509 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
520llvm::Expected<CompilerType>
522 std::shared_ptr<ExecutionContextScope> ctx,
527 llvm::APInt apint = literal->
GetValue();
529 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
540 for (
auto [signed_, unsigned_] : candidates) {
544 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
546 return size.takeError();
547 if (!literal->
IsUnsigned() && apint.isIntN(*size - 1))
553 return llvm::make_error<DILDiagnosticError>(
555 "integer literal is too large to be represented in any integer type",
559llvm::Expected<lldb::ValueObjectSP>
561 llvm::Expected<lldb::TypeSystemSP> type_system =
564 return type_system.takeError();
566 llvm::Expected<CompilerType> type =
569 return type.takeError();
574 llvm::Expected<uint64_t> type_bitsize =
577 return type_bitsize.takeError();
583llvm::Expected<lldb::ValueObjectSP>
585 llvm::Expected<lldb::TypeSystemSP> type_system =
588 return type_system.takeError();
591 &node->
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
597 return llvm::make_error<DILDiagnosticError>(
605llvm::Expected<lldb::ValueObjectSP>
static llvm::raw_ostream & error(Stream &strm)
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
lldb::LanguageType GetLanguage()
Generic representation of a type in a programming language.
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
bool IsPointerToVoid() const
CompilerType GetNonReferenceType() const
If this type is a reference to a type (L value or R value reference), return a new type with the refe...
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< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsScalarType() const
bool IsPointerType(CompilerType *pointee_type=nullptr) const
A uniqued constant string class.
llvm::StringRef GetStringRef() const
Get the string value as a llvm::StringRef.
void TruncOrExtendTo(uint16_t bits, bool sign)
Convert to an integer with bits and the given signedness.
bool Fail() const
Test for error condition.
bool Success() const
Test for success condition.
const char * GetData() const
Defines a symbol context baton that can be handed other debug core functions.
llvm::StringRef GetInstanceVariableName()
Determines the name of the instance variable for the this decl context.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, lldb::RegisterContextSP ®_ctx_sp, const RegisterInfo *reg_info)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
static lldb::ValueObjectSP CreateValueObjectFromBool(lldb::TargetSP target, bool value, llvm::StringRef name)
Create a value object containing the given boolean value.
static lldb::ValueObjectSP CreateValueObjectFromScalar(lldb::TargetSP target, Scalar &s, CompilerType type, llvm::StringRef name)
Create a value object containing the given Scalar value.
The rest of the classes in this file, except for the Visitor class at the very end,...
uint32_t GetLocation() const
virtual llvm::Expected< lldb::ValueObjectSP > Accept(Visitor *v) const =0
ASTNode * GetBase() const
const llvm::APFloat & GetValue() const
std::string GetName() const
uint32_t GetRadix() const
IntegerTypeSuffix GetTypeSuffix() const
const llvm::APInt & GetValue() const
std::shared_ptr< StackFrame > m_exe_ctx_scope
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode *node) override
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode *node)
Interpreter(lldb::TargetSP target, llvm::StringRef expr, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, bool use_synthetic, bool fragile_ivar, bool check_ptr_vs_member)
bool m_check_ptr_vs_member
lldb::DynamicValueType m_use_dynamic
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, std::shared_ptr< ExecutionContextScope > ctx, const IntegerLiteralNode *literal)
llvm::StringRef GetFieldName() const
ASTNode * GetBase() const
ASTNode * GetOperand() const
UnaryOpKind GetKind() const
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(std::shared_ptr< StackFrame > ctx)
static CompilerType GetBasicType(lldb::TypeSystemSP type_system, lldb::BasicType basic_type)
static lldb::VariableSP DILFindVariable(ConstString name, VariableList &variable_list)
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::TargetSP target_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier, check to see if it matches the name of a global variable.
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedLongLong
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
LanguageType
Programming language type.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::VariableList > VariableListSP
std::shared_ptr< lldb_private::Variable > VariableSP
std::shared_ptr< lldb_private::Target > TargetSP
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Every register is described in detail including its name, alternate name (optional),...