[Lldb-commits] [lldb] r281799 - Convert many functions to use StringRefs.
Zachary Turner via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 16 19:00:03 PDT 2016
Author: zturner
Date: Fri Sep 16 21:00:02 2016
New Revision: 281799
URL: http://llvm.org/viewvc/llvm-project?rev=281799&view=rev
Log:
Convert many functions to use StringRefs.
Where possible, remove the const char* version. To keep the
risk and impact here minimal, I've only done the simplest
functions.
In the process, I found a few opportunities for adding some
unit tests, so I added those as well.
Tested on Windows, Linux, and OSX.
Added:
lldb/trunk/unittests/Breakpoint/
lldb/trunk/unittests/Breakpoint/BreakpointIDTest.cpp
lldb/trunk/unittests/Breakpoint/CMakeLists.txt
lldb/trunk/unittests/Platform/
lldb/trunk/unittests/Platform/CMakeLists.txt
lldb/trunk/unittests/Platform/PlatformDarwinTest.cpp
Modified:
lldb/trunk/include/lldb/Breakpoint/BreakpointID.h
lldb/trunk/include/lldb/Interpreter/Args.h
lldb/trunk/include/lldb/Target/Language.h
lldb/trunk/source/Breakpoint/Breakpoint.cpp
lldb/trunk/source/Breakpoint/BreakpointID.cpp
lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp
lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
lldb/trunk/source/Interpreter/Args.cpp
lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
lldb/trunk/source/Interpreter/OptionValueLanguage.cpp
lldb/trunk/source/Interpreter/Property.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
lldb/trunk/source/Target/Language.cpp
lldb/trunk/unittests/CMakeLists.txt
lldb/trunk/unittests/Interpreter/TestArgs.cpp
Modified: lldb/trunk/include/lldb/Breakpoint/BreakpointID.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Breakpoint/BreakpointID.h?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Breakpoint/BreakpointID.h (original)
+++ lldb/trunk/include/lldb/Breakpoint/BreakpointID.h Fri Sep 16 21:00:02 2016
@@ -17,6 +17,8 @@
#include "lldb/lldb-private.h"
+#include "llvm/ADT/StringRef.h"
+
namespace lldb_private {
//----------------------------------------------------------------------
@@ -87,8 +89,7 @@ public:
/// \b true if the name is a breakpoint name (as opposed to an ID or
/// range) false otherwise.
//------------------------------------------------------------------
- // TODO: Convert this function to use a StringRef.
- static bool StringIsBreakpointName(const char *name, Error &error);
+ static bool StringIsBreakpointName(llvm::StringRef str, Error &error);
//------------------------------------------------------------------
/// Takes a breakpoint ID and the breakpoint location id and returns
Modified: lldb/trunk/include/lldb/Interpreter/Args.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Interpreter/Args.h?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Interpreter/Args.h (original)
+++ lldb/trunk/include/lldb/Interpreter/Args.h Fri Sep 16 21:00:02 2016
@@ -394,9 +394,8 @@ public:
static uint32_t StringToGenericRegister(llvm::StringRef s);
- // TODO: Update to take a StringRef
- static const char *StringToVersion(const char *s, uint32_t &major,
- uint32_t &minor, uint32_t &update);
+ static bool StringToVersion(llvm::StringRef string, uint32_t &major,
+ uint32_t &minor, uint32_t &update);
static const char *GetShellSafeArgument(const FileSpec &shell,
const char *unsafe_arg,
Modified: lldb/trunk/include/lldb/Target/Language.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Language.h?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Language.h (original)
+++ lldb/trunk/include/lldb/Target/Language.h Fri Sep 16 21:00:02 2016
@@ -142,8 +142,8 @@ public:
// These are accessors for general information about the Languages lldb knows
// about:
- // TODO: Convert this to using a StringRef.
static lldb::LanguageType GetLanguageTypeFromString(const char *string);
+ static lldb::LanguageType GetLanguageTypeFromString(llvm::StringRef string);
static const char *GetNameForLanguageType(lldb::LanguageType language);
Modified: lldb/trunk/source/Breakpoint/Breakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/Breakpoint.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/Breakpoint.cpp (original)
+++ lldb/trunk/source/Breakpoint/Breakpoint.cpp Fri Sep 16 21:00:02 2016
@@ -764,7 +764,7 @@ size_t Breakpoint::GetNumLocations() con
bool Breakpoint::AddName(const char *new_name, Error &error) {
if (!new_name)
return false;
- if (!BreakpointID::StringIsBreakpointName(new_name, error)) {
+ if (!BreakpointID::StringIsBreakpointName(llvm::StringRef(new_name), error)) {
error.SetErrorStringWithFormat("input name \"%s\" not a breakpoint name.",
new_name);
return false;
Modified: lldb/trunk/source/Breakpoint/BreakpointID.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointID.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointID.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointID.cpp Fri Sep 16 21:00:02 2016
@@ -107,14 +107,21 @@ bool BreakpointID::ParseCanonicalReferen
return false;
}
-bool BreakpointID::StringIsBreakpointName(const char *name, Error &error) {
+bool BreakpointID::StringIsBreakpointName(llvm::StringRef str, Error &error) {
error.Clear();
+ if (str.empty())
+ return false;
+
+ // First character must be a letter or _
+ if (!isalpha(str[0]) || str[0] != '_')
+ return false;
- if (name && (name[0] >= 'A' && name[0] <= 'z')) {
- if (strcspn(name, ".- ") != strlen(name)) {
- error.SetErrorStringWithFormat("invalid breakpoint name: \"%s\"", name);
- }
- return true;
- } else
+ // Cannot contain ., -, or space.
+ if (str.find_first_of(".- ") != llvm::StringRef::npos) {
+ error.SetErrorStringWithFormat("invalid breakpoint name: \"%s\"",
+ str.str().c_str());
return false;
+ }
+
+ return true;
}
Modified: lldb/trunk/source/Breakpoint/BreakpointIDList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointIDList.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointIDList.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointIDList.cpp Fri Sep 16 21:00:02 2016
@@ -168,7 +168,8 @@ void BreakpointIDList::FindAndReplaceIDR
is_range = true;
range_start.assign(current_arg, range_start_len);
range_end = current_arg + range_end_pos;
- } else if (BreakpointID::StringIsBreakpointName(current_arg, error)) {
+ } else if (BreakpointID::StringIsBreakpointName(
+ llvm::StringRef(current_arg), error)) {
if (!error.Success()) {
new_args.Clear();
result.AppendError(error.AsCString());
Modified: lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp (original)
+++ lldb/trunk/source/Breakpoint/BreakpointResolverName.cpp Fri Sep 16 21:00:02 2016
@@ -98,7 +98,7 @@ BreakpointResolver *BreakpointResolverNa
bool success = options_dict.GetValueForKeyAsString(
GetKey(OptionNames::LanguageName), language_name);
if (success) {
- language = Language::GetLanguageTypeFromString(language_name.c_str());
+ language = Language::GetLanguageTypeFromString(language_name);
if (language == eLanguageTypeUnknown) {
error.SetErrorStringWithFormat("BRN::CFSD: Unknown language: %s.",
language_name.c_str());
Modified: lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectBreakpoint.cpp Fri Sep 16 21:00:02 2016
@@ -92,6 +92,7 @@ public:
ExecutionContext *execution_context) override {
Error error;
const int short_option = m_getopt_table[option_idx].val;
+ llvm::StringRef option_strref(option_arg ? option_arg : "");
switch (short_option) {
case 'a': {
@@ -245,10 +246,11 @@ public:
m_func_name_type_mask |= eFunctionNameTypeAuto;
break;
- case 'N':
- if (BreakpointID::StringIsBreakpointName(option_arg, error))
+ case 'N': {
+ if (BreakpointID::StringIsBreakpointName(option_strref, error))
m_breakpoint_names.push_back(option_arg);
break;
+ }
case 'R': {
lldb::addr_t tmp_offset_addr;
@@ -1785,12 +1787,13 @@ public:
ExecutionContext *execution_context) override {
Error error;
const int short_option = g_breakpoint_name_options[option_idx].short_option;
+ llvm::StringRef option_strref(option_value ? option_value : "");
switch (short_option) {
case 'N':
- if (BreakpointID::StringIsBreakpointName(option_value, error) &&
+ if (BreakpointID::StringIsBreakpointName(option_strref, error) &&
error.Success())
- m_name.SetValueFromString(option_value);
+ m_name.SetValueFromString(option_strref);
break;
case 'B':
Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Fri Sep 16 21:00:02 2016
@@ -765,37 +765,27 @@ char Args::StringToChar(llvm::StringRef
return s[0];
}
-const char *Args::StringToVersion(const char *s, uint32_t &major,
- uint32_t &minor, uint32_t &update) {
+bool Args::StringToVersion(llvm::StringRef string, uint32_t &major,
+ uint32_t &minor, uint32_t &update) {
major = UINT32_MAX;
minor = UINT32_MAX;
update = UINT32_MAX;
- if (s && s[0]) {
- char *pos = nullptr;
- unsigned long uval32 = ::strtoul(s, &pos, 0);
- if (pos == s)
- return s;
- major = uval32;
- if (*pos == '\0') {
- return pos; // Decoded major and got end of string
- } else if (*pos == '.') {
- const char *minor_cstr = pos + 1;
- uval32 = ::strtoul(minor_cstr, &pos, 0);
- if (pos == minor_cstr)
- return pos; // Didn't get any digits for the minor version...
- minor = uval32;
- if (*pos == '.') {
- const char *update_cstr = pos + 1;
- uval32 = ::strtoul(update_cstr, &pos, 0);
- if (pos == update_cstr)
- return pos;
- update = uval32;
- }
- return pos;
- }
- }
- return nullptr;
+ if (string.empty())
+ return false;
+
+ llvm::StringRef major_str, minor_str, update_str;
+
+ std::tie(major_str, minor_str) = string.split('.');
+ std::tie(minor_str, update_str) = minor_str.split('.');
+ if (major_str.getAsInteger(10, major))
+ return false;
+ if (!minor_str.empty() && minor_str.getAsInteger(10, minor))
+ return false;
+ if (!update_str.empty() && update_str.getAsInteger(10, update))
+ return false;
+
+ return true;
}
const char *Args::GetShellSafeArgument(const FileSpec &shell,
Modified: lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionGroupPlatform.cpp Fri Sep 16 21:00:02 2016
@@ -105,6 +105,7 @@ Error OptionGroupPlatform::SetOptionValu
++option_idx;
const int short_option = g_option_table[option_idx].short_option;
+ llvm::StringRef option_strref(option_arg ? option_arg : "");
switch (short_option) {
case 'p':
@@ -112,9 +113,8 @@ Error OptionGroupPlatform::SetOptionValu
break;
case 'v':
- if (Args::StringToVersion(option_arg, m_os_version_major,
- m_os_version_minor,
- m_os_version_update) == option_arg)
+ if (!Args::StringToVersion(option_strref, m_os_version_major,
+ m_os_version_minor, m_os_version_update))
error.SetErrorStringWithFormat("invalid version string '%s'", option_arg);
break;
Modified: lldb/trunk/source/Interpreter/OptionValueLanguage.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/OptionValueLanguage.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/OptionValueLanguage.cpp (original)
+++ lldb/trunk/source/Interpreter/OptionValueLanguage.cpp Fri Sep 16 21:00:02 2016
@@ -49,7 +49,7 @@ Error OptionValueLanguage::SetValueFromS
languages_for_expressions);
LanguageType new_type =
- Language::GetLanguageTypeFromString(lang_name.GetCString());
+ Language::GetLanguageTypeFromString(lang_name.GetStringRef());
if (new_type && languages_for_types.count(new_type)) {
m_value_was_set = true;
m_current_value = new_type;
Modified: lldb/trunk/source/Interpreter/Property.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Property.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Property.cpp (original)
+++ lldb/trunk/source/Interpreter/Property.cpp Fri Sep 16 21:00:02 2016
@@ -139,7 +139,8 @@ Property::Property(const PropertyDefinit
{
LanguageType new_lang = eLanguageTypeUnknown;
if (definition.default_cstr_value)
- Language::GetLanguageTypeFromString(definition.default_cstr_value);
+ Language::GetLanguageTypeFromString(
+ llvm::StringRef(definition.default_cstr_value));
else
new_lang = (LanguageType)definition.default_uint_value;
m_value_sp.reset(new OptionValueLanguage(new_lang));
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp Fri Sep 16 21:00:02 2016
@@ -1667,6 +1667,24 @@ FileSpec PlatformDarwin::GetSDKDirectory
return FindSDKInXcodeForModules(sdk_type, sdks_spec);
}
+std::tuple<uint32_t, uint32_t, uint32_t, llvm::StringRef>
+PlatformDarwin::ParseVersionBuildDir(llvm::StringRef dir) {
+ uint32_t major, minor, update;
+ llvm::StringRef build;
+ llvm::StringRef version_str;
+ llvm::StringRef build_str;
+ std::tie(version_str, build_str) = dir.split(' ');
+ if (Args::StringToVersion(version_str, major, minor, update) ||
+ build_str.empty()) {
+ if (build_str.consume_front("(")) {
+ size_t pos = build_str.find(')');
+ build = build_str.slice(0, pos);
+ }
+ }
+
+ return std::make_tuple(major, minor, update, build);
+}
+
void PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
Target *target, std::vector<std::string> &options, SDKType sdk_type) {
const std::vector<std::string> apple_arguments = {
@@ -1783,14 +1801,11 @@ bool PlatformDarwin::GetOSVersion(uint32
const char *env_cstr = env.GetArgumentAtIndex(i);
if (env_cstr) {
llvm::StringRef env_str(env_cstr);
- if (env_str.startswith(k_runtime_version)) {
- llvm::StringRef version_str(
- env_str.substr(k_runtime_version.size()));
- Args::StringToVersion(version_str.data(), major, minor, update);
- if (major != UINT32_MAX)
+ if (env_str.consume_front(k_runtime_version)) {
+ if (Args::StringToVersion(env_str, major, minor, update))
return true;
- } else if (env_str.startswith(k_dyld_root_path)) {
- dyld_root_path = env_str.substr(k_dyld_root_path.size()).str();
+ } else if (env_str.consume_front(k_dyld_root_path)) {
+ dyld_root_path = env_str;
}
}
}
@@ -1801,8 +1816,7 @@ bool PlatformDarwin::GetOSVersion(uint32
std::string product_version;
if (system_version_plist.GetValueAsString("ProductVersion",
product_version)) {
- Args::StringToVersion(product_version.c_str(), major, minor, update);
- return major != UINT32_MAX;
+ return Args::StringToVersion(product_version, major, minor, update);
}
}
}
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformDarwin.h Fri Sep 16 21:00:02 2016
@@ -12,12 +12,15 @@
// C Includes
// C++ Includes
-#include <string>
// Other libraries and framework includes
// Project includes
#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
#include "lldb/Host/FileSpec.h"
+#include "llvm/ADT/StringRef.h"
+
+#include <string>
+#include <tuple>
class PlatformDarwin : public PlatformPOSIX {
public:
@@ -89,6 +92,9 @@ public:
lldb_private::Error
LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
+ static std::tuple<uint32_t, uint32_t, uint32_t, llvm::StringRef>
+ ParseVersionBuildDir(llvm::StringRef str);
+
protected:
void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp Fri Sep 16 21:00:02 2016
@@ -47,16 +47,11 @@ PlatformRemoteAppleTV::SDKDirectoryInfo:
const lldb_private::FileSpec &sdk_dir)
: directory(sdk_dir), build(), version_major(0), version_minor(0),
version_update(0), user_cached(false) {
- const char *dirname_cstr = sdk_dir.GetFilename().GetCString();
- const char *pos = Args::StringToVersion(dirname_cstr, version_major,
- version_minor, version_update);
-
- if (pos && pos[0] == ' ' && pos[1] == '(') {
- const char *build_start = pos + 2;
- const char *end_paren = strchr(build_start, ')');
- if (end_paren && build_start < end_paren)
- build.SetCStringWithLength(build_start, end_paren - build_start);
- }
+ llvm::StringRef dirname_str = sdk_dir.GetFilename().GetStringRef();
+ llvm::StringRef build_str;
+ std::tie(version_major, version_minor, version_update, build_str) =
+ ParseVersionBuildDir(dirname_str);
+ build.SetString(build_str);
}
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp Fri Sep 16 21:00:02 2016
@@ -47,16 +47,11 @@ PlatformRemoteAppleWatch::SDKDirectoryIn
const lldb_private::FileSpec &sdk_dir)
: directory(sdk_dir), build(), version_major(0), version_minor(0),
version_update(0), user_cached(false) {
- const char *dirname_cstr = sdk_dir.GetFilename().GetCString();
- const char *pos = Args::StringToVersion(dirname_cstr, version_major,
- version_minor, version_update);
-
- if (pos && pos[0] == ' ' && pos[1] == '(') {
- const char *build_start = pos + 2;
- const char *end_paren = strchr(build_start, ')');
- if (end_paren && build_start < end_paren)
- build.SetCStringWithLength(build_start, end_paren - build_start);
- }
+ llvm::StringRef dirname_str = sdk_dir.GetFilename().GetStringRef();
+ llvm::StringRef build_str;
+ std::tie(version_major, version_minor, version_update, build_str) =
+ ParseVersionBuildDir(dirname_str);
+ build.SetString(build_str);
}
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp Fri Sep 16 21:00:02 2016
@@ -34,16 +34,11 @@ PlatformRemoteiOS::SDKDirectoryInfo::SDK
const lldb_private::FileSpec &sdk_dir)
: directory(sdk_dir), build(), version_major(0), version_minor(0),
version_update(0), user_cached(false) {
- const char *dirname_cstr = sdk_dir.GetFilename().GetCString();
- const char *pos = Args::StringToVersion(dirname_cstr, version_major,
- version_minor, version_update);
-
- if (pos && pos[0] == ' ' && pos[1] == '(') {
- const char *build_start = pos + 2;
- const char *end_paren = strchr(build_start, ')');
- if (end_paren && build_start < end_paren)
- build.SetCStringWithLength(build_start, end_paren - build_start);
- }
+ llvm::StringRef dirname_str = sdk_dir.GetFilename().GetStringRef();
+ llvm::StringRef build_str;
+ std::tie(version_major, version_minor, version_update, build_str) =
+ ParseVersionBuildDir(dirname_str);
+ build.SetString(build_str);
}
//------------------------------------------------------------------
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Fri Sep 16 21:00:02 2016
@@ -1194,8 +1194,8 @@ bool GDBRemoteCommunicationClient::GetHo
// "version" key instead of
// "os_version"...
{
- Args::StringToVersion(value.str().c_str(), m_os_version_major,
- m_os_version_minor, m_os_version_update);
+ Args::StringToVersion(value, m_os_version_major, m_os_version_minor,
+ m_os_version_update);
if (m_os_version_major != UINT32_MAX)
++num_keys_decoded;
} else if (name.equals("watchpoint_exceptions_received")) {
Modified: lldb/trunk/source/Target/Language.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Language.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/source/Target/Language.cpp (original)
+++ lldb/trunk/source/Target/Language.cpp Fri Sep 16 21:00:02 2016
@@ -171,11 +171,16 @@ struct language_name_pair language_names
static uint32_t num_languages =
sizeof(language_names) / sizeof(struct language_name_pair);
-LanguageType Language::GetLanguageTypeFromString(const char *string) {
- for (uint32_t i = 0; i < num_languages; i++) {
- if (strcasecmp(language_names[i].name, string) == 0)
- return (LanguageType)language_names[i].type;
+LanguageType Language::GetLanguageTypeFromString(const char *s) {
+ return GetLanguageTypeFromString(llvm::StringRef(s ? s : ""));
+}
+
+LanguageType Language::GetLanguageTypeFromString(llvm::StringRef string) {
+ for (const auto &L : language_names) {
+ if (string.equals_lower(L.name))
+ return static_cast<LanguageType>(L.type);
}
+
return eLanguageTypeUnknown;
}
Added: lldb/trunk/unittests/Breakpoint/BreakpointIDTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Breakpoint/BreakpointIDTest.cpp?rev=281799&view=auto
==============================================================================
--- lldb/trunk/unittests/Breakpoint/BreakpointIDTest.cpp (added)
+++ lldb/trunk/unittests/Breakpoint/BreakpointIDTest.cpp Fri Sep 16 21:00:02 2016
@@ -0,0 +1,30 @@
+//===-- BreakpointIDTest.cpp ------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Breakpoint/BreakpointID.h"
+#include "lldb/Core/Error.h"
+
+#include "llvm/ADT/StringRef.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(BreakpointIDTest, StringIsBreakpointName) {
+ Error E;
+ EXPECT_FALSE(BreakpointID::StringIsBreakpointName("1breakpoint", E));
+ EXPECT_FALSE(BreakpointID::StringIsBreakpointName("-", E));
+ EXPECT_FALSE(BreakpointID::StringIsBreakpointName("", E));
+ EXPECT_FALSE(BreakpointID::StringIsBreakpointName("3.4", E));
+
+ EXPECT_TRUE(BreakpointID::StringIsBreakpointName("_", E));
+ EXPECT_TRUE(BreakpointID::StringIsBreakpointName("a123", E));
+ EXPECT_TRUE(BreakpointID::StringIsBreakpointName("test", E));
+}
Added: lldb/trunk/unittests/Breakpoint/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Breakpoint/CMakeLists.txt?rev=281799&view=auto
==============================================================================
--- lldb/trunk/unittests/Breakpoint/CMakeLists.txt (added)
+++ lldb/trunk/unittests/Breakpoint/CMakeLists.txt Fri Sep 16 21:00:02 2016
@@ -0,0 +1,3 @@
+add_lldb_unittest(LLDBBreakpointTests
+ BreakpointIDTest.cpp
+ )
Modified: lldb/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/CMakeLists.txt?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/unittests/CMakeLists.txt (original)
+++ lldb/trunk/unittests/CMakeLists.txt Fri Sep 16 21:00:02 2016
@@ -38,12 +38,14 @@ function(add_unittest_inputs test_name i
endforeach()
endfunction()
+add_subdirectory(Breakpoint)
add_subdirectory(Core)
add_subdirectory(Editline)
add_subdirectory(Expression)
add_subdirectory(Host)
add_subdirectory(Interpreter)
add_subdirectory(Language)
+add_subdirectory(Platform)
add_subdirectory(Process)
add_subdirectory(ScriptInterpreter)
add_subdirectory(Symbol)
Modified: lldb/trunk/unittests/Interpreter/TestArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestArgs.cpp?rev=281799&r1=281798&r2=281799&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestArgs.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestArgs.cpp Fri Sep 16 21:00:02 2016
@@ -150,4 +150,6 @@ TEST(ArgsTest, StringToScriptLanguage) {
Args::StringToScriptLanguage("invalid", lldb::eScriptLanguagePython,
&success));
EXPECT_FALSE(success);
-}
\ No newline at end of file
+}
+
+TEST(ArgsTest, StringToVersion) {}
Added: lldb/trunk/unittests/Platform/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Platform/CMakeLists.txt?rev=281799&view=auto
==============================================================================
--- lldb/trunk/unittests/Platform/CMakeLists.txt (added)
+++ lldb/trunk/unittests/Platform/CMakeLists.txt Fri Sep 16 21:00:02 2016
@@ -0,0 +1,3 @@
+add_lldb_unittest(LLDBPlatformTests
+ PlatformDarwinTest.cpp
+ )
Added: lldb/trunk/unittests/Platform/PlatformDarwinTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Platform/PlatformDarwinTest.cpp?rev=281799&view=auto
==============================================================================
--- lldb/trunk/unittests/Platform/PlatformDarwinTest.cpp (added)
+++ lldb/trunk/unittests/Platform/PlatformDarwinTest.cpp Fri Sep 16 21:00:02 2016
@@ -0,0 +1,56 @@
+//===-- PlatformDarwinTest.cpp ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "Plugins/Platform/MacOSX/PlatformDarwin.h"
+
+#include "llvm/ADT/StringRef.h"
+
+#include <tuple>
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(PlatformDarwinTest, TestParseVersionBuildDir) {
+ uint32_t A, B, C;
+ llvm::StringRef D;
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test1)");
+ EXPECT_EQ(1, A);
+ EXPECT_EQ(2, B);
+ EXPECT_EQ(3, C);
+ EXPECT_EQ("test1", D);
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("2.3 (test2)");
+ EXPECT_EQ(2, A);
+ EXPECT_EQ(3, B);
+ EXPECT_EQ("test2", D);
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("3 (test3)");
+ EXPECT_EQ(3, A);
+ EXPECT_EQ("test3", D);
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("1.2.3 (test");
+ EXPECT_EQ(1, A);
+ EXPECT_EQ(2, B);
+ EXPECT_EQ(3, C);
+ EXPECT_EQ("test", D);
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("2.3.4 test");
+ EXPECT_EQ(2, A);
+ EXPECT_EQ(3, B);
+ EXPECT_EQ(4, C);
+ EXPECT_EQ("", D);
+
+ std::tie(A, B, C, D) = PlatformDarwin::ParseVersionBuildDir("3.4.5");
+ EXPECT_EQ(3, A);
+ EXPECT_EQ(4, B);
+ EXPECT_EQ(5, C);
+}
\ No newline at end of file
More information about the lldb-commits
mailing list