21#include "llvm/Support/ErrorExtras.h"
22#include "llvm/Support/FormatAdapters.h"
30 return type_system.get()->GetBasicTypeFromAST(basic_type);
37 llvm::StringRef name) {
51 return llvm::createStringErrorV(
"no compile unit for frame: {}",
56 return symbol_context.
module_sp->GetTypeSystemForLanguage(language);
59llvm::Expected<lldb::ValueObjectSP>
62 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
64 llvm::Expected<lldb::TypeSystemSP> type_system =
67 return type_system.takeError();
70 if (valobj->IsBitfield()) {
75 uint32_t bitfield_size = valobj->GetBitfieldBitSize();
78 if (bitfield_size > 0 && in_type.
IsInteger()) {
82 llvm::Expected<uint64_t> int_bit_size =
85 return int_bit_size.takeError();
86 llvm::Expected<uint64_t> uint_bit_size =
89 return uint_bit_size.takeError();
90 if (bitfield_size < *int_bit_size ||
91 (in_type.
IsSigned() && bitfield_size == *int_bit_size))
92 return valobj->CastToBasicType(int_type);
93 if (bitfield_size <= *uint_bit_size)
94 return valobj->CastToBasicType(uint_type);
97 bool resolved = valobj->ResolveValue(scalar);
99 return llvm::createStringError(
"invalid scalar value");
109 valobj->GetCompilerType().GetPromotedIntegerType();
111 return valobj->CastToBasicType(promoted_type);
156 switch (basic_type) {
175llvm::Expected<CompilerType>
180 llvm::Expected<uint64_t> lhs_size =
183 return lhs_size.takeError();
184 llvm::Expected<uint64_t> rhs_size =
187 return rhs_size.takeError();
189 if (*rhs_size == *lhs_size) {
190 llvm::Expected<lldb::TypeSystemSP> type_system =
193 return type_system.takeError();
198 return r_type_unsigned;
204llvm::Expected<CompilerType>
210 return lhs_or_err.takeError();
214 return rhs_or_err.takeError();
230 if (l_rank == 0 || r_rank == 0)
231 return llvm::make_error<DILDiagnosticError>(
232 m_expr,
"unexpected basic type in arithmetic operation", location);
237 using Rank = std::tuple<size_t, bool>;
238 Rank int_l_rank = {l_rank, !lhs_type.
IsSigned()};
239 Rank int_r_rank = {r_rank, !rhs_type.
IsSigned()};
240 if (int_l_rank < int_r_rank) {
243 return type_or_err.takeError();
246 if (int_l_rank > int_r_rank) {
249 return type_or_err.takeError();
264 std::vector<lldb::VariableSP> possible_matches;
267 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
269 str_ref_name.consume_front(
"::");
275 if (var_sp->NameMatches(name))
276 possible_matches.push_back(var_sp);
280 if (possible_matches.size() > 0)
281 return possible_matches[0];
287 llvm::StringRef name_ref, std::shared_ptr<StackFrame> stack_frame,
291 stack_frame->GetSymbolContext(lldb::eSymbolContextCompUnit);
296 name_ref.consume_front(
"::");
303 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
311 target_sp->GetImages().FindGlobalVariables(
312 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
315 if (!modules_var_list.
Empty()) {
328 std::shared_ptr<StackFrame> stack_frame,
332 if (name_ref.consume_front(
"$")) {
337 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
343 if (!name_ref.contains(
"::")) {
347 stack_frame->GetInScopeVariableList(
false));
352 variable_list->FindVariable(
ConstString(name_ref));
355 stack_frame->GetValueObjectForFrameVariable(var_sp, use_dynamic);
363 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
365 value_sp = stack_frame->FindVariable(
ConstString(instance_name));
367 value_sp = value_sp->GetChildMemberWithName(name_ref);
377 if (name_ref.contains(
"::")) {
378 llvm::StringRef enum_typename, enumerator_name;
381 std::tie(enum_typename, enumerator_name) = name_ref.rsplit(
"::");
386 const llvm::APSInt &value) ->
bool {
387 if (name == enumerator_name) {
390 enum_type,
"result");
401 std::shared_ptr<StackFrame> frame_sp,
406 const bool check_ptr_vs_member =
408 const bool no_synth_child =
410 const bool allow_var_updates =
412 const bool disallow_globals =
423 auto value_or_error = node.
Accept(
this);
425 if (value_or_error && !*value_or_error)
426 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
430 return value_or_error;
433llvm::Expected<lldb::ValueObjectSP>
435 auto valobj_or_err =
Evaluate(node);
437 return valobj_or_err;
441 if (valobj->GetCompilerType().IsReferenceType()) {
442 valobj = valobj->Dereference(
error);
444 return error.ToError();
449llvm::Expected<lldb::ValueObjectSP>
465 llvm::formatv(
"use of undeclared identifier '{0}'", node.
GetName());
466 return llvm::make_error<DILDiagnosticError>(
473llvm::Expected<lldb::ValueObjectSP>
486 operand = dynamic_op;
492 child_sp = synth_obj_sp->Dereference(
error);
496 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
505 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
511 if (operand->GetCompilerType().IsReferenceType()) {
512 operand = operand->Dereference(
error);
514 return error.ToError();
516 llvm::Expected<lldb::ValueObjectSP> conv_op =
524 llvm::formatv(
"invalid argument type '{0}' to unary expression",
526 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
530 bool resolved = operand->ResolveValue(scalar);
541 if (operand->GetCompilerType().IsReferenceType()) {
542 operand = operand->Dereference(
error);
544 return error.ToError();
546 llvm::Expected<lldb::ValueObjectSP> conv_op =
556 llvm::formatv(
"invalid argument type '{0}' to unary expression",
558 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
564 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
568llvm::Expected<lldb::ValueObjectSP>
572 if (ptr->GetCompilerType().IsPointerToVoid())
573 return llvm::make_error<DILDiagnosticError>(
574 m_expr,
"arithmetic on a pointer to void", location);
575 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
576 return llvm::make_error<DILDiagnosticError>(
577 m_expr,
"arithmetic on a nullptr is undefined", location);
580 int64_t offset_int = offset->GetValueAsSigned(0, &success);
582 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
583 offset->GetError().AsCString());
584 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
588 llvm::Expected<uint64_t> byte_size =
589 ptr->GetCompilerType().GetPointeeType().GetByteSize(
592 return byte_size.takeError();
593 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
595 ptr_addr -= offset_int * (*byte_size);
597 ptr_addr += offset_int * (*byte_size);
605llvm::Expected<lldb::ValueObjectSP>
610 bool l_resolved = lhs->ResolveValue(
l);
613 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
614 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
616 bool r_resolved = rhs->ResolveValue(r);
619 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
620 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
623 auto value_object = [
this, result_type](
Scalar scalar) {
625 result_type,
"result");
630 return value_object(
l + r);
632 return value_object(
l - r);
634 return value_object(
l * r);
636 return value_object(
l / r);
638 return value_object(
l % r);
640 return value_object(
l << r);
642 return value_object(
l >> r);
646 return llvm::make_error<DILDiagnosticError>(
647 m_expr,
"invalid arithmetic operation", location);
656 auto orig_lhs_type = lhs->GetCompilerType();
657 auto orig_rhs_type = rhs->GetCompilerType();
660 return type_or_err.takeError();
669 if (lhs->GetCompilerType().IsPointerType()) {
672 }
else if (rhs->GetCompilerType().IsPointerType()) {
677 if (!ptr || !offset->GetCompilerType().IsInteger()) {
679 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
680 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
681 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
694 auto orig_lhs_type = lhs->GetCompilerType();
695 auto orig_rhs_type = rhs->GetCompilerType();
698 return type_or_err.takeError();
704 auto lhs_type = lhs->GetCompilerType();
705 auto rhs_type = rhs->GetCompilerType();
708 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
712 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
713 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
714 return llvm::make_error<DILDiagnosticError>(
715 m_expr,
"arithmetic on pointers to void", location);
720 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
721 std::string errMsg = llvm::formatv(
722 "'{0}' and '{1}' are not pointers to compatible types",
723 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
724 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
727 llvm::Expected<uint64_t> lhs_byte_size =
730 return lhs_byte_size.takeError();
732 int64_t item_size = *lhs_byte_size;
733 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
734 rhs->GetValueAsUnsigned(0));
735 assert(item_size > 0 &&
"Pointee size cannot be 0");
736 if (diff % item_size != 0) {
739 return llvm::make_error<DILDiagnosticError>(
740 m_expr,
"undefined pointer arithmetic", location);
744 llvm::Expected<lldb::TypeSystemSP> type_system =
747 return type_system.takeError();
748 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
750 return llvm::make_error<DILDiagnosticError>(
751 m_expr,
"unable to determine pointer diff type", location);
755 ptrdiff_type,
"result");
759 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
760 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
761 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
769 auto orig_lhs_type = lhs->GetCompilerType();
770 auto orig_rhs_type = rhs->GetCompilerType();
773 return type_or_err.takeError();
778 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
779 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
780 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
791 auto orig_lhs_type = lhs->GetCompilerType();
792 auto orig_rhs_type = rhs->GetCompilerType();
795 return type_or_err.takeError();
800 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
801 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
802 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
807 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
808 return llvm::make_error<DILDiagnosticError>(
809 m_expr,
"division by zero is undefined", location);
819 auto orig_lhs_type = lhs->GetCompilerType();
820 auto orig_rhs_type = rhs->GetCompilerType();
823 return type_or_err.takeError();
828 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
829 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
830 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
834 if (rhs->GetValueAsSigned(-1) == 0) {
835 return llvm::make_error<DILDiagnosticError>(
836 m_expr,
"division by zero is undefined", location);
852 return llvm::createStringError(
853 "Illegal type for lhs of assignment (not scalar numeric type)");
858 return llvm::createStringError(
859 "Illegal type for rhs of assignment (not scalar numeric type)");
864 return llvm::createStringError(
865 "Invalid assignment: Can only assign pointers to pointers");
870 lhs_type != rhs_type) {
871 std::string err_msg =
872 llvm::formatv(
"Incompatible types for assignment: Cannot assign {0} "
875 return llvm::createStringError(err_msg);
881llvm::Expected<lldb::ValueObjectSP>
888 return all_ok.takeError();
896llvm::Expected<lldb::ValueObjectSP>
905 return lhs_or_err.takeError();
909 return rhs_or_err.takeError();
916 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
918 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
922 uint64_t amount = rhs->GetValueAsUnsigned(0, &success);
924 return llvm::make_error<DILDiagnosticError>(
925 m_expr,
"could not get the shift amount as an integer", location);
926 llvm::Expected<uint64_t> lhs_size =
929 return lhs_size.takeError();
930 if (amount >= *lhs_size)
931 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid shift amount",
937llvm::Expected<lldb::ValueObjectSP>
949 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
951 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
952 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
954 return llvm::make_error<DILDiagnosticError>(
988 return llvm::make_error<DILDiagnosticError>(
992llvm::Expected<lldb::ValueObjectSP>
1004 if (!base->IsPointerType() && base->HasSyntheticValue()) {
1007 base->GetSyntheticValue()->Dereference(deref_error);
1008 synth_deref_sp && deref_error.
Success()) {
1009 base = std::move(synth_deref_sp);
1011 if (!base || deref_error.
Fail()) {
1012 std::string errMsg = llvm::formatv(
1013 "Failed to dereference synthetic value: {0}", deref_error);
1014 return llvm::make_error<DILDiagnosticError>(
1020 std::string errMsg =
"Failed to dereference synthetic value";
1021 return llvm::make_error<DILDiagnosticError>(
1024 expr_is_ptr =
false;
1029 bool base_is_ptr = base->IsPointerType();
1031 if (expr_is_ptr != base_is_ptr) {
1033 std::string errMsg =
1034 llvm::formatv(
"member reference type {0} is a pointer; "
1035 "did you mean to use '->'?",
1036 base->GetCompilerType().TypeDescription());
1037 return llvm::make_error<DILDiagnosticError>(
1040 std::string errMsg =
1041 llvm::formatv(
"member reference type {0} is not a pointer; "
1042 "did you mean to use '.'?",
1043 base->GetCompilerType().TypeDescription());
1044 return llvm::make_error<DILDiagnosticError>(
1054 field_obj = base->GetSyntheticValue();
1056 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
1060 std::string errMsg = llvm::formatv(
1061 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1062 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1063 return llvm::make_error<DILDiagnosticError>(
1073 field_obj = dynamic_val_sp;
1079 if (node.
GetIsArrow() && base->IsPointerType())
1081 std::string errMsg = llvm::formatv(
1082 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1083 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1084 return llvm::make_error<DILDiagnosticError>(
1088llvm::Expected<lldb::ValueObjectSP>
1095 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1096 return llvm::make_error<DILDiagnosticError>(
1101 uint64_t child_idx = idx->GetValueAsUnsigned(0);
1109 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
1110 base->GetExpressionPath(var_expr_path_strm);
1111 bool is_incomplete_array =
false;
1113 bool is_objc_pointer =
true;
1116 is_objc_pointer =
false;
1117 else if (!base->GetCompilerType().IsPointerType())
1118 is_objc_pointer =
false;
1121 std::string err_msg = llvm::formatv(
1122 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
1123 base->GetTypeName().AsCString(
"<invalid type>"),
1124 var_expr_path_strm.
GetData());
1125 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1128 if (is_objc_pointer) {
1130 if (!synthetic || synthetic == base) {
1131 std::string err_msg =
1132 llvm::formatv(
"\"({0}) {1}\" is not an array type",
1133 base->GetTypeName().AsCString(
"<invalid type>"),
1134 var_expr_path_strm.
GetData());
1135 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1138 if (
static_cast<uint32_t
>(child_idx) >=
1139 synthetic->GetNumChildrenIgnoringErrors()) {
1140 std::string err_msg = llvm::formatv(
1141 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1142 base->GetTypeName().AsCString(
"<invalid type>"),
1143 var_expr_path_strm.
GetData());
1144 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1147 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1148 if (!child_valobj_sp) {
1149 std::string err_msg = llvm::formatv(
1150 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1151 base->GetTypeName().AsCString(
"<invalid type>"),
1152 var_expr_path_strm.
GetData());
1153 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1157 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1158 child_valobj_sp = std::move(dynamic_sp);
1160 return child_valobj_sp;
1163 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1164 if (!child_valobj_sp) {
1165 std::string err_msg = llvm::formatv(
1166 "failed to use pointer as array for index {0} for "
1168 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1169 var_expr_path_strm.
GetData());
1171 err_msg =
"subscript of pointer to incomplete type 'void'";
1172 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1175 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1176 child_valobj_sp = base->GetChildAtIndex(child_idx);
1178 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1179 if (!child_valobj_sp) {
1180 std::string err_msg = llvm::formatv(
1181 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1182 base->GetTypeName().AsCString(
"<invalid type>"),
1183 var_expr_path_strm.
GetData());
1184 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1189 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1190 if (!child_valobj_sp) {
1191 std::string err_msg = llvm::formatv(
1192 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1193 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1194 var_expr_path_strm.
GetData());
1195 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1201 std::string err_msg =
1202 llvm::formatv(
"\"{0}\" is not an array type",
1203 base->GetTypeName().AsCString(
"<invalid type>"));
1204 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1207 if (
static_cast<uint32_t
>(child_idx) >=
1208 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1209 std::string err_msg = llvm::formatv(
1210 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1211 base->GetTypeName().AsCString(
"<invalid type>"),
1212 var_expr_path_strm.
GetData());
1213 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1216 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1217 if (!child_valobj_sp) {
1218 std::string err_msg = llvm::formatv(
1219 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1220 base->GetTypeName().AsCString(
"<invalid type>"),
1221 var_expr_path_strm.
GetData());
1222 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1227 if (child_valobj_sp) {
1229 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1230 child_valobj_sp = std::move(dynamic_sp);
1232 return child_valobj_sp;
1236 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1238 return llvm::make_error<DILDiagnosticError>(
1239 m_expr,
"could not get the index as an integer",
1241 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1244llvm::Expected<lldb::ValueObjectSP>
1247 if (!first_idx_or_err)
1248 return first_idx_or_err;
1251 if (!last_idx_or_err)
1252 return last_idx_or_err;
1255 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1256 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1257 return llvm::make_error<DILDiagnosticError>(
1261 bool success_first, success_last;
1262 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1263 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1264 if (!success_first || !success_last)
1265 return llvm::make_error<DILDiagnosticError>(
1269 if (first_index > last_index)
1270 std::swap(first_index, last_index);
1277 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1278 if (!child_valobj_sp) {
1279 std::string message = llvm::formatv(
1280 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1281 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1282 base->GetName().GetStringRef());
1283 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1286 return child_valobj_sp;
1289llvm::Expected<CompilerType>
1291 std::shared_ptr<ExecutionContextScope> ctx,
1296 llvm::APInt apint = literal.
GetValue();
1298 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1309 for (
auto [signed_, unsigned_] : candidates) {
1310 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1313 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
1315 return size.takeError();
1316 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1319 return type_system->GetBasicTypeFromAST(unsigned_);
1322 return llvm::make_error<DILDiagnosticError>(
1324 "integer literal is too large to be represented in any integer type",
1328llvm::Expected<lldb::ValueObjectSP>
1330 llvm::Expected<lldb::TypeSystemSP> type_system =
1333 return type_system.takeError();
1335 llvm::Expected<CompilerType> type =
1338 return type.takeError();
1343 llvm::Expected<uint64_t> type_bitsize =
1346 return type_bitsize.takeError();
1350 if (type->IsSigned())
1356llvm::Expected<lldb::ValueObjectSP>
1358 llvm::Expected<lldb::TypeSystemSP> type_system =
1361 return type_system.takeError();
1364 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1370 return llvm::make_error<DILDiagnosticError>(
1378llvm::Expected<lldb::ValueObjectSP>
1381 llvm::Expected<lldb::TypeSystemSP> type_system =
1384 return type_system.takeError();
1389llvm::Expected<CastKind>
1394 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1395 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1398 return llvm::make_error<DILDiagnosticError>(
1399 m_expr, std::move(errMsg), location,
1409 uint64_t type_byte_size = 0;
1410 uint64_t rhs_type_byte_size = 0;
1412 type_byte_size = *temp;
1414 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1417 "GetByteSize failed: {0}");
1418 return llvm::make_error<DILDiagnosticError>(
1419 m_expr, std::move(errMsg), location,
1424 rhs_type_byte_size = *temp;
1426 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1429 "GetByteSize failed: {0}");
1430 return llvm::make_error<DILDiagnosticError>(
1431 m_expr, std::move(errMsg), location,
1435 if (type_byte_size < rhs_type_byte_size) {
1436 std::string errMsg = llvm::formatv(
1437 "cast from pointer to smaller type {0} loses information",
1439 return llvm::make_error<DILDiagnosticError>(
1440 m_expr, std::move(errMsg), location,
1445 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1449 return llvm::make_error<DILDiagnosticError>(
1450 m_expr, std::move(errMsg), location,
1456llvm::Expected<CastKind>
1467 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1471 return llvm::make_error<DILDiagnosticError>(
1472 m_expr, std::move(errMsg), location,
1482 std::string errMsg = llvm::formatv(
1483 "cannot cast from type {0} to pointer type {1}",
1486 return llvm::make_error<DILDiagnosticError>(
1487 m_expr, std::move(errMsg), location,
1494 std::string errMsg = llvm::formatv(
1495 "casting of {0} to {1} is not implemented yet",
1497 return llvm::make_error<DILDiagnosticError>(
1498 m_expr, std::move(errMsg), location,
1505 if (!operand_or_err)
1506 return operand_or_err;
1516 operand->GetName().GetStringRef());
1517 op_type = operand->GetCompilerType();
1522 return type_or_err.takeError();
1525 if (operand->GetCompilerType().IsReferenceType()) {
1527 operand = operand->Dereference(
error);
1529 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1533 switch (cast_kind) {
1538 return operand->CastToEnumType(target_type);
1544 return operand->CastToBasicType(target_type);
1549 ? operand->GetLoadAddress()
1550 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1551 : operand->GetValueAsUnsigned(0));
1552 llvm::StringRef name =
"result";
1563 std::string errMsg =
1564 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1566 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
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 IsEnumerationType(bool &is_signed) const
lldb::BasicType GetBasicTypeEnumeration() const
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.
llvm::Expected< uint64_t > GetByteSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bytes.
bool IsPointerToVoid() const
void ForEachEnumerator(std::function< bool(const CompilerType &integer_type, ConstString name, const llvm::APSInt &value)> const &callback) const
If this type is an enumeration, iterate through all of its enumerators using a callback.
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...
ConstString GetTypeName(bool BaseOnly=false) const
bool IsReferenceType(CompilerType *pointee_type=nullptr, bool *is_rvalue=nullptr) const
std::string TypeDescription()
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...
bool IsUnscopedEnumerationType() const
uint32_t GetTypeInfo(CompilerType *pointee_or_element_compiler_type=nullptr) const
bool CompareTypes(CompilerType rhs) const
llvm::Expected< uint64_t > GetBitSize(ExecutionContextScope *exe_scope) const
Return the size of the type in bits.
bool IsScalarType() const
bool IsNullPtrType() const
CompilerType GetCanonicalType() 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.
This base class provides an interface to stack frames.
@ eExpressionPathOptionCheckPtrVsMember
@ eExpressionPathOptionsDisallowGlobals
@ eExpressionPathOptionsAllowVarUpdates
@ eExpressionPathOptionsNoSyntheticChildren
virtual const char * GetFunctionName()
Get the frame's demangled name.
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
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 GetInstanceName()
Determines the name of the instance for 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 CreateValueObjectFromScalar(const ExecutionContext &exe_ctx, Scalar &s, CompilerType type, llvm::StringRef name, ValueObject *parent=nullptr)
Create a value object containing the given Scalar value.
static lldb::ValueObjectSP CreateValueObjectFromBool(const ExecutionContext &exe_ctx, lldb::TypeSystemSP typesystem, bool value, llvm::StringRef name, ValueObject *parent=nullptr)
Create a value object containing the given boolean value.
lldb::addr_t GetLoadAddress()
Return the target load address associated with this value object.
CompilerType GetCompilerType()
static lldb::ValueObjectSP CreateValueObjectFromAddress(llvm::StringRef name, uint64_t address, const ExecutionContext &exe_ctx, CompilerType type, bool do_deref=true, ValueObject *parent=nullptr)
Given an address either create a value object containing the value at that address,...
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 & GetIndex() const
BinaryOpKind GetKind() const
ASTNode & GetOperand() const
CompilerType GetType() 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 > EvaluateBinaryRemainder(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > Evaluate(const ASTNode &node)
Evaluate an ASTNode.
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryAddition(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > EvaluateAndDereference(const ASTNode &node)
Evaluate an ASTNode.
llvm::Expected< lldb::ValueObjectSP > PointerOffset(lldb::ValueObjectSP ptr, lldb::ValueObjectSP offset, BinaryOpKind operation, uint32_t location)
Add or subtract the offset to the pointer according to the pointee type byte size.
llvm::Expected< lldb::ValueObjectSP > EvaluateScalarOp(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, CompilerType result_type, uint32_t location)
llvm::Expected< CompilerType > PromoteSignedInteger(CompilerType &lhs_type, CompilerType &rhs_type)
If lhs_type is unsigned and rhs_type is signed, check whether it can represent all of the values of l...
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryShift(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > EvaluateBinarySubtraction(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< lldb::ValueObjectSP > UnaryConversion(lldb::ValueObjectSP valobj, uint32_t location)
Perform usual unary conversions on a value.
llvm::Expected< lldb::ValueObjectSP > Visit(const IdentifierNode &node) override
bool m_check_ptr_vs_member
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, std::shared_ptr< ExecutionContextScope > ctx, const IntegerLiteralNode &literal)
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
Interpreter(lldb::TargetSP target, llvm::StringRef expr, std::shared_ptr< StackFrame > frame_sp, lldb::DynamicValueType use_dynamic, uint32_t options)
lldb::DynamicValueType m_use_dynamic
llvm::Expected< CompilerType > ArithmeticConversion(lldb::ValueObjectSP &lhs, lldb::ValueObjectSP &rhs, uint32_t location)
Perform an arithmetic conversion on two values from an arithmetic operation.
llvm::Expected< lldb::ValueObjectSP > EvaluateBinaryMultiplication(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< CastKind > VerifyCastType(lldb::ValueObjectSP operand, CompilerType source_type, CompilerType target_type, int location)
As a preparation for type casting, compare the requested 'target' type of the cast with the type of t...
llvm::Expected< lldb::ValueObjectSP > EvaluateAssignment(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
llvm::Expected< CastKind > VerifyArithmeticCast(CompilerType source_type, CompilerType target_type, int location)
A helper function for VerifyCastType (below).
llvm::StringRef GetFieldName() const
ASTNode & GetBase() const
UnaryOpKind GetKind() const
ASTNode & GetOperand() const
CastKind
The type casts allowed by DIL.
@ eEnumeration
Casting from a scalar to an enumeration type.
@ ePointer
Casting to a pointer type.
@ eNone
Invalid promotion type (results in error).
@ eArithmetic
Casting to a scalar.
static lldb::BasicType BasicTypeToUnsigned(lldb::BasicType basic_type)
static llvm::Expected< lldb::TypeSystemSP > GetTypeSystemFromCU(StackFrame &ctx)
static CompilerType GetBasicType(lldb::TypeSystemSP type_system, lldb::BasicType basic_type)
static lldb::ValueObjectSP ArrayToPointerConversion(ValueObject &valobj, ExecutionContextScope &ctx, llvm::StringRef name)
BinaryOpKind
The binary operators recognized by DIL.
static llvm::Expected< bool > VerifyAssignmentTypes(CompilerType lhs_type, CompilerType rhs_type)
lldb::ValueObjectSP LookupEnumValue(llvm::StringRef name_ref, ExecutionContextScope &ctx_scope)
Given the name of an identifier, attempt to find an enumeration value.
static size_t ConversionRank(CompilerType type)
Basic types with a lower rank are converted to the basic type with a higher rank.
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.
CompilerType ResolveTypeByName(const std::string &name, ExecutionContextScope &ctx_scope)
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 bool HasFloatingRepresentation(CompilerType ct)
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
std::shared_ptr< lldb_private::TypeSystem > TypeSystemSP
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eBasicTypeUnsignedShort
@ eBasicTypeUnsignedInt128
@ 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),...