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"
20 #include "llvm/Support/Path.h"
21 #include "llvm/ADT/SmallString.h"
24 using namespace lldb_private;
29 SBHostOS::GetProgramFileSpec ()
31 SBFileSpec sb_filespec;
32 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
37 SBHostOS::GetLLDBPythonPath ()
39 SBFileSpec sb_lldb_python_filespec;
40 FileSpec lldb_python_spec;
41 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
43 sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
45 return sb_lldb_python_filespec;
50 SBHostOS::GetLLDBPath (lldb::PathType path_type)
54 if (HostInfo::GetLLDBPath(path_type, fspec))
55 sb_fspec.SetFileSpec (fspec);
60 SBHostOS::GetUserHomeDirectory ()
64 llvm::SmallString<64> home_dir_path;
65 llvm::sys::path::home_directory (home_dir_path);
66 FileSpec homedir (home_dir_path.c_str(), true);
68 sb_fspec.SetFileSpec (homedir);
73 SBHostOS::ThreadCreate
76 lldb::thread_func_t thread_function,
81 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
84 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
85 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
86 static_cast<void*>(thread_arg),
87 static_cast<void*>(error_ptr));
89 // FIXME: You should log the return value?
91 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
92 return thread.Release();
96 SBHostOS::ThreadCreated (const char *name)
101 SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
104 HostThread host_thread(thread);
105 error = host_thread.Cancel();
107 error_ptr->SetError(error);
108 host_thread.Release();
109 return error.Success();
113 SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
118 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
120 HostThread host_thread(thread);
121 error = host_thread.GetNativeThread().Detach();
123 error_ptr->SetError(error);
124 host_thread.Release();
126 return error.Success();
130 SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
133 HostThread host_thread(thread);
134 error = host_thread.Join(result);
136 error_ptr->SetError(error);
137 host_thread.Release();
138 return error.Success();