diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2015-02-06 21:38:51 +0000 | 
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2015-02-06 21:38:51 +0000 | 
| commit | 205afe679855a4ce8149cdaa94d3f0868ce796dc (patch) | |
| tree | 09bc83f73246ee3c7a779605cd0122093d2a8a19 /source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | |
| parent | 0cac4ca3916ac24ab6139d03cbfd18db9e715bfe (diff) | |
Notes
Diffstat (limited to 'source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp')
| -rw-r--r-- | source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 134 | 
1 files changed, 90 insertions, 44 deletions
| diff --git a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index f35d954caa7b..fe99706969c8 100644 --- a/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -14,7 +14,6 @@  #include <errno.h>  #include <stdlib.h>  #ifndef LLDB_DISABLE_POSIX -#include <spawn.h>  #include <netinet/in.h>  #include <sys/mman.h>       // for mmap  #endif @@ -32,7 +31,7 @@  #include "lldb/Interpreter/Args.h"  #include "lldb/Core/ArchSpec.h"  #include "lldb/Core/Debugger.h" -#include "lldb/Core/ConnectionFileDescriptor.h" +#include "lldb/Host/ConnectionFileDescriptor.h"  #include "lldb/Host/FileSpec.h"  #include "lldb/Core/Module.h"  #include "lldb/Core/ModuleSpec.h" @@ -42,7 +41,9 @@  #include "lldb/Core/StreamString.h"  #include "lldb/Core/Timer.h"  #include "lldb/Core/Value.h" +#include "lldb/Host/HostThread.h"  #include "lldb/Host/Symbols.h" +#include "lldb/Host/ThreadLauncher.h"  #include "lldb/Host/TimeValue.h"  #include "lldb/Interpreter/CommandInterpreter.h"  #include "lldb/Interpreter/CommandObject.h" @@ -272,8 +273,6 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) :      m_last_stop_packet_mutex (Mutex::eMutexTypeNormal),      m_register_info (),      m_async_broadcaster (NULL, "lldb.process.gdb-remote.async-broadcaster"), -    m_async_thread (LLDB_INVALID_HOST_THREAD), -    m_async_thread_state(eAsyncThreadNotStarted),      m_async_thread_state_mutex(Mutex::eMutexTypeRecursive),      m_thread_ids (),      m_continue_c_tids (), @@ -749,8 +748,12 @@ ProcessGDBRemote::WillLaunchOrAttach ()  Error  ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)  { +    Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));      Error error; +    if (log) +        log->Printf ("ProcessGDBRemote::%s() entered", __FUNCTION__); +      uint32_t launch_flags = launch_info.GetFlags().Get();      const char *stdin_path = NULL;      const char *stdout_path = NULL; @@ -777,10 +780,21 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)              stderr_path = file_action->GetPath();      } +    if (log) +    { +        if (stdin_path || stdout_path || stderr_path) +            log->Printf ("ProcessGDBRemote::%s provided with STDIO paths via launch_info: stdin=%s, stdout=%s, stdout=%s", +                         __FUNCTION__, +                         stdin_path ? stdin_path : "<null>", +                         stdout_path ? stdout_path : "<null>", +                         stderr_path ? stderr_path : "<null>"); +        else +            log->Printf ("ProcessGDBRemote::%s no STDIO paths given via launch_info", __FUNCTION__); +    } +      //  ::LogSetBitMask (GDBR_LOG_DEFAULT);      //  ::LogSetOptions (LLDB_LOG_OPTION_THREADSAFE | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_PROC_AND_THREAD);      //  ::LogSetLogFile ("/dev/stdout"); -    Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));      ObjectFile * object_file = exe_module->GetObjectFile();      if (object_file) @@ -817,6 +831,13 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)                  if (stderr_path == NULL)                      stderr_path = slave_name; + +                if (log) +                    log->Printf ("ProcessGDBRemote::%s adjusted STDIO paths for local platform (IsHost() is true) using slave: stdin=%s, stdout=%s, stdout=%s", +                                 __FUNCTION__, +                                 stdin_path ? stdin_path : "<null>", +                                 stdout_path ? stdout_path : "<null>", +                                 stderr_path ? stderr_path : "<null>");              }              // Set STDIN to /dev/null if we want STDIO disabled or if either @@ -834,7 +855,14 @@ ProcessGDBRemote::DoLaunch (Module *exe_module, ProcessLaunchInfo &launch_info)              if (disable_stdio || (stderr_path == NULL && (stdin_path || stdout_path)))                  stderr_path = "/dev/null"; -            if (stdin_path)  +            if (log) +                log->Printf ("ProcessGDBRemote::%s final STDIO paths after all adjustments: stdin=%s, stdout=%s, stdout=%s", +                             __FUNCTION__, +                             stdin_path ? stdin_path : "<null>", +                             stdout_path ? stdout_path : "<null>", +                             stderr_path ? stderr_path : "<null>"); + +            if (stdin_path)                  m_gdb_comm.SetSTDIN (stdin_path);              if (stdout_path)                  m_gdb_comm.SetSTDOUT (stdout_path); @@ -1026,18 +1054,38 @@ ProcessGDBRemote::DidLaunchOrAttach (ArchSpec& process_arch)          // prefer that over the Host information as it will be more specific          // to our process. -        if (m_gdb_comm.GetProcessArchitecture().IsValid()) -            process_arch = m_gdb_comm.GetProcessArchitecture(); +        const ArchSpec &remote_process_arch = m_gdb_comm.GetProcessArchitecture(); +        if (remote_process_arch.IsValid()) +        { +            process_arch = remote_process_arch; +            if (log) +                log->Printf ("ProcessGDBRemote::%s gdb-remote had process architecture, using %s %s", +                             __FUNCTION__, +                             process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", +                             process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); +        }          else +        {              process_arch = m_gdb_comm.GetHostArchitecture(); +            if (log) +                log->Printf ("ProcessGDBRemote::%s gdb-remote did not have process architecture, using gdb-remote host architecture %s %s", +                             __FUNCTION__, +                             process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", +                             process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>"); +        }          if (process_arch.IsValid())          {              ArchSpec &target_arch = GetTarget().GetArchitecture(); -              if (target_arch.IsValid())              { -                // If the remote host is ARM and we have apple as the vendor, then  +                if (log) +                    log->Printf ("ProcessGDBRemote::%s analyzing target arch, currently %s %s", +                                 __FUNCTION__, +                                 target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", +                                 target_arch.GetTriple().getTriple ().c_str() ? target_arch.GetTriple().getTriple ().c_str() : "<null>"); + +                // If the remote host is ARM and we have apple as the vendor, then                  // ARM executables and shared libraries can have mixed ARM architectures.                  // You can have an armv6 executable, and if the host is armv7, then the                  // system will load the best possible architecture for all shared libraries @@ -1048,6 +1096,11 @@ ProcessGDBRemote::DidLaunchOrAttach (ArchSpec& process_arch)                      process_arch.GetTriple().getVendor() == llvm::Triple::Apple)                  {                      GetTarget().SetArchitecture (process_arch); +                    if (log) +                        log->Printf ("ProcessGDBRemote::%s remote process is ARM/Apple, setting target arch to %s %s", +                                     __FUNCTION__, +                                     process_arch.GetArchitectureName () ? process_arch.GetArchitectureName () : "<null>", +                                     process_arch.GetTriple().getTriple ().c_str() ? process_arch.GetTriple().getTriple ().c_str() : "<null>");                  }                  else                  { @@ -1066,7 +1119,14 @@ ProcessGDBRemote::DidLaunchOrAttach (ArchSpec& process_arch)                                  target_triple.setEnvironment (remote_triple.getEnvironment());                          }                      } +                  } + +                if (log) +                    log->Printf ("ProcessGDBRemote::%s final target arch after adjustments for remote architecture: %s %s", +                                 __FUNCTION__, +                                 target_arch.GetArchitectureName () ? target_arch.GetArchitectureName () : "<null>", +                                 target_arch.GetTriple().getTriple ().c_str() ? target_arch.GetTriple().getTriple ().c_str() : "<null>");              }              else              { @@ -1095,7 +1155,12 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid)  Error  ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const ProcessAttachInfo &attach_info)  { +    Log *log (ProcessGDBRemoteLog::GetLogIfAllCategoriesSet (GDBR_LOG_PROCESS));      Error error; + +    if (log) +        log->Printf ("ProcessGDBRemote::%s()", __FUNCTION__); +      // Clear out and clean up from any current state      Clear();      if (attach_pid != LLDB_INVALID_PROCESS_ID) @@ -1118,13 +1183,14 @@ ProcessGDBRemote::DoAttachToProcessWithID (lldb::pid_t attach_pid, const Process          if (error.Success())          {              m_gdb_comm.SetDetachOnError(attach_info.GetDetachOnError()); -             +              char packet[64];              const int packet_len = ::snprintf (packet, sizeof(packet), "vAttach;%" PRIx64, attach_pid);              SetID (attach_pid);                          m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncContinue, new EventDataBytes (packet, packet_len));          }      } +      return error;  } @@ -1432,7 +1498,7 @@ ProcessGDBRemote::DoResume ()              TimeValue timeout;              timeout = TimeValue::Now();              timeout.OffsetWithSeconds (5); -            if (!IS_VALID_LLDB_HOST_THREAD(m_async_thread)) +            if (!m_async_thread.IsJoinable())              {                  error.SetErrorString ("Trying to resume but the async thread is dead.");                  if (log) @@ -2891,30 +2957,17 @@ ProcessGDBRemote::StartAsyncThread ()          log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__);      Mutex::Locker start_locker(m_async_thread_state_mutex); -    if (m_async_thread_state == eAsyncThreadNotStarted) +    if (!m_async_thread.IsJoinable())      {          // Create a thread that watches our internal state and controls which          // events make it to clients (into the DCProcess event queue). -        m_async_thread = Host::ThreadCreate ("<lldb.process.gdb-remote.async>", ProcessGDBRemote::AsyncThread, this, NULL); -        if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) -        { -            m_async_thread_state = eAsyncThreadRunning; -            return true; -        } -        else -            return false; -    } -    else -    { -        // Somebody tried to start the async thread while it was either being started or stopped.  If the former, and -        // it started up successfully, then say all's well.  Otherwise it is an error, since we aren't going to restart it. -        if (log) -            log->Printf ("ProcessGDBRemote::%s () - Called when Async thread was in state: %d.", __FUNCTION__, m_async_thread_state); -        if (m_async_thread_state == eAsyncThreadRunning) -            return true; -        else -            return false; + +        m_async_thread = ThreadLauncher::LaunchThread("<lldb.process.gdb-remote.async>", ProcessGDBRemote::AsyncThread, this, NULL);      } +    else if (log) +        log->Printf("ProcessGDBRemote::%s () - Called when Async thread was already running.", __FUNCTION__); + +    return m_async_thread.IsJoinable();  }  void @@ -2926,7 +2979,7 @@ ProcessGDBRemote::StopAsyncThread ()          log->Printf ("ProcessGDBRemote::%s ()", __FUNCTION__);      Mutex::Locker start_locker(m_async_thread_state_mutex); -    if (m_async_thread_state == eAsyncThreadRunning) +    if (m_async_thread.IsJoinable())      {          m_async_broadcaster.BroadcastEvent (eBroadcastBitAsyncThreadShouldExit); @@ -2934,17 +2987,10 @@ ProcessGDBRemote::StopAsyncThread ()          m_gdb_comm.Disconnect();    // Disconnect from the debug server.          // Stop the stdio thread -        if (IS_VALID_LLDB_HOST_THREAD(m_async_thread)) -        { -            Host::ThreadJoin (m_async_thread, NULL, NULL); -        } -        m_async_thread_state = eAsyncThreadDone; -    } -    else -    { -        if (log) -            log->Printf ("ProcessGDBRemote::%s () - Called when Async thread was in state: %d.", __FUNCTION__, m_async_thread_state); +        m_async_thread.Join(nullptr);      } +    else if (log) +        log->Printf("ProcessGDBRemote::%s () - Called when Async thread was not running.", __FUNCTION__);  } @@ -3086,7 +3132,7 @@ ProcessGDBRemote::AsyncThread (void *arg)      if (log)          log->Printf ("ProcessGDBRemote::%s (arg = %p, pid = %" PRIu64 ") thread exiting...", __FUNCTION__, arg, process->GetID()); -    process->m_async_thread = LLDB_INVALID_HOST_THREAD; +    process->m_async_thread.Reset();      return NULL;  } | 
