19#include "llvm/Support/FormatAdapters.h"
24static llvm::Expected<lldb::TypeSystemSP>
26 auto stack_frame = ctx->CalculateStackFrame();
28 return llvm::createStringError(
"no stack frame in this context");
30 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
33 symbol_context = stack_frame->GetSymbolContext(lldb::eSymbolContextModule);
34 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
40 return type_system.get()->GetBasicTypeFromAST(basic_type);
51 "result", addr, exe_ctx,
56llvm::Expected<lldb::ValueObjectSP>
59 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
61 llvm::Expected<lldb::TypeSystemSP> type_system =
64 return type_system.takeError();
67 if (valobj->IsBitfield()) {
72 uint32_t bitfield_size = valobj->GetBitfieldBitSize();
75 if (bitfield_size > 0 && in_type.
IsInteger()) {
79 llvm::Expected<uint64_t> int_bit_size =
82 return int_bit_size.takeError();
83 llvm::Expected<uint64_t> uint_bit_size =
86 return int_bit_size.takeError();
87 if (bitfield_size < *int_bit_size ||
88 (in_type.
IsSigned() && bitfield_size == *int_bit_size))
89 return valobj->CastToBasicType(int_type);
90 if (bitfield_size <= *uint_bit_size)
91 return valobj->CastToBasicType(uint_type);
94 bool resolved = valobj->ResolveValue(scalar);
96 return llvm::createStringError(
"invalid scalar value");
105 if (valobj->GetCompilerType().IsInteger() ||
106 valobj->GetCompilerType().IsUnscopedEnumerationType()) {
107 llvm::Expected<CompilerType> promoted_type =
108 type_system.get()->DoIntegralPromotion(valobj->GetCompilerType(),
111 return promoted_type.takeError();
112 if (!promoted_type->CompareTypes(valobj->GetCompilerType()))
113 return valobj->CastToBasicType(*promoted_type);
122 std::vector<lldb::VariableSP> possible_matches;
125 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
127 str_ref_name.consume_front(
"::");
133 if (var_sp->NameMatches(name))
134 possible_matches.push_back(var_sp);
138 if (possible_matches.size() > 0)
139 return possible_matches[0];
145 llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
149 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
154 name_ref.consume_front(
"::");
161 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
169 target_sp->GetImages().FindGlobalVariables(
170 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
173 if (!modules_var_list.
Empty()) {
186 std::shared_ptr<StackFrame> stack_frame,
190 if (name_ref.consume_front(
"$")) {
195 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
201 if (!name_ref.contains(
"::")) {
205 stack_frame->GetInScopeVariableList(
false));
210 variable_list->FindVariable(
ConstString(name_ref));
213 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
221 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
223 value_sp = stack_frame->FindVariable(
ConstString(ivar_name));
225 value_sp = value_sp->GetChildMemberWithName(name_ref);
234 std::shared_ptr<StackFrame> frame_sp,
236 bool fragile_ivar,
bool check_ptr_vs_member)
244 auto value_or_error = node->
Accept(
this);
246 if (value_or_error && !*value_or_error)
247 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
251 return value_or_error;
254llvm::Expected<lldb::ValueObjectSP>
266 llvm::formatv(
"use of undeclared identifier '{0}'", node->
GetName());
267 return llvm::make_error<DILDiagnosticError>(
274llvm::Expected<lldb::ValueObjectSP>
287 operand = dynamic_op;
293 child_sp = synth_obj_sp->Dereference(
error);
297 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
306 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
312 if (operand->GetCompilerType().IsReferenceType()) {
313 operand = operand->Dereference(
error);
315 return error.ToError();
317 llvm::Expected<lldb::ValueObjectSP> conv_op =
325 llvm::formatv(
"invalid argument type '{0}' to unary expression",
327 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
331 bool resolved = operand->ResolveValue(scalar);
338 m_target, scalar, operand->GetCompilerType(),
"result");
342 if (operand->GetCompilerType().IsReferenceType()) {
343 operand = operand->Dereference(
error);
345 return error.ToError();
347 llvm::Expected<lldb::ValueObjectSP> conv_op =
357 llvm::formatv(
"invalid argument type '{0}' to unary expression",
359 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
365 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
369llvm::Expected<lldb::ValueObjectSP>
382 const uint32_t pointer_type_flags =
383 base->GetCompilerType().GetTypeInfo(
nullptr);
384 if ((pointer_type_flags & lldb::eTypeIsObjC) &&
385 (pointer_type_flags & lldb::eTypeIsPointer)) {
394 if (!base->IsPointerType() && base->HasSyntheticValue()) {
397 base->GetSyntheticValue()->Dereference(deref_error);
398 synth_deref_sp && deref_error.
Success()) {
399 base = std::move(synth_deref_sp);
401 if (!base || deref_error.
Fail()) {
402 std::string errMsg = llvm::formatv(
403 "Failed to dereference synthetic value: {0}", deref_error);
404 return llvm::make_error<DILDiagnosticError>(
410 std::string errMsg =
"Failed to dereference synthetic value";
411 return llvm::make_error<DILDiagnosticError>(
419 bool base_is_ptr = base->IsPointerType();
421 if (expr_is_ptr != base_is_ptr) {
424 llvm::formatv(
"member reference type {0} is a pointer; "
425 "did you mean to use '->'?",
426 base->GetCompilerType().TypeDescription());
427 return llvm::make_error<DILDiagnosticError>(
431 llvm::formatv(
"member reference type {0} is not a pointer; "
432 "did you mean to use '.'?",
433 base->GetCompilerType().TypeDescription());
434 return llvm::make_error<DILDiagnosticError>(
444 field_obj = base->GetSyntheticValue();
446 field_obj = field_obj->GetChildMemberWithName(node->
GetFieldName());
450 std::string errMsg = llvm::formatv(
451 "\"{0}\" is not a member of \"({1}) {2}\"", node->
GetFieldName(),
452 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
453 return llvm::make_error<DILDiagnosticError>(
463 field_obj = dynamic_val_sp;
469 if (node->
GetIsArrow() && base->IsPointerType())
471 std::string errMsg = llvm::formatv(
472 "\"{0}\" is not a member of \"({1}) {2}\"", node->
GetFieldName(),
473 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
474 return llvm::make_error<DILDiagnosticError>(
478llvm::Expected<lldb::ValueObjectSP>
486 uint64_t child_idx = node->
GetIndex();
489 bool is_incomplete_array =
false;
490 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
491 base->GetExpressionPath(var_expr_path_strm);
494 bool is_objc_pointer =
true;
497 is_objc_pointer =
false;
498 else if (!base->GetCompilerType().IsPointerType())
499 is_objc_pointer =
false;
502 std::string err_msg = llvm::formatv(
503 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
504 base->GetTypeName().AsCString(
"<invalid type>"),
506 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
509 if (is_objc_pointer) {
511 if (!synthetic || synthetic == base) {
512 std::string err_msg =
513 llvm::formatv(
"\"({0}) {1}\" is not an array type",
514 base->GetTypeName().AsCString(
"<invalid type>"),
516 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
519 if (
static_cast<uint32_t
>(child_idx) >=
520 synthetic->GetNumChildrenIgnoringErrors()) {
521 std::string err_msg = llvm::formatv(
522 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
523 base->GetTypeName().AsCString(
"<invalid type>"),
525 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
528 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
529 if (!child_valobj_sp) {
530 std::string err_msg = llvm::formatv(
531 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
532 base->GetTypeName().AsCString(
"<invalid type>"),
534 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
538 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
539 child_valobj_sp = std::move(dynamic_sp);
541 return child_valobj_sp;
544 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
545 if (!child_valobj_sp) {
546 std::string err_msg = llvm::formatv(
547 "failed to use pointer as array for index {0} for "
549 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
552 err_msg =
"subscript of pointer to incomplete type 'void'";
553 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
556 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
557 child_valobj_sp = base->GetChildAtIndex(child_idx);
559 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
560 if (!child_valobj_sp) {
561 std::string err_msg = llvm::formatv(
562 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
563 base->GetTypeName().AsCString(
"<invalid type>"),
565 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
570 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
571 if (!child_valobj_sp) {
572 std::string err_msg = llvm::formatv(
573 "bitfield range {0}-{1} is not valid for \"({2}) {3}\"", child_idx,
574 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
576 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
582 std::string err_msg =
583 llvm::formatv(
"\"{0}\" is not an array type",
584 base->GetTypeName().AsCString(
"<invalid type>"));
585 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
588 if (
static_cast<uint32_t
>(child_idx) >=
589 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
590 std::string err_msg = llvm::formatv(
591 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
592 base->GetTypeName().AsCString(
"<invalid type>"),
594 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
597 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
598 if (!child_valobj_sp) {
599 std::string err_msg = llvm::formatv(
600 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
601 base->GetTypeName().AsCString(
"<invalid type>"),
603 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
608 if (child_valobj_sp) {
610 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
611 child_valobj_sp = std::move(dynamic_sp);
613 return child_valobj_sp;
616 int64_t signed_child_idx = node->
GetIndex();
617 return base->GetSyntheticArrayMember(signed_child_idx,
true);
620llvm::Expected<lldb::ValueObjectSP>
630 if (first_index > last_index)
631 std::swap(first_index, last_index);
634 if (base->GetCompilerType().IsReferenceType()) {
635 base = base->Dereference(
error);
637 return error.ToError();
640 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
641 if (!child_valobj_sp) {
642 std::string message = llvm::formatv(
643 "bitfield range {0}-{1} is not valid for \"({2}) {3}\"", first_index,
644 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
645 base->GetName().AsCString());
646 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
649 return child_valobj_sp;
652llvm::Expected<CompilerType>
654 std::shared_ptr<ExecutionContextScope> ctx,
659 llvm::APInt apint = literal->
GetValue();
661 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
672 for (
auto [signed_, unsigned_] : candidates) {
673 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
676 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
678 return size.takeError();
679 if (!literal->
IsUnsigned() && apint.isIntN(*size - 1))
682 return type_system->GetBasicTypeFromAST(unsigned_);
685 return llvm::make_error<DILDiagnosticError>(
687 "integer literal is too large to be represented in any integer type",
691llvm::Expected<lldb::ValueObjectSP>
693 llvm::Expected<lldb::TypeSystemSP> type_system =
696 return type_system.takeError();
698 llvm::Expected<CompilerType> type =
701 return type.takeError();
706 llvm::Expected<uint64_t> type_bitsize =
709 return type_bitsize.takeError();
715llvm::Expected<lldb::ValueObjectSP>
717 llvm::Expected<lldb::TypeSystemSP> type_system =
720 return type_system.takeError();
723 &node->
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
729 return llvm::make_error<DILDiagnosticError>(
737llvm::Expected<lldb::ValueObjectSP>
746 return operand_or_err;
751 return llvm::make_error<DILDiagnosticError>(
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.
bool IsArrayType(CompilerType *element_type=nullptr, uint64_t *size=nullptr, bool *is_incomplete=nullptr) const
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
bool IsPointerToVoid() const
ConstString GetTypeName(bool BaseOnly=false) const
CompilerType GetArrayElementType(ExecutionContextScope *exe_scope) const
Creating related types.
bool IsInteger() const
This is used when you don't care about the signedness of the integer.
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.
"lldb/Target/ExecutionContextScope.h" Inherit from this if your object can reconstruct its execution ...
virtual void CalculateExecutionContext(ExecutionContext &exe_ctx)=0
Reconstruct the object's execution context into sc.
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
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.
CompilerType GetCompilerType()
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true)
Given an address either create a value object containing the value at that address,...
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
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
ASTNode * GetOperand() 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)
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
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 CompilerType GetBasicType(lldb::TypeSystemSP type_system, lldb::BasicType basic_type)
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(std::shared_ptr< ExecutionContextScope > ctx)
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...
static lldb::ValueObjectSP ArrayToPointerConversion(ValueObject &valobj, ExecutionContextScope &ctx)
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),...