Fixed Process::Halt() as it was broken for "process halt" after recent changes
to the DoHalt down in ProcessGDBRemote. I also moved the functionality that
was in ProcessGDBRemote::DoHalt up into Process::Halt so not every class has
to implement a tricky halt/resume on the internal state thread. The 
functionality is the same as it was before with two changes:
- when we eat the event we now just reuse the event we consume when the private
  state thread is paused and set the interrupted bool on the event if needed
- we also properly update the Process::m_public_state with the state of the
  event we consume.
  
Prior to this, if you issued a "process halt" it would eat the event, not 
update the process state, and then produce a new event with the interrupted
bit set and send it. Anyone listening to the event would get the stopped event
with a process that whose state was set to "running".

Fixed debugserver to not have to be spawned with the architecture of the
inferior process. This worked fine for launching processes, but when attaching
to processes by name or pid without a file in lldb, it would fail.

Now debugserver can support multiple architectures for a native debug session
on the current host. This currently means i386 and x86_64 are supported in
the same binary and a x86_64 debugserver can attach to a i386 executable.
This change involved a lot of changes to make sure we dynamically detect the
correct registers for the inferior process.



git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@119680 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index fcbd523..5496a02 100644
--- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -105,7 +105,6 @@
     m_dynamic_loader_ap (),
     m_flags (0),
     m_stdio_mutex (Mutex::eMutexTypeRecursive),
-    m_byte_order (eByteOrderHost),
     m_gdb_comm(),
     m_debugserver_pid (LLDB_INVALID_PROCESS_ID),
     m_debugserver_thread (LLDB_INVALID_HOST_THREAD),
@@ -339,13 +338,13 @@
 }
 
 Error
-ProcessGDBRemote::WillAttach (lldb::pid_t pid)
+ProcessGDBRemote::WillAttachToProcessWithID (lldb::pid_t pid)
 {
     return WillLaunchOrAttach ();
 }
 
 Error
-ProcessGDBRemote::WillAttach (const char *process_name, bool wait_for_launch)
+ProcessGDBRemote::WillAttachToProcessWithName (const char *process_name, bool wait_for_launch)
 {
     return WillLaunchOrAttach ();
 }
@@ -556,8 +555,6 @@
             if (response.IsOKPacket())
                 m_gdb_comm.SetAckMode (false);
         }
-
-        BuildDynamicRegisterInfo ();
     }
     return error;
 }
@@ -574,22 +571,23 @@
     {
         m_dispatch_queue_offsets_addr = LLDB_INVALID_ADDRESS;
 
-        Module * exe_module = GetTarget().GetExecutableModule ().get();        
+        BuildDynamicRegisterInfo ();
+
+        m_byte_order = m_gdb_comm.GetByteOrder();
+
+        Module * exe_module = GetTarget().GetExecutableModule().get();        
         assert(exe_module);
 
         ObjectFile *exe_objfile = exe_module->GetObjectFile();
         assert(exe_objfile);
 
-        m_byte_order = exe_objfile->GetByteOrder();
-        assert (m_byte_order != eByteOrderInvalid);
-
         StreamString strm;
 
         ArchSpec inferior_arch;
         // See if the GDB server supports the qHostInfo information
         const char *vendor = m_gdb_comm.GetVendorString().AsCString();
         const char *os_type = m_gdb_comm.GetOSString().AsCString();
-        ArchSpec arch_spec = GetTarget().GetArchitecture();
+        ArchSpec arch_spec (GetTarget().GetArchitecture());
         
         if (arch_spec.IsValid() && arch_spec == ArchSpec ("arm"))
         {
@@ -858,25 +856,8 @@
 void
 ProcessGDBRemote::DidAttach ()
 {
-    // If we haven't got an executable module yet, then we should make a dynamic loader, and
-    // see if it can find the executable module for us.  If we do have an executable module,
-    // make sure it matches the process we've just attached to.
-    
-    ModuleSP exe_module_sp = GetTarget().GetExecutableModule();        
-    if (!m_dynamic_loader_ap.get())
-    {
-       m_dynamic_loader_ap.reset(DynamicLoader::FindPlugin(this, "dynamic-loader.macosx-dyld"));
-    }
-
     if (m_dynamic_loader_ap.get())
         m_dynamic_loader_ap->DidAttach();
-
-    Module * new_exe_module = GetTarget().GetExecutableModule().get();        
-    if (new_exe_module == NULL)
-    {
-        
-    }
-    
     DidLaunchOrAttach ();
 }
 
@@ -1124,45 +1105,26 @@
 ProcessGDBRemote::DoHalt (bool &caused_stop)
 {
     Error error;
-    caused_stop = false;
     
     if (m_gdb_comm.IsRunning())
     {
-        PausePrivateStateThread();
+        caused_stop = true;
         bool timed_out = false;
         Mutex::Locker locker;
 
-        if (m_gdb_comm.SendInterrupt (locker, 2, &timed_out))
-        {
-            EventSP event_sp;
-            TimeValue timeout_time;
-            timeout_time = TimeValue::Now();
-            timeout_time.OffsetWithSeconds(2);
-
-            StateType state = WaitForStateChangedEventsPrivate (&timeout_time, event_sp);
-
-            if (!StateIsStoppedState (state))
-            {
-                LogSP log(ProcessGDBRemoteLog::GetLogIfAllCategoriesSet(GDBR_LOG_PROCESS));
-                if (log)
-                    log->Printf("ProcessGDBRemote::DoHalt() failed to stop after sending interrupt");
-                error.SetErrorString ("Did not get stopped event after interrupt succeeded.");
-            }
-            else
-                caused_stop = true;
-        }
-        else
+        if (!m_gdb_comm.SendInterrupt (locker, 2, &timed_out))
         {
             if (timed_out)
                 error.SetErrorString("timed out sending interrupt packet");
             else
                 error.SetErrorString("unknown error sending interrupt packet");
         }
-        
-        // Resume the private state thread at this point.
-        ResumePrivateStateThread();
-
     }
+    else
+    {
+        caused_stop = false;
+    }
+
     return error;
 }
 
@@ -1265,12 +1227,6 @@
     return error;
 }
 
-ByteOrder
-ProcessGDBRemote::GetByteOrder () const
-{
-    return m_byte_order;
-}
-
 //------------------------------------------------------------------
 // Process Queries
 //------------------------------------------------------------------