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>
464 llvm::formatv(
"use of undeclared identifier '{0}'", node.
GetName());
465 return llvm::make_error<DILDiagnosticError>(
472llvm::Expected<lldb::ValueObjectSP>
485 operand = dynamic_op;
491 child_sp = synth_obj_sp->Dereference(
error);
495 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
504 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
510 if (operand->GetCompilerType().IsReferenceType()) {
511 operand = operand->Dereference(
error);
513 return error.ToError();
515 llvm::Expected<lldb::ValueObjectSP> conv_op =
523 llvm::formatv(
"invalid argument type '{0}' to unary expression",
525 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
529 bool resolved = operand->ResolveValue(scalar);
536 m_stack_frame, scalar, operand->GetCompilerType(),
"result");
540 if (operand->GetCompilerType().IsReferenceType()) {
541 operand = operand->Dereference(
error);
543 return error.ToError();
545 llvm::Expected<lldb::ValueObjectSP> conv_op =
555 llvm::formatv(
"invalid argument type '{0}' to unary expression",
557 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
563 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
567llvm::Expected<lldb::ValueObjectSP>
571 if (ptr->GetCompilerType().IsPointerToVoid())
572 return llvm::make_error<DILDiagnosticError>(
573 m_expr,
"arithmetic on a pointer to void", location);
574 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
575 return llvm::make_error<DILDiagnosticError>(
576 m_expr,
"arithmetic on a nullptr is undefined", location);
579 int64_t offset_int = offset->GetValueAsSigned(0, &success);
581 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
582 offset->GetError().AsCString());
583 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
587 llvm::Expected<uint64_t> byte_size =
588 ptr->GetCompilerType().GetPointeeType().GetByteSize(&
m_stack_frame);
590 return byte_size.takeError();
591 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
593 ptr_addr -= offset_int * (*byte_size);
595 ptr_addr += offset_int * (*byte_size);
603llvm::Expected<lldb::ValueObjectSP>
608 bool l_resolved = lhs->ResolveValue(
l);
611 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
612 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
614 bool r_resolved = rhs->ResolveValue(r);
617 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
618 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
621 auto value_object = [
this, result_type](
Scalar scalar) {
623 result_type,
"result");
628 return value_object(
l + r);
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);
644 return llvm::make_error<DILDiagnosticError>(
645 m_expr,
"invalid arithmetic operation", location);
654 auto orig_lhs_type = lhs->GetCompilerType();
655 auto orig_rhs_type = rhs->GetCompilerType();
658 return type_or_err.takeError();
667 if (lhs->GetCompilerType().IsPointerType()) {
670 }
else if (rhs->GetCompilerType().IsPointerType()) {
675 if (!ptr || !offset->GetCompilerType().IsInteger()) {
677 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
678 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
679 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
692 auto orig_lhs_type = lhs->GetCompilerType();
693 auto orig_rhs_type = rhs->GetCompilerType();
696 return type_or_err.takeError();
702 auto lhs_type = lhs->GetCompilerType();
703 auto rhs_type = rhs->GetCompilerType();
706 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
710 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
711 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
712 return llvm::make_error<DILDiagnosticError>(
713 m_expr,
"arithmetic on pointers to void", location);
718 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
719 std::string errMsg = llvm::formatv(
720 "'{0}' and '{1}' are not pointers to compatible types",
721 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
722 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
725 llvm::Expected<uint64_t> lhs_byte_size =
728 return lhs_byte_size.takeError();
730 int64_t item_size = *lhs_byte_size;
731 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
732 rhs->GetValueAsUnsigned(0));
733 assert(item_size > 0 &&
"Pointee size cannot be 0");
734 if (diff % item_size != 0) {
737 return llvm::make_error<DILDiagnosticError>(
738 m_expr,
"undefined pointer arithmetic", location);
742 llvm::Expected<lldb::TypeSystemSP> type_system =
745 return type_system.takeError();
746 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
748 return llvm::make_error<DILDiagnosticError>(
749 m_expr,
"unable to determine pointer diff type", location);
753 ptrdiff_type,
"result");
757 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
758 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
759 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
767 auto orig_lhs_type = lhs->GetCompilerType();
768 auto orig_rhs_type = rhs->GetCompilerType();
771 return type_or_err.takeError();
776 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
777 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
778 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
789 auto orig_lhs_type = lhs->GetCompilerType();
790 auto orig_rhs_type = rhs->GetCompilerType();
793 return type_or_err.takeError();
798 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
799 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
800 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
805 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
806 return llvm::make_error<DILDiagnosticError>(
807 m_expr,
"division by zero is undefined", location);
817 auto orig_lhs_type = lhs->GetCompilerType();
818 auto orig_rhs_type = rhs->GetCompilerType();
821 return type_or_err.takeError();
826 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
827 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
828 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
832 if (rhs->GetValueAsSigned(-1) == 0) {
833 return llvm::make_error<DILDiagnosticError>(
834 m_expr,
"division by zero is undefined", location);
850 return llvm::createStringError(
851 "Illegal type for lhs of assignment (not scalar numeric type)");
856 return llvm::createStringError(
857 "Illegal type for rhs of assignment (not scalar numeric type)");
862 return llvm::createStringError(
863 "Invalid assignment: Can only assign pointers to pointers");
868 lhs_type != rhs_type) {
869 std::string err_msg =
870 llvm::formatv(
"Incompatible types for assignment: Cannot assign {0} "
873 return llvm::createStringError(err_msg);
879llvm::Expected<lldb::ValueObjectSP>
886 return all_ok.takeError();
894llvm::Expected<lldb::ValueObjectSP>
903 return lhs_or_err.takeError();
907 return rhs_or_err.takeError();
914 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
916 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
920 uint64_t amount = rhs->GetValueAsUnsigned(0, &success);
922 return llvm::make_error<DILDiagnosticError>(
923 m_expr,
"could not get the shift amount as an integer", location);
926 return lhs_size.takeError();
927 if (amount >= *lhs_size)
928 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid shift amount",
934llvm::Expected<lldb::ValueObjectSP>
946 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
948 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
949 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
951 return llvm::make_error<DILDiagnosticError>(
985 return llvm::make_error<DILDiagnosticError>(
989llvm::Expected<lldb::ValueObjectSP>
1001 if (!base->IsPointerType() && base->HasSyntheticValue()) {
1004 base->GetSyntheticValue()->Dereference(deref_error);
1005 synth_deref_sp && deref_error.
Success()) {
1006 base = std::move(synth_deref_sp);
1008 if (!base || deref_error.
Fail()) {
1009 std::string errMsg = llvm::formatv(
1010 "Failed to dereference synthetic value: {0}", deref_error);
1011 return llvm::make_error<DILDiagnosticError>(
1017 std::string errMsg =
"Failed to dereference synthetic value";
1018 return llvm::make_error<DILDiagnosticError>(
1021 expr_is_ptr =
false;
1026 bool base_is_ptr = base->IsPointerType();
1028 if (expr_is_ptr != base_is_ptr) {
1030 std::string errMsg =
1031 llvm::formatv(
"member reference type {0} is a pointer; "
1032 "did you mean to use '->'?",
1033 base->GetCompilerType().TypeDescription());
1034 return llvm::make_error<DILDiagnosticError>(
1037 std::string errMsg =
1038 llvm::formatv(
"member reference type {0} is not a pointer; "
1039 "did you mean to use '.'?",
1040 base->GetCompilerType().TypeDescription());
1041 return llvm::make_error<DILDiagnosticError>(
1051 field_obj = base->GetSyntheticValue();
1053 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
1057 std::string errMsg = llvm::formatv(
1058 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1059 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1060 return llvm::make_error<DILDiagnosticError>(
1070 field_obj = dynamic_val_sp;
1076 if (node.
GetIsArrow() && base->IsPointerType())
1078 std::string errMsg = llvm::formatv(
1079 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1080 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1081 return llvm::make_error<DILDiagnosticError>(
1085llvm::Expected<lldb::ValueObjectSP>
1092 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1093 return llvm::make_error<DILDiagnosticError>(
1098 uint64_t child_idx = idx->GetValueAsUnsigned(0);
1106 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
1107 base->GetExpressionPath(var_expr_path_strm);
1108 bool is_incomplete_array =
false;
1110 bool is_objc_pointer =
true;
1113 is_objc_pointer =
false;
1114 else if (!base->GetCompilerType().IsPointerType())
1115 is_objc_pointer =
false;
1118 std::string err_msg = llvm::formatv(
1119 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
1120 base->GetTypeName().AsCString(
"<invalid type>"),
1121 var_expr_path_strm.
GetData());
1122 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1125 if (is_objc_pointer) {
1127 if (!synthetic || synthetic == base) {
1128 std::string err_msg =
1129 llvm::formatv(
"\"({0}) {1}\" is not an array type",
1130 base->GetTypeName().AsCString(
"<invalid type>"),
1131 var_expr_path_strm.
GetData());
1132 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1135 if (
static_cast<uint32_t
>(child_idx) >=
1136 synthetic->GetNumChildrenIgnoringErrors()) {
1137 std::string err_msg = llvm::formatv(
1138 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1139 base->GetTypeName().AsCString(
"<invalid type>"),
1140 var_expr_path_strm.
GetData());
1141 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1144 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1145 if (!child_valobj_sp) {
1146 std::string err_msg = llvm::formatv(
1147 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1148 base->GetTypeName().AsCString(
"<invalid type>"),
1149 var_expr_path_strm.
GetData());
1150 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1154 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1155 child_valobj_sp = std::move(dynamic_sp);
1157 return child_valobj_sp;
1160 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1161 if (!child_valobj_sp) {
1162 std::string err_msg = llvm::formatv(
1163 "failed to use pointer as array for index {0} for "
1165 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1166 var_expr_path_strm.
GetData());
1168 err_msg =
"subscript of pointer to incomplete type 'void'";
1169 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1172 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1173 child_valobj_sp = base->GetChildAtIndex(child_idx);
1175 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1176 if (!child_valobj_sp) {
1177 std::string err_msg = llvm::formatv(
1178 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1179 base->GetTypeName().AsCString(
"<invalid type>"),
1180 var_expr_path_strm.
GetData());
1181 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1186 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1187 if (!child_valobj_sp) {
1188 std::string err_msg = llvm::formatv(
1189 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1190 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1191 var_expr_path_strm.
GetData());
1192 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1198 std::string err_msg =
1199 llvm::formatv(
"\"{0}\" is not an array type",
1200 base->GetTypeName().AsCString(
"<invalid type>"));
1201 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1204 if (
static_cast<uint32_t
>(child_idx) >=
1205 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1206 std::string err_msg = llvm::formatv(
1207 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1208 base->GetTypeName().AsCString(
"<invalid type>"),
1209 var_expr_path_strm.
GetData());
1210 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1213 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1214 if (!child_valobj_sp) {
1215 std::string err_msg = llvm::formatv(
1216 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1217 base->GetTypeName().AsCString(
"<invalid type>"),
1218 var_expr_path_strm.
GetData());
1219 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1224 if (child_valobj_sp) {
1226 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1227 child_valobj_sp = std::move(dynamic_sp);
1229 return child_valobj_sp;
1233 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1235 return llvm::make_error<DILDiagnosticError>(
1236 m_expr,
"could not get the index as an integer",
1238 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1241llvm::Expected<lldb::ValueObjectSP>
1244 if (!first_idx_or_err)
1245 return first_idx_or_err;
1248 if (!last_idx_or_err)
1249 return last_idx_or_err;
1252 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1253 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1254 return llvm::make_error<DILDiagnosticError>(
1258 bool success_first, success_last;
1259 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1260 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1261 if (!success_first || !success_last)
1262 return llvm::make_error<DILDiagnosticError>(
1266 if (first_index > last_index)
1267 std::swap(first_index, last_index);
1274 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1275 if (!child_valobj_sp) {
1276 std::string message = llvm::formatv(
1277 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1278 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1279 base->GetName().GetStringRef());
1280 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1283 return child_valobj_sp;
1286llvm::Expected<CompilerType>
1293 llvm::APInt apint = literal.
GetValue();
1295 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1306 for (
auto [signed_, unsigned_] : candidates) {
1307 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1310 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(&ctx);
1312 return size.takeError();
1313 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1316 return type_system->GetBasicTypeFromAST(unsigned_);
1319 return llvm::make_error<DILDiagnosticError>(
1321 "integer literal is too large to be represented in any integer type",
1325llvm::Expected<lldb::ValueObjectSP>
1327 llvm::Expected<lldb::TypeSystemSP> type_system =
1330 return type_system.takeError();
1332 llvm::Expected<CompilerType> type =
1335 return type.takeError();
1340 llvm::Expected<uint64_t> type_bitsize = type->GetBitSize(&
m_stack_frame);
1342 return type_bitsize.takeError();
1346 if (type->IsSigned())
1352llvm::Expected<lldb::ValueObjectSP>
1354 llvm::Expected<lldb::TypeSystemSP> type_system =
1357 return type_system.takeError();
1360 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1366 return llvm::make_error<DILDiagnosticError>(
1374llvm::Expected<lldb::ValueObjectSP>
1377 llvm::Expected<lldb::TypeSystemSP> type_system =
1380 return type_system.takeError();
1385llvm::Expected<CastKind>
1390 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1391 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1394 return llvm::make_error<DILDiagnosticError>(
1395 m_expr, std::move(errMsg), location,
1405 uint64_t type_byte_size = 0;
1406 uint64_t rhs_type_byte_size = 0;
1408 type_byte_size = *temp;
1410 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1413 "GetByteSize failed: {0}");
1414 return llvm::make_error<DILDiagnosticError>(
1415 m_expr, std::move(errMsg), location,
1420 rhs_type_byte_size = *temp;
1422 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1425 "GetByteSize failed: {0}");
1426 return llvm::make_error<DILDiagnosticError>(
1427 m_expr, std::move(errMsg), location,
1431 if (type_byte_size < rhs_type_byte_size) {
1432 std::string errMsg = llvm::formatv(
1433 "cast from pointer to smaller type {0} loses information",
1435 return llvm::make_error<DILDiagnosticError>(
1436 m_expr, std::move(errMsg), location,
1441 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1445 return llvm::make_error<DILDiagnosticError>(
1446 m_expr, std::move(errMsg), location,
1452llvm::Expected<CastKind>
1463 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1467 return llvm::make_error<DILDiagnosticError>(
1468 m_expr, std::move(errMsg), location,
1478 std::string errMsg = llvm::formatv(
1479 "cannot cast from type {0} to pointer type {1}",
1482 return llvm::make_error<DILDiagnosticError>(
1483 m_expr, std::move(errMsg), location,
1490 std::string errMsg = llvm::formatv(
1491 "casting of {0} to {1} is not implemented yet",
1493 return llvm::make_error<DILDiagnosticError>(
1494 m_expr, std::move(errMsg), location,
1501 if (!operand_or_err)
1502 return operand_or_err;
1512 operand->GetName().GetStringRef());
1513 op_type = operand->GetCompilerType();
1518 return type_or_err.takeError();
1521 if (operand->GetCompilerType().IsReferenceType()) {
1523 operand = operand->Dereference(
error);
1525 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1529 switch (cast_kind) {
1534 return operand->CastToEnumType(target_type);
1540 return operand->CastToBasicType(target_type);
1545 ? operand->GetLoadAddress()
1546 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1547 : operand->GetValueAsUnsigned(0));
1548 llvm::StringRef name =
"result";
1559 std::string errMsg =
1560 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1562 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).
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),...