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);
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);
840llvm::Expected<lldb::ValueObjectSP>
849 return lhs_or_err.takeError();
853 return rhs_or_err.takeError();
860 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
862 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
866 uint64_t amount = rhs->GetValueAsUnsigned(0, &success);
868 return llvm::make_error<DILDiagnosticError>(
869 m_expr,
"could not get the shift amount as an integer", location);
870 llvm::Expected<uint64_t> lhs_size =
873 return lhs_size.takeError();
874 if (amount >= *lhs_size)
875 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid shift amount",
881llvm::Expected<lldb::ValueObjectSP>
893 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
895 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
896 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
898 return llvm::make_error<DILDiagnosticError>(
918 return llvm::make_error<DILDiagnosticError>(
922llvm::Expected<lldb::ValueObjectSP>
934 if (!base->IsPointerType() && base->HasSyntheticValue()) {
937 base->GetSyntheticValue()->Dereference(deref_error);
938 synth_deref_sp && deref_error.
Success()) {
939 base = std::move(synth_deref_sp);
941 if (!base || deref_error.
Fail()) {
942 std::string errMsg = llvm::formatv(
943 "Failed to dereference synthetic value: {0}", deref_error);
944 return llvm::make_error<DILDiagnosticError>(
950 std::string errMsg =
"Failed to dereference synthetic value";
951 return llvm::make_error<DILDiagnosticError>(
959 bool base_is_ptr = base->IsPointerType();
961 if (expr_is_ptr != base_is_ptr) {
964 llvm::formatv(
"member reference type {0} is a pointer; "
965 "did you mean to use '->'?",
966 base->GetCompilerType().TypeDescription());
967 return llvm::make_error<DILDiagnosticError>(
971 llvm::formatv(
"member reference type {0} is not a pointer; "
972 "did you mean to use '.'?",
973 base->GetCompilerType().TypeDescription());
974 return llvm::make_error<DILDiagnosticError>(
984 field_obj = base->GetSyntheticValue();
986 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
990 std::string errMsg = llvm::formatv(
991 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
992 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
993 return llvm::make_error<DILDiagnosticError>(
1003 field_obj = dynamic_val_sp;
1009 if (node.
GetIsArrow() && base->IsPointerType())
1011 std::string errMsg = llvm::formatv(
1012 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1013 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1014 return llvm::make_error<DILDiagnosticError>(
1018llvm::Expected<lldb::ValueObjectSP>
1025 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1026 return llvm::make_error<DILDiagnosticError>(
1031 uint64_t child_idx = idx->GetValueAsUnsigned(0);
1039 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
1040 base->GetExpressionPath(var_expr_path_strm);
1041 bool is_incomplete_array =
false;
1043 bool is_objc_pointer =
true;
1046 is_objc_pointer =
false;
1047 else if (!base->GetCompilerType().IsPointerType())
1048 is_objc_pointer =
false;
1051 std::string err_msg = llvm::formatv(
1052 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
1053 base->GetTypeName().AsCString(
"<invalid type>"),
1054 var_expr_path_strm.
GetData());
1055 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1058 if (is_objc_pointer) {
1060 if (!synthetic || synthetic == base) {
1061 std::string err_msg =
1062 llvm::formatv(
"\"({0}) {1}\" is not an array type",
1063 base->GetTypeName().AsCString(
"<invalid type>"),
1064 var_expr_path_strm.
GetData());
1065 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1068 if (
static_cast<uint32_t
>(child_idx) >=
1069 synthetic->GetNumChildrenIgnoringErrors()) {
1070 std::string err_msg = llvm::formatv(
1071 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1072 base->GetTypeName().AsCString(
"<invalid type>"),
1073 var_expr_path_strm.
GetData());
1074 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1077 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1078 if (!child_valobj_sp) {
1079 std::string err_msg = llvm::formatv(
1080 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1081 base->GetTypeName().AsCString(
"<invalid type>"),
1082 var_expr_path_strm.
GetData());
1083 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1087 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1088 child_valobj_sp = std::move(dynamic_sp);
1090 return child_valobj_sp;
1093 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1094 if (!child_valobj_sp) {
1095 std::string err_msg = llvm::formatv(
1096 "failed to use pointer as array for index {0} for "
1098 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1099 var_expr_path_strm.
GetData());
1101 err_msg =
"subscript of pointer to incomplete type 'void'";
1102 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1105 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1106 child_valobj_sp = base->GetChildAtIndex(child_idx);
1108 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1109 if (!child_valobj_sp) {
1110 std::string err_msg = llvm::formatv(
1111 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1112 base->GetTypeName().AsCString(
"<invalid type>"),
1113 var_expr_path_strm.
GetData());
1114 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1119 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1120 if (!child_valobj_sp) {
1121 std::string err_msg = llvm::formatv(
1122 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1123 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1124 var_expr_path_strm.
GetData());
1125 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1131 std::string err_msg =
1132 llvm::formatv(
"\"{0}\" is not an array type",
1133 base->GetTypeName().AsCString(
"<invalid type>"));
1134 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1137 if (
static_cast<uint32_t
>(child_idx) >=
1138 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1139 std::string err_msg = llvm::formatv(
1140 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1141 base->GetTypeName().AsCString(
"<invalid type>"),
1142 var_expr_path_strm.
GetData());
1143 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1146 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1147 if (!child_valobj_sp) {
1148 std::string err_msg = llvm::formatv(
1149 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1150 base->GetTypeName().AsCString(
"<invalid type>"),
1151 var_expr_path_strm.
GetData());
1152 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1157 if (child_valobj_sp) {
1159 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1160 child_valobj_sp = std::move(dynamic_sp);
1162 return child_valobj_sp;
1166 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1168 return llvm::make_error<DILDiagnosticError>(
1169 m_expr,
"could not get the index as an integer",
1171 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1174llvm::Expected<lldb::ValueObjectSP>
1177 if (!first_idx_or_err)
1178 return first_idx_or_err;
1181 if (!last_idx_or_err)
1182 return last_idx_or_err;
1185 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1186 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1187 return llvm::make_error<DILDiagnosticError>(
1191 bool success_first, success_last;
1192 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1193 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1194 if (!success_first || !success_last)
1195 return llvm::make_error<DILDiagnosticError>(
1199 if (first_index > last_index)
1200 std::swap(first_index, last_index);
1207 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1208 if (!child_valobj_sp) {
1209 std::string message = llvm::formatv(
1210 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1211 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1212 base->GetName().GetStringRef());
1213 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1216 return child_valobj_sp;
1219llvm::Expected<CompilerType>
1221 std::shared_ptr<ExecutionContextScope> ctx,
1226 llvm::APInt apint = literal.
GetValue();
1228 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1239 for (
auto [signed_, unsigned_] : candidates) {
1240 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1243 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(ctx.get());
1245 return size.takeError();
1246 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1249 return type_system->GetBasicTypeFromAST(unsigned_);
1252 return llvm::make_error<DILDiagnosticError>(
1254 "integer literal is too large to be represented in any integer type",
1258llvm::Expected<lldb::ValueObjectSP>
1260 llvm::Expected<lldb::TypeSystemSP> type_system =
1263 return type_system.takeError();
1265 llvm::Expected<CompilerType> type =
1268 return type.takeError();
1273 llvm::Expected<uint64_t> type_bitsize =
1276 return type_bitsize.takeError();
1280 if (type->IsSigned())
1286llvm::Expected<lldb::ValueObjectSP>
1288 llvm::Expected<lldb::TypeSystemSP> type_system =
1291 return type_system.takeError();
1294 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1300 return llvm::make_error<DILDiagnosticError>(
1308llvm::Expected<lldb::ValueObjectSP>
1311 llvm::Expected<lldb::TypeSystemSP> type_system =
1314 return type_system.takeError();
1319llvm::Expected<CastKind>
1324 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1325 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1328 return llvm::make_error<DILDiagnosticError>(
1329 m_expr, std::move(errMsg), location,
1339 uint64_t type_byte_size = 0;
1340 uint64_t rhs_type_byte_size = 0;
1342 type_byte_size = *temp;
1344 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1347 "GetByteSize failed: {0}");
1348 return llvm::make_error<DILDiagnosticError>(
1349 m_expr, std::move(errMsg), location,
1354 rhs_type_byte_size = *temp;
1356 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1359 "GetByteSize failed: {0}");
1360 return llvm::make_error<DILDiagnosticError>(
1361 m_expr, std::move(errMsg), location,
1365 if (type_byte_size < rhs_type_byte_size) {
1366 std::string errMsg = llvm::formatv(
1367 "cast from pointer to smaller type {0} loses information",
1369 return llvm::make_error<DILDiagnosticError>(
1370 m_expr, std::move(errMsg), location,
1375 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1379 return llvm::make_error<DILDiagnosticError>(
1380 m_expr, std::move(errMsg), location,
1386llvm::Expected<CastKind>
1397 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1401 return llvm::make_error<DILDiagnosticError>(
1402 m_expr, std::move(errMsg), location,
1412 std::string errMsg = llvm::formatv(
1413 "cannot cast from type {0} to pointer type {1}",
1416 return llvm::make_error<DILDiagnosticError>(
1417 m_expr, std::move(errMsg), location,
1424 std::string errMsg = llvm::formatv(
1425 "casting of {0} to {1} is not implemented yet",
1427 return llvm::make_error<DILDiagnosticError>(
1428 m_expr, std::move(errMsg), location,
1435 if (!operand_or_err)
1436 return operand_or_err;
1446 operand->GetName().GetStringRef());
1447 op_type = operand->GetCompilerType();
1452 return type_or_err.takeError();
1455 if (operand->GetCompilerType().IsReferenceType()) {
1457 operand = operand->Dereference(
error);
1459 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1463 switch (cast_kind) {
1468 return operand->CastToEnumType(target_type);
1474 return operand->CastToBasicType(target_type);
1479 ? operand->GetLoadAddress()
1480 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1481 : operand->GetValueAsUnsigned(0));
1482 llvm::StringRef name =
"result";
1493 std::string errMsg =
1494 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1496 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...
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< 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.
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...
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),...