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/Host.h"
13 #include "lldb/Host/HostInfo.h"
14 #include "lldb/Host/HostNativeThread.h"
15 #include "lldb/Host/HostThread.h"
16 #include "lldb/Host/ThreadLauncher.h"
17 #include "lldb/Utility/FileSpec.h"
18 #include "lldb/Utility/Log.h"
20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/Support/Path.h"
24 using namespace lldb_private;
26 SBFileSpec SBHostOS::GetProgramFileSpec() {
27 SBFileSpec sb_filespec;
28 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
32 SBFileSpec SBHostOS::GetLLDBPythonPath() {
33 SBFileSpec sb_lldb_python_filespec;
34 FileSpec lldb_python_spec;
35 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec)) {
36 sb_lldb_python_filespec.SetFileSpec(lldb_python_spec);
38 return sb_lldb_python_filespec;
41 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
44 if (HostInfo::GetLLDBPath(path_type, fspec))
45 sb_fspec.SetFileSpec(fspec);
49 SBFileSpec SBHostOS::GetUserHomeDirectory() {
52 llvm::SmallString<64> home_dir_path;
53 llvm::sys::path::home_directory(home_dir_path);
54 FileSpec homedir(home_dir_path.c_str(), true);
56 sb_fspec.SetFileSpec(homedir);
60 lldb::thread_t SBHostOS::ThreadCreate(const char *name,
61 lldb::thread_func_t thread_function,
62 void *thread_arg, SBError *error_ptr) {
63 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
67 "SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, "
68 "thread_arg=%p, error_ptr=%p)",
70 reinterpret_cast<void *>(reinterpret_cast<intptr_t>(thread_function)),
71 static_cast<void *>(thread_arg), static_cast<void *>(error_ptr));
73 // FIXME: You should log the return value?
75 HostThread thread(ThreadLauncher::LaunchThread(
76 name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
77 return thread.Release();
80 void SBHostOS::ThreadCreated(const char *name) {}
82 bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
84 HostThread host_thread(thread);
85 error = host_thread.Cancel();
87 error_ptr->SetError(error);
88 host_thread.Release();
89 return error.Success();
92 bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
96 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
98 HostThread host_thread(thread);
99 error = host_thread.GetNativeThread().Detach();
101 error_ptr->SetError(error);
102 host_thread.Release();
104 return error.Success();
107 bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
108 SBError *error_ptr) {
110 HostThread host_thread(thread);
111 error = host_thread.Join(result);
113 error_ptr->SetError(error);
114 host_thread.Release();
115 return error.Success();