summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-11-17 23:05:28 +0000
committerZachary Turner <zturner@google.com>2016-11-17 23:05:28 +0000
commitb379d7df12b50199303f56df60b21663c2c2144e (patch)
tree3d2bb9c3f59aa2eb01370cb9dba944acefd066be /lldb/source
parent2174b6fe728b7056ab41003cdd5a99fd3b1f6395 (diff)
downloadbcm5719-llvm-b379d7df12b50199303f56df60b21663c2c2144e.tar.gz
bcm5719-llvm-b379d7df12b50199303f56df60b21663c2c2144e.zip
Change RegisterValue getters / setters to use StringRef.
In the process, found some functions that were duplicates of existing StringRef member functions. So deleted those functions and used the StringRef functions instead. llvm-svn: 287279
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Commands/CommandObjectRegister.cpp8
-rw-r--r--lldb/source/Core/RegisterValue.cpp179
-rw-r--r--lldb/source/Core/ValueObjectRegister.cpp3
-rw-r--r--lldb/source/Core/ValueObjectVariable.cpp2
4 files changed, 97 insertions, 95 deletions
diff --git a/lldb/source/Commands/CommandObjectRegister.cpp b/lldb/source/Commands/CommandObjectRegister.cpp
index e5e80898a24..8d7afbdb186 100644
--- a/lldb/source/Commands/CommandObjectRegister.cpp
+++ b/lldb/source/Commands/CommandObjectRegister.cpp
@@ -356,7 +356,7 @@ protected:
result.SetStatus(eReturnStatusFailed);
} else {
const char *reg_name = command.GetArgumentAtIndex(0);
- const char *value_str = command.GetArgumentAtIndex(1);
+ llvm::StringRef value_str = command.GetArgumentAtIndex(1);
// in most LLDB commands we accept $rbx as the name for register RBX - and
// here we would
@@ -373,7 +373,7 @@ protected:
if (reg_info) {
RegisterValue reg_value;
- Error error(reg_value.SetValueFromCString(reg_info, value_str));
+ Error error(reg_value.SetValueFromString(reg_info, value_str));
if (error.Success()) {
if (reg_ctx->WriteRegister(reg_info, reg_value)) {
// Toss all frames and anything else in the thread
@@ -386,11 +386,11 @@ protected:
if (error.AsCString()) {
result.AppendErrorWithFormat(
"Failed to write register '%s' with value '%s': %s\n", reg_name,
- value_str, error.AsCString());
+ value_str.str().c_str(), error.AsCString());
} else {
result.AppendErrorWithFormat(
"Failed to write register '%s' with value '%s'", reg_name,
- value_str);
+ value_str.str().c_str());
}
result.SetStatus(eReturnStatusFailed);
} else {
diff --git a/lldb/source/Core/RegisterValue.cpp b/lldb/source/Core/RegisterValue.cpp
index 62d83050dff..f1cfa4bc65c 100644
--- a/lldb/source/Core/RegisterValue.cpp
+++ b/lldb/source/Core/RegisterValue.cpp
@@ -347,51 +347,35 @@ Error RegisterValue::SetValueFromData(const RegisterInfo *reg_info,
return error;
}
-static inline void StripSpaces(llvm::StringRef &Str) {
- while (!Str.empty() && isspace(Str[0]))
- Str = Str.substr(1);
- while (!Str.empty() && isspace(Str.back()))
- Str = Str.substr(0, Str.size() - 1);
-}
-
-static inline void LStrip(llvm::StringRef &Str, char c) {
- if (!Str.empty() && Str.front() == c)
- Str = Str.substr(1);
-}
-
-static inline void RStrip(llvm::StringRef &Str, char c) {
- if (!Str.empty() && Str.back() == c)
- Str = Str.substr(0, Str.size() - 1);
-}
-
-// Helper function for RegisterValue::SetValueFromCString()
+// Helper function for RegisterValue::SetValueFromString()
static bool ParseVectorEncoding(const RegisterInfo *reg_info,
- const char *vector_str,
+ llvm::StringRef vector_str,
const uint32_t byte_size,
RegisterValue *reg_value) {
// Example: vector_str = "{0x2c 0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a
// 0x2a 0x3e 0x84 0x4f 0x2a 0x3e}".
- llvm::StringRef Str(vector_str);
- StripSpaces(Str);
- LStrip(Str, '{');
- RStrip(Str, '}');
- StripSpaces(Str);
+ vector_str = vector_str.trim();
+ vector_str.consume_front("{");
+ vector_str.consume_back("}");
+ vector_str = vector_str.trim();
char Sep = ' ';
// The first split should give us:
// ('0x2c', '0x4b 0x2a 0x3e 0xd0 0x4f 0x2a 0x3e 0xac 0x4a 0x2a 0x3e 0x84 0x4f
// 0x2a 0x3e').
- std::pair<llvm::StringRef, llvm::StringRef> Pair = Str.split(Sep);
+ llvm::StringRef car;
+ llvm::StringRef cdr = vector_str;
+ std::tie(car, cdr) = vector_str.split(cdr);
std::vector<uint8_t> bytes;
unsigned byte = 0;
// Using radix auto-sensing by passing 0 as the radix.
// Keep on processing the vector elements as long as the parsing succeeds and
// the vector size is < byte_size.
- while (!Pair.first.getAsInteger(0, byte) && bytes.size() < byte_size) {
+ while (!car.getAsInteger(0, byte) && bytes.size() < byte_size) {
bytes.push_back(byte);
- Pair = Pair.second.split(Sep);
+ std::tie(car, cdr) = cdr.split(Sep);
}
// Check for vector of exact byte_size elements.
@@ -402,112 +386,129 @@ static bool ParseVectorEncoding(const RegisterInfo *reg_info,
return true;
}
-Error RegisterValue::SetValueFromCString(const RegisterInfo *reg_info,
- const char *value_str) {
+Error RegisterValue::SetValueFromString(const RegisterInfo *reg_info,
+ llvm::StringRef value_str) {
Error error;
if (reg_info == nullptr) {
error.SetErrorString("Invalid register info argument.");
return error;
}
- if (value_str == nullptr || value_str[0] == '\0') {
+ m_type = eTypeInvalid;
+ if (value_str.empty()) {
error.SetErrorString("Invalid c-string value string.");
return error;
}
- bool success = false;
const uint32_t byte_size = reg_info->byte_size;
- static float flt_val;
- static double dbl_val;
- static long double ldbl_val;
+
+ uint64_t uval64;
+ int64_t ival64;
+ float flt_val;
+ double dbl_val;
+ long double ldbl_val;
switch (reg_info->encoding) {
case eEncodingInvalid:
error.SetErrorString("Invalid encoding.");
break;
case eEncodingUint:
- if (byte_size <= sizeof(uint64_t)) {
- uint64_t uval64 =
- StringConvert::ToUInt64(value_str, UINT64_MAX, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat(
- "'%s' is not a valid unsigned integer string value", value_str);
- else if (!Args::UInt64ValueIsValidForByteSize(uval64, byte_size))
- error.SetErrorStringWithFormat(
- "value 0x%" PRIx64
- " is too large to fit in a %u byte unsigned integer value",
- uval64, byte_size);
- else {
- if (!SetUInt(uval64, reg_info->byte_size))
- error.SetErrorStringWithFormat(
- "unsupported unsigned integer byte size: %u", byte_size);
- }
- } else {
+ if (byte_size > sizeof(uint64_t)) {
error.SetErrorStringWithFormat(
"unsupported unsigned integer byte size: %u", byte_size);
- return error;
+ break;
}
+ if (value_str.getAsInteger(0, uval64)) {
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid unsigned integer string value",
+ value_str.str().c_str());
+ break;
+ }
+
+ if (!Args::UInt64ValueIsValidForByteSize(uval64, byte_size)) {
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64
+ " is too large to fit in a %u byte unsigned integer value",
+ uval64, byte_size);
+ break;
+ }
+
+ if (!SetUInt(uval64, reg_info->byte_size)) {
+ error.SetErrorStringWithFormat(
+ "unsupported unsigned integer byte size: %u", byte_size);
+ break;
+ }
+ // TODO: Shouldn't we be setting m_type here?
break;
case eEncodingSint:
- if (byte_size <= sizeof(long long)) {
- uint64_t sval64 =
- StringConvert::ToSInt64(value_str, INT64_MAX, 0, &success);
- if (!success)
- error.SetErrorStringWithFormat(
- "'%s' is not a valid signed integer string value", value_str);
- else if (!Args::SInt64ValueIsValidForByteSize(sval64, byte_size))
- error.SetErrorStringWithFormat(
- "value 0x%" PRIx64
- " is too large to fit in a %u byte signed integer value",
- sval64, byte_size);
- else {
- if (!SetUInt(sval64, reg_info->byte_size))
- error.SetErrorStringWithFormat(
- "unsupported signed integer byte size: %u", byte_size);
- }
- } else {
+ if (byte_size > sizeof(long long)) {
error.SetErrorStringWithFormat("unsupported signed integer byte size: %u",
byte_size);
- return error;
+ break;
+ }
+
+ if (value_str.getAsInteger(0, ival64)) {
+ error.SetErrorStringWithFormat(
+ "'%s' is not a valid signed integer string value",
+ value_str.str().c_str());
+ break;
+ }
+
+ if (!Args::SInt64ValueIsValidForByteSize(ival64, byte_size)) {
+ error.SetErrorStringWithFormat(
+ "value 0x%" PRIx64
+ " is too large to fit in a %u byte signed integer value",
+ ival64, byte_size);
+ break;
+ }
+
+ if (!SetUInt(ival64, reg_info->byte_size)) {
+ error.SetErrorStringWithFormat("unsupported signed integer byte size: %u",
+ byte_size);
+ break;
}
+
+ // TODO: Shouldn't we be setting m_type here?
break;
- case eEncodingIEEE754:
+ case eEncodingIEEE754: {
+ std::string value_string = value_str;
if (byte_size == sizeof(float)) {
- if (::sscanf(value_str, "%f", &flt_val) == 1) {
- m_scalar = flt_val;
- m_type = eTypeFloat;
- } else
+ if (::sscanf(value_string.c_str(), "%f", &flt_val) != 1) {
error.SetErrorStringWithFormat("'%s' is not a valid float string value",
- value_str);
+ value_string.c_str());
+ break;
+ }
+ m_scalar = flt_val;
+ m_type = eTypeFloat;
} else if (byte_size == sizeof(double)) {
- if (::sscanf(value_str, "%lf", &dbl_val) == 1) {
- m_scalar = dbl_val;
- m_type = eTypeDouble;
- } else
+ if (::sscanf(value_string.c_str(), "%lf", &dbl_val) != 1) {
error.SetErrorStringWithFormat("'%s' is not a valid float string value",
- value_str);
+ value_string.c_str());
+ break;
+ }
+ m_scalar = dbl_val;
+ m_type = eTypeDouble;
} else if (byte_size == sizeof(long double)) {
- if (::sscanf(value_str, "%Lf", &ldbl_val) == 1) {
- m_scalar = ldbl_val;
- m_type = eTypeLongDouble;
- } else
+ if (::sscanf(value_string.c_str(), "%Lf", &ldbl_val) != 1) {
error.SetErrorStringWithFormat("'%s' is not a valid float string value",
- value_str);
+ value_string.c_str());
+ break;
+ }
+ m_scalar = ldbl_val;
+ m_type = eTypeLongDouble;
} else {
error.SetErrorStringWithFormat("unsupported float byte size: %u",
byte_size);
return error;
}
break;
-
+ }
case eEncodingVector:
if (!ParseVectorEncoding(reg_info, value_str, byte_size, this))
error.SetErrorString("unrecognized vector encoding string value.");
break;
}
- if (error.Fail())
- m_type = eTypeInvalid;
return error;
}
diff --git a/lldb/source/Core/ValueObjectRegister.cpp b/lldb/source/Core/ValueObjectRegister.cpp
index 0dc2cc013f2..80e00e4007c 100644
--- a/lldb/source/Core/ValueObjectRegister.cpp
+++ b/lldb/source/Core/ValueObjectRegister.cpp
@@ -311,7 +311,8 @@ bool ValueObjectRegister::UpdateValue() {
bool ValueObjectRegister::SetValueFromCString(const char *value_str,
Error &error) {
// The new value will be in the m_data. Copy that into our register value.
- error = m_reg_value.SetValueFromCString(&m_reg_info, value_str);
+ error =
+ m_reg_value.SetValueFromString(&m_reg_info, llvm::StringRef(value_str));
if (error.Success()) {
if (m_reg_ctx_sp->WriteRegister(&m_reg_info, m_reg_value)) {
SetNeedsUpdate();
diff --git a/lldb/source/Core/ValueObjectVariable.cpp b/lldb/source/Core/ValueObjectVariable.cpp
index f0695d85ac2..f8eedc30e70 100644
--- a/lldb/source/Core/ValueObjectVariable.cpp
+++ b/lldb/source/Core/ValueObjectVariable.cpp
@@ -343,7 +343,7 @@ bool ValueObjectVariable::SetValueFromCString(const char *value_str,
error.SetErrorString("unable to retrieve register info");
return false;
}
- error = reg_value.SetValueFromCString(reg_info, value_str);
+ error = reg_value.SetValueFromString(reg_info, llvm::StringRef(value_str));
if (error.Fail())
return false;
if (reg_ctx->WriteRegister(reg_info, reg_value)) {
OpenPOWER on IntegriCloud