[Lldb-commits] [lldb] r154945 - /lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp

Johnny Chen johnny.chen at apple.com
Tue Apr 17 13:05:24 PDT 2012


Author: johnny
Date: Tue Apr 17 15:05:24 2012
New Revision: 154945

URL: http://llvm.org/viewvc/llvm-project?rev=154945&view=rev
Log:
Add a hidden option '--stay-alive' to lldb-platform so that it acts like a daemon constantly waiting for the client to connect.
This could be useful in a test setting.

Modified:
    lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp

Modified: lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp?rev=154945&r1=154944&r2=154945&view=diff
==============================================================================
--- lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp (original)
+++ lldb/branches/lldb-platform-work/tools/lldb-platform/lldb-platform.cpp Tue Apr 17 15:05:24 2012
@@ -35,11 +35,13 @@
 
 int g_debug = 0;
 int g_verbose = 0;
+int g_stay_alive = 0;
 
 static struct option g_long_options[] =
 {
     { "debug",              no_argument,        &g_debug,           1   },
     { "verbose",            no_argument,        &g_verbose,         1   },
+    { "stay-alive",         no_argument,        &g_stay_alive,      1   },
     { "log-file",           required_argument,  NULL,               'l' },
     { "log-flags",          required_argument,  NULL,               'f' },
     { "listen",             required_argument,  NULL,               'L' },
@@ -196,53 +198,55 @@
     argv += optind;
 
 
-    GDBRemoteCommunicationServer gdb_server (true);
-    if (!listen_host_port.empty())
-    {
-        for (int j = 0; j < listen_host_port.size(); j++)
-        {
-            char c = listen_host_port[j];
-            if (c > '9' || c < '0')
-                printf("WARNING: passing anything but a number as argument to --listen will most probably make connecting impossible.\n");
-        }
-        std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
-        if (conn_ap.get())
+    do {
+        GDBRemoteCommunicationServer gdb_server (true);
+        if (!listen_host_port.empty())
         {
-            std::string connect_url ("listen://");
-            connect_url.append(listen_host_port.c_str());
-
-            printf ("Listening for a connection on %s...\n", listen_host_port.c_str());
-            if (conn_ap->Connect(connect_url.c_str(), &error) == eConnectionStatusSuccess)
+            for (int j = 0; j < listen_host_port.size(); j++)
+            {
+                char c = listen_host_port[j];
+                if (c > '9' || c < '0')
+                    printf("WARNING: passing anything but a number as argument to --listen will most probably make connecting impossible.\n");
+            }
+            std::auto_ptr<ConnectionFileDescriptor> conn_ap(new ConnectionFileDescriptor());
+            if (conn_ap.get())
             {
-                printf ("Connection established.\n");
-                gdb_server.SetConnection (conn_ap.release());
+                std::string connect_url ("listen://");
+                connect_url.append(listen_host_port.c_str());
+
+                printf ("Listening for a connection on %s...\n", listen_host_port.c_str());
+                if (conn_ap->Connect(connect_url.c_str(), &error) == eConnectionStatusSuccess)
+                {
+                    printf ("Connection established.\n");
+                    gdb_server.SetConnection (conn_ap.release());
+                }
             }
         }
-    }
 
-    if (gdb_server.IsConnected())
-    {
-        // After we connected, we need to get an initial ack from...
-        if (gdb_server.HandshakeWithClient(&error))
+        if (gdb_server.IsConnected())
         {
-            bool interrupt = false;
-            bool done = false;
-            while (!interrupt && !done)
+            // After we connected, we need to get an initial ack from...
+            if (gdb_server.HandshakeWithClient(&error))
             {
-                if (!gdb_server.GetPacketAndSendResponse (UINT32_MAX, error, interrupt, done))
-                    break;
+                bool interrupt = false;
+                bool done = false;
+                while (!interrupt && !done)
+                {
+                    if (!gdb_server.GetPacketAndSendResponse (UINT32_MAX, error, interrupt, done))
+                        break;
+                }
+                
+                if (error.Fail())
+                {
+                    fprintf(stderr, "error: %s\n", error.AsCString());
+                }
             }
-            
-            if (error.Fail())
+            else
             {
-                fprintf(stderr, "error: %s\n", error.AsCString());
+                fprintf(stderr, "error: handshake with client failed\n");
             }
         }
-        else
-        {
-            fprintf(stderr, "error: handshake with client failed\n");
-        }
-    }
+    } while (g_stay_alive);
 
     Debugger::Terminate();
 





More information about the lldb-commits mailing list