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 "lldb/API/SBError.h"
11 #include "lldb/Host/Config.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/Host.h"
14 #include "lldb/Host/HostInfo.h"
16 #include "lldb/Host/HostThread.h"
18 #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 
35  SBFileSpec sb_filespec;
36  sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
37  return sb_filespec;
38 }
39 
42 
43  return GetLLDBPath(ePathTypePythonDir);
44 }
45 
47  LLDB_INSTRUMENT_VA(path_type);
48 
49  FileSpec fspec;
50  switch (path_type) {
52  fspec = HostInfo::GetShlibDir();
53  break;
55  fspec = HostInfo::GetSupportExeDir();
56  break;
57  case ePathTypeHeaderDir:
58  fspec = HostInfo::GetHeaderDir();
59  break;
60  case ePathTypePythonDir:
61 #if LLDB_ENABLE_PYTHON
62  fspec = ScriptInterpreterPython::GetPythonDir();
63 #endif
64  break;
66  fspec = HostInfo::GetSystemPluginDir();
67  break;
69  fspec = HostInfo::GetUserPluginDir();
70  break;
72  fspec = HostInfo::GetProcessTempDir();
73  break;
75  fspec = HostInfo::GetGlobalTempDir();
76  break;
77  case ePathTypeClangDir:
78  fspec = GetClangResourceDir();
79  break;
80  }
81 
82  SBFileSpec sb_fspec;
83  sb_fspec.SetFileSpec(fspec);
84  return sb_fspec;
85 }
86 
89 
90  FileSpec homedir;
91  FileSystem::Instance().GetHomeDirectory(homedir);
92  FileSystem::Instance().Resolve(homedir);
93 
94  SBFileSpec sb_fspec;
95  sb_fspec.SetFileSpec(homedir);
96 
97  return sb_fspec;
98 }
99 
101  lldb::thread_func_t thread_function,
102  void *thread_arg, SBError *error_ptr) {
103  LLDB_INSTRUMENT_VA(name, thread_function, thread_arg, error_ptr);
104  llvm::Expected<HostThread> thread =
105  ThreadLauncher::LaunchThread(name, thread_function, thread_arg);
106  if (!thread) {
107  if (error_ptr)
108  error_ptr->SetError(Status(thread.takeError()));
109  else
110  llvm::consumeError(thread.takeError());
112  }
113 
114  return thread->Release();
115 }
116 
117 void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); }
118 
120  LLDB_INSTRUMENT_VA(thread, error_ptr);
121 
122  Status error;
123  HostThread host_thread(thread);
124  error = host_thread.Cancel();
125  if (error_ptr)
126  error_ptr->SetError(error);
127  host_thread.Release();
128  return error.Success();
129 }
130 
132  LLDB_INSTRUMENT_VA(thread, error_ptr);
133 
134  Status error;
135 #if defined(_WIN32)
136  if (error_ptr)
137  error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
138 #else
139  HostThread host_thread(thread);
140  error = host_thread.GetNativeThread().Detach();
141  if (error_ptr)
142  error_ptr->SetError(error);
143  host_thread.Release();
144 #endif
145  return error.Success();
146 }
147 
149  SBError *error_ptr) {
150  LLDB_INSTRUMENT_VA(thread, result, error_ptr);
151 
152  Status error;
153  HostThread host_thread(thread);
154  error = host_thread.Join(result);
155  if (error_ptr)
156  error_ptr->SetError(error);
157  host_thread.Release();
158  return error.Success();
159 }
Instrumentation.h
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::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
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:100
lldb::SBError
Definition: SBError.h:20
lldb::SBHostOS::ThreadDetach
static bool ThreadDetach(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:131
lldb_private::GetClangResourceDir
FileSpec GetClangResourceDir()
Definition: ClangHost.cpp:153
LLDB_INSTRUMENT
#define LLDB_INSTRUMENT()
Definition: Instrumentation.h:97
ClangHost.h
ThreadLauncher.h
lldb::SBFileSpec::SetFileSpec
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
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::SBHostOS::GetProgramFileSpec
static lldb::SBFileSpec GetProgramFileSpec()
Definition: SBHostOS.cpp:32
lldb::SBHostOS::GetUserHomeDirectory
static lldb::SBFileSpec GetUserHomeDirectory()
Definition: SBHostOS.cpp:87
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:46
lldb::SBHostOS::ThreadJoin
static bool ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, lldb::SBError *err)
Definition: SBHostOS.cpp:148
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:119
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:117
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_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:100
HostNativeThread.h
lldb
Definition: SBAddress.h:15
lldb::SBHostOS::GetLLDBPythonPath
static lldb::SBFileSpec GetLLDBPythonPath()
Definition: SBHostOS.cpp:40
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