[Lldb-commits] [PATCH] Factor out common URL handling code in PlatformRemoteGDBServer

Pavel Labath labath at google.com
Thu Feb 19 04:27:33 PST 2015


Hi tberghammer,

this also gets rid of a compiler warning in release builds by using a dynamically allocated
buffer. Therefore, a size assertion is not necessary (and probably should have been an error in
the first place).

http://reviews.llvm.org/D7751

Files:
  source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp

Index: source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
===================================================================
--- source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
+++ source/Plugins/Platform/gdb-server/PlatformRemoteGDBServer.cpp
@@ -37,6 +37,18 @@
 
 static bool g_initialized = false;
 
+static std::string MakeConnectUrl (const std::string &platform_hostname, uint16_t port)
+{
+    const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
+    const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
+    int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
+    lldb_private::StreamString result;
+    result.Printf("connect://%s:%u",
+            override_hostname ? override_hostname : platform_hostname.c_str(),
+            port + port_offset);
+    return result.GetString();
+}
+
 void
 PlatformRemoteGDBServer::Initialize ()
 {
@@ -576,20 +588,11 @@
                     
                     if (process_sp)
                     {
-                        char connect_url[256];
-                        const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
-                        const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
-                        int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
-                        const int connect_url_len = ::snprintf (connect_url,
-                                                                sizeof(connect_url),
-                                                                "connect://%s:%u",
-                                                                override_hostname ? override_hostname : m_platform_hostname.c_str(),
-                                                                port + port_offset);
-                        assert (connect_url_len < (int)sizeof(connect_url));
-                        error = process_sp->ConnectRemote (NULL, connect_url);
+                        std::string connect_url = MakeConnectUrl(m_platform_hostname, port);
+                        error = process_sp->ConnectRemote (NULL, connect_url.c_str());
                         // Retry the connect remote one time...
                         if (error.Fail())
-                            error = process_sp->ConnectRemote (NULL, connect_url);
+                            error = process_sp->ConnectRemote (NULL, connect_url.c_str());
                         if (error.Success())
                             error = process_sp->Launch(launch_info);
                         else if (debugserver_pid != LLDB_INVALID_PROCESS_ID)
@@ -680,17 +683,8 @@
                     
                     if (process_sp)
                     {
-                        char connect_url[256];
-                        const char *override_hostname = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_HOSTNAME");
-                        const char *port_offset_c_str = getenv("LLDB_PLATFORM_REMOTE_GDB_SERVER_PORT_OFFSET");
-                        int port_offset = port_offset_c_str ? ::atoi(port_offset_c_str) : 0;
-                        const int connect_url_len = ::snprintf (connect_url, 
-                                                                sizeof(connect_url), 
-                                                                "connect://%s:%u", 
-                                                                override_hostname ? override_hostname : m_platform_hostname.c_str(),
-                                                                port + port_offset);
-                        assert (connect_url_len < (int)sizeof(connect_url));
-                        error = process_sp->ConnectRemote(nullptr, connect_url);
+                        std::string connect_url = MakeConnectUrl(m_platform_hostname, port);
+                        error = process_sp->ConnectRemote(nullptr, connect_url.c_str());
                         if (error.Success())
                         {
                             auto listener = attach_info.GetHijackListener();

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7751.20278.patch
Type: text/x-patch
Size: 4141 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20150219/eb55fbc6/attachment.bin>


More information about the lldb-commits mailing list