summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/macosx/Host.mm
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/source/Host/macosx/Host.mm')
-rw-r--r--lldb/source/Host/macosx/Host.mm140
1 files changed, 16 insertions, 124 deletions
diff --git a/lldb/source/Host/macosx/Host.mm b/lldb/source/Host/macosx/Host.mm
index efc95c70bbb..37ff095817d 100644
--- a/lldb/source/Host/macosx/Host.mm
+++ b/lldb/source/Host/macosx/Host.mm
@@ -47,7 +47,9 @@
#include "lldb/Core/StreamString.h"
#include "lldb/Host/Endian.h"
#include "lldb/Host/FileSpec.h"
+#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
+#include "lldb/Host/ThreadLauncher.h"
#include "lldb/Target/Platform.h"
#include "lldb/Target/Process.h"
#include "lldb/Utility/CleanUp.h"
@@ -77,107 +79,6 @@ extern "C"
using namespace lldb;
using namespace lldb_private;
-static pthread_once_t g_thread_create_once = PTHREAD_ONCE_INIT;
-static pthread_key_t g_thread_create_key = 0;
-
-class MacOSXDarwinThread
-{
-public:
- MacOSXDarwinThread(const char *thread_name) :
- m_pool (nil)
- {
- // Register our thread with the collector if garbage collection is enabled.
- if (objc_collectingEnabled())
- {
-#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5
- // On Leopard and earlier there is no way objc_registerThreadWithCollector
- // function, so we do it manually.
- auto_zone_register_thread(auto_zone());
-#else
- // On SnowLeopard and later we just call the thread registration function.
- objc_registerThreadWithCollector();
-#endif
- }
- else
- {
- m_pool = [[NSAutoreleasePool alloc] init];
- }
-
-
- Host::SetThreadName (LLDB_INVALID_PROCESS_ID, LLDB_INVALID_THREAD_ID, thread_name);
- }
-
- ~MacOSXDarwinThread()
- {
- if (m_pool)
- {
- [m_pool drain];
- m_pool = nil;
- }
- }
-
- static void PThreadDestructor (void *v)
- {
- if (v)
- delete static_cast<MacOSXDarwinThread*>(v);
- ::pthread_setspecific (g_thread_create_key, NULL);
- }
-
-protected:
- NSAutoreleasePool * m_pool;
-private:
- DISALLOW_COPY_AND_ASSIGN (MacOSXDarwinThread);
-};
-
-static void
-InitThreadCreated()
-{
- ::pthread_key_create (&g_thread_create_key, MacOSXDarwinThread::PThreadDestructor);
-}
-
-void
-Host::ThreadCreated (const char *thread_name)
-{
- ::pthread_once (&g_thread_create_once, InitThreadCreated);
- if (g_thread_create_key)
- {
- ::pthread_setspecific (g_thread_create_key, new MacOSXDarwinThread(thread_name));
- }
-}
-
-std::string
-Host::GetThreadName (lldb::pid_t pid, lldb::tid_t tid)
-{
- std::string thread_name;
-#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5
- // We currently can only get the name of a thread in the current process.
- if (pid == Host::GetCurrentProcessID())
- {
- char pthread_name[1024];
- if (::pthread_getname_np (::pthread_from_mach_thread_np (tid), pthread_name, sizeof(pthread_name)) == 0)
- {
- if (pthread_name[0])
- {
- thread_name = pthread_name;
- }
- }
- else
- {
- dispatch_queue_t current_queue = ::dispatch_get_current_queue ();
- if (current_queue != NULL)
- {
- const char *queue_name = dispatch_queue_get_label (current_queue);
- if (queue_name && queue_name[0])
- {
- thread_name = queue_name;
- }
- }
- }
- }
-#endif
- return thread_name;
-}
-
bool
Host::GetBundleDirectory (const FileSpec &file, FileSpec &bundle_directory)
{
@@ -642,28 +543,23 @@ LaunchInNewTerminalWithAppleScript (const char *exe_path, ProcessLaunchInfo &lau
// in a shell and the shell will fork/exec a couple of times before we get
// to the process that we wanted to launch. So when our process actually
// gets launched, we will handshake with it and get the process ID for it.
- lldb::thread_t accept_thread = Host::ThreadCreate (unix_socket_name,
- AcceptPIDFromInferior,
- connect_url,
- &lldb_error);
-
+ HostThread accept_thread = ThreadLauncher::LaunchThread(unix_socket_name, AcceptPIDFromInferior, connect_url, &lldb_error);
[applescript executeAndReturnError:nil];
thread_result_t accept_thread_result = NULL;
- if (Host::ThreadJoin (accept_thread, &accept_thread_result, &lldb_error))
+ lldb_error = accept_thread.Join(&accept_thread_result);
+ if (lldb_error.Success() && accept_thread_result)
{
- if (accept_thread_result)
- {
- pid = (intptr_t)accept_thread_result;
-
- // Wait for process to be stopped at the entry point by watching
- // for the process status to be set to SSTOP which indicates it it
- // SIGSTOP'ed at the entry point
- WaitForProcessToSIGSTOP (pid, 5);
- }
+ pid = (intptr_t)accept_thread_result;
+
+ // Wait for process to be stopped at the entry point by watching
+ // for the process status to be set to SSTOP which indicates it it
+ // SIGSTOP'ed at the entry point
+ WaitForProcessToSIGSTOP(pid, 5);
}
- ::unlink (unix_socket_name);
+
+ FileSystem::Unlink(unix_socket_name);
[applescript release];
if (pid != LLDB_INVALID_PROCESS_ID)
launch_info.SetProcessID (pid);
@@ -1492,13 +1388,9 @@ Host::LaunchProcess (ProcessLaunchInfo &launch_info)
return error;
}
-lldb::thread_t
-Host::StartMonitoringChildProcess (Host::MonitorChildProcessCallback callback,
- void *callback_baton,
- lldb::pid_t pid,
- bool monitor_signals)
+HostThread
+Host::StartMonitoringChildProcess(Host::MonitorChildProcessCallback callback, void *callback_baton, lldb::pid_t pid, bool monitor_signals)
{
- lldb::thread_t thread = LLDB_INVALID_HOST_THREAD;
unsigned long mask = DISPATCH_PROC_EXIT;
if (monitor_signals)
mask |= DISPATCH_PROC_SIGNAL;
@@ -1584,7 +1476,7 @@ Host::StartMonitoringChildProcess (Host::MonitorChildProcessCallback callback,
::dispatch_resume (source);
}
- return thread;
+ return HostThread();
}
//----------------------------------------------------------------------
OpenPOWER on IntegriCloud