Author: Michał Górny Date: 2021-09-25T14:19:19+02:00 New Revision: 3a6ba3675177cb5e47dee325f300aced4cd864ed
URL: https://github.com/llvm/llvm-project/commit/3a6ba3675177cb5e47dee325f300aced4cd864ed DIFF: https://github.com/llvm/llvm-project/commit/3a6ba3675177cb5e47dee325f300aced4cd864ed.diff LOG: [lldb] Convert misc. StringConvert uses Replace misc. StringConvert uses with llvm::to_integer() and llvm::to_float(), except for cases where further refactoring is planned. The purpose of this change is to eliminate the StringConvert API that is duplicate to LLVM, and less correct in behavior at the same time. Differential Revision: https://reviews.llvm.org/D110447 Added: Modified: 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/tools/lldb-server/lldb-gdbserver.cpp lldb/unittests/debugserver/RNBSocketTest.cpp Removed: ################################################################################ diff --git a/lldb/source/Interpreter/OptionValueArray.cpp b/lldb/source/Interpreter/OptionValueArray.cpp index b1545bdebf10e..4468fe57702e6 100644 --- a/lldb/source/Interpreter/OptionValueArray.cpp +++ b/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" @@ -167,13 +166,12 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) { case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: if (argc > 1) { - uint32_t idx = - StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX); + uint32_t idx; const uint32_t count = GetSize(); - if (idx > count) { + if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) { error.SetErrorStringWithFormat( - "invalid insert array index %u, index must be 0 through %u", idx, - count); + "invalid insert array index %s, index must be 0 through %u", + args.GetArgumentAtIndex(0), count); } else { if (op == eVarSetOperationInsertAfter) ++idx; @@ -207,9 +205,8 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) { 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 @@ -249,13 +246,12 @@ Status OptionValueArray::SetArgs(const Args &args, VarSetOperationType op) { case eVarSetOperationReplace: if (argc > 1) { - uint32_t idx = - StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX); + uint32_t idx; const uint32_t count = GetSize(); - if (idx > count) { + if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) { error.SetErrorStringWithFormat( - "invalid replace array index %u, index must be 0 through %u", idx, - count); + "invalid replace array index %s, index must be 0 through %u", + args.GetArgumentAtIndex(0), count); } else { for (size_t i = 1; i < argc; ++i, ++idx) { lldb::OptionValueSP value_sp(CreateValueFromCStringForTypeMask( diff --git a/lldb/source/Interpreter/OptionValueFileSpecList.cpp b/lldb/source/Interpreter/OptionValueFileSpecList.cpp index 2160fd61d4282..6566eee09d738 100644 --- a/lldb/source/Interpreter/OptionValueFileSpecList.cpp +++ b/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,13 +56,12 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value, case eVarSetOperationReplace: if (argc > 1) { - uint32_t idx = - StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX); + uint32_t idx; const uint32_t count = m_current_value.GetSize(); - if (idx > count) { + 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 { for (size_t i = 1; i < argc; ++i, ++idx) { FileSpec file(args.GetArgumentAtIndex(i)); @@ -101,13 +99,12 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value, case eVarSetOperationInsertBefore: case eVarSetOperationInsertAfter: if (argc > 1) { - uint32_t idx = - StringConvert::ToUInt32(args.GetArgumentAtIndex(0), UINT32_MAX); + uint32_t idx; const uint32_t count = m_current_value.GetSize(); - if (idx > count) { + if (!llvm::to_integer(args.GetArgumentAtIndex(0), idx) || idx > count) { error.SetErrorStringWithFormat( - "invalid insert file list index %u, index must be 0 through %u", - idx, count); + "invalid insert file list index %s, index must be 0 through %u", + args.GetArgumentAtIndex(0), count); } else { if (op == eVarSetOperationInsertAfter) ++idx; @@ -129,9 +126,8 @@ Status OptionValueFileSpecList::SetValueFromString(llvm::StringRef value, bool all_indexes_valid = true; size_t i; for (i = 0; all_indexes_valid && i < argc; ++i) { - const int idx = - StringConvert::ToSInt32(args.GetArgumentAtIndex(i), INT32_MAX); - if (idx == INT32_MAX) + int idx; + if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx)) all_indexes_valid = false; else remove_indexes.push_back(idx); diff --git a/lldb/source/Interpreter/OptionValuePathMappings.cpp b/lldb/source/Interpreter/OptionValuePathMappings.cpp index 4dceb56327163..c6b8c57bbcdc4 100644 --- a/lldb/source/Interpreter/OptionValuePathMappings.cpp +++ b/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 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, // 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); + uint32_t idx; const uint32_t count = m_path_mappings.GetSize(); - if (idx > count) { + 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 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, // 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); + uint32_t idx; const uint32_t count = m_path_mappings.GetSize(); - if (idx > count) { + 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) @@ -169,9 +166,9 @@ Status OptionValuePathMappings::SetValueFromString(llvm::StringRef value, if (argc > 0) { std::vector<int> 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()) { + int idx; + if (!llvm::to_integer(args.GetArgumentAtIndex(i), idx) || idx < 0 || + idx >= (int)m_path_mappings.GetSize()) { error.SetErrorStringWithFormat( "invalid array index '%s', aborting remove operation", args.GetArgumentAtIndex(i)); diff --git a/lldb/source/Interpreter/OptionValueSInt64.cpp b/lldb/source/Interpreter/OptionValueSInt64.cpp index b875ba8e35360..c1db5056cd948 100644 --- a/lldb/source/Interpreter/OptionValueSInt64.cpp +++ b/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 @@ Status OptionValueSInt64::SetValueFromString(llvm::StringRef value_ref, 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) { + llvm::StringRef value_trimmed = value_ref.trim(); + int64_t value; + if (llvm::to_integer(value_trimmed, value)) { if (value >= m_min_value && value <= m_max_value) { m_value_was_set = true; m_current_value = value; diff --git a/lldb/source/Interpreter/OptionValueUInt64.cpp b/lldb/source/Interpreter/OptionValueUInt64.cpp index a2751a4d02eb8..1999c63d11aff 100644 --- a/lldb/source/Interpreter/OptionValueUInt64.cpp +++ b/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 @@ Status OptionValueUInt64::SetValueFromString(llvm::StringRef value_ref, 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) { + llvm::StringRef value_trimmed = value_ref.trim(); + uint64_t value; + if (llvm::to_integer(value_trimmed, 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; diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp index 55400a2bc42de..410562f274f18 100644 --- a/lldb/source/Interpreter/Property.cpp +++ b/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" @@ -176,28 +175,32 @@ Property::Property(const PropertyDefinition &definition) 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. + int64_t value = 0; + // FIXME: improve error handling for llvm::to_integer() + if (definition.default_cstr_value) + llvm::to_integer(definition.default_cstr_value, value); m_value_sp = std::make_shared<OptionValueSInt64>( - definition.default_cstr_value - ? StringConvert::ToSInt64(definition.default_cstr_value) - : definition.default_uint_value); + definition.default_cstr_value ? value : definition.default_uint_value); break; - - case OptionValue::eTypeUInt64: + } + case OptionValue::eTypeUInt64: { + uint64_t value = 0; + // FIXME: improve error handling for llvm::to_integer() + if (definition.default_cstr_value) + llvm::to_integer(definition.default_cstr_value, value); // "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); + definition.default_cstr_value ? value : definition.default_uint_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 diff --git a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp b/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp index 53ba68aca4e40..ba52b8dac0752 100644 --- a/lldb/source/Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.cpp +++ b/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" @@ -4566,10 +4565,8 @@ class CommandObjectRenderScriptRuntimeAllocationDump 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); return false; @@ -4713,10 +4710,8 @@ class CommandObjectRenderScriptRuntimeAllocationLoad 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); return false; @@ -4762,10 +4757,8 @@ class CommandObjectRenderScriptRuntimeAllocationSave 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); return false; diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp index 2cd4abbf14ad8..f4642ba2c30bb 100644 --- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp +++ b/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" @@ -290,7 +289,8 @@ uint32_t PlatformAndroid::GetSdkVersion() { return 0; } - m_sdk_version = StringConvert::ToUInt32(version_string.c_str()); + // FIXME: improve error handling + llvm::to_integer(version_string, m_sdk_version); return m_sdk_version; } diff --git a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp b/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp index 721a03745c3ef..a3a9d963c2213 100644 --- a/lldb/source/Plugins/Process/Utility/DynamicRegisterInfo.cpp +++ b/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 @@ DynamicRegisterInfo::SetRegisterInfo(const StructuredData::Dictionary &dict, 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; + uint32_t lsbit; + 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; diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp index 013d407c0fc11..adc8d6f1e8d0b 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +++ b/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 @@ Status GDBRemoteCommunication::StartDebugserverProcess( 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 = 0; + // FIXME: improve error handling + llvm::to_integer(port_cstr, child_port); if (*port == 0 || *port == child_port) { *port = child_port; LLDB_LOGF(log, diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 6209a45c4c784..ad49f9ddad2cc 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -1999,6 +1999,7 @@ ProcessGDBRemote::SetThreadStopInfo(StructuredData::Dictionary *thread_dict) { // Iterate through all of the thread dictionary key/value pairs from the // structured data dictionary + // FIXME: we're silently ignoring invalid data here thread_dict->ForEach([this, &tid, &expedited_register_map, &thread_name, &signo, &reason, &description, &exc_type, &exc_data, &thread_dispatch_qaddr, &queue_vars_valid, @@ -2063,9 +2064,8 @@ ProcessGDBRemote::SetThreadStopInfo(StructuredData::Dictionary *thread_dict) { 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.AsCString(), reg)) expedited_register_map[reg] = std::string(object->GetStringValue()); return true; // Keep iterating through all array items @@ -4343,6 +4343,7 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info, bool encoding_set = false; bool format_set = false; + // FIXME: we're silently ignoring invalid data here reg_node.ForEachAttribute([&target_info, &gdb_group, &gdb_type, &encoding_set, &format_set, ®_info]( const llvm::StringRef &name, @@ -4350,21 +4351,16 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info, if (name == "name") { reg_info.name.SetString(value); } else if (name == "bitsize") { - reg_info.byte_size = - StringConvert::ToUInt32(value.data(), 0, 0) / CHAR_BIT; + if (llvm::to_integer(value, reg_info.byte_size)) + reg_info.byte_size /= CHAR_BIT; } 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) { - reg_info.regnum_remote = regnum; - } + llvm::to_integer(value, reg_info.regnum_remote); } else if (name == "offset") { - reg_info.byte_offset = - StringConvert::ToUInt32(value.data(), LLDB_INVALID_INDEX32, 0); + llvm::to_integer(value, reg_info.byte_offset); } else if (name == "altname") { reg_info.alt_name.SetString(value); } else if (name == "encoding") { @@ -4388,18 +4384,16 @@ bool ParseRegisters(XMLNode feature_node, GdbServerTargetInfo &target_info, .Case("vector-uint128", eFormatVectorOfUInt128) .Default(eFormatInvalid); } else if (name == "group_id") { - const uint32_t set_id = - StringConvert::ToUInt32(value.data(), UINT32_MAX, 0); + uint32_t set_id = UINT32_MAX; + llvm::to_integer(value, set_id); RegisterSetMap::const_iterator pos = target_info.reg_set_map.find(set_id); if (pos != target_info.reg_set_map.end()) reg_info.set_name = pos->second.name; } else if (name == "gcc_regnum" || name == "ehframe_regnum") { - reg_info.regnum_ehframe = - StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); + llvm::to_integer(value, reg_info.regnum_ehframe); } else if (name == "dwarf_regnum") { - reg_info.regnum_dwarf = - StringConvert::ToUInt32(value.data(), LLDB_INVALID_REGNUM, 0); + llvm::to_integer(value, reg_info.regnum_dwarf); } else if (name == "generic") { reg_info.regnum_generic = Args::StringToGenericRegister(value); } else if (name == "value_regnums") { @@ -4510,9 +4504,9 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfoXMLAndProcess( node.ForEachAttribute( [&set_id, &set_info](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { + // FIXME: we're silently ignoring invalid data here if (name == "id") - set_id = StringConvert::ToUInt32(value.data(), - UINT32_MAX, 0); + llvm::to_integer(value, set_id); if (name == "name") set_info.name = ConstString(value); return true; // Keep iterating through all attributes @@ -4708,38 +4702,39 @@ llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() { // 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); - } + // FIXME: we're silently ignoring invalid data here + if (!main_lm.empty()) + llvm::to_integer(main_lm, list.m_link_map); root_element.ForEachChildElementWithName( "library", [log, &list](const XMLNode &library) -> bool { LoadedModuleInfoList::LoadedModuleInfo module; + // FIXME: we're silently ignoring invalid data here library.ForEachAttribute( [&module](const llvm::StringRef &name, const llvm::StringRef &value) -> bool { + uint64_t uint_value = LLDB_INVALID_ADDRESS; if (name == "name") 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)); + llvm::to_integer(value, uint_value); + module.set_link_map(uint_value); } 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)); + llvm::to_integer(value, uint_value); + module.set_base(uint_value); // base address is always a displacement, not an absolute // value. module.set_base_is_offset(true); } else if (name == "l_ld") { // the memory address of the libraries PT_DYNAMIC section. - module.set_dynamic(StringConvert::ToUInt64( - value.data(), LLDB_INVALID_ADDRESS, 0)); + llvm::to_integer(value, uint_value); + module.set_dynamic(uint_value); } return true; // Keep iterating over all properties of "library" @@ -4794,6 +4789,7 @@ llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() { return llvm::createStringError(llvm::inconvertibleErrorCode(), "Error finding library-list xml element"); + // FIXME: we're silently ignoring invalid data here root_element.ForEachChildElementWithName( "library", [log, &list](const XMLNode &library) -> bool { LoadedModuleInfoList::LoadedModuleInfo module; @@ -4807,8 +4803,9 @@ llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() { const XMLNode §ion = library.FindFirstChildElementWithName("section"); llvm::StringRef address = section.GetAttributeValue("address"); - module.set_base( - StringConvert::ToUInt64(address.data(), LLDB_INVALID_ADDRESS, 0)); + uint64_t address_value = LLDB_INVALID_ADDRESS; + llvm::to_integer(address, address_value); + module.set_base(address_value); // These addresses are absolute values. module.set_base_is_offset(false); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 988c1a75f5450..ca91469fedca9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/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" @@ -687,12 +686,10 @@ void DWARFUnit::ParseProducerInfo() { 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); + // FIXME: improve error handling + llvm::to_integer(matches[1], m_producer_version_major); + llvm::to_integer(matches[2], m_producer_version_minor); + llvm::to_integer(matches[3], m_producer_version_update); } m_producer = eProducerClang; } else if (strstr(producer_cstr, "GNU")) diff --git a/lldb/source/Symbol/SymbolContext.cpp b/lldb/source/Symbol/SymbolContext.cpp index 2e8fe1cec30e5..f1c3a9e5b4e0f 100644 --- a/lldb/source/Symbol/SymbolContext.cpp +++ b/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" @@ -977,13 +976,11 @@ bool SymbolContextSpecifier::AddSpecification(const char *spec_string, m_type |= eFileSpecified; break; case eLineStartSpecified: - m_start_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value); - if (return_value) + if ((return_value = llvm::to_integer(spec_string, m_start_line))) m_type |= eLineStartSpecified; break; case eLineEndSpecified: - m_end_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value); - if (return_value) + if ((return_value = llvm::to_integer(spec_string, m_end_line))) m_type |= eLineEndSpecified; break; case eFunctionSpecified: diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp index 4ec2e25c7e3b0..6e857e6618d39 100644 --- a/lldb/source/Target/UnixSignals.cpp +++ b/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; @@ -156,9 +155,8 @@ int32_t UnixSignals::GetSignalNumberFromName(const char *name) const { 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; } diff --git a/lldb/tools/lldb-server/lldb-gdbserver.cpp b/lldb/tools/lldb-server/lldb-gdbserver.cpp index 888ba728fa911..9e599963c5b72 100644 --- a/lldb/tools/lldb-server/lldb-gdbserver.cpp +++ b/lldb/tools/lldb-server/lldb-gdbserver.cpp @@ -26,7 +26,6 @@ #include "lldb/Host/FileSystem.h" #include "lldb/Host/Pipe.h" #include "lldb/Host/Socket.h" -#include "lldb/Host/StringConvert.h" #include "lldb/Host/common/NativeProcessProtocol.h" #include "lldb/Target/Process.h" #include "lldb/Utility/Status.h" @@ -238,7 +237,8 @@ void ConnectToRemote(MainLoop &mainloop, if (colon_pos != std::string::npos) { connection_host = final_host_and_port.substr(0, colon_pos); connection_port = final_host_and_port.substr(colon_pos + 1); - connection_portno = StringConvert::ToUInt32(connection_port.c_str(), 0); + // FIXME: improve error handling + llvm::to_integer(connection_port, connection_portno); } diff --git a/lldb/unittests/debugserver/RNBSocketTest.cpp b/lldb/unittests/debugserver/RNBSocketTest.cpp index 2625a6d36b5ce..8db4c9b8bb4d2 100644 --- a/lldb/unittests/debugserver/RNBSocketTest.cpp +++ b/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" _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits