Skip to content

Commit b6051ed

Browse files
committed
[LLDB] Fix error returns in CastToBasicType and CastToEnumType in ValueObject.
Update the error returns in ValueObject::CastToBasicType and ValueObject::CastToEnumType to create new errors and return a ValueObjectConstResult with the error, rather tnan updating the error in (and returning) the input ValueObject.
1 parent 4ab5e90 commit b6051ed

File tree

1 file changed

+53
-34
lines changed

1 file changed

+53
-34
lines changed

lldb/source/ValueObject/ValueObject.cpp

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,16 +3194,19 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
31943194
GetCompilerType().IsPointerType() || GetCompilerType().IsNullPtrType();
31953195
bool is_float = GetCompilerType().IsFloat();
31963196
bool is_integer = GetCompilerType().IsInteger();
3197+
ExecutionContext exe_ctx(GetExecutionContextRef());
31973198

31983199
if (!type.IsScalarType()) {
3199-
m_error = Status::FromErrorString("target type must be a scalar");
3200-
return GetSP();
3200+
Status error = Status::FromErrorString("target type must be a scalar");
3201+
return ValueObjectConstResult::Create(
3202+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32013203
}
32023204

32033205
if (!is_scalar && !is_enum && !is_pointer) {
3204-
m_error =
3206+
Status error =
32053207
Status::FromErrorString("argument must be a scalar, enum, or pointer");
3206-
return GetSP();
3208+
return ValueObjectConstResult::Create(
3209+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32073210
}
32083211

32093212
lldb::TargetSP target = GetTargetSP();
@@ -3216,14 +3219,16 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
32163219

32173220
if (is_pointer) {
32183221
if (!type.IsInteger() && !type.IsBoolean()) {
3219-
m_error =
3222+
Status error =
32203223
Status::FromErrorString("target type must be an integer or boolean");
3221-
return GetSP();
3224+
return ValueObjectConstResult::Create(
3225+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32223226
}
32233227
if (!type.IsBoolean() && type_byte_size < val_byte_size) {
3224-
m_error = Status::FromErrorString(
3228+
Status error = Status::FromErrorString(
32253229
"target type cannot be smaller than the pointer type");
3226-
return GetSP();
3230+
return ValueObjectConstResult::Create(
3231+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32273232
}
32283233
}
32293234

@@ -3237,10 +3242,11 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
32373242
return ValueObject::CreateValueObjectFromBool(
32383243
target, !float_value_or_err->isZero(), "result");
32393244
else {
3240-
m_error = Status::FromErrorStringWithFormat(
3245+
Status error = Status::FromErrorStringWithFormat(
32413246
"cannot get value as APFloat: %s",
32423247
llvm::toString(float_value_or_err.takeError()).c_str());
3243-
return GetSP();
3248+
return ValueObjectConstResult::Create(
3249+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32443250
}
32453251
}
32463252
}
@@ -3256,11 +3262,12 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
32563262
return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
32573263
"result");
32583264
} else {
3259-
m_error = Status::FromErrorStringWithFormat(
3265+
Status error = Status::FromErrorStringWithFormat(
32603266
"cannot get value as APSInt: %s",
32613267
llvm::toString(int_value_or_err.takeError()).c_str());
32623268
;
3263-
return GetSP();
3269+
return ValueObjectConstResult::Create(
3270+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32643271
}
32653272
} else if (is_scalar && is_float) {
32663273
llvm::APSInt integer(type_byte_size * CHAR_BIT, !type.IsSigned());
@@ -3274,10 +3281,11 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
32743281
// Casting floating point values that are out of bounds of the target
32753282
// type is undefined behaviour.
32763283
if (status & llvm::APFloatBase::opInvalidOp) {
3277-
m_error = Status::FromErrorStringWithFormat(
3284+
Status error = Status::FromErrorStringWithFormat(
32783285
"invalid type cast detected: %s",
32793286
llvm::toString(float_value_or_err.takeError()).c_str());
3280-
return GetSP();
3287+
return ValueObjectConstResult::Create(
3288+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
32813289
}
32823290
return ValueObject::CreateValueObjectFromAPInt(target, integer, type,
32833291
"result");
@@ -3297,10 +3305,11 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
32973305
return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
32983306
"result");
32993307
} else {
3300-
m_error = Status::FromErrorStringWithFormat(
3308+
Status error = Status::FromErrorStringWithFormat(
33013309
"cannot get value as APSInt: %s",
33023310
llvm::toString(int_value_or_err.takeError()).c_str());
3303-
return GetSP();
3311+
return ValueObjectConstResult::Create(
3312+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33043313
}
33053314
} else {
33063315
if (is_integer) {
@@ -3312,10 +3321,11 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
33123321
return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
33133322
"result");
33143323
} else {
3315-
m_error = Status::FromErrorStringWithFormat(
3324+
Status error = Status::FromErrorStringWithFormat(
33163325
"cannot get value as APSInt: %s",
33173326
llvm::toString(int_value_or_err.takeError()).c_str());
3318-
return GetSP();
3327+
return ValueObjectConstResult::Create(
3328+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33193329
}
33203330
}
33213331
if (is_float) {
@@ -3327,33 +3337,38 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
33273337
return ValueObject::CreateValueObjectFromAPFloat(target, f, type,
33283338
"result");
33293339
} else {
3330-
m_error = Status::FromErrorStringWithFormat(
3340+
Status error = Status::FromErrorStringWithFormat(
33313341
"cannot get value as APFloat: %s",
33323342
llvm::toString(float_value_or_err.takeError()).c_str());
3333-
return GetSP();
3343+
return ValueObjectConstResult::Create(
3344+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33343345
}
33353346
}
33363347
}
33373348
}
33383349

3339-
m_error = Status::FromErrorString("Unable to perform requested cast");
3340-
return GetSP();
3350+
Status error = Status::FromErrorString("Unable to perform requested cast");
3351+
return ValueObjectConstResult::Create(
3352+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33413353
}
33423354

33433355
lldb::ValueObjectSP ValueObject::CastToEnumType(CompilerType type) {
33443356
bool is_enum = GetCompilerType().IsEnumerationType();
33453357
bool is_integer = GetCompilerType().IsInteger();
33463358
bool is_float = GetCompilerType().IsFloat();
3359+
ExecutionContext exe_ctx(GetExecutionContextRef());
33473360

33483361
if (!is_enum && !is_integer && !is_float) {
3349-
m_error = Status::FromErrorString(
3362+
Status error = Status::FromErrorString(
33503363
"argument must be an integer, a float, or an enum");
3351-
return GetSP();
3364+
return ValueObjectConstResult::Create(
3365+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33523366
}
33533367

33543368
if (!type.IsEnumerationType()) {
3355-
m_error = Status::FromErrorString("target type must be an enum");
3356-
return GetSP();
3369+
Status error = Status::FromErrorString("target type must be an enum");
3370+
return ValueObjectConstResult::Create(
3371+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33573372
}
33583373

33593374
lldb::TargetSP target = GetTargetSP();
@@ -3372,16 +3387,18 @@ lldb::ValueObjectSP ValueObject::CastToEnumType(CompilerType type) {
33723387
// Casting floating point values that are out of bounds of the target
33733388
// type is undefined behaviour.
33743389
if (status & llvm::APFloatBase::opInvalidOp) {
3375-
m_error = Status::FromErrorStringWithFormat(
3390+
Status error = Status::FromErrorStringWithFormat(
33763391
"invalid type cast detected: %s",
33773392
llvm::toString(value_or_err.takeError()).c_str());
3378-
return GetSP();
3393+
return ValueObjectConstResult::Create(
3394+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33793395
}
33803396
return ValueObject::CreateValueObjectFromAPInt(target, integer, type,
33813397
"result");
33823398
} else {
3383-
m_error = Status::FromErrorString("cannot get value as APFloat");
3384-
return GetSP();
3399+
Status error = Status::FromErrorString("cannot get value as APFloat");
3400+
return ValueObjectConstResult::Create(
3401+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33853402
}
33863403
} else {
33873404
// Get the value as APSInt and extend or truncate it to the requested size.
@@ -3391,14 +3408,16 @@ lldb::ValueObjectSP ValueObject::CastToEnumType(CompilerType type) {
33913408
return ValueObject::CreateValueObjectFromAPInt(target, ext, type,
33923409
"result");
33933410
} else {
3394-
m_error = Status::FromErrorStringWithFormat(
3411+
Status error = Status::FromErrorStringWithFormat(
33953412
"cannot get value as APSInt: %s",
33963413
llvm::toString(value_or_err.takeError()).c_str());
3397-
return GetSP();
3414+
return ValueObjectConstResult::Create(
3415+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
33983416
}
33993417
}
3400-
m_error = Status::FromErrorString("Cannot perform requested cast");
3401-
return GetSP();
3418+
Status error = Status::FromErrorString("Cannot perform requested cast");
3419+
return ValueObjectConstResult::Create(
3420+
exe_ctx.GetBestExecutionContextScope(), error.Clone());
34023421
}
34033422

34043423
ValueObject::EvaluationPoint::EvaluationPoint() : m_mod_id(), m_exe_ctx_ref() {}

0 commit comments

Comments
 (0)