summaryrefslogtreecommitdiffstats
path: root/lldb/source
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2016-11-17 01:38:02 +0000
committerZachary Turner <zturner@google.com>2016-11-17 01:38:02 +0000
commit245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd (patch)
tree6ff373d6c04675d624f323b6452d3c5da1eac12f /lldb/source
parent24bd3178714d8f9f10d0fd4c1a4de2605da20404 (diff)
downloadbcm5719-llvm-245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd.tar.gz
bcm5719-llvm-245f7fdcfa9fb4351f53ab9d96b31e1e472e81bd.zip
Convert UriParser to use StringRef.
llvm-svn: 287190
Diffstat (limited to 'lldb/source')
-rw-r--r--lldb/source/Core/UUID.cpp6
-rw-r--r--lldb/source/Interpreter/OptionValueUUID.cpp5
-rw-r--r--lldb/source/Plugins/Platform/Android/AdbClient.cpp4
-rw-r--r--lldb/source/Plugins/Platform/Android/AdbClient.h2
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp2
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp14
-rw-r--r--lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h2
-rw-r--r--lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp7
-rw-r--r--lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp8
-rw-r--r--lldb/source/Utility/UriParser.cpp36
-rw-r--r--lldb/source/Utility/UriParser.h8
11 files changed, 47 insertions, 47 deletions
diff --git a/lldb/source/Core/UUID.cpp b/lldb/source/Core/UUID.cpp
index d7ebea72fb4..a08a748821d 100644
--- a/lldb/source/Core/UUID.cpp
+++ b/lldb/source/Core/UUID.cpp
@@ -128,6 +128,7 @@ static inline int xdigit_to_int(char ch) {
llvm::StringRef UUID::DecodeUUIDBytesFromString(llvm::StringRef p,
ValueType &uuid_bytes,
+ uint32_t &bytes_decoded,
uint32_t num_uuid_bytes) {
::memset(uuid_bytes, 0, sizeof(uuid_bytes));
size_t uuid_byte_idx = 0;
@@ -157,6 +158,7 @@ llvm::StringRef UUID::DecodeUUIDBytesFromString(llvm::StringRef p,
// Clear trailing bytes to 0.
for (uint32_t i = uuid_byte_idx; i < sizeof(ValueType); i++)
uuid_bytes[i] = 0;
+ bytes_decoded = uuid_byte_idx;
return p;
}
size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) {
@@ -169,9 +171,9 @@ size_t UUID::SetFromCString(const char *cstr, uint32_t num_uuid_bytes) {
// Skip leading whitespace characters
p = p.ltrim();
+ uint32_t bytes_decoded = 0;
llvm::StringRef rest =
- UUID::DecodeUUIDBytesFromString(p, m_uuid, num_uuid_bytes);
- size_t bytes_decoded = p.size() - rest.size();
+ UUID::DecodeUUIDBytesFromString(p, m_uuid, bytes_decoded, num_uuid_bytes);
// If we successfully decoded a UUID, return the amount of characters that
// were consumed
diff --git a/lldb/source/Interpreter/OptionValueUUID.cpp b/lldb/source/Interpreter/OptionValueUUID.cpp
index bd6858cee67..a1f16e146a3 100644
--- a/lldb/source/Interpreter/OptionValueUUID.cpp
+++ b/lldb/source/Interpreter/OptionValueUUID.cpp
@@ -79,8 +79,9 @@ size_t OptionValueUUID::AutoComplete(CommandInterpreter &interpreter,
const size_t num_modules = target->GetImages().GetSize();
if (num_modules > 0) {
UUID::ValueType uuid_bytes;
- llvm::StringRef rest = UUID::DecodeUUIDBytesFromString(s, uuid_bytes);
- const size_t num_bytes_decoded = s.size() - rest.size();
+ size_t num_bytes_decoded = 0;
+ llvm::StringRef rest =
+ UUID::DecodeUUIDBytesFromString(s, uuid_bytes, num_bytes_decoded);
for (size_t i = 0; i < num_modules; ++i) {
ModuleSP module_sp(target->GetImages().GetModuleAtIndex(i));
if (module_sp) {
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.cpp b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
index 7c9c70ac845..fbf6dee87bf 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.cpp
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.cpp
@@ -185,7 +185,7 @@ Error AdbClient::SetPortForwarding(const uint16_t local_port,
}
Error AdbClient::SetPortForwarding(const uint16_t local_port,
- const char *remote_socket_name,
+ llvm::StringRef remote_socket_name,
const UnixSocketNamespace socket_namespace) {
char message[PATH_MAX];
const char *sock_namespace_str =
@@ -193,7 +193,7 @@ Error AdbClient::SetPortForwarding(const uint16_t local_port,
? kSocketNamespaceAbstract
: kSocketNamespaceFileSystem;
snprintf(message, sizeof(message), "forward:tcp:%d;%s:%s", local_port,
- sock_namespace_str, remote_socket_name);
+ sock_namespace_str, remote_socket_name.str().c_str());
const auto error = SendDeviceMessage(message);
if (error.Fail())
diff --git a/lldb/source/Plugins/Platform/Android/AdbClient.h b/lldb/source/Plugins/Platform/Android/AdbClient.h
index 471dce5ea75..56bb04e3904 100644
--- a/lldb/source/Plugins/Platform/Android/AdbClient.h
+++ b/lldb/source/Plugins/Platform/Android/AdbClient.h
@@ -96,7 +96,7 @@ public:
const uint16_t remote_port);
Error SetPortForwarding(const uint16_t local_port,
- const char *remote_socket_name,
+ llvm::StringRef remote_socket_name,
const UnixSocketNamespace socket_namespace);
Error DeletePortForwarding(const uint16_t local_port);
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
index 9f1a38924fd..7d701728635 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroid.cpp
@@ -168,7 +168,7 @@ Error PlatformAndroid::ConnectRemote(Args &args) {
m_remote_platform_sp = PlatformSP(new PlatformAndroidRemoteGDBServer());
int port;
- std::string scheme, host, path;
+ llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
return Error("URL is null.");
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
index 9650fb4028c..288accfe871 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.cpp
@@ -27,7 +27,7 @@ static const lldb::pid_t g_remote_platform_pid =
static Error ForwardPortWithAdb(
const uint16_t local_port, const uint16_t remote_port,
- const char *remote_socket_name,
+ llvm::StringRef remote_socket_name,
const llvm::Optional<AdbClient::UnixSocketNamespace> &socket_namespace,
std::string &device_id) {
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_PLATFORM));
@@ -50,7 +50,7 @@ static Error ForwardPortWithAdb(
if (log)
log->Printf("Forwarding remote socket \"%s\" to local TCP port %d",
- remote_socket_name, local_port);
+ remote_socket_name.str().c_str(), local_port);
if (!socket_namespace)
return Error("Invalid socket namespace");
@@ -114,7 +114,7 @@ Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
return Error("\"platform connect\" takes a single argument: <connect-url>");
int remote_port;
- std::string scheme, host, path;
+ llvm::StringRef scheme, host, path;
const char *url = args.GetArgumentAtIndex(0);
if (!url)
return Error("URL is null.");
@@ -132,7 +132,7 @@ Error PlatformAndroidRemoteGDBServer::ConnectRemote(Args &args) {
std::string connect_url;
auto error =
MakeConnectURL(g_remote_platform_pid, (remote_port < 0) ? 0 : remote_port,
- path.c_str(), connect_url);
+ path, connect_url);
if (error.Fail())
return error;
@@ -175,7 +175,7 @@ void PlatformAndroidRemoteGDBServer::DeleteForwardPort(lldb::pid_t pid) {
Error PlatformAndroidRemoteGDBServer::MakeConnectURL(
const lldb::pid_t pid, const uint16_t remote_port,
- const char *remote_socket_name, std::string &connect_url) {
+ llvm::StringRef remote_socket_name, std::string &connect_url) {
static const int kAttempsNum = 5;
Error error;
@@ -214,7 +214,7 @@ lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess(
static lldb::pid_t s_remote_gdbserver_fake_pid = 0xffffffffffffffffULL;
int remote_port;
- std::string scheme, host, path;
+ llvm::StringRef scheme, host, path;
if (!UriParser::Parse(connect_url, scheme, host, remote_port, path)) {
error.SetErrorStringWithFormat("Invalid URL: %s", connect_url);
return nullptr;
@@ -222,7 +222,7 @@ lldb::ProcessSP PlatformAndroidRemoteGDBServer::ConnectProcess(
std::string new_connect_url;
error = MakeConnectURL(s_remote_gdbserver_fake_pid--,
- (remote_port < 0) ? 0 : remote_port, path.c_str(),
+ (remote_port < 0) ? 0 : remote_port, path,
new_connect_url);
if (error.Fail())
return nullptr;
diff --git a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
index 9748c86b969..f9593fa8e80 100644
--- a/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
+++ b/lldb/source/Plugins/Platform/Android/PlatformAndroidRemoteGDBServer.h
@@ -55,7 +55,7 @@ protected:
void DeleteForwardPort(lldb::pid_t pid);
Error MakeConnectURL(const lldb::pid_t pid, const uint16_t remote_port,
- const char *remote_socket_name,
+ llvm::StringRef remote_socket_name,
std::string &connect_url);
private:
diff --git a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
index 1a5df93fbd6..ccc73015adc 100644
--- a/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ b/lldb/source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -309,9 +309,12 @@ Error PlatformRemoteGDBServer::ConnectRemote(Args &args) {
const char *url = args.GetArgumentAtIndex(0);
if (!url)
return Error("URL is null.");
- if (!UriParser::Parse(url, m_platform_scheme, m_platform_hostname, port,
- path))
+ llvm::StringRef scheme, hostname, pathname;
+ if (!UriParser::Parse(url, scheme, hostname, port, pathname))
return Error("Invalid URL: %s", url);
+ m_platform_scheme = scheme;
+ m_platform_hostname = hostname;
+ path = pathname;
const ConnectionStatus status = m_gdb_client.Connect(url, &error);
if (status == eConnectionStatusSuccess) {
diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
index 8bf48e93537..11069749186 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerPlatform.cpp
@@ -124,10 +124,10 @@ Error GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
this, std::placeholders::_1),
false);
- std::string platform_scheme;
- std::string platform_ip;
+ llvm::StringRef platform_scheme;
+ llvm::StringRef platform_ip;
int platform_port;
- std::string platform_path;
+ llvm::StringRef platform_path;
bool ok = UriParser::Parse(GetConnection()->GetURI(), platform_scheme,
platform_ip, platform_port, platform_path);
UNUSED_IF_ASSERT_DISABLED(ok);
@@ -140,7 +140,7 @@ Error GDBRemoteCommunicationServerPlatform::LaunchGDBServer(
#endif
uint16_t *port_ptr = &port;
if (m_socket_protocol == Socket::ProtocolTcp)
- url << platform_ip << ":" << port;
+ url << platform_ip.str() << ":" << port;
else {
socket_name = GetDomainSocketPath("gdbserver").GetPath();
url << socket_name;
diff --git a/lldb/source/Utility/UriParser.cpp b/lldb/source/Utility/UriParser.cpp
index 6a1f0303b97..a1d6e4c3d85 100644
--- a/lldb/source/Utility/UriParser.cpp
+++ b/lldb/source/Utility/UriParser.cpp
@@ -23,18 +23,19 @@ using namespace lldb_private;
//----------------------------------------------------------------------
// UriParser::Parse
//----------------------------------------------------------------------
-bool UriParser::Parse(const std::string &uri, std::string &scheme,
- std::string &hostname, int &port, std::string &path) {
- std::string tmp_scheme, tmp_hostname, tmp_port, tmp_path;
+bool UriParser::Parse(llvm::StringRef uri, llvm::StringRef &scheme,
+ llvm::StringRef &hostname, int &port,
+ llvm::StringRef &path) {
+ llvm::StringRef tmp_scheme, tmp_hostname, tmp_port, tmp_path;
- static const char *kSchemeSep = "://";
+ const llvm::StringRef kSchemeSep("://");
auto pos = uri.find(kSchemeSep);
if (pos == std::string::npos)
return false;
// Extract path.
tmp_scheme = uri.substr(0, pos);
- auto host_pos = pos + strlen(kSchemeSep);
+ auto host_pos = pos + kSchemeSep.size();
auto path_pos = uri.find('/', host_pos);
if (path_pos != std::string::npos)
tmp_path = uri.substr(path_pos);
@@ -53,28 +54,19 @@ bool UriParser::Parse(const std::string &uri, std::string &scheme,
return false;
tmp_hostname = host_port.substr(1, pos - 1);
- host_port.erase(0, pos + 1);
+ host_port = host_port.drop_front(pos + 1);
+ if (!host_port.empty() && !host_port.consume_front(":"))
+ return false;
} else {
- pos = host_port.find(':');
- tmp_hostname = host_port.substr(
- 0, (pos != std::string::npos) ? pos : host_port.size());
- host_port.erase(0, (pos != std::string::npos) ? pos : host_port.size());
+ std::tie(tmp_hostname, host_port) = host_port.split(':');
}
// Extract port
- tmp_port = host_port;
- if (!tmp_port.empty()) {
- if (tmp_port[0] != ':')
- return false;
- tmp_port = tmp_port.substr(1);
- bool success = false;
- auto port_tmp =
- StringConvert::ToUInt32(tmp_port.c_str(), UINT32_MAX, 10, &success);
- if (!success || port_tmp > 65535) {
- // there are invalid characters in port_buf
+ if (!host_port.empty()) {
+ uint16_t port_value = 0;
+ if (host_port.getAsInteger(0, port_value))
return false;
- }
- port = port_tmp;
+ port = port_value;
} else
port = -1;
diff --git a/lldb/source/Utility/UriParser.h b/lldb/source/Utility/UriParser.h
index 56bd194ae64..7ebf76f89ca 100644
--- a/lldb/source/Utility/UriParser.h
+++ b/lldb/source/Utility/UriParser.h
@@ -12,9 +12,10 @@
// C Includes
// C++ Includes
-#include <string>
// Other libraries and framework includes
+#include "llvm/ADT/StringRef.h"
+
// Project includes
class UriParser {
@@ -27,8 +28,9 @@ public:
//
// if the url is invalid, function returns false and
// output parameters remain unchanged
- static bool Parse(const std::string &uri, std::string &scheme,
- std::string &hostname, int &port, std::string &path);
+ static bool Parse(llvm::StringRef uri, llvm::StringRef &scheme,
+ llvm::StringRef &hostname, int &port,
+ llvm::StringRef &path);
};
#endif // utility_UriParser_h_
OpenPOWER on IntegriCloud