summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Breakpoint/BreakpointID.h5
-rw-r--r--lldb/include/lldb/Interpreter/Args.h5
-rw-r--r--lldb/include/lldb/Target/Language.h2
-rw-r--r--lldb/source/Breakpoint/Breakpoint.cpp2
-rw-r--r--lldb/source/Breakpoint/BreakpointID.cpp21
-rw-r--r--lldb/source/Breakpoint/BreakpointIDList.cpp3
-rw-r--r--lldb/source/Breakpoint/BreakpointResolverName.cpp2
-rw-r--r--lldb/source/Commands/CommandObjectBreakpoint.cpp11
-rw-r--r--lldb/source/Interpreter/Args.cpp44
-rw-r--r--lldb/source/Interpreter/OptionGroupPlatform.cpp6
-rw-r--r--lldb/source/Interpreter/OptionValueLanguage.cpp2
-rw-r--r--lldb/source/Interpreter/Property.cpp3
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp32
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h8
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp15
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp15
-rw-r--r--lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp15
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp4
-rw-r--r--lldb/source/Target/Language.cpp13
-rw-r--r--lldb/unittests/Breakpoint/BreakpointIDTest.cpp30
-rw-r--r--lldb/unittests/Breakpoint/CMakeLists.txt3
-rw-r--r--lldb/unittests/CMakeLists.txt2
-rw-r--r--lldb/unittests/Interpreter/TestArgs.cpp4
-rw-r--r--lldb/unittests/Platform/CMakeLists.txt3
-rw-r--r--lldb/unittests/Platform/PlatformDarwinTest.cpp56
25 files changed, 207 insertions, 99 deletions
diff --git a/lldb/include/lldb/Breakpoint/BreakpointID.h b/lldb/include/lldb/Breakpoint/BreakpointID.h
index de44b2bfa8b..c3560acbae6 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointID.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointID.h
@@ -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
diff --git a/lldb/include/lldb/Interpreter/Args.h b/lldb/include/lldb/Interpreter/Args.h
index a0e3d1ec94a..4696477d97f 100644
--- a/lldb/include/lldb/Interpreter/Args.h
+++ b/lldb/include/lldb/Interpreter/Args.h
@@ -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,
diff --git a/lldb/include/lldb/Target/Language.h b/lldb/include/lldb/Target/Language.h
index f324ae13dd4..7c8a6f03893 100644
--- a/lldb/include/lldb/Target/Language.h
+++ b/lldb/include/lldb/Target/Language.h
@@ -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);
diff --git a/lldb/source/Breakpoint/Breakpoint.cpp b/lldb/source/Breakpoint/Breakpoint.cpp
index ebed4e96068..567ceaaee24 100644
--- a/lldb/source/Breakpoint/Breakpoint.cpp
+++ b/lldb/source/Breakpoint/Breakpoint.cpp
@@ -764,7 +764,7 @@ size_t Breakpoint::GetNumLocations() const { return m_locations.GetSize(); }
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;
diff --git a/lldb/source/Breakpoint/BreakpointID.cpp b/lldb/source/Breakpoint/BreakpointID.cpp
index 9ab7adf48c4..c237b22ec1d 100644
--- a/lldb/source/Breakpoint/BreakpointID.cpp
+++ b/lldb/source/Breakpoint/BreakpointID.cpp
@@ -107,14 +107,21 @@ bool BreakpointID::ParseCanonicalReference(const char *input,
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;
- if (name && (name[0] >= 'A' && name[0] <= 'z')) {
- if (strcspn(name, ".- ") != strlen(name)) {
- error.SetErrorStringWithFormat("invalid breakpoint name: \"%s\"", name);
- }
- return true;
- } else
+ // First character must be a letter or _
+ if (!isalpha(str[0]) || str[0] != '_')
+ return false;
+
+ // 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;
}
diff --git a/lldb/source/Breakpoint/BreakpointIDList.cpp b/lldb/source/Breakpoint/BreakpointIDList.cpp
index 4c09bd7410b..0c5ff82082b 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -168,7 +168,8 @@ void BreakpointIDList::FindAndReplaceIDRanges(Args &old_args, Target *target,
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());
diff --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index 175eebd557d..39c9f20d69d 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -98,7 +98,7 @@ BreakpointResolver *BreakpointResolverName::CreateFromStructuredData(
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());
diff --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index c5576e527e2..682e26bbbb4 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -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':
diff --git a/lldb/source/Interpreter/Args.cpp b/lldb/source/Interpreter/Args.cpp
index 0edb9bcd02b..b6a60263e8f 100644
--- a/lldb/source/Interpreter/Args.cpp
+++ b/lldb/source/Interpreter/Args.cpp
@@ -765,37 +765,27 @@ char Args::StringToChar(llvm::StringRef s, char fail_value, bool *success_ptr) {
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,
diff --git a/lldb/source/Interpreter/OptionGroupPlatform.cpp b/lldb/source/Interpreter/OptionGroupPlatform.cpp
index 4b3eeeabf1a..776bac79da4 100644
--- a/lldb/source/Interpreter/OptionGroupPlatform.cpp
+++ b/lldb/source/Interpreter/OptionGroupPlatform.cpp
@@ -105,6 +105,7 @@ Error OptionGroupPlatform::SetOptionValue(uint32_t option_idx,
++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::SetOptionValue(uint32_t option_idx,
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;
diff --git a/lldb/source/Interpreter/OptionValueLanguage.cpp b/lldb/source/Interpreter/OptionValueLanguage.cpp
index f5505f70320..a59419f649e 100644
--- a/lldb/source/Interpreter/OptionValueLanguage.cpp
+++ b/lldb/source/Interpreter/OptionValueLanguage.cpp
@@ -49,7 +49,7 @@ Error OptionValueLanguage::SetValueFromString(llvm::StringRef value,
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;
diff --git a/lldb/source/Interpreter/Property.cpp b/lldb/source/Interpreter/Property.cpp
index 0030d375adf..ba859a5398c 100644
--- a/lldb/source/Interpreter/Property.cpp
+++ b/lldb/source/Interpreter/Property.cpp
@@ -139,7 +139,8 @@ Property::Property(const PropertyDefinition &definition)
{
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));
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
index 66f09923c93..d554ba8b768 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.cpp
@@ -1667,6 +1667,24 @@ FileSpec PlatformDarwin::GetSDKDirectoryForModules(SDKType sdk_type) {
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_t &major, uint32_t &minor,
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_t &major, uint32_t &minor,
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);
}
}
}
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
index d72aedfe848..2abff92fa90 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h
@@ -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);
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
index 13c302fd142..fef09f0519a 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp
@@ -47,16 +47,11 @@ PlatformRemoteAppleTV::SDKDirectoryInfo::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);
}
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
index 28374abda19..b815e4fb9fc 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp
@@ -47,16 +47,11 @@ PlatformRemoteAppleWatch::SDKDirectoryInfo::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);
}
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
index 500e271cc2b..889c501a646 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp
@@ -34,16 +34,11 @@ PlatformRemoteiOS::SDKDirectoryInfo::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);
}
//------------------------------------------------------------------
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index e554fafa00c..a18ab224ecc 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -1194,8 +1194,8 @@ bool GDBRemoteCommunicationClient::GetHostInfo(bool force) {
// "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")) {
diff --git a/lldb/source/Target/Language.cpp b/lldb/source/Target/Language.cpp
index f62073b3d17..2f11d274e4b 100644
--- a/lldb/source/Target/Language.cpp
+++ b/lldb/source/Target/Language.cpp
@@ -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;
}
diff --git a/lldb/unittests/Breakpoint/BreakpointIDTest.cpp b/lldb/unittests/Breakpoint/BreakpointIDTest.cpp
new file mode 100644
index 00000000000..a449d40a335
--- /dev/null
+++ b/lldb/unittests/Breakpoint/BreakpointIDTest.cpp
@@ -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));
+}
diff --git a/lldb/unittests/Breakpoint/CMakeLists.txt b/lldb/unittests/Breakpoint/CMakeLists.txt
new file mode 100644
index 00000000000..5adaf9e78cf
--- /dev/null
+++ b/lldb/unittests/Breakpoint/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_lldb_unittest(LLDBBreakpointTests
+ BreakpointIDTest.cpp
+ )
diff --git a/lldb/unittests/CMakeLists.txt b/lldb/unittests/CMakeLists.txt
index 1044034e576..a42421304a3 100644
--- a/lldb/unittests/CMakeLists.txt
+++ b/lldb/unittests/CMakeLists.txt
@@ -38,12 +38,14 @@ function(add_unittest_inputs test_name inputs)
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)
diff --git a/lldb/unittests/Interpreter/TestArgs.cpp b/lldb/unittests/Interpreter/TestArgs.cpp
index bec9340d6f9..52b528434ca 100644
--- a/lldb/unittests/Interpreter/TestArgs.cpp
+++ b/lldb/unittests/Interpreter/TestArgs.cpp
@@ -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) {}
diff --git a/lldb/unittests/Platform/CMakeLists.txt b/lldb/unittests/Platform/CMakeLists.txt
new file mode 100644
index 00000000000..af1121dac7b
--- /dev/null
+++ b/lldb/unittests/Platform/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_lldb_unittest(LLDBPlatformTests
+ PlatformDarwinTest.cpp
+ )
diff --git a/lldb/unittests/Platform/PlatformDarwinTest.cpp b/lldb/unittests/Platform/PlatformDarwinTest.cpp
new file mode 100644
index 00000000000..e4881f12cab
--- /dev/null
+++ b/lldb/unittests/Platform/PlatformDarwinTest.cpp
@@ -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
OpenPOWER on IntegriCloud