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 #ifndef LLDB_DISABLE_PYTHON
11 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
14 #include "lldb/API/SBError.h"
15 #include "lldb/API/SBHostOS.h"
16 #include "lldb/Host/FileSystem.h"
17 #include "lldb/Host/Host.h"
18 #include "lldb/Host/HostInfo.h"
19 #include "lldb/Host/HostNativeThread.h"
20 #include "lldb/Host/HostThread.h"
21 #include "lldb/Host/ThreadLauncher.h"
22 #include "lldb/Utility/FileSpec.h"
23 #include "lldb/Utility/Log.h"
25 #include "Plugins/ExpressionParser/Clang/ClangHost.h"
26 #ifndef LLDB_DISABLE_PYTHON
27 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
30 #include "llvm/ADT/SmallString.h"
31 #include "llvm/Support/Path.h"
34 using namespace lldb_private;
36 SBFileSpec SBHostOS::GetProgramFileSpec() {
37 SBFileSpec sb_filespec;
38 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
42 SBFileSpec SBHostOS::GetLLDBPythonPath() {
43 return GetLLDBPath(ePathTypePythonDir);
46 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
49 case ePathTypeLLDBShlibDir:
50 fspec = HostInfo::GetShlibDir();
52 case ePathTypeSupportExecutableDir:
53 fspec = HostInfo::GetSupportExeDir();
55 case ePathTypeHeaderDir:
56 fspec = HostInfo::GetHeaderDir();
58 case ePathTypePythonDir:
59 #ifndef LLDB_DISABLE_PYTHON
60 fspec = ScriptInterpreterPython::GetPythonDir();
63 case ePathTypeLLDBSystemPlugins:
64 fspec = HostInfo::GetSystemPluginDir();
66 case ePathTypeLLDBUserPlugins:
67 fspec = HostInfo::GetUserPluginDir();
69 case ePathTypeLLDBTempSystemDir:
70 fspec = HostInfo::GetProcessTempDir();
72 case ePathTypeGlobalLLDBTempSystemDir:
73 fspec = HostInfo::GetGlobalTempDir();
75 case ePathTypeClangDir:
76 fspec = GetClangResourceDir();
81 sb_fspec.SetFileSpec(fspec);
85 SBFileSpec SBHostOS::GetUserHomeDirectory() {
88 llvm::SmallString<64> home_dir_path;
89 llvm::sys::path::home_directory(home_dir_path);
90 FileSpec homedir(home_dir_path.c_str());
91 FileSystem::Instance().Resolve(homedir);
93 sb_fspec.SetFileSpec(homedir);
97 lldb::thread_t SBHostOS::ThreadCreate(const char *name,
98 lldb::thread_func_t thread_function,
99 void *thread_arg, SBError *error_ptr) {
100 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
104 "SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, "
105 "thread_arg=%p, error_ptr=%p)",
107 reinterpret_cast<void *>(reinterpret_cast<intptr_t>(thread_function)),
108 static_cast<void *>(thread_arg), static_cast<void *>(error_ptr));
110 // FIXME: You should log the return value?
112 HostThread thread(ThreadLauncher::LaunchThread(
113 name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
114 return thread.Release();
117 void SBHostOS::ThreadCreated(const char *name) {}
119 bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
121 HostThread host_thread(thread);
122 error = host_thread.Cancel();
124 error_ptr->SetError(error);
125 host_thread.Release();
126 return error.Success();
129 bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
133 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
135 HostThread host_thread(thread);
136 error = host_thread.GetNativeThread().Detach();
138 error_ptr->SetError(error);
139 host_thread.Release();
141 return error.Success();
144 bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
145 SBError *error_ptr) {
147 HostThread host_thread(thread);
148 error = host_thread.Join(result);
150 error_ptr->SetError(error);
151 host_thread.Release();
152 return error.Success();