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  return thread_function(thread_arg);
107  });
108  if (!thread) {
109  if (error_ptr)
110  error_ptr->SetError(Status(thread.takeError()));
111  else
112  llvm::consumeError(thread.takeError());
114  }
115 
116  return thread->Release();
117 }
118 
119 void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); }
120 
122  LLDB_INSTRUMENT_VA(thread, error_ptr);
123 
124  Status error;
125  HostThread host_thread(thread);
126  error = host_thread.Cancel();
127  if (error_ptr)
128  error_ptr->SetError(error);
129  host_thread.Release();
130  return error.Success();
131 }
132 
134  LLDB_INSTRUMENT_VA(thread, error_ptr);
135 
136  Status error;
137 #if defined(_WIN32)
138  if (error_ptr)
139  error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
140 #else
141  HostThread host_thread(thread);
142  error = host_thread.GetNativeThread().Detach();
143  if (error_ptr)
144  error_ptr->SetError(error);
145  host_thread.Release();
146 #endif
147  return error.Success();
148 }
149 
151  SBError *error_ptr) {
152  LLDB_INSTRUMENT_VA(thread, result, error_ptr);
153 
154  Status error;
155  HostThread host_thread(thread);
156  error = host_thread.Join(result);
157  if (error_ptr)
158  error_ptr->SetError(error);
159  host_thread.Release();
160  return error.Success();
161 }
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:216
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:133
lldb_private::GetClangResourceDir
FileSpec GetClangResourceDir()
Definition: ClangHost.cpp:154
LLDB_INSTRUMENT
#define LLDB_INSTRUMENT()
Definition: Instrumentation.h:95
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:1019
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:1033
lldb::ePathTypeGlobalLLDBTempSystemDir
@ ePathTypeGlobalLLDBTempSystemDir
The LLDB temp directory for this system, NOT cleaned up on a process exit.
Definition: lldb-enumerations.h:1030
lldb_private::HostThread::Cancel
Status Cancel()
Definition: HostThread.cpp:24
lldb::ePathTypeLLDBUserPlugins
@ ePathTypeLLDBUserPlugins
User plug-ins directory.
Definition: lldb-enumerations.h:1027
lldb::ePathTypeSupportExecutableDir
@ ePathTypeSupportExecutableDir
Find LLDB support executable directory (debugserver, etc)
Definition: lldb-enumerations.h:1022
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:1028
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:150
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:121
lldb::ePathTypeLLDBSystemPlugins
@ ePathTypeLLDBSystemPlugins
System plug-ins directory.
Definition: lldb-enumerations.h:1026
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:241
lldb::SBFileSpec
Definition: SBFileSpec.h:16
lldb::SBHostOS::ThreadCreated
static void ThreadCreated(const char *name)
Definition: SBHostOS.cpp:119
lldb::ePathTypePythonDir
@ ePathTypePythonDir
Find Python modules (PYTHONPATH) directory.
Definition: lldb-enumerations.h:1025
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:1020
FileSpec.h
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
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:1024