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");
612 if (operand->GetCompilerType().IsReferenceType()) {
613 operand = operand->Dereference(
error);
615 return error.ToError();
620 llvm::formatv(
"invalid argument type '{0}' to unary expression",
622 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
625 llvm::Expected<lldb::TypeSystemSP> type_system =
628 return type_system.takeError();
629 auto value_or_err = operand->GetValueAsBool();
631 return value_or_err.takeError();
633 !(*value_or_err),
"result");
636 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid unary operation",
640llvm::Expected<lldb::ValueObjectSP>
644 if (ptr->GetCompilerType().IsPointerToVoid())
645 return llvm::make_error<DILDiagnosticError>(
646 m_expr,
"arithmetic on a pointer to void", location);
647 if (ptr->GetValueAsUnsigned(0) == 0 && offset != 0)
648 return llvm::make_error<DILDiagnosticError>(
649 m_expr,
"arithmetic on a nullptr is undefined", location);
652 int64_t offset_int = offset->GetValueAsSigned(0, &success);
654 std::string errMsg = llvm::formatv(
"could not get the offset: {0}",
655 offset->GetError().AsCString());
656 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
660 llvm::Expected<uint64_t> byte_size =
661 ptr->GetCompilerType().GetPointeeType().GetByteSize(&
m_stack_frame);
663 return byte_size.takeError();
664 uint64_t ptr_addr = ptr->GetValueAsUnsigned(0);
666 ptr_addr -= offset_int * (*byte_size);
668 ptr_addr += offset_int * (*byte_size);
676llvm::Expected<lldb::ValueObjectSP>
681 bool l_resolved = lhs->ResolveValue(
l);
684 llvm::formatv(
"invalid lhs value: {0}", lhs->GetError().AsCString());
685 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
687 bool r_resolved = rhs->ResolveValue(r);
690 llvm::formatv(
"invalid rhs value: {0}", rhs->GetError().AsCString());
691 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
694 auto value_object = [
this, result_type](
Scalar scalar) {
696 result_type,
"result");
701 return value_object(
l + r);
703 return value_object(
l - r);
705 return value_object(
l * r);
707 return value_object(
l / r);
709 return value_object(
l % r);
711 return value_object(
l & r);
713 return value_object(
l ^ r);
715 return value_object(
l | r);
717 return value_object(
l << r);
719 return value_object(
l >> r);
723 return llvm::make_error<DILDiagnosticError>(
724 m_expr,
"invalid arithmetic operation", location);
733 auto orig_lhs_type = lhs->GetCompilerType();
734 auto orig_rhs_type = rhs->GetCompilerType();
737 return type_or_err.takeError();
746 if (lhs->GetCompilerType().IsPointerType()) {
749 }
else if (rhs->GetCompilerType().IsPointerType()) {
754 if (!ptr || !offset->GetCompilerType().IsInteger()) {
756 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
757 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
758 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
771 auto orig_lhs_type = lhs->GetCompilerType();
772 auto orig_rhs_type = rhs->GetCompilerType();
775 return type_or_err.takeError();
781 auto lhs_type = lhs->GetCompilerType();
782 auto rhs_type = rhs->GetCompilerType();
785 if (lhs_type.IsPointerType() && rhs_type.IsInteger())
789 if (lhs_type.IsPointerType() && rhs_type.IsPointerType()) {
790 if (lhs_type.IsPointerToVoid() && rhs_type.IsPointerToVoid()) {
791 return llvm::make_error<DILDiagnosticError>(
792 m_expr,
"arithmetic on pointers to void", location);
797 if (!lhs_unqualified_type.
CompareTypes(rhs_unqualified_type)) {
798 std::string errMsg = llvm::formatv(
799 "'{0}' and '{1}' are not pointers to compatible types",
800 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
801 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
804 llvm::Expected<uint64_t> lhs_byte_size =
807 return lhs_byte_size.takeError();
809 int64_t item_size = *lhs_byte_size;
810 int64_t diff =
static_cast<int64_t
>(lhs->GetValueAsUnsigned(0) -
811 rhs->GetValueAsUnsigned(0));
812 assert(item_size > 0 &&
"Pointee size cannot be 0");
813 if (diff % item_size != 0) {
816 return llvm::make_error<DILDiagnosticError>(
817 m_expr,
"undefined pointer arithmetic", location);
821 llvm::Expected<lldb::TypeSystemSP> type_system =
824 return type_system.takeError();
825 CompilerType ptrdiff_type = type_system.get()->GetPointerDiffType(
true);
827 return llvm::make_error<DILDiagnosticError>(
828 m_expr,
"unable to determine pointer diff type", location);
832 ptrdiff_type,
"result");
836 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
837 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
838 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
846 auto orig_lhs_type = lhs->GetCompilerType();
847 auto orig_rhs_type = rhs->GetCompilerType();
850 return type_or_err.takeError();
855 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
856 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
857 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
868 auto orig_lhs_type = lhs->GetCompilerType();
869 auto orig_rhs_type = rhs->GetCompilerType();
872 return type_or_err.takeError();
877 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
878 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
879 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
884 if (result_type.
IsInteger() && rhs->GetValueAsSigned(-1) == 0) {
885 return llvm::make_error<DILDiagnosticError>(
886 m_expr,
"division by zero is undefined", location);
896 auto orig_lhs_type = lhs->GetCompilerType();
897 auto orig_rhs_type = rhs->GetCompilerType();
900 return type_or_err.takeError();
905 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
906 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
907 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
911 if (rhs->GetValueAsSigned(-1) == 0) {
912 return llvm::make_error<DILDiagnosticError>(
913 m_expr,
"division by zero is undefined", location);
929 return llvm::createStringError(
930 "Illegal type for lhs of assignment (not scalar numeric type)");
935 return llvm::createStringError(
936 "Illegal type for rhs of assignment (not scalar numeric type)");
941 return llvm::createStringError(
942 "Invalid assignment: Can only assign pointers to pointers");
947 lhs_type != rhs_type) {
948 std::string err_msg =
949 llvm::formatv(
"Incompatible types for assignment: Cannot assign {0} "
952 return llvm::createStringError(err_msg);
958llvm::Expected<lldb::ValueObjectSP>
965 return all_ok.takeError();
973llvm::Expected<lldb::ValueObjectSP>
978 auto orig_lhs_type = lhs->GetCompilerType();
979 auto orig_rhs_type = rhs->GetCompilerType();
982 return type_or_err.takeError();
987 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
988 orig_lhs_type.GetTypeName(), orig_rhs_type.GetTypeName());
989 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
995llvm::Expected<lldb::ValueObjectSP>
1004 return lhs_or_err.takeError();
1008 return rhs_or_err.takeError();
1014 std::string errMsg =
1015 llvm::formatv(
"invalid operands to binary expression ('{0}' and '{1}')",
1017 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg, location);
1021 uint64_t amount = rhs->GetValueAsUnsigned(0, &success);
1023 return llvm::make_error<DILDiagnosticError>(
1024 m_expr,
"could not get the shift amount as an integer", location);
1027 return lhs_size.takeError();
1028 if (amount >= *lhs_size)
1029 return llvm::make_error<DILDiagnosticError>(
m_expr,
"invalid shift amount",
1035llvm::Expected<lldb::ValueObjectSP>
1045 auto lhs_type = lhs->GetCompilerType();
1046 if (!lhs_type.IsContextuallyConvertibleToBool()) {
1047 std::string errMsg = llvm::formatv(
1048 "value of type {0} is not contextually convertible to 'bool'",
1049 lhs_type.TypeDescription());
1050 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
1053 llvm::Expected<lldb::TypeSystemSP> type_system =
1056 return type_system.takeError();
1060 auto lvalue_or_err = lhs->GetValueAsBool();
1062 return lvalue_or_err.takeError();
1063 bool lhs_val = *lvalue_or_err;
1074 auto rhs_type = rhs->GetCompilerType();
1075 if (!rhs_type.IsContextuallyConvertibleToBool()) {
1076 std::string errMsg = llvm::formatv(
1077 "value of type {0} is not contextually convertible to 'bool'",
1078 rhs_type.TypeDescription());
1079 return llvm::make_error<DILDiagnosticError>(
m_expr, errMsg,
1083 auto rvalue_or_err = rhs->GetValueAsBool();
1085 return rvalue_or_err.takeError();
1087 *rvalue_or_err,
"result");
1090llvm::Expected<lldb::ValueObjectSP>
1107 lhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
1109 rhs->GetCompilerType().GetTypeSystem().GetSharedPointer();
1110 if (lhs_system->GetPluginName() != rhs_system->GetPluginName()) {
1112 return llvm::make_error<DILDiagnosticError>(
1152 return llvm::make_error<DILDiagnosticError>(
1156llvm::Expected<lldb::ValueObjectSP>
1168 if (!base->IsPointerType() && base->HasSyntheticValue()) {
1171 base->GetSyntheticValue()->Dereference(deref_error);
1172 synth_deref_sp && deref_error.
Success()) {
1173 base = std::move(synth_deref_sp);
1175 if (!base || deref_error.
Fail()) {
1176 std::string errMsg = llvm::formatv(
1177 "Failed to dereference synthetic value: {0}", deref_error);
1178 return llvm::make_error<DILDiagnosticError>(
1184 std::string errMsg =
"Failed to dereference synthetic value";
1185 return llvm::make_error<DILDiagnosticError>(
1188 expr_is_ptr =
false;
1193 bool base_is_ptr = base->IsPointerType();
1195 if (expr_is_ptr != base_is_ptr) {
1197 std::string errMsg =
1198 llvm::formatv(
"member reference type {0} is a pointer; "
1199 "did you mean to use '->'?",
1200 base->GetCompilerType().TypeDescription());
1201 return llvm::make_error<DILDiagnosticError>(
1204 std::string errMsg =
1205 llvm::formatv(
"member reference type {0} is not a pointer; "
1206 "did you mean to use '.'?",
1207 base->GetCompilerType().TypeDescription());
1208 return llvm::make_error<DILDiagnosticError>(
1218 field_obj = base->GetSyntheticValue();
1220 field_obj = field_obj->GetChildMemberWithName(node.
GetFieldName());
1224 std::string errMsg = llvm::formatv(
1225 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1226 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1227 return llvm::make_error<DILDiagnosticError>(
1237 field_obj = dynamic_val_sp;
1243 if (node.
GetIsArrow() && base->IsPointerType())
1245 std::string errMsg = llvm::formatv(
1246 "\"{0}\" is not a member of \"({1}) {2}\"", node.
GetFieldName(),
1247 base->GetTypeName().AsCString(
"<invalid type>"), base->GetName());
1248 return llvm::make_error<DILDiagnosticError>(
1252llvm::Expected<lldb::ValueObjectSP>
1259 if (!idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1260 return llvm::make_error<DILDiagnosticError>(
1265 uint64_t child_idx = idx->GetValueAsUnsigned(0);
1273 CompilerType base_type = base->GetCompilerType().GetNonReferenceType();
1274 base->GetExpressionPath(var_expr_path_strm);
1275 bool is_incomplete_array =
false;
1277 bool is_objc_pointer =
true;
1280 is_objc_pointer =
false;
1281 else if (!base->GetCompilerType().IsPointerType())
1282 is_objc_pointer =
false;
1285 std::string err_msg = llvm::formatv(
1286 "\"({0}) {1}\" is an Objective-C pointer, and cannot be subscripted",
1287 base->GetTypeName().AsCString(
"<invalid type>"),
1288 var_expr_path_strm.
GetData());
1289 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1292 if (is_objc_pointer) {
1294 if (!synthetic || synthetic == base) {
1295 std::string err_msg =
1296 llvm::formatv(
"\"({0}) {1}\" is not an array type",
1297 base->GetTypeName().AsCString(
"<invalid type>"),
1298 var_expr_path_strm.
GetData());
1299 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1302 if (
static_cast<uint32_t
>(child_idx) >=
1303 synthetic->GetNumChildrenIgnoringErrors()) {
1304 std::string err_msg = llvm::formatv(
1305 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1306 base->GetTypeName().AsCString(
"<invalid type>"),
1307 var_expr_path_strm.
GetData());
1308 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1311 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1312 if (!child_valobj_sp) {
1313 std::string err_msg = llvm::formatv(
1314 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1315 base->GetTypeName().AsCString(
"<invalid type>"),
1316 var_expr_path_strm.
GetData());
1317 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1321 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1322 child_valobj_sp = std::move(dynamic_sp);
1324 return child_valobj_sp;
1327 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1328 if (!child_valobj_sp) {
1329 std::string err_msg = llvm::formatv(
1330 "failed to use pointer as array for index {0} for "
1332 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1333 var_expr_path_strm.
GetData());
1335 err_msg =
"subscript of pointer to incomplete type 'void'";
1336 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1339 }
else if (base_type.
IsArrayType(
nullptr,
nullptr, &is_incomplete_array)) {
1340 child_valobj_sp = base->GetChildAtIndex(child_idx);
1342 child_valobj_sp = base->GetSyntheticArrayMember(child_idx,
true);
1343 if (!child_valobj_sp) {
1344 std::string err_msg = llvm::formatv(
1345 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1346 base->GetTypeName().AsCString(
"<invalid type>"),
1347 var_expr_path_strm.
GetData());
1348 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1353 base->GetSyntheticBitFieldChild(child_idx, child_idx,
true);
1354 if (!child_valobj_sp) {
1355 std::string err_msg = llvm::formatv(
1356 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", child_idx,
1357 child_idx, base->GetTypeName().AsCString(
"<invalid type>"),
1358 var_expr_path_strm.
GetData());
1359 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1365 std::string err_msg =
1366 llvm::formatv(
"\"{0}\" is not an array type",
1367 base->GetTypeName().AsCString(
"<invalid type>"));
1368 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1371 if (
static_cast<uint32_t
>(child_idx) >=
1372 synthetic->GetNumChildrenIgnoringErrors(child_idx + 1)) {
1373 std::string err_msg = llvm::formatv(
1374 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1375 base->GetTypeName().AsCString(
"<invalid type>"),
1376 var_expr_path_strm.
GetData());
1377 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1380 child_valobj_sp = synthetic->GetChildAtIndex(child_idx);
1381 if (!child_valobj_sp) {
1382 std::string err_msg = llvm::formatv(
1383 "array index {0} is not valid for \"({1}) {2}\"", child_idx,
1384 base->GetTypeName().AsCString(
"<invalid type>"),
1385 var_expr_path_strm.
GetData());
1386 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(err_msg),
1391 if (child_valobj_sp) {
1393 if (
auto dynamic_sp = child_valobj_sp->GetDynamicValue(
m_use_dynamic))
1394 child_valobj_sp = std::move(dynamic_sp);
1396 return child_valobj_sp;
1400 int64_t signed_child_idx = idx->GetValueAsSigned(0, &success);
1402 return llvm::make_error<DILDiagnosticError>(
1403 m_expr,
"could not get the index as an integer",
1405 return base->GetSyntheticArrayMember(signed_child_idx,
true);
1408llvm::Expected<lldb::ValueObjectSP>
1411 if (!first_idx_or_err)
1412 return first_idx_or_err;
1415 if (!last_idx_or_err)
1416 return last_idx_or_err;
1419 if (!first_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType() ||
1420 !last_idx->GetCompilerType().IsIntegerOrUnscopedEnumerationType()) {
1421 return llvm::make_error<DILDiagnosticError>(
1425 bool success_first, success_last;
1426 int64_t first_index = first_idx->GetValueAsSigned(0, &success_first);
1427 int64_t last_index = last_idx->GetValueAsSigned(0, &success_last);
1428 if (!success_first || !success_last)
1429 return llvm::make_error<DILDiagnosticError>(
1435 if (first_index < 0 || last_index < 0) {
1436 std::string message =
1437 llvm::formatv(
"bitfield range {0}:{1} is not valid (negative index)",
1438 first_index, last_index);
1439 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1444 if (first_index > last_index)
1445 std::swap(first_index, last_index);
1450 if (last_index - first_index >= 64) {
1451 std::string message =
1452 llvm::formatv(
"bitfield range {0}:{1} is not valid (more than 64 bits)",
1453 first_index, last_index);
1454 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1466 llvm::Expected<uint64_t> base_bit_size =
1469 return base_bit_size.takeError();
1470 if (
static_cast<uint64_t
>(last_index) >= *base_bit_size) {
1471 std::string message = llvm::formatv(
1472 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1473 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1474 base->GetName().GetStringRef());
1475 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1480 base->GetSyntheticBitFieldChild(first_index, last_index,
true);
1481 if (!child_valobj_sp) {
1482 std::string message = llvm::formatv(
1483 "bitfield range {0}:{1} is not valid for \"({2}) {3}\"", first_index,
1484 last_index, base->GetTypeName().AsCString(
"<invalid type>"),
1485 base->GetName().GetStringRef());
1486 return llvm::make_error<DILDiagnosticError>(
m_expr, message,
1489 return child_valobj_sp;
1492llvm::Expected<CompilerType>
1499 llvm::APInt apint = literal.
GetValue();
1501 llvm::SmallVector<std::pair<lldb::BasicType, lldb::BasicType>, 3> candidates;
1512 for (
auto [signed_, unsigned_] : candidates) {
1513 CompilerType signed_type = type_system->GetBasicTypeFromAST(signed_);
1516 llvm::Expected<uint64_t> size = signed_type.
GetBitSize(&ctx);
1518 return size.takeError();
1519 if (!literal.
IsUnsigned() && apint.isIntN(*size - 1))
1522 return type_system->GetBasicTypeFromAST(unsigned_);
1525 return llvm::make_error<DILDiagnosticError>(
1527 "integer literal is too large to be represented in any integer type",
1531llvm::Expected<lldb::ValueObjectSP>
1533 llvm::Expected<lldb::TypeSystemSP> type_system =
1536 return type_system.takeError();
1538 llvm::Expected<CompilerType> type =
1541 return type.takeError();
1546 llvm::Expected<uint64_t> type_bitsize = type->GetBitSize(&
m_stack_frame);
1548 return type_bitsize.takeError();
1552 if (type->IsSigned())
1558llvm::Expected<lldb::ValueObjectSP>
1560 llvm::Expected<lldb::TypeSystemSP> type_system =
1563 return type_system.takeError();
1566 &node.
GetValue().getSemantics() == &llvm::APFloat::IEEEsingle();
1572 return llvm::make_error<DILDiagnosticError>(
1580llvm::Expected<lldb::ValueObjectSP>
1583 llvm::Expected<lldb::TypeSystemSP> type_system =
1586 return type_system.takeError();
1591llvm::Expected<CastKind>
1596 if (target_type.
GetTypeInfo() & lldb::eTypeIsFloat) {
1597 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1600 return llvm::make_error<DILDiagnosticError>(
1601 m_expr, std::move(errMsg), location,
1611 uint64_t type_byte_size = 0;
1612 uint64_t rhs_type_byte_size = 0;
1614 type_byte_size = *temp;
1616 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1619 "GetByteSize failed: {0}");
1620 return llvm::make_error<DILDiagnosticError>(
1621 m_expr, std::move(errMsg), location,
1626 rhs_type_byte_size = *temp;
1628 std::string errMsg = llvm::formatv(
"unable to get byte size for type {0}",
1631 "GetByteSize failed: {0}");
1632 return llvm::make_error<DILDiagnosticError>(
1633 m_expr, std::move(errMsg), location,
1637 if (type_byte_size < rhs_type_byte_size) {
1638 std::string errMsg = llvm::formatv(
1639 "cast from pointer to smaller type {0} loses information",
1641 return llvm::make_error<DILDiagnosticError>(
1642 m_expr, std::move(errMsg), location,
1647 std::string errMsg = llvm::formatv(
"cannot convert {0} to {1}",
1651 return llvm::make_error<DILDiagnosticError>(
1652 m_expr, std::move(errMsg), location,
1658llvm::Expected<CastKind>
1669 std::string errMsg = llvm::formatv(
"Cast from {0} to {1} is not allowed",
1673 return llvm::make_error<DILDiagnosticError>(
1674 m_expr, std::move(errMsg), location,
1684 std::string errMsg = llvm::formatv(
1685 "cannot cast from type {0} to pointer type {1}",
1688 return llvm::make_error<DILDiagnosticError>(
1689 m_expr, std::move(errMsg), location,
1696 std::string errMsg = llvm::formatv(
1697 "casting of {0} to {1} is not implemented yet",
1699 return llvm::make_error<DILDiagnosticError>(
1700 m_expr, std::move(errMsg), location,
1707 if (!operand_or_err)
1708 return operand_or_err;
1718 operand->GetName().GetStringRef());
1719 op_type = operand->GetCompilerType();
1724 return type_or_err.takeError();
1727 if (operand->GetCompilerType().IsReferenceType()) {
1729 operand = operand->Dereference(
error);
1731 return llvm::make_error<DILDiagnosticError>(
m_expr,
error.AsCString(),
1735 switch (cast_kind) {
1740 return operand->CastToEnumType(target_type);
1746 return operand->CastToBasicType(target_type);
1751 ? operand->GetLoadAddress()
1752 : (op_type.
IsSigned() ? operand->GetValueAsSigned(0)
1753 : operand->GetValueAsUnsigned(0));
1754 llvm::StringRef name =
"result";
1765 std::string errMsg =
1766 llvm::formatv(
"unable to cast from '{0}' to '{1}'",
1768 return llvm::make_error<DILDiagnosticError>(
m_expr, std::move(errMsg),
1780 return byte_size.takeError();
1788 if (arg->IsBitfield())
1789 return llvm::make_error<DILDiagnosticError>(
1790 m_expr,
"invalid application of 'sizeof' to bit-field",
1793 llvm::Expected<uint64_t> byte_size = arg->GetByteSize();
1795 return byte_size.takeError();
1799 llvm::Expected<lldb::TypeSystemSP> type_system =
1802 return type_system.takeError();
1803 CompilerType size_type = type_system.get()->GetSizeType();
1805 return llvm::make_error<DILDiagnosticError>(
1809 size_type,
"result");
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.
bool IsContextuallyConvertibleToBool() const
This may only be defined in TypeSystemClang.
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 > EvaluateLogical(const BinaryOpNode &node)
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
ASTNode & GetNodeArg() const
CompilerType GetTypeArg() 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),...