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/SBHostOS.h"
15 #include "lldb/API/SBError.h"
16 #include "lldb/Host/Host.h"
17 #include "lldb/Host/HostInfo.h"
18 #include "lldb/Host/HostNativeThread.h"
19 #include "lldb/Host/HostThread.h"
20 #include "lldb/Host/ThreadLauncher.h"
21 #include "lldb/Utility/FileSpec.h"
22 #include "lldb/Utility/Log.h"
24 #include "Plugins/ExpressionParser/Clang/ClangHost.h"
25 #ifndef LLDB_DISABLE_PYTHON
26 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
29 #include "llvm/ADT/SmallString.h"
30 #include "llvm/Support/Path.h"
33 using namespace lldb_private;
35 SBFileSpec SBHostOS::GetProgramFileSpec() {
36 SBFileSpec sb_filespec;
37 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
41 SBFileSpec SBHostOS::GetLLDBPythonPath() {
42 return GetLLDBPath(ePathTypePythonDir);
45 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
48 case ePathTypeLLDBShlibDir:
49 fspec = HostInfo::GetShlibDir();
51 case ePathTypeSupportExecutableDir:
52 fspec = HostInfo::GetSupportExeDir();
54 case ePathTypeHeaderDir:
55 fspec = HostInfo::GetHeaderDir();
57 case ePathTypePythonDir:
58 #ifndef LLDB_DISABLE_PYTHON
59 fspec = ScriptInterpreterPython::GetPythonDir();
62 case ePathTypeLLDBSystemPlugins:
63 fspec = HostInfo::GetSystemPluginDir();
65 case ePathTypeLLDBUserPlugins:
66 fspec = HostInfo::GetUserPluginDir();
68 case ePathTypeLLDBTempSystemDir:
69 fspec = HostInfo::GetProcessTempDir();
71 case ePathTypeGlobalLLDBTempSystemDir:
72 fspec = HostInfo::GetGlobalTempDir();
74 case ePathTypeClangDir:
75 fspec = GetClangResourceDir();
80 sb_fspec.SetFileSpec(fspec);
84 SBFileSpec SBHostOS::GetUserHomeDirectory() {
87 llvm::SmallString<64> home_dir_path;
88 llvm::sys::path::home_directory(home_dir_path);
89 FileSpec homedir(home_dir_path.c_str(), true);
91 sb_fspec.SetFileSpec(homedir);
95 lldb::thread_t SBHostOS::ThreadCreate(const char *name,
96 lldb::thread_func_t thread_function,
97 void *thread_arg, SBError *error_ptr) {
98 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
102 "SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, "
103 "thread_arg=%p, error_ptr=%p)",
105 reinterpret_cast<void *>(reinterpret_cast<intptr_t>(thread_function)),
106 static_cast<void *>(thread_arg), static_cast<void *>(error_ptr));
108 // FIXME: You should log the return value?
110 HostThread thread(ThreadLauncher::LaunchThread(
111 name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
112 return thread.Release();
115 void SBHostOS::ThreadCreated(const char *name) {}
117 bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
119 HostThread host_thread(thread);
120 error = host_thread.Cancel();
122 error_ptr->SetError(error);
123 host_thread.Release();
124 return error.Success();
127 bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
131 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
133 HostThread host_thread(thread);
134 error = host_thread.GetNativeThread().Detach();
136 error_ptr->SetError(error);
137 host_thread.Release();
139 return error.Success();
142 bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
143 SBError *error_ptr) {
145 HostThread host_thread(thread);
146 error = host_thread.Join(result);
148 error_ptr->SetError(error);
149 host_thread.Release();
150 return error.Success();