Fixed not being able to launch the i386 slice of a universal binary by adding
a new "QLaunchArch:<arch-name>" where <arch-name> is the architecture name.
This allows us to remotely launch a debugserver and then set the architecture
for the binary we will launch.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@131064 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index d4f6592..f8eb8de 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -705,6 +705,26 @@
     return -1;
 }
 
+int
+GDBRemoteCommunicationClient::SendLaunchArchPacket (char const *arch)
+{
+    if (arch && arch[0])
+    {
+        StreamString packet;
+        packet.Printf("QLaunchArch:%s", arch);
+        StringExtractorGDBRemote response;
+        if (SendPacketAndWaitForResponse (packet.GetData(), packet.GetSize(), response, false))
+        {
+            if (response.IsOKResponse())
+                return 0;
+            uint8_t error = response.GetError();
+            if (error)
+                return error;
+        }
+    }
+    return -1;
+}
+
 bool
 GDBRemoteCommunicationClient::GetOSVersion (uint32_t &major, 
                                             uint32_t &minor, 
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
index 5c24d64..d8f317a 100644
--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
+++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
@@ -123,6 +123,8 @@
     int
     SendEnvironmentPacket (char const *name_equal_value);
 
+    int
+    SendLaunchArchPacket (const char *arch);
     //------------------------------------------------------------------
     /// Sends a "vAttach:PID" where PID is in hex. 
     ///
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index afd6af6..cba830e 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -486,6 +486,7 @@
 
             m_gdb_comm.SetDisableASLR (launch_flags & eLaunchFlagDisableASLR);
 
+            m_gdb_comm.SendLaunchArchPacket (m_target.GetArchitecture().GetArchitectureName());
             
             if (working_dir && working_dir[0])
             {
diff --git a/tools/debugserver/source/RNBRemote.cpp b/tools/debugserver/source/RNBRemote.cpp
index 22bcb01..5eed2c5 100644
--- a/tools/debugserver/source/RNBRemote.cpp
+++ b/tools/debugserver/source/RNBRemote.cpp
@@ -175,6 +175,7 @@
     t.push_back (Packet (set_max_packet_size,           &RNBRemote::HandlePacket_QSetMaxPacketSize      , NULL, "QSetMaxPacketSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized packet gdb can handle"));
     t.push_back (Packet (set_max_payload_size,          &RNBRemote::HandlePacket_QSetMaxPayloadSize     , NULL, "QSetMaxPayloadSize:", "Tell " DEBUGSERVER_PROGRAM_NAME " the max sized payload gdb can handle"));
     t.push_back (Packet (set_environment_variable,      &RNBRemote::HandlePacket_QEnvironment           , NULL, "QEnvironment:", "Add an environment variable to the inferior's environment"));
+    t.push_back (Packet (set_launch_arch,               &RNBRemote::HandlePacket_QLaunchArch            , NULL, "QLaunchArch:", "Set the architecture to use when launching a process for hosts that can run multiple architecture slices from universal files."));
     t.push_back (Packet (set_disable_aslr,              &RNBRemote::HandlePacket_QSetDisableASLR        , NULL, "QSetDisableASLR:", "Set wether to disable ASLR when launching the process with the set argv ('A') packet"));
     t.push_back (Packet (set_stdin,                     &RNBRemote::HandlePacket_QSetSTDIO              , NULL, "QSetSTDIN:", "Set the standard input for a process to be launched with the 'A' packet"));
     t.push_back (Packet (set_stdout,                    &RNBRemote::HandlePacket_QSetSTDIO              , NULL, "QSetSTDOUT:", "Set the standard output for a process to be launched with the 'A' packet"));
@@ -1883,6 +1884,15 @@
     return SendPacket ("OK");
 }
 
+rnb_err_t
+RNBRemote::HandlePacket_QLaunchArch (const char *p)
+{
+    p += sizeof ("QLaunchArch:") - 1;
+    if (DNBSetArchitecture(p))
+        return SendPacket ("OK");
+    return SendPacket ("E63");
+}
+
 void
 append_hex_value (std::ostream& ostrm, const uint8_t* buf, size_t buf_size, bool swap)
 {
diff --git a/tools/debugserver/source/RNBRemote.h b/tools/debugserver/source/RNBRemote.h
index 538fad4..f727718 100644
--- a/tools/debugserver/source/RNBRemote.h
+++ b/tools/debugserver/source/RNBRemote.h
@@ -98,6 +98,7 @@
         set_max_packet_size,            // 'QSetMaxPacketSize:'
         set_max_payload_size,           // 'QSetMaxPayloadSize:'
         set_environment_variable,       // 'QEnvironment:'
+        set_launch_arch,                // 'QLaunchArch:'
         set_disable_aslr,               // 'QSetDisableASLR:'
         set_stdin,                      // 'QSetSTDIN:'
         set_stdout,                     // 'QSetSTDOUT:'
@@ -170,6 +171,7 @@
     rnb_err_t HandlePacket_QSetMaxPayloadSize (const char *p);
     rnb_err_t HandlePacket_QSetMaxPacketSize (const char *p);
     rnb_err_t HandlePacket_QEnvironment (const char *p);
+    rnb_err_t HandlePacket_QLaunchArch (const char *p);
     rnb_err_t HandlePacket_QPrefixRegisterPacketsWithThreadID (const char *p);
     rnb_err_t HandlePacket_last_signal (const char *p);
     rnb_err_t HandlePacket_m (const char *p);