[Lldb-commits] [lldb] 586c375 - [lldb] Remove [US]IntValueIsValidForSize from CommandObjectMemory
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Wed Nov 4 07:28:55 PST 2020
Author: Pavel Labath
Date: 2020-11-04T16:28:10+01:00
New Revision: 586c375fa3f0bb6f685a69ea43d7f235b76b6a9f
URL: https://github.com/llvm/llvm-project/commit/586c375fa3f0bb6f685a69ea43d7f235b76b6a9f
DIFF: https://github.com/llvm/llvm-project/commit/586c375fa3f0bb6f685a69ea43d7f235b76b6a9f.diff
LOG: [lldb] Remove [US]IntValueIsValidForSize from CommandObjectMemory
Use llvm::is(U)IntN (MathExtras.h) instead.
Added:
Modified:
lldb/source/Commands/CommandObjectMemory.cpp
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectMemory.cpp b/lldb/source/Commands/CommandObjectMemory.cpp
index d4c2808dc159..20a1fbb0f1b2 100644
--- a/lldb/source/Commands/CommandObjectMemory.cpp
+++ b/lldb/source/Commands/CommandObjectMemory.cpp
@@ -33,8 +33,7 @@
#include "lldb/Utility/DataBufferHeap.h"
#include "lldb/Utility/DataBufferLLVM.h"
#include "lldb/Utility/StreamString.h"
-
-
+#include "llvm/Support/MathExtras.h"
#include <cinttypes>
#include <memory>
@@ -1281,29 +1280,6 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
Options *GetOptions() override { return &m_option_group; }
- bool UIntValueIsValidForSize(uint64_t uval64, size_t total_byte_size) {
- if (total_byte_size > 8)
- return false;
-
- if (total_byte_size == 8)
- return true;
-
- const uint64_t max = ((uint64_t)1 << (uint64_t)(total_byte_size * 8)) - 1;
- return uval64 <= max;
- }
-
- bool SIntValueIsValidForSize(int64_t sval64, size_t total_byte_size) {
- if (total_byte_size > 8)
- return false;
-
- if (total_byte_size == 8)
- return true;
-
- const int64_t max = ((int64_t)1 << (uint64_t)(total_byte_size * 8 - 1)) - 1;
- const int64_t min = ~(max);
- return min <= sval64 && sval64 <= max;
- }
-
protected:
bool DoExecute(Args &command, CommandReturnObject &result) override {
// No need to check "process" for validity as eCommandRequiresProcess
@@ -1449,7 +1425,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
"'%s' is not a valid hex string value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
+ } else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
result.AppendErrorWithFormat("Value 0x%" PRIx64
" is too large to fit in a %" PRIu64
" byte unsigned integer value.\n",
@@ -1477,7 +1453,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
"'%s' is not a valid binary string value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
+ } else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
result.AppendErrorWithFormat("Value 0x%" PRIx64
" is too large to fit in a %" PRIu64
" byte unsigned integer value.\n",
@@ -1516,7 +1492,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
"'%s' is not a valid signed decimal value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!SIntValueIsValidForSize(sval64, item_byte_size)) {
+ } else if (!llvm::isIntN(item_byte_size * 8, sval64)) {
result.AppendErrorWithFormat(
"Value %" PRIi64 " is too large or small to fit in a %" PRIu64
" byte signed integer value.\n",
@@ -1535,7 +1511,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
+ } else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
result.AppendErrorWithFormat("Value %" PRIu64
" is too large to fit in a %" PRIu64
" byte unsigned integer value.\n",
@@ -1552,7 +1528,7 @@ class CommandObjectMemoryWrite : public CommandObjectParsed {
"'%s' is not a valid octal string value.\n", entry.c_str());
result.SetStatus(eReturnStatusFailed);
return false;
- } else if (!UIntValueIsValidForSize(uval64, item_byte_size)) {
+ } else if (!llvm::isUIntN(item_byte_size * 8, uval64)) {
result.AppendErrorWithFormat("Value %" PRIo64
" is too large to fit in a %" PRIu64
" byte unsigned integer value.\n",
More information about the lldb-commits
mailing list