1 //===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBHostOS.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/Host/FileSpec.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Host/HostInfo.h"
16 #include "lldb/Host/HostNativeThread.h"
17 #include "lldb/Host/HostThread.h"
18 #include "lldb/Host/ThreadLauncher.h"
21 using namespace lldb_private;
26 SBHostOS::GetProgramFileSpec ()
28 SBFileSpec sb_filespec;
29 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
34 SBHostOS::GetLLDBPythonPath ()
36 SBFileSpec sb_lldb_python_filespec;
37 FileSpec lldb_python_spec;
38 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
40 sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
42 return sb_lldb_python_filespec;
47 SBHostOS::GetLLDBPath (lldb::PathType path_type)
51 if (HostInfo::GetLLDBPath(path_type, fspec))
52 sb_fspec.SetFileSpec (fspec);
57 SBHostOS::ThreadCreate
60 lldb::thread_func_t thread_function,
65 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
68 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
69 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
70 static_cast<void*>(thread_arg),
71 static_cast<void*>(error_ptr));
73 // FIXME: You should log the return value?
75 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
76 return thread.Release();
80 SBHostOS::ThreadCreated (const char *name)
85 SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
88 HostThread host_thread(thread);
89 error = host_thread.Cancel();
91 error_ptr->SetError(error);
92 host_thread.Release();
93 return error.Success();
97 SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
102 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
104 HostThread host_thread(thread);
105 error = host_thread.GetNativeThread().Detach();
107 error_ptr->SetError(error);
108 host_thread.Release();
110 return error.Success();
114 SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
117 HostThread host_thread(thread);
118 error = host_thread.Join(result);
120 error_ptr->SetError(error);
121 host_thread.Release();
122 return error.Success();