|
8 | 8 |
|
9 | 9 | #include "lldb/Utility/RegisterValue.h" |
10 | 10 |
|
11 | | -#include "lldb/Utility/Args.h" |
12 | 11 | #include "lldb/Utility/DataExtractor.h" |
13 | 12 | #include "lldb/Utility/Scalar.h" |
14 | 13 | #include "lldb/Utility/Status.h" |
@@ -330,6 +329,35 @@ static bool ParseVectorEncoding(const RegisterInfo *reg_info, |
330 | 329 | return true; |
331 | 330 | } |
332 | 331 |
|
| 332 | +static bool UInt64ValueIsValidForByteSize(uint64_t uval64, |
| 333 | + size_t total_byte_size) { |
| 334 | + if (total_byte_size > 8) |
| 335 | + return false; |
| 336 | + |
| 337 | + if (total_byte_size == 8) |
| 338 | + return true; |
| 339 | + |
| 340 | + const uint64_t max = |
| 341 | + (static_cast<uint64_t>(1) << static_cast<uint64_t>(total_byte_size * 8)) - |
| 342 | + 1; |
| 343 | + return uval64 <= max; |
| 344 | +} |
| 345 | + |
| 346 | +static bool SInt64ValueIsValidForByteSize(int64_t sval64, |
| 347 | + size_t total_byte_size) { |
| 348 | + if (total_byte_size > 8) |
| 349 | + return false; |
| 350 | + |
| 351 | + if (total_byte_size == 8) |
| 352 | + return true; |
| 353 | + |
| 354 | + const int64_t max = (static_cast<int64_t>(1) |
| 355 | + << static_cast<uint64_t>(total_byte_size * 8 - 1)) - |
| 356 | + 1; |
| 357 | + const int64_t min = ~(max); |
| 358 | + return min <= sval64 && sval64 <= max; |
| 359 | +} |
| 360 | + |
333 | 361 | Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info, |
334 | 362 | llvm::StringRef value_str) { |
335 | 363 | Status error; |
@@ -368,7 +396,7 @@ Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info, |
368 | 396 | break; |
369 | 397 | } |
370 | 398 |
|
371 | | - if (!Args::UInt64ValueIsValidForByteSize(uval64, byte_size)) { |
| 399 | + if (!UInt64ValueIsValidForByteSize(uval64, byte_size)) { |
372 | 400 | error.SetErrorStringWithFormat( |
373 | 401 | "value 0x%" PRIx64 |
374 | 402 | " is too large to fit in a %u byte unsigned integer value", |
@@ -397,7 +425,7 @@ Status RegisterValue::SetValueFromString(const RegisterInfo *reg_info, |
397 | 425 | break; |
398 | 426 | } |
399 | 427 |
|
400 | | - if (!Args::SInt64ValueIsValidForByteSize(ival64, byte_size)) { |
| 428 | + if (!SInt64ValueIsValidForByteSize(ival64, byte_size)) { |
401 | 429 | error.SetErrorStringWithFormat( |
402 | 430 | "value 0x%" PRIx64 |
403 | 431 | " is too large to fit in a %u byte signed integer value", |
|
0 commit comments