LLDB  mainline
SBHostOS.cpp
Go to the documentation of this file.
1 //===-- SBHostOS.cpp ------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/API/SBHostOS.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBError.h"
12 #include "lldb/Host/Config.h"
13 #include "lldb/Host/FileSystem.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Host/HostInfo.h"
17 #include "lldb/Host/HostThread.h"
19 #include "lldb/Utility/FileSpec.h"
20 
22 #if LLDB_ENABLE_PYTHON
24 #endif
25 
26 #include "llvm/ADT/SmallString.h"
27 #include "llvm/Support/Path.h"
28 
29 using namespace lldb;
30 using namespace lldb_private;
31 
34  GetProgramFileSpec);
35 
36  SBFileSpec sb_filespec;
37  sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
38  return LLDB_RECORD_RESULT(sb_filespec);
39 }
40 
43  GetLLDBPythonPath);
44 
45  return LLDB_RECORD_RESULT(GetLLDBPath(ePathTypePythonDir));
46 }
47 
50  (lldb::PathType), path_type);
51 
52  FileSpec fspec;
53  switch (path_type) {
55  fspec = HostInfo::GetShlibDir();
56  break;
58  fspec = HostInfo::GetSupportExeDir();
59  break;
60  case ePathTypeHeaderDir:
61  fspec = HostInfo::GetHeaderDir();
62  break;
63  case ePathTypePythonDir:
64 #if LLDB_ENABLE_PYTHON
65  fspec = ScriptInterpreterPython::GetPythonDir();
66 #endif
67  break;
69  fspec = HostInfo::GetSystemPluginDir();
70  break;
72  fspec = HostInfo::GetUserPluginDir();
73  break;
75  fspec = HostInfo::GetProcessTempDir();
76  break;
78  fspec = HostInfo::GetGlobalTempDir();
79  break;
80  case ePathTypeClangDir:
81  fspec = GetClangResourceDir();
82  break;
83  }
84 
85  SBFileSpec sb_fspec;
86  sb_fspec.SetFileSpec(fspec);
87  return LLDB_RECORD_RESULT(sb_fspec);
88 }
89 
92  GetUserHomeDirectory);
93 
94  FileSpec homedir;
95  FileSystem::Instance().GetHomeDirectory(homedir);
96  FileSystem::Instance().Resolve(homedir);
97 
98  SBFileSpec sb_fspec;
99  sb_fspec.SetFileSpec(homedir);
100 
101  return LLDB_RECORD_RESULT(sb_fspec);
102 }
103 
105  lldb::thread_func_t thread_function,
106  void *thread_arg, SBError *error_ptr) {
108  (lldb::thread_func_t, void *, SBError *), name,
109  thread_function, thread_arg, error_ptr);
110  llvm::Expected<HostThread> thread =
111  ThreadLauncher::LaunchThread(name, thread_function, thread_arg);
112  if (!thread) {
113  if (error_ptr)
114  error_ptr->SetError(Status(thread.takeError()));
115  else
116  llvm::consumeError(thread.takeError());
118  }
119 
120  return thread->Release();
121 }
122 
123 void SBHostOS::ThreadCreated(const char *name) {
124  LLDB_RECORD_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *),
125  name);
126 }
127 
129  LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadCancel,
130  (lldb::thread_t, lldb::SBError *), thread,
131  error_ptr);
132 
133  Status error;
134  HostThread host_thread(thread);
135  error = host_thread.Cancel();
136  if (error_ptr)
137  error_ptr->SetError(error);
138  host_thread.Release();
139  return error.Success();
140 }
141 
143  LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadDetach,
144  (lldb::thread_t, lldb::SBError *), thread,
145  error_ptr);
146 
147  Status error;
148 #if defined(_WIN32)
149  if (error_ptr)
150  error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
151 #else
152  HostThread host_thread(thread);
153  error = host_thread.GetNativeThread().Detach();
154  if (error_ptr)
155  error_ptr->SetError(error);
156  host_thread.Release();
157 #endif
158  return error.Success();
159 }
160 
162  SBError *error_ptr) {
164  bool, SBHostOS, ThreadJoin,
166  result, error_ptr);
167 
168  Status error;
169  HostThread host_thread(thread);
170  error = host_thread.Join(result);
171  if (error_ptr)
172  error_ptr->SetError(error);
173  host_thread.Release();
174  return error.Success();
175 }
176 
177 namespace lldb_private {
178 namespace repro {
179 
180 template <>
183  ());
185  ());
187  (lldb::PathType));
189  GetUserHomeDirectory, ());
190  LLDB_REGISTER_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *));
191 }
192 
193 }
194 }
LLDB_RECORD_STATIC_METHOD_NO_ARGS
#define LLDB_RECORD_STATIC_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:174
lldb_private::Status::SetError
int void SetError(ValueType err, lldb::ErrorType type)
Set accessor with an error value and type.
Definition: Status.cpp:217
lldb_private::repro::RegisterMethods< SBHostOS >
void RegisterMethods< SBHostOS >(Registry &R)
Definition: SBHostOS.cpp:181
lldb::thread_func_t
void *(* thread_func_t)(void *)
Definition: lldb-types.h:63
lldb_private::HostThread::GetNativeThread
HostNativeThread & GetNativeThread()
Definition: HostThread.cpp:32
FileSystem.h
lldb_private::HostThread
Definition: HostThread.h:29
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
Host.h
lldb::SBHostOS::ThreadCreate
static lldb::thread_t ThreadCreate(const char *name, lldb::thread_func_t thread_function, void *thread_arg, lldb::SBError *err)
Definition: SBHostOS.cpp:104
lldb::SBError
Definition: SBError.h:20
lldb::SBHostOS::ThreadDetach
static bool ThreadDetach(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:142
lldb_private::GetClangResourceDir
FileSpec GetClangResourceDir()
Definition: ClangHost.cpp:153
SBReproducerPrivate.h
lldb::SBHostOS
Definition: SBHostOS.h:17
ClangHost.h
ThreadLauncher.h
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:170
lldb::PathType
PathType
Used with SBHostOS::GetLLDBPath (lldb::PathType) to find files that are related to LLDB on the curren...
Definition: lldb-enumerations.h:1000
lldb_private::HostThread::Release
lldb::thread_t Release()
Definition: HostThread.cpp:28
lldb_private::FileSpec
Definition: FileSpec.h:56
error
static llvm::raw_ostream & error(Stream &strm)
Definition: CommandReturnObject.cpp:17
HostThread.h
lldb::thread_t
pthread_t thread_t
Definition: lldb-types.h:58
lldb::ePathTypeClangDir
@ ePathTypeClangDir
Find path to Clang builtin headers.
Definition: lldb-enumerations.h:1014
lldb::ePathTypeGlobalLLDBTempSystemDir
@ ePathTypeGlobalLLDBTempSystemDir
The LLDB temp directory for this system, NOT cleaned up on a process exit.
Definition: lldb-enumerations.h:1011
lldb_private::HostThread::Cancel
Status Cancel()
Definition: HostThread.cpp:24
lldb::ePathTypeLLDBUserPlugins
@ ePathTypeLLDBUserPlugins
User plug-ins directory.
Definition: lldb-enumerations.h:1008
lldb::ePathTypeSupportExecutableDir
@ ePathTypeSupportExecutableDir
Find LLDB support executable directory (debugserver, etc)
Definition: lldb-enumerations.h:1003
ScriptInterpreterPython.h
SBHostOS.h
HostInfo.h
LLDB_REGISTER_STATIC_METHOD
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:103
lldb::SBHostOS::GetProgramFileSpec
static lldb::SBFileSpec GetProgramFileSpec()
Definition: SBHostOS.cpp:32
lldb::SBHostOS::GetUserHomeDirectory
static lldb::SBFileSpec GetUserHomeDirectory()
Definition: SBHostOS.cpp:90
lldb::ePathTypeLLDBTempSystemDir
@ ePathTypeLLDBTempSystemDir
The LLDB temp directory for this system that will be cleaned up on exit.
Definition: lldb-enumerations.h:1009
lldb::SBHostOS::GetLLDBPath
static lldb::SBFileSpec GetLLDBPath(lldb::PathType path_type)
Definition: SBHostOS.cpp:48
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBHostOS::ThreadJoin
static bool ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, lldb::SBError *err)
Definition: SBHostOS.cpp:161
lldb_private::HostThread::Join
Status Join(lldb::thread_result_t *result)
Definition: HostThread.cpp:20
lldb_private::Status
Definition: Status.h:44
lldb::SBHostOS::ThreadCancel
static bool ThreadCancel(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:128
lldb::ePathTypeLLDBSystemPlugins
@ ePathTypeLLDBSystemPlugins
System plug-ins directory.
Definition: lldb-enumerations.h:1007
lldb::thread_result_t
void * thread_result_t
Definition: lldb-types.h:62
lldb_private::HostThreadPosix::Detach
Status Detach()
Definition: HostThreadPosix.cpp:53
lldb_private::Status::SetErrorString
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:242
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb::SBHostOS::ThreadCreated
static void ThreadCreated(const char *name)
Definition: SBHostOS.cpp:123
lldb::ePathTypePythonDir
@ ePathTypePythonDir
Find Python modules (PYTHONPATH) directory.
Definition: lldb-enumerations.h:1006
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::ePathTypeLLDBShlibDir
@ ePathTypeLLDBShlibDir
The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists.
Definition: lldb-enumerations.h:1001
FileSpec.h
LLDB_RECORD_STATIC_METHOD
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:171
LLDB_RECORD_DUMMY
#define LLDB_RECORD_DUMMY(Result, Class, Method, Signature,...)
The LLDB_RECORD_DUMMY macro is special because it doesn't actually record anything.
Definition: ReproducerInstrumentation.h:216
HostNativeThread.h
lldb
Definition: SBAddress.h:15
lldb::SBHostOS::GetLLDBPythonPath
static lldb::SBFileSpec GetLLDBPythonPath()
Definition: SBHostOS.cpp:41
SBError.h
LLDB_INVALID_HOST_THREAD
#define LLDB_INVALID_HOST_THREAD
Definition: lldb-types.h:79
lldb::ePathTypeHeaderDir
@ ePathTypeHeaderDir
Find LLDB header file directory.
Definition: lldb-enumerations.h:1005