LLDB  mainline
SBHostOS.cpp
Go to the documentation of this file.
1 //===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===//
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 "SBReproducerPrivate.h"
10 #include "lldb/API/SBError.h"
11 #include "lldb/API/SBHostOS.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"
19 
21 #ifndef LLDB_DISABLE_PYTHON
23 #endif
24 
25 #include "llvm/ADT/SmallString.h"
26 #include "llvm/Support/Path.h"
27 
28 using namespace lldb;
29 using namespace lldb_private;
30 
33  GetProgramFileSpec);
34 
35  SBFileSpec sb_filespec;
36  sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
37  return LLDB_RECORD_RESULT(sb_filespec);
38 }
39 
42  GetLLDBPythonPath);
43 
44  return LLDB_RECORD_RESULT(GetLLDBPath(ePathTypePythonDir));
45 }
46 
49  (lldb::PathType), path_type);
50 
51  FileSpec fspec;
52  switch (path_type) {
54  fspec = HostInfo::GetShlibDir();
55  break;
57  fspec = HostInfo::GetSupportExeDir();
58  break;
59  case ePathTypeHeaderDir:
60  fspec = HostInfo::GetHeaderDir();
61  break;
62  case ePathTypePythonDir:
63 #ifndef LLDB_DISABLE_PYTHON
64  fspec = ScriptInterpreterPython::GetPythonDir();
65 #endif
66  break;
68  fspec = HostInfo::GetSystemPluginDir();
69  break;
71  fspec = HostInfo::GetUserPluginDir();
72  break;
74  fspec = HostInfo::GetProcessTempDir();
75  break;
77  fspec = HostInfo::GetGlobalTempDir();
78  break;
79  case ePathTypeClangDir:
80  fspec = GetClangResourceDir();
81  break;
82  }
83 
84  SBFileSpec sb_fspec;
85  sb_fspec.SetFileSpec(fspec);
86  return LLDB_RECORD_RESULT(sb_fspec);
87 }
88 
91  GetUserHomeDirectory);
92 
93  SBFileSpec sb_fspec;
94 
95  llvm::SmallString<64> home_dir_path;
96  llvm::sys::path::home_directory(home_dir_path);
97  FileSpec homedir(home_dir_path.c_str());
98  FileSystem::Instance().Resolve(homedir);
99 
100  sb_fspec.SetFileSpec(homedir);
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  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  LLDB_RECORD_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *),
117  name);
118 }
119 
121  LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadCancel,
122  (lldb::thread_t, lldb::SBError *), thread,
123  error_ptr);
124 
125  Status error;
126  HostThread host_thread(thread);
127  error = host_thread.Cancel();
128  if (error_ptr)
129  error_ptr->SetError(error);
130  host_thread.Release();
131  return error.Success();
132 }
133 
135  LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadDetach,
136  (lldb::thread_t, lldb::SBError *), thread,
137  error_ptr);
138 
139  Status error;
140 #if defined(_WIN32)
141  if (error_ptr)
142  error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
143 #else
144  HostThread host_thread(thread);
145  error = host_thread.GetNativeThread().Detach();
146  if (error_ptr)
147  error_ptr->SetError(error);
148  host_thread.Release();
149 #endif
150  return error.Success();
151 }
152 
154  SBError *error_ptr) {
156  bool, SBHostOS, ThreadJoin,
158  result, error_ptr);
159 
160  Status error;
161  HostThread host_thread(thread);
162  error = host_thread.Join(result);
163  if (error_ptr)
164  error_ptr->SetError(error);
165  host_thread.Release();
166  return error.Success();
167 }
168 
169 namespace lldb_private {
170 namespace repro {
171 
172 template <>
175  ());
177  ());
179  (lldb::PathType));
181  GetUserHomeDirectory, ());
182  LLDB_REGISTER_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *));
183 }
184 
185 }
186 }
The registry contains a unique mapping between functions and their ID.
FileSpec GetClangResourceDir()
Definition: ClangHost.cpp:155
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
static bool ThreadDetach(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:134
HostNativeThread & GetNativeThread()
Definition: HostThread.cpp:32
static lldb::SBFileSpec GetUserHomeDirectory()
Definition: SBHostOS.cpp:89
#define LLDB_RECORD_STATIC_METHOD(Result, Class, Method, Signature,...)
#define LLDB_RECORD_DUMMY(Result, Class, Method, Signature,...)
The LLDB_RECORD_DUMMY macro is special because it doesn&#39;t actually record anything.
#define LLDB_RECORD_STATIC_METHOD_NO_ARGS(Result, Class, Method)
A file utility class.
Definition: FileSpec.h:55
#define LLDB_REGISTER_STATIC_METHOD(Result, Class, Method, Signature)
static lldb::SBFileSpec GetProgramFileSpec()
Definition: SBHostOS.cpp:31
void *(* thread_func_t)(void *)
Definition: lldb-types.h:63
static bool ThreadCancel(lldb::thread_t thread, lldb::SBError *err)
Definition: SBHostOS.cpp:120
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:241
static void ThreadCreated(const char *name)
Definition: SBHostOS.cpp:115
bool Success() const
Test for success condition.
Definition: Status.cpp:287
Status Join(lldb::thread_result_t *result)
Definition: HostThread.cpp:20
lldb::thread_t Release()
Definition: HostThread.cpp:28
static lldb::SBFileSpec GetLLDBPythonPath()
Definition: SBHostOS.cpp:40
void RegisterMethods< SBHostOS >(Registry &R)
Definition: SBHostOS.cpp:173
pthread_t thread_t
Definition: lldb-types.h:58
static lldb::thread_t ThreadCreate(const char *name, lldb::thread_func_t thread_function, void *thread_arg, lldb::SBError *err)
Definition: SBHostOS.cpp:104
int void SetError(ValueType err, lldb::ErrorType type)
Set accesssor with an error value and type.
Definition: Status.cpp:216
static bool ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, lldb::SBError *err)
Definition: SBHostOS.cpp:153
Definition: SBAddress.h:15
static lldb::SBFileSpec GetLLDBPath(lldb::PathType path_type)
Definition: SBHostOS.cpp:47
#define LLDB_RECORD_RESULT(Result)
An error handling class.
Definition: Status.h:44
void * thread_result_t
Definition: lldb-types.h:62