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>
182 return lhs_size.takeError();
185 return rhs_size.takeError();
187 if (*rhs_size == *lhs_size) {
188 llvm::Expected<lldb::TypeSystemSP> type_system =
191 return type_system.takeError();
196 return r_type_unsigned;
202llvm::Expected<CompilerType>
208 return lhs_or_err.takeError();
212 return rhs_or_err.takeError();
228 if (l_rank == 0 || r_rank == 0)
229 return llvm::make_error<DILDiagnosticError>(
230 m_expr,
"unexpected basic type in arithmetic operation", location);
235 using Rank = std::tuple<size_t, bool>;
236 Rank int_l_rank = {l_rank, !lhs_type.
IsSigned()};
237 Rank int_r_rank = {r_rank, !rhs_type.
IsSigned()};
238 if (int_l_rank < int_r_rank) {
241 return type_or_err.takeError();
244 if (int_l_rank > int_r_rank) {
247 return type_or_err.takeError();
262 std::vector<lldb::VariableSP> possible_matches;
265 llvm::StringRef str_ref_name = var_sp->GetName().GetStringRef();
267 str_ref_name.consume_front(
"::");
273 if (var_sp->NameMatches(name))
274 possible_matches.push_back(var_sp);
278 if (possible_matches.size() > 0)
279 return possible_matches[0];
295 name_ref.consume_front(
"::");
310 target_sp->GetImages().FindGlobalVariables(
311 ConstString(name_ref), std::numeric_limits<uint32_t>::max(),
314 if (!modules_var_list.
Empty()) {
331 if (name_ref.consume_front(
"$")) {
336 if (
const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName(name_ref))
342 if (!name_ref.contains(
"::")) {
351 variable_list->FindVariable(
ConstString(name_ref));
362 lldb::eSymbolContextFunction | lldb::eSymbolContextBlock);
366 value_sp = value_sp->GetChildMemberWithName(name_ref);
376 if (name_ref.contains(
"::")) {
377 llvm::StringRef enum_typename, enumerator_name;
380 std::tie(enum_typename, enumerator_name) = name_ref.rsplit(
"::");
385 const llvm::APSInt &value) ->
bool {
386 if (name == enumerator_name) {
389 enum_type,
"result");
405 const bool check_ptr_vs_member =
407 const bool no_synth_child =
409 const bool allow_var_updates =
411 const bool disallow_globals =
422 auto value_or_error = node.
Accept(
this);
424 if (value_or_error && !*value_or_error)
425 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid value object",
429 return value_or_error;
432llvm::Expected<lldb::ValueObjectSP>
434 auto valobj_or_err =
Evaluate(node);
436 return valobj_or_err;
440 if (valobj->GetCompilerType().IsReferenceType()) {
441 valobj = valobj->Dereference(
error);
443 return error.ToError();
448llvm::Expected<lldb::ValueObjectSP>
462 if (!identifier && node.
GetName() ==
"nullptr") {
465 llvm::Expected<lldb::TypeSystemSP> type_system =
468 return type_system.takeError();
469 type_system.get()->GetPointerByteSize();
470 llvm::APInt value(type_system.get()->GetPointerByteSize() * CHAR_BIT, 0);
479 llvm::formatv(
"use of undeclared identifier '{0}'", node.
GetName());
480 return llvm::make_error<DILDiagnosticError>(
487llvm::Expected<lldb::ValueObjectSP>
500 operand = dynamic_op;
506 child_sp = synth_obj_sp->Dereference(
error);
510 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
519 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
525 if (operand->GetCompilerType().IsReferenceType()) {
526 operand = operand->Dereference(
error);
528 return error.ToError();
530 llvm::Expected<lldb::ValueObjectSP> conv_op =
538 llvm::formatv(
"invalid argument type '{0}' to unary expression",
540 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
544 bool resolved = operand->ResolveValue(scalar);
551 m_stack_frame, scalar, operand->GetCompilerType(),
"result");
555 if (operand->GetCompilerType().IsReferenceType()) {
556 operand = operand->Dereference(
error);
558 return error.ToError();
560 llvm::Expected<lldb::ValueObjectSP> conv_op =
570 llvm::formatv(
"invalid argument type '{0}' to unary expression",
572 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
578 if (operand->GetCompilerType().IsReferenceType()) {
579 operand = operand->Dereference(
error);
581 return error.ToError();
583 llvm::Expected<lldb::ValueObjectSP> conv_op =
591 llvm::formatv(
"invalid argument type '{0}' to unary expression",
593 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
597 bool resolved = operand->ResolveValue(scalar);
599 std::string errMsg = llvm::formatv(
"invalid operand value: {0}",
600 operand->GetError().AsCString());
601 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
608 m_stack_frame, scalar, operand->GetCompilerType(),
"result");
611 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
615llvm::Expected<lldb::ValueObjectSP>
619 if (ptr->GetCompilerType().IsPointerToVoid())
620 return llvm::make_error<DILDiagnosticError>(
621 m_expr,
"arithmetic on a pointer to void", location);
622 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
623 return llvm::make_error<DILDiagnosticError>(
624 m_expr,
"arithmetic on a nullptr is undefined", location);
627 int64_t offset_int = offset->GetValueAsSigned(0, &success);
629 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
630 offset->GetError().AsCString());
631 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
635 llvm::Expected<uint64_t> byte_size =
636 ptr->GetCompilerType().GetPointeeType().GetByteSize(&
m_stack_frame);
638 return byte_size.takeError();
639 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
641 ptr_addr -= offset_int * (*byte_size);
643 ptr_addr += offset_int * (*byte_size);
651llvm::Expected<lldb::ValueObjectSP>
656 bool l_resolved = lhs->ResolveValue(
l);
659 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
660 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
662 bool r_resolved = rhs->ResolveValue(r);
665 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
666 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
669 auto value_object = [
this, result_type](
Scalar scalar) {
671 result_type,
"result");
676 return value_object(
l + r);
678 return value_object(
l - r);
680 return value_object(
l * r);
682 return value_object(
l / r);
684 return value_object(
l % r);
686 return value_object(
l & r);
688 return value_object(
l ^ r);
690 return value_object(
l | r);
692 return value_object(
l << r);
694 return value_object(
l >> r);
698 return llvm::make_error<DILDiagnosticError>(
699 m_expr,
"invalid arithmetic operation", location);
708 auto orig_lhs_type = lhs->GetCompilerType();
709 auto orig_rhs_type = rhs->GetCompilerType();
712 return type_or_err.takeError();
721 if (lhs->GetCompilerType().IsPointerType()) {
724 }
else if (rhs->GetCompilerType().IsPointerType()) {
729 if (!ptr || !offset->GetCompilerType().IsInteger()) {
731 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
732 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
733 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
746 auto orig_lhs_type = lhs->GetCompilerType();
747 auto orig_rhs_type = rhs->GetCompilerType();
750 return type_or_err.takeError();
756 auto lhs_type = lhs->GetCompilerType();
757 auto rhs_type = rhs->GetCompilerType();
760 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
764 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
765 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
766 return llvm::make_error<DILDiagnosticError>(
767 m_expr,
"arithmetic on pointers to void", location);
772 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
773 std::string errMsg = llvm::formatv(
774 "'{0}' and '{1}' are not pointers to compatible types",
775 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
776 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
779 llvm::Expected<uint64_t> lhs_byte_size =
782 return lhs_byte_size.takeError();
784 int64_t item_size = *lhs_byte_size;
785 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
786 rhs->GetValueAsUnsigned(0));
787 assert(item_size > 0 &&
"Pointee size cannot be 0");
788 if (diff % item_size != 0) {
791 return llvm::make_error<DILDiagnosticError>(
792 m_expr,
"undefined pointer arithmetic", location);
796 llvm::Expected<lldb::TypeSystemSP> type_system =
799 return type_system.takeError();
800 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
802 return llvm::make_error<DILDiagnosticError>(
803 m_expr,
"unable to determine pointer diff type", location);
807 ptrdiff_type,
"result");
811 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
812 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
813 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
821 auto orig_lhs_type = lhs->GetCompilerType();
822 auto orig_rhs_type = rhs->GetCompilerType();
825 return type_or_err.takeError();
830 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
831 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
832 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
843 auto orig_lhs_type = lhs->GetCompilerType();
844 auto orig_rhs_type = rhs->GetCompilerType();
847 return type_or_err.takeError();
852 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
853 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
854 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
859 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
860 return llvm::make_error<DILDiagnosticError>(
861 m_expr,
"division by zero is undefined", location);
871 auto orig_lhs_type = lhs->GetCompilerType();
872 auto orig_rhs_type = rhs->GetCompilerType();
875 return type_or_err.takeError();
880 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
881 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
882 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
886 if (rhs->GetValueAsSigned(-1) == 0) {
887 return llvm::make_error<DILDiagnosticError>(
888 m_expr,
"division by zero is undefined", location);
904 return llvm::createStringError(
905 "Illegal type for lhs of assignment (not scalar numeric type)");
910 return llvm::createStringError(
911 "Illegal type for rhs of assignment (not scalar numeric type)");
916 return llvm::createStringError(
917 "Invalid assignment: Can only assign pointers to pointers");
922 lhs_type != rhs_type) {
923 std::string err_msg =
924 llvm::formatv(
"Incompatible types for assignment: Cannot assign {0} "
927 return llvm::createStringError(err_msg);
933llvm::Expected<lldb::ValueObjectSP>
940 return all_ok.takeError();
948llvm::Expected<lldb::ValueObjectSP>
953 auto orig_lhs_type = lhs->GetCompilerType();
954 auto orig_rhs_type = rhs->GetCompilerType();
957 return type_or_err.takeError();
962 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
963 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
964 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
970llvm::Expected<lldb::ValueObjectSP>
979 return lhs_or_err.takeError();
983 return rhs_or_err.takeError();
990 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
992 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
996 uint64_t amount = rhs->GetValueAsUnsigned(0, &success);
998 return llvm::make_error<DILDiagnosticError>(
999 m_expr,
"could not get the shift amount as an integer", location);
1002 return lhs_size.takeError();
1003 if (amount >= *lhs_size)
1004 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid shift amount",
1010llvm::Expected<lldb::ValueObjectSP>
1022 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
1024 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
1025 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
1027 return llvm::make_error<DILDiagnosticError>(
1065 return llvm::make_error<DILDiagnosticError>(
1069llvm::Expected<lldb::ValueObjectSP>
1081 if (!base->IsPointerType() && base->HasSyntheticValue()) {
1084 base->GetSyntheticValue()->Dereference(deref_error);
1085 synth_deref_sp && deref_error.
Success()) {
1086 base = std::move(synth_deref_sp);
1088 if (!base || deref_error.
Fail()) {
1089 std::string errMsg = llvm::formatv(
1090 "Failed to dereference synthetic value: {0}", deref_error);
1091 return llvm::make_error<DILDiagnosticError>(
1097 std::string errMsg =
"Failed to dereference synthetic value";
1098 return llvm::make_error<DILDiagnosticError>(
1101 expr_is_ptr =
false;
1106 bool base_is_ptr = base->IsPointerType();
1108 if (expr_is_ptr != base_is_ptr) {
1110 std::string errMsg =
1111 llvm::formatv(
"member reference type {0} is a pointer; "
1112 "did you mean to use '->'?",
1113 base->GetCompilerType().TypeDescription());
1114 return llvm::make_error<DILDiagnosticError>(
1117 std::string errMsg =
1118 llvm::formatv(
"member reference type {0} is not a pointer; "
1119 "did you mean to use '.'?",
1120 base->GetCompilerType().TypeDescription());
1121 return llvm::make_error<DILDiagnosticError>(
1131 field_obj = base->GetSyntheticValue();
1133 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
1137 std::string errMsg = llvm::formatv(
1138 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1139 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1140 return llvm::make_error<DILDiagnosticError>(
1150 field_obj = dynamic_val_sp;
1156 if (node.
GetIsArrow() && base->IsPointerType())
1158 std::string errMsg = llvm::formatv(
1159 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1160 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1161 return llvm::make_error<DILDiagnosticError>(
1165llvm::Expected<lldb::ValueObjectSP>
1172 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1173 return llvm::make_error<DILDiagnosticError>(
1178 uint64_t child_idx = idx->GetValueAsUnsigned(0);
1186 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
1187 base->GetExpressionPath(var_expr_path_strm);
1188 bool is_incomplete_array =
false;
1190 bool is_objc_pointer =
true;
1193 is_objc_pointer =
false;
1194 else if (!base->GetCompilerType().IsPointerType())
1195 is_objc_pointer =
false;
1198 std::string err_msg = llvm::formatv(
1199 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
1200 base->GetTypeName().AsCString(
"<invalid type>"),
1201 var_expr_path_strm.
GetData());
1202 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1205 if (is_objc_pointer) {
1207 if (!synthetic || synthetic == base) {
1208 std::string err_msg =
1209 llvm::formatv(
"\"({0}) {1}\" is not an array type",
1210 base->GetTypeName().AsCString(
"<invalid type>"),
1211 var_expr_path_strm.
GetData());
1212 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1215 if (
static_cast<uint32_t
>(child_idx) >=
1216 synthetic->GetNumChildrenIgnoringErrors()) {
1217 std::string err_msg = llvm::formatv(
1218 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1219 base->GetTypeName().AsCString(
"<invalid type>"),
1220 var_expr_path_strm.
GetData());
1221 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1224 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1225 if (!child_valobj_sp) {
1226 std::string err_msg = llvm::formatv(
1227 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1228 base->GetTypeName().AsCString(
"<invalid type>"),
1229 var_expr_path_strm.
GetData());
1230 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1234 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1235 child_valobj_sp = std::move(dynamic_sp);
1237 return child_valobj_sp;
1240 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1241 if (!child_valobj_sp) {
1242 std::string err_msg = llvm::formatv(
1243 "failed to use pointer as array for index {0} for "
1245 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1246 var_expr_path_strm.
GetData());
1248 err_msg =
"subscript of pointer to incomplete type 'void'";
1249 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1252 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1253 child_valobj_sp = base->GetChildAtIndex(child_idx);
1255 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1256 if (!child_valobj_sp) {
1257 std::string err_msg = llvm::formatv(
1258 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1259 base->GetTypeName().AsCString(
"<invalid type>"),
1260 var_expr_path_strm.
GetData());
1261 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1266 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1267 if (!child_valobj_sp) {
1268 std::string err_msg = llvm::formatv(
1269 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1270 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1271 var_expr_path_strm.
GetData());
1272 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1278 std::string err_msg =
1279 llvm::formatv(
"\"{0}\" is not an array type",
1280 base->GetTypeName().AsCString(
"<invalid type>"));
1281 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1284 if (
static_cast<uint32_t
>(child_idx) >=
1285 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1286 std::string err_msg = llvm::formatv(
1287 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1288 base->GetTypeName().AsCString(
"<invalid type>"),
1289 var_expr_path_strm.
GetData());
1290 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1293 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1294 if (!child_valobj_sp) {
1295 std::string err_msg = llvm::formatv(
1296 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1297 base->GetTypeName().AsCString(
"<invalid type>"),
1298 var_expr_path_strm.
GetData());
1299 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1304 if (child_valobj_sp) {
1306 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1307 child_valobj_sp = std::move(dynamic_sp);
1309 return child_valobj_sp;
1313 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1315 return llvm::make_error<DILDiagnosticError>(
1316 m_expr,
"could not get the index as an integer",
1318 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1321llvm::Expected<lldb::ValueObjectSP>
1324 if (!first_idx_or_err)
1325 return first_idx_or_err;
1328 if (!last_idx_or_err)
1329 return last_idx_or_err;
1332 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1333 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1334 return llvm::make_error<DILDiagnosticError>(
1338 bool success_first, success_last;
1339 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1340 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1341 if (!success_first || !success_last)
1342 return llvm::make_error<DILDiagnosticError>(
1346 if (first_index > last_index)
1347 std::swap(first_index, last_index);
1354 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1355 if (!child_valobj_sp) {
1356 std::string message = llvm::formatv(
1357 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1358 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1359 base->GetName().GetStringRef());
1360 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1363 return child_valobj_sp;
1366llvm::Expected<CompilerType>
1373 llvm::APInt apint = literal.
GetValue();
1375 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1386 for (
auto [signed_, unsigned_] : candidates) {
1387 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1390 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(&ctx);
1392 return size.takeError();
1393 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1396 return type_system->GetBasicTypeFromAST(unsigned_);
1399 return llvm::make_error<DILDiagnosticError>(
1401 "integer literal is too large to be represented in any integer type",
1405llvm::Expected<lldb::ValueObjectSP>
1407 llvm::Expected<lldb::TypeSystemSP> type_system =
1410 return type_system.takeError();
1412 llvm::Expected<CompilerType> type =
1415 return type.takeError();
1420 llvm::Expected<uint64_t> type_bitsize = type->GetBitSize(&
m_stack_frame);
1422 return type_bitsize.takeError();
1426 if (type->IsSigned())
1432llvm::Expected<lldb::ValueObjectSP>
1434 llvm::Expected<lldb::TypeSystemSP> type_system =
1437 return type_system.takeError();
1440 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1446 return llvm::make_error<DILDiagnosticError>(
1454llvm::Expected<lldb::ValueObjectSP>
1457 llvm::Expected<lldb::TypeSystemSP> type_system =
1460 return type_system.takeError();
1465llvm::Expected<CastKind>
1470 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1471 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1474 return llvm::make_error<DILDiagnosticError>(
1475 m_expr, std::move(errMsg), location,
1485 uint64_t type_byte_size = 0;
1486 uint64_t rhs_type_byte_size = 0;
1488 type_byte_size = *temp;
1490 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1493 "GetByteSize failed: {0}");
1494 return llvm::make_error<DILDiagnosticError>(
1495 m_expr, std::move(errMsg), location,
1500 rhs_type_byte_size = *temp;
1502 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1505 "GetByteSize failed: {0}");
1506 return llvm::make_error<DILDiagnosticError>(
1507 m_expr, std::move(errMsg), location,
1511 if (type_byte_size < rhs_type_byte_size) {
1512 std::string errMsg = llvm::formatv(
1513 "cast from pointer to smaller type {0} loses information",
1515 return llvm::make_error<DILDiagnosticError>(
1516 m_expr, std::move(errMsg), location,
1521 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1525 return llvm::make_error<DILDiagnosticError>(
1526 m_expr, std::move(errMsg), location,
1532llvm::Expected<CastKind>
1543 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1547 return llvm::make_error<DILDiagnosticError>(
1548 m_expr, std::move(errMsg), location,
1558 std::string errMsg = llvm::formatv(
1559 "cannot cast from type {0} to pointer type {1}",
1562 return llvm::make_error<DILDiagnosticError>(
1563 m_expr, std::move(errMsg), location,
1570 std::string errMsg = llvm::formatv(
1571 "casting of {0} to {1} is not implemented yet",
1573 return llvm::make_error<DILDiagnosticError>(
1574 m_expr, std::move(errMsg), location,
1581 if (!operand_or_err)
1582 return operand_or_err;
1592 operand->GetName().GetStringRef());
1593 op_type = operand->GetCompilerType();
1598 return type_or_err.takeError();
1601 if (operand->GetCompilerType().IsReferenceType()) {
1603 operand = operand->Dereference(
error);
1605 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1609 switch (cast_kind) {
1614 return operand->CastToEnumType(target_type);
1620 return operand->CastToBasicType(target_type);
1625 ? operand->GetLoadAddress()
1626 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1627 : operand->GetValueAsUnsigned(0));
1628 llvm::StringRef name =
"result";
1639 std::string errMsg =
1640 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1642 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 lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
virtual lldb::ValueObjectSP GetValueObjectForFrameVariable(const lldb::VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Create a ValueObject for a given Variable in this StackFrame.
virtual const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
virtual lldb::VariableListSP GetInScopeVariableList(bool get_file_globals, bool include_synthetic_vars=true, bool must_have_valid_location=false)
Retrieve the list of variables that are in scope at this StackFrame's pc.
virtual lldb::ValueObjectSP FindVariable(ConstString name)
Attempt to reconstruct the ValueObject for a variable with a given name from within the current Stack...
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
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< lldb::ValueObjectSP > EvaluateBinaryDivision(lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
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...
Interpreter(lldb::TargetSP target, llvm::StringRef expr, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic, uint32_t options)
llvm::Expected< CompilerType > PickIntegerType(lldb::TypeSystemSP type_system, ExecutionContextScope &ctx, const IntegerLiteralNode &literal)
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::Expected< lldb::ValueObjectSP > EvaluateBinaryBitwise(BinaryOpKind kind, lldb::ValueObjectSP lhs, lldb::ValueObjectSP rhs, uint32_t location)
StackFrame & m_stack_frame
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)
lldb::ValueObjectSP LookupIdentifier(llvm::StringRef name_ref, StackFrame &stack_frame, lldb::DynamicValueType use_dynamic)
Given the name of an identifier (variable name, member name, type name, etc.), find the ValueObject f...
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.
lldb::ValueObjectSP LookupGlobalIdentifier(llvm::StringRef name_ref, StackFrame &stack_frame, 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.
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)
CompilerType ResolveTypeByName(const std::string &name, ExecutionContextScope &ctx_scope)
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),...