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"
13#include "lldb/Host/Host.h"
14#include "lldb/Host/HostInfo.h"
20
22#if LLDB_ENABLE_PYTHON
24#endif
25
26#include "llvm/ADT/SmallString.h"
27#include "llvm/Support/Path.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
34
35 SBFileSpec sb_filespec;
36 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
37 return sb_filespec;
38}
39
42
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;
58 fspec = HostInfo::GetHeaderDir();
59 break;
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;
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;
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
119void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); }
120
122 LLDB_INSTRUMENT_VA(thread, error_ptr);
123
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
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
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}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
void SetFileSpec(const lldb_private::FileSpec &fspec)
Definition: SBFileSpec.cpp:164
static lldb::SBFileSpec GetUserHomeDirectory()
Definition: SBHostOS.cpp:87
static lldb::SBFileSpec GetProgramFileSpec()
Definition: SBHostOS.cpp:32
static lldb::thread_t ThreadCreate(const char *name, lldb::thread_func_t thread_function, void *thread_arg, lldb::SBError *err)
Definition: SBHostOS.cpp:100
static lldb::SBFileSpec GetLLDBPythonPath()
Definition: SBHostOS.cpp:40
static bool ThreadDetach(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:133
static void ThreadCreated(const char *name)
Definition: SBHostOS.cpp:119
static bool ThreadCancel(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:121
static bool ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, lldb::SBError *err)
Definition: SBHostOS.cpp:150
static lldb::SBFileSpec GetLLDBPath(lldb::PathType path_type)
Definition: SBHostOS.cpp:46
A file utility class.
Definition: FileSpec.h:56
void Resolve(llvm::SmallVectorImpl< char > &path)
Resolve path to make it canonical.
bool GetHomeDirectory(llvm::SmallVectorImpl< char > &path) const
Get the user home directory.
static FileSystem & Instance()
Status Join(lldb::thread_result_t *result)
Definition: HostThread.cpp:20
lldb::thread_t Release()
Definition: HostThread.cpp:28
HostNativeThread & GetNativeThread()
Definition: HostThread.cpp:32
An error handling class.
Definition: Status.h:44
int void SetError(ValueType err, lldb::ErrorType type)
Set accessor with an error value and type.
Definition: Status.cpp:216
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
static llvm::Expected< HostThread > LaunchThread(llvm::StringRef name, std::function< lldb::thread_result_t()> thread_function, size_t min_stack_byte_size=0)
#define LLDB_INVALID_HOST_THREAD
Definition: lldb-types.h:69
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
FileSpec GetClangResourceDir()
Definition: ClangHost.cpp:159
Definition: SBAddress.h:15
void * thread_result_t
Definition: lldb-types.h:62
PathType
Used with SBHostOS::GetLLDBPath (lldb::PathType) to find files that are related to LLDB on the curren...
@ ePathTypeGlobalLLDBTempSystemDir
The LLDB temp directory for this system, NOT cleaned up on a process exit.
@ ePathTypeHeaderDir
Find LLDB header file directory.
@ ePathTypeLLDBSystemPlugins
System plug-ins directory.
@ ePathTypeLLDBTempSystemDir
The LLDB temp directory for this system that will be cleaned up on exit.
@ ePathTypeClangDir
Find path to Clang builtin headers.
@ ePathTypeLLDBUserPlugins
User plug-ins directory.
@ ePathTypeSupportExecutableDir
Find LLDB support executable directory (debugserver, etc)
@ ePathTypePythonDir
Find Python modules (PYTHONPATH) directory.
@ ePathTypeLLDBShlibDir
The directory where the lldb.so (unix) or LLDB mach-o file in LLDB.framework (MacOSX) exists.
pthread_t thread_t
Definition: lldb-types.h:58
void *(* thread_func_t)(void *)
Definition: lldb-types.h:63