[Lldb-commits] [lldb] r287282 - Resubmit "Change RegisterValue getters / setters to use StringRef."
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Thu Nov 17 15:47:31 PST 2016
Author: zturner
Date: Thu Nov 17 17:47:31 2016
New Revision: 287282
URL: http://llvm.org/viewvc/llvm-project?rev=287282&view=rev
Log:
Resubmit "Change RegisterValue getters / setters to use StringRef."
This resubmits r287279 with a fix for the original issue, which
was a trivial typo.
Modified:
lldb/trunk/include/lldb/Core/RegisterValue.h
lldb/trunk/source/Commands/CommandObjectRegister.cpp
lldb/trunk/source/Core/RegisterValue.cpp
lldb/trunk/source/Core/ValueObjectRegister.cpp
lldb/trunk/source/Core/ValueObjectVariable.cpp
Modified: lldb/trunk/include/lldb/Core/RegisterValue.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/RegisterValue.h?rev=287282&r1=287281&r2=287282&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/RegisterValue.h (original)
+++ lldb/trunk/include/lldb/Core/RegisterValue.h Thu Nov 17 17:47:31 2016
@@ -233,8 +233,10 @@ public:
bool SignExtend(uint32_t sign_bitpos);
- Error SetValueFromCString(const RegisterInfo *reg_info,
- const char *value_str);
+ Error SetValueFromString(const RegisterInfo *reg_info,
+ llvm::StringRef value_str);
+ Error SetValueFromString(const RegisterInfo *reg_info,
+ const char *value_str) = delete;
Error SetValueFromData(const RegisterInfo *reg_info, DataExtractor &data,
lldb::offset_t offset, bool partial_data_ok);
Modified: lldb/trunk/source/Commands/CommandObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectRegister.cpp?rev=287282&r1=287281&r2=287282&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectRegister.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectRegister.cpp Thu Nov 17 17:47:31 2016
@@ -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 {
Modified: lldb/trunk/source/Core/RegisterValue.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/RegisterValue.cpp?rev=287282&r1=287281&r2=287282&view=diff
==============================================================================
--- lldb/trunk/source/Core/RegisterValue.cpp (original)
+++ lldb/trunk/source/Core/RegisterValue.cpp Thu Nov 17 17:47:31 2016
@@ -347,51 +347,35 @@ Error RegisterValue::SetValueFromData(co
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(Sep);
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 Re
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;
}
Modified: lldb/trunk/source/Core/ValueObjectRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectRegister.cpp?rev=287282&r1=287281&r2=287282&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectRegister.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectRegister.cpp Thu Nov 17 17:47:31 2016
@@ -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();
Modified: lldb/trunk/source/Core/ValueObjectVariable.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/ValueObjectVariable.cpp?rev=287282&r1=287281&r2=287282&view=diff
==============================================================================
--- lldb/trunk/source/Core/ValueObjectVariable.cpp (original)
+++ lldb/trunk/source/Core/ValueObjectVariable.cpp Thu Nov 17 17:47:31 2016
@@ -343,7 +343,7 @@ bool ValueObjectVariable::SetValueFromCS
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)) {
More information about the lldb-commits
mailing list