teemperor created this revision.
teemperor added a reviewer: LLDB.
Herald added subscribers: JDevlieghere, abidh.
teemperor edited the summary of this revision.
This replaces most uses of LLDB's own String to int/float conversion
implementation with
LLVM's to_integer. The only remaining code in LLDB that now still uses
StringConvert is
debugserver which can't use LLVM code, so I'll leave that part for a future
commit.
Unlike the other StringConvert patch this doesn't try to add any missing error
handling
but just does a NFC refactoring to `to_integer`.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D82382
Files:
lldb/source/Host/common/Socket.cpp
lldb/source/Host/common/XML.cpp
lldb/source/Interpreter/OptionValueArray.cpp
lldb/source/Interpreter/OptionValueFileSpecList.cpp
lldb/source/Interpreter/OptionValuePathMappings.cpp
lldb/source/Interpreter/OptionValueSInt64.cpp
lldb/source/Interpreter/OptionValueUInt64.cpp
lldb/source/Interpreter/Property.cpp
lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
lldb/source/Symbol/SymbolContext.cpp
lldb/source/Target/UnixSignals.cpp
lldb/unittests/debugserver/RNBSocketTest.cpp
Index: lldb/unittests/debugserver/RNBSocketTest.cpp
===================================================================
--- lldb/unittests/debugserver/RNBSocketTest.cpp
+++ lldb/unittests/debugserver/RNBSocketTest.cpp
@@ -15,7 +15,6 @@
#include "RNBDefs.h"
#include "RNBSocket.h"
#include "lldb/Host/Socket.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Host/common/TCPSocket.h"
#include "llvm/Testing/Support/Error.h"
Index: lldb/source/Target/UnixSignals.cpp
===================================================================
--- lldb/source/Target/UnixSignals.cpp
+++ lldb/source/Target/UnixSignals.cpp
@@ -12,7 +12,6 @@
#include "Plugins/Process/Utility/MipsLinuxSignals.h"
#include "Plugins/Process/Utility/NetBSDSignals.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/ArchSpec.h"
using namespace lldb_private;
@@ -162,9 +161,8 @@
return pos->first;
}
- const int32_t signo =
- StringConvert::ToSInt32(name, LLDB_INVALID_SIGNAL_NUMBER, 0);
- if (signo != LLDB_INVALID_SIGNAL_NUMBER)
+ int32_t signo;
+ if (llvm::to_integer(name, signo))
return signo;
return LLDB_INVALID_SIGNAL_NUMBER;
}
Index: lldb/source/Symbol/SymbolContext.cpp
===================================================================
--- lldb/source/Symbol/SymbolContext.cpp
+++ lldb/source/Symbol/SymbolContext.cpp
@@ -11,7 +11,6 @@
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Host/Host.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Symbol/Block.h"
#include "lldb/Symbol/CompileUnit.h"
#include "lldb/Symbol/ObjectFile.h"
@@ -972,12 +971,12 @@
m_type |= eFileSpecified;
break;
case eLineStartSpecified:
- m_start_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
+ return_value = llvm::to_integer(spec_string, m_start_line);
if (return_value)
m_type |= eLineStartSpecified;
break;
case eLineEndSpecified:
- m_end_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
+ return_value = llvm::to_integer(spec_string, m_end_line);
if (return_value)
m_type |= eLineEndSpecified;
break;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp
@@ -9,7 +9,6 @@
#include "DWARFUnit.h"
#include "lldb/Core/Module.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Symbol/ObjectFile.h"
#include "lldb/Utility/LLDBAssert.h"
#include "lldb/Utility/StreamString.h"
@@ -616,12 +615,12 @@
llvm::SmallVector<llvm::StringRef, 4> matches;
if (g_clang_version_regex.Execute(llvm::StringRef(producer_cstr),
&matches)) {
- m_producer_version_major =
- StringConvert::ToUInt32(matches[1].str().c_str(), UINT32_MAX, 10);
- m_producer_version_minor =
- StringConvert::ToUInt32(matches[2].str().c_str(), UINT32_MAX, 10);
- m_producer_version_update =
- StringConvert::ToUInt32(matches[3].str().c_str(), UINT32_MAX, 10);
+ if (!llvm::to_integer(matches[1], m_producer_version_major))
+ m_producer_version_major = UINT32_MAX;
+ if (!llvm::to_integer(matches[2], m_producer_version_minor))
+ m_producer_version_minor = UINT32_MAX;
+ if (!llvm::to_integer(matches[3], m_producer_version_update))
+ m_producer_version_update = UINT32_MAX;
}
m_producer = eProducerClang;
} else if (strstr(producer_cstr, "GNU"))
Index: lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -40,7 +40,6 @@
#include "lldb/Host/HostThread.h"
#include "lldb/Host/PosixApi.h"
#include "lldb/Host/PseudoTerminal.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/XML.h"
#include "lldb/Interpreter/CommandInterpreter.h"
@@ -397,9 +396,8 @@
do {
value_pair = value_pair.second.split(',');
if (!value_pair.first.empty()) {
- uint32_t reg = StringConvert::ToUInt32(value_pair.first.str().c_str(),
- LLDB_INVALID_REGNUM, base);
- if (reg != LLDB_INVALID_REGNUM)
+ uint32_t reg;
+ if (llvm::to_integer(value_pair.first, reg, base))
regnums.push_back(reg);
}
} while (!value_pair.second.empty());
@@ -1507,13 +1505,11 @@
while ((comma_pos = value.find(',')) != std::string::npos) {
value[comma_pos] = '\0';
// thread in big endian hex
- tid = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_THREAD_ID, 16);
- if (tid != LLDB_INVALID_THREAD_ID)
+ if (llvm::to_integer(value.c_str(), tid, 16))
m_thread_ids.push_back(tid);
value.erase(0, comma_pos + 1);
}
- tid = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_THREAD_ID, 16);
- if (tid != LLDB_INVALID_THREAD_ID)
+ if (llvm::to_integer(value.c_str(), tid, 16))
m_thread_ids.push_back(tid);
return m_thread_ids.size();
}
@@ -1525,13 +1521,11 @@
lldb::addr_t pc;
while ((comma_pos = value.find(',')) != std::string::npos) {
value[comma_pos] = '\0';
- pc = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_ADDRESS, 16);
- if (pc != LLDB_INVALID_ADDRESS)
+ if (llvm::to_integer(value.c_str(), pc, 16))
m_thread_pcs.push_back(pc);
value.erase(0, comma_pos + 1);
}
- pc = StringConvert::ToUInt64(value.c_str(), LLDB_INVALID_ADDRESS, 16);
- if (pc != LLDB_INVALID_THREAD_ID)
+ if (llvm::to_integer(value.c_str(), pc, 16))
m_thread_pcs.push_back(pc);
return m_thread_pcs.size();
}
@@ -2080,9 +2074,8 @@
registers_dict->ForEach(
[&expedited_register_map](ConstString key,
StructuredData::Object *object) -> bool {
- const uint32_t reg =
- StringConvert::ToUInt32(key.GetCString(), UINT32_MAX, 10);
- if (reg != UINT32_MAX)
+ uint32_t reg;
+ if (llvm::to_integer(key.GetStringRef(), reg, 10))
expedited_register_map[reg] =
std::string(object->GetStringValue());
return true; // Keep iterating through all array items
@@ -4320,20 +4313,22 @@
if (name == "name") {
reg_name.SetString(value);
} else if (name == "bitsize") {
- reg_info.byte_size =
- StringConvert::ToUInt32(value.data(), 0, 0) / CHAR_BIT;
+ uint32_t bit_size;
+ if (llvm::to_integer(value, bit_size))
+ reg_info.byte_size = bit_size / CHAR_BIT;
+ else
+ reg_info.byte_size = 0;
} else if (name == "type") {
gdb_type = value.str();
} else if (name == "group") {
gdb_group = value.str();
} else if (name == "regnum") {
- const uint32_t regnum =
- StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
- if (regnum != LLDB_INVALID_REGNUM) {
+ uint32_t regnum;
+ if (llvm::to_integer(value, regnum))
reg_info.kinds[eRegisterKindProcessPlugin] = regnum;
- }
} else if (name == "offset") {
- reg_offset = StringConvert::ToUInt32(value.data(), UINT32_MAX, 0);
+ if (!llvm::to_integer(value, reg_offset))
+ reg_offset = UINT32_MAX;
} else if (name == "altname") {
alt_name.SetString(value);
} else if (name == "encoding") {
@@ -4364,18 +4359,23 @@
else if (value == "vector-uint128")
reg_info.format = eFormatVectorOfUInt128;
} else if (name == "group_id") {
- const uint32_t set_id =
- StringConvert::ToUInt32(value.data(), UINT32_MAX, 0);
+ uint32_t set_id;
+ if (!llvm::to_integer(value, set_id))
+ set_id = UINT32_MAX;
RegisterSetMap::const_iterator pos =
target_info.reg_set_map.find(set_id);
if (pos != target_info.reg_set_map.end())
set_name = pos->second.name;
} else if (name == "gcc_regnum" || name == "ehframe_regnum") {
- reg_info.kinds[eRegisterKindEHFrame] =
- StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
+ uint32_t reg;
+ if (!llvm::to_integer(value, reg))
+ reg = LLDB_INVALID_REGNUM;
+ reg_info.kinds[eRegisterKindEHFrame] = reg;
} else if (name == "dwarf_regnum") {
- reg_info.kinds[eRegisterKindDWARF] =
- StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0);
+ uint32_t reg;
+ if (!llvm::to_integer(value, reg))
+ reg = LLDB_INVALID_REGNUM;
+ reg_info.kinds[eRegisterKindDWARF] = reg;
} else if (name == "generic") {
reg_info.kinds[eRegisterKindGeneric] =
Args::StringToGenericRegister(value);
@@ -4501,9 +4501,10 @@
node.ForEachAttribute(
[&set_id, &set_info](const llvm::StringRef &name,
const llvm::StringRef &value) -> bool {
- if (name == "id")
- set_id = StringConvert::ToUInt32(value.data(),
- UINT32_MAX, 0);
+ if (name == "id") {
+ if (!llvm::to_integer(value, set_id))
+ set_id = UINT32_MAX;
+ }
if (name == "name")
set_info.name = ConstString(value);
return true; // Keep iterating through all attributes
@@ -4638,8 +4639,8 @@
// main link map structure
llvm::StringRef main_lm = root_element.GetAttributeValue("main-lm");
if (!main_lm.empty()) {
- list.m_link_map =
- StringConvert::ToUInt64(main_lm.data(), LLDB_INVALID_ADDRESS, 0);
+ if (!llvm::to_integer(main_lm, list.m_link_map))
+ list.m_link_map = 0;
}
root_element.ForEachChildElementWithName(
@@ -4655,20 +4656,26 @@
module.set_name(value.str());
else if (name == "lm") {
// the address of the link_map struct.
- module.set_link_map(StringConvert::ToUInt64(
- value.data(), LLDB_INVALID_ADDRESS, 0));
+ lldb::addr_t link_map;
+ if (!llvm::to_integer(value, link_map))
+ link_map = LLDB_INVALID_ADDRESS;
+ module.set_link_map(link_map);
} else if (name == "l_addr") {
// the displacement as read from the field 'l_addr' of the
// link_map struct.
- module.set_base(StringConvert::ToUInt64(
- value.data(), LLDB_INVALID_ADDRESS, 0));
+ lldb::addr_t base;
+ if (!llvm::to_integer(value, base))
+ base = LLDB_INVALID_ADDRESS;
+ module.set_base(base);
// base address is always a displacement, not an absolute
// value.
module.set_base_is_offset(true);
} else if (name == "l_ld") {
+ lldb::addr_t dynamic;
+ if (!llvm::to_integer(value, dynamic))
+ dynamic = LLDB_INVALID_ADDRESS;
// the memory address of the libraries PT_DYNAMIC section.
- module.set_dynamic(StringConvert::ToUInt64(
- value.data(), LLDB_INVALID_ADDRESS, 0));
+ module.set_dynamic(dynamic);
}
return true; // Keep iterating over all properties of "library"
@@ -4736,8 +4743,10 @@
const XMLNode §ion =
library.FindFirstChildElementWithName("section");
llvm::StringRef address = section.GetAttributeValue("address");
- module.set_base(
- StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0));
+ lldb::addr_t base;
+ if (!llvm::to_integer(address, base))
+ base = LLDB_INVALID_ADDRESS;
+ module.set_base(base);
// These addresses are absolute values.
module.set_base_is_offset(false);
Index: lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
===================================================================
--- lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
+++ lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
@@ -22,7 +22,6 @@
#include "lldb/Host/Pipe.h"
#include "lldb/Host/ProcessLaunchInfo.h"
#include "lldb/Host/Socket.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Host/common/TCPSocket.h"
#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
@@ -1173,7 +1172,9 @@
port_cstr, num_bytes, std::chrono::seconds{10}, num_bytes);
if (error.Success() && (port != nullptr)) {
assert(num_bytes > 0 && port_cstr[num_bytes - 1] == '\0');
- uint16_t child_port = StringConvert::ToUInt32(port_cstr, 0);
+ uint16_t child_port;
+ if (!llvm::to_integer(port_cstr, child_port))
+ child_port = 0;
if (*port == 0 || *port == child_port) {
*port = child_port;
LLDB_LOGF(log,
Index: lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
===================================================================
--- lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
+++ lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp
@@ -10,7 +10,6 @@
#include "lldb/Core/StreamFile.h"
#include "lldb/DataFormatters/FormatManager.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/Utility/RegularExpression.h"
@@ -142,11 +141,10 @@
std::string reg_name_str = matches[1].str();
std::string msbit_str = matches[2].str();
std::string lsbit_str = matches[3].str();
- const uint32_t msbit =
- StringConvert::ToUInt32(msbit_str.c_str(), UINT32_MAX);
- const uint32_t lsbit =
- StringConvert::ToUInt32(lsbit_str.c_str(), UINT32_MAX);
- if (msbit != UINT32_MAX && lsbit != UINT32_MAX) {
+ uint32_t msbit = 0;
+ uint32_t lsbit = 0;
+ if (llvm::to_integer(msbit_str, msbit) &&
+ llvm::to_integer(lsbit_str, lsbit)) {
if (msbit > lsbit) {
const uint32_t msbyte = msbit / 8;
const uint32_t lsbyte = lsbit / 8;
Index: lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
===================================================================
--- lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -11,7 +11,6 @@
#include "lldb/Core/Section.h"
#include "lldb/Core/ValueObject.h"
#include "lldb/Host/HostInfo.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Log.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/UriParser.h"
@@ -292,7 +291,8 @@
return 0;
}
- m_sdk_version = StringConvert::ToUInt32(version_string.c_str());
+ if (!llvm::to_integer(version_string, m_sdk_version))
+ m_sdk_version = 0;
return m_sdk_version;
}
Index: lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
===================================================================
--- lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
+++ lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp
@@ -17,7 +17,6 @@
#include "lldb/DataFormatters/DumpValueObjectOptions.h"
#include "lldb/Expression/UserExpression.h"
#include "lldb/Host/OptionParser.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/CommandObjectMultiword.h"
#include "lldb/Interpreter/CommandReturnObject.h"
@@ -4577,10 +4576,8 @@
eLanguageTypeExtRenderScript));
const char *id_cstr = command.GetArgumentAtIndex(0);
- bool success = false;
- const uint32_t id =
- StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
- if (!success) {
+ uint32_t id;
+ if (!llvm::to_integer(id_cstr, id)) {
result.AppendErrorWithFormat("invalid allocation id argument '%s'",
id_cstr);
result.SetStatus(eReturnStatusFailed);
@@ -4726,10 +4723,8 @@
eLanguageTypeExtRenderScript));
const char *id_cstr = command.GetArgumentAtIndex(0);
- bool success = false;
- const uint32_t id =
- StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
- if (!success) {
+ uint32_t id;
+ if (!llvm::to_integer(id_cstr, id)) {
result.AppendErrorWithFormat("invalid allocation id argument '%s'",
id_cstr);
result.SetStatus(eReturnStatusFailed);
@@ -4777,10 +4772,8 @@
eLanguageTypeExtRenderScript));
const char *id_cstr = command.GetArgumentAtIndex(0);
- bool success = false;
- const uint32_t id =
- StringConvert::ToUInt32(id_cstr, UINT32_MAX, 0, &success);
- if (!success) {
+ uint32_t id;
+ if (!llvm::to_integer(id_cstr, id)) {
result.AppendErrorWithFormat("invalid allocation id argument '%s'",
id_cstr);
result.SetStatus(eReturnStatusFailed);
Index: lldb/source/Interpreter/Property.cpp
===================================================================
--- lldb/source/Interpreter/Property.cpp
+++ lldb/source/Interpreter/Property.cpp
@@ -9,7 +9,6 @@
#include "lldb/Interpreter/Property.h"
#include "lldb/Core/UserSettingsController.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Interpreter/CommandInterpreter.h"
#include "lldb/Interpreter/OptionArgParser.h"
#include "lldb/Interpreter/OptionValues.h"
@@ -170,28 +169,37 @@
std::make_shared<OptionValueRegex>(definition.default_cstr_value);
break;
- case OptionValue::eTypeSInt64:
+ case OptionValue::eTypeSInt64: {
// "definition.default_uint_value" is the default integer value if
// "definition.default_cstr_value" is NULL, otherwise interpret
// "definition.default_cstr_value" as a string value that represents the
// default value.
- m_value_sp = std::make_shared<OptionValueSInt64>(
- definition.default_cstr_value
- ? StringConvert::ToSInt64(definition.default_cstr_value)
- : definition.default_uint_value);
+ int64_t value;
+ if (definition.default_cstr_value) {
+ if (!llvm::to_integer(definition.default_cstr_value, value))
+ value = 0;
+ } else {
+ value = definition.default_uint_value;
+ }
+ m_value_sp = std::make_shared<OptionValueSInt64>(value);
break;
+ }
- case OptionValue::eTypeUInt64:
+ case OptionValue::eTypeUInt64: {
// "definition.default_uint_value" is the default unsigned integer value if
// "definition.default_cstr_value" is NULL, otherwise interpret
// "definition.default_cstr_value" as a string value that represents the
// default value.
- m_value_sp = std::make_shared<OptionValueUInt64>(
- definition.default_cstr_value
- ? StringConvert::ToUInt64(definition.default_cstr_value)
- : definition.default_uint_value);
+ uint64_t value;
+ if (definition.default_cstr_value) {
+ if (!llvm::to_integer(definition.default_cstr_value, value))
+ value = 0;
+ } else {
+ value = definition.default_uint_value;
+ }
+ m_value_sp = std::make_shared<OptionValueUInt64>(value);
break;
-
+ }
case OptionValue::eTypeUUID:
// "definition.default_uint_value" is not used for a OptionValue::eTypeUUID
// "definition.default_cstr_value" can contain a default UUID value
Index: lldb/source/Interpreter/OptionValueUInt64.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueUInt64.cpp
+++ lldb/source/Interpreter/OptionValueUInt64.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueUInt64.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -45,16 +44,15 @@
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
- bool success = false;
- std::string value_str = value_ref.trim().str();
- uint64_t value = StringConvert::ToUInt64(value_str.c_str(), 0, 0, &success);
- if (success) {
+ value_ref = value_ref.trim();
+ uint64_t value;
+ if (llvm::to_integer(value_ref, value)) {
m_value_was_set = true;
m_current_value = value;
NotifyValueChanged();
} else {
error.SetErrorStringWithFormat("invalid uint64_t string value: '%s'",
- value_str.c_str());
+ value_ref.str().c_str());
}
} break;
Index: lldb/source/Interpreter/OptionValueSInt64.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueSInt64.cpp
+++ lldb/source/Interpreter/OptionValueSInt64.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueSInt64.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -41,10 +40,9 @@
case eVarSetOperationReplace:
case eVarSetOperationAssign: {
- bool success = false;
- std::string value_str = value_ref.trim().str();
- int64_t value = StringConvert::ToSInt64(value_str.c_str(), 0, 0, &success);
- if (success) {
+ value_ref = value_ref.trim();
+ int64_t value;
+ if (llvm::to_integer(value_ref, value)) {
if (value >= m_min_value && value <= m_max_value) {
m_value_was_set = true;
m_current_value = value;
Index: lldb/source/Interpreter/OptionValuePathMappings.cpp
===================================================================
--- lldb/source/Interpreter/OptionValuePathMappings.cpp
+++ lldb/source/Interpreter/OptionValuePathMappings.cpp
@@ -9,7 +9,6 @@
#include "lldb/Interpreter/OptionValuePathMappings.h"
#include "lldb/Host/FileSystem.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/FileSpec.h"
#include "lldb/Utility/Stream.h"
@@ -52,13 +51,12 @@
// Must be at least one index + 1 pair of paths, and the pair count must be
// even
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
const uint32_t count = m_path_mappings.GetSize();
- if (idx > count) {
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx >= count) {
error.SetErrorStringWithFormat(
- "invalid file list index %u, index must be 0 through %u", idx,
- count);
+ "invalid file list index '%s', index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
bool changed = false;
for (size_t i = 1; i < argc; idx++, i += 2) {
@@ -128,13 +126,12 @@
// Must be at least one index + 1 pair of paths, and the pair count must be
// even
if (argc >= 3 && (((argc - 1) & 1) == 0)) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
const uint32_t count = m_path_mappings.GetSize();
- if (idx > count) {
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) {
error.SetErrorStringWithFormat(
- "invalid file list index %u, index must be 0 through %u", idx,
- count);
+ "invalid file list index '%s', index must be 0 through %u",
+ args.GetArgumentAtIndex(0), count);
} else {
bool changed = false;
if (op == eVarSetOperationInsertAfter)
@@ -167,11 +164,11 @@
case eVarSetOperationRemove:
if (argc > 0) {
- std::vector<int> remove_indexes;
+ std::vector<size_t> remove_indexes;
for (size_t i = 0; i < argc; ++i) {
- int idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx < 0 || idx >= (int)m_path_mappings.GetSize()) {
+ size_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) ||
+ idx >= m_path_mappings.GetSize()) {
error.SetErrorStringWithFormat(
"invalid array index '%s', aborting remove operation",
args.GetArgumentAtIndex(i));
Index: lldb/source/Interpreter/OptionValueFileSpecList.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueFileSpecList.cpp
+++ lldb/source/Interpreter/OptionValueFileSpecList.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueFileSpecList.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -57,8 +56,9 @@
case eVarSetOperationReplace:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx))
+ idx = UINT32_MAX;
const uint32_t count = m_current_value.GetSize();
if (idx > count) {
error.SetErrorStringWithFormat(
@@ -101,8 +101,9 @@
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx))
+ idx = UINT32_MAX;
const uint32_t count = m_current_value.GetSize();
if (idx > count) {
error.SetErrorStringWithFormat(
@@ -128,12 +129,13 @@
std::vector<int> remove_indexes;
bool all_indexes_valid = true;
size_t i;
+ const std::size_t size = m_current_value.GetSize();
for (i = 0; all_indexes_valid && i < argc; ++i) {
- const int idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx == INT32_MAX)
+ size_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx >= size) {
all_indexes_valid = false;
- else
+ break;
+ } else
remove_indexes.push_back(idx);
}
Index: lldb/source/Interpreter/OptionValueArray.cpp
===================================================================
--- lldb/source/Interpreter/OptionValueArray.cpp
+++ lldb/source/Interpreter/OptionValueArray.cpp
@@ -8,7 +8,6 @@
#include "lldb/Interpreter/OptionValueArray.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Utility/Args.h"
#include "lldb/Utility/Stream.h"
@@ -166,8 +165,9 @@
case eVarSetOperationInsertBefore:
case eVarSetOperationInsertAfter:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx))
+ idx = UINT32_MAX;
const uint32_t count = GetSize();
if (idx > count) {
error.SetErrorStringWithFormat(
@@ -206,9 +206,8 @@
bool all_indexes_valid = true;
size_t i;
for (i = 0; i < argc; ++i) {
- const size_t idx =
- StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX);
- if (idx >= size) {
+ size_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx >= size) {
all_indexes_valid = false;
break;
} else
@@ -248,8 +247,9 @@
case eVarSetOperationReplace:
if (argc > 1) {
- uint32_t idx =
- StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX);
+ uint32_t idx;
+ if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx))
+ idx = UINT32_MAX;
const uint32_t count = GetSize();
if (idx > count) {
error.SetErrorStringWithFormat(
Index: lldb/source/Host/common/XML.cpp
===================================================================
--- lldb/source/Host/common/XML.cpp
+++ lldb/source/Host/common/XML.cpp
@@ -9,7 +9,6 @@
#include <stdlib.h> /* atof */
#include "lldb/Host/Config.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Host/XML.h"
using namespace lldb;
@@ -158,9 +157,11 @@
#else
llvm::StringRef str_value;
#endif
- bool success = false;
- value = StringConvert::ToUInt64(str_value.data(), fail_value, base, &success);
- return success;
+ if (!llvm::to_integer(str_value, value, base)) {
+ value = fail_value;
+ return false;
+ }
+ return true;
}
void XMLNode::ForEachChildNode(NodeCallback const &callback) const {
@@ -307,7 +308,7 @@
if (IsValid()) {
std::string text;
if (GetElementText(text))
- value = StringConvert::ToUInt64(text.c_str(), fail_value, base, &success);
+ success = llvm::to_integer(text, value, base);
}
#endif
if (!success)
Index: lldb/source/Host/common/Socket.cpp
===================================================================
--- lldb/source/Host/common/Socket.cpp
+++ lldb/source/Host/common/Socket.cpp
@@ -11,7 +11,6 @@
#include "lldb/Host/Config.h"
#include "lldb/Host/Host.h"
#include "lldb/Host/SocketAddress.h"
-#include "lldb/Host/StringConvert.h"
#include "lldb/Host/common/TCPSocket.h"
#include "lldb/Host/common/UDPSocket.h"
#include "lldb/Utility/Log.h"
@@ -284,8 +283,7 @@
// IPv6 addresses are wrapped in [] when specified with ports
if (host_str.front() == '[' && host_str.back() == ']')
host_str = host_str.substr(1, host_str.size() - 2);
- bool ok = false;
- port = StringConvert::ToUInt32(port_str.c_str(), UINT32_MAX, 10, &ok);
+ bool ok = llvm::to_integer(port_str, port);
if (ok && port <= UINT16_MAX) {
if (error_ptr)
error_ptr->Clear();
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits