]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/API/SBHostOS.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / API / SBHostOS.cpp
1 //===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLDB_DISABLE_PYTHON
11 #include "Plugins/ScriptInterpreter/Python/lldb-python.h"
12 #endif
13
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"
23
24 #include "Plugins/ExpressionParser/Clang/ClangHost.h"
25 #ifndef LLDB_DISABLE_PYTHON
26 #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
27 #endif
28
29 #include "llvm/ADT/SmallString.h"
30 #include "llvm/Support/Path.h"
31
32 using namespace lldb;
33 using namespace lldb_private;
34
35 SBFileSpec SBHostOS::GetProgramFileSpec() {
36   SBFileSpec sb_filespec;
37   sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
38   return sb_filespec;
39 }
40
41 SBFileSpec SBHostOS::GetLLDBPythonPath() {
42   return GetLLDBPath(ePathTypePythonDir);
43 }
44
45 SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
46   FileSpec fspec;
47   switch (path_type) {
48   case ePathTypeLLDBShlibDir:
49     fspec = HostInfo::GetShlibDir();
50     break;
51   case ePathTypeSupportExecutableDir:
52     fspec = HostInfo::GetSupportExeDir();
53     break;
54   case ePathTypeHeaderDir:
55     fspec = HostInfo::GetHeaderDir();
56     break;
57   case ePathTypePythonDir:
58 #ifndef LLDB_DISABLE_PYTHON
59     fspec = ScriptInterpreterPython::GetPythonDir();
60 #endif
61     break;
62   case ePathTypeLLDBSystemPlugins:
63     fspec = HostInfo::GetSystemPluginDir();
64     break;
65   case ePathTypeLLDBUserPlugins:
66     fspec = HostInfo::GetUserPluginDir();
67     break;
68   case ePathTypeLLDBTempSystemDir:
69     fspec = HostInfo::GetProcessTempDir();
70     break;
71   case ePathTypeGlobalLLDBTempSystemDir:
72     fspec = HostInfo::GetGlobalTempDir();
73     break;
74   case ePathTypeClangDir:
75     fspec = GetClangResourceDir();
76     break;
77   }
78
79   SBFileSpec sb_fspec;
80   sb_fspec.SetFileSpec(fspec);
81   return sb_fspec;
82 }
83
84 SBFileSpec SBHostOS::GetUserHomeDirectory() {
85   SBFileSpec sb_fspec;
86
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);
90
91   sb_fspec.SetFileSpec(homedir);
92   return sb_fspec;
93 }
94
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));
99
100   if (log)
101     log->Printf(
102         "SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, "
103         "thread_arg=%p, error_ptr=%p)",
104         name,
105         reinterpret_cast<void *>(reinterpret_cast<intptr_t>(thread_function)),
106         static_cast<void *>(thread_arg), static_cast<void *>(error_ptr));
107
108   // FIXME: You should log the return value?
109
110   HostThread thread(ThreadLauncher::LaunchThread(
111       name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
112   return thread.Release();
113 }
114
115 void SBHostOS::ThreadCreated(const char *name) {}
116
117 bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
118   Status error;
119   HostThread host_thread(thread);
120   error = host_thread.Cancel();
121   if (error_ptr)
122     error_ptr->SetError(error);
123   host_thread.Release();
124   return error.Success();
125 }
126
127 bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
128   Status error;
129 #if defined(_WIN32)
130   if (error_ptr)
131     error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
132 #else
133   HostThread host_thread(thread);
134   error = host_thread.GetNativeThread().Detach();
135   if (error_ptr)
136     error_ptr->SetError(error);
137   host_thread.Release();
138 #endif
139   return error.Success();
140 }
141
142 bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
143                           SBError *error_ptr) {
144   Status error;
145   HostThread host_thread(thread);
146   error = host_thread.Join(result);
147   if (error_ptr)
148     error_ptr->SetError(error);
149   host_thread.Release();
150   return error.Success();
151 }