xref: /src/contrib/llvm-project/lldb/source/API/SBHostOS.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1cfca06d7SDimitry Andric //===-- SBHostOS.cpp ------------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9706b4fc4SDimitry Andric #include "lldb/API/SBHostOS.h"
10f034231aSEd Maste #include "lldb/API/SBError.h"
11706b4fc4SDimitry Andric #include "lldb/Host/Config.h"
1294994d37SDimitry Andric #include "lldb/Host/FileSystem.h"
13f034231aSEd Maste #include "lldb/Host/Host.h"
140cac4ca3SEd Maste #include "lldb/Host/HostInfo.h"
15205afe67SEd Maste #include "lldb/Host/HostNativeThread.h"
16205afe67SEd Maste #include "lldb/Host/HostThread.h"
17205afe67SEd Maste #include "lldb/Host/ThreadLauncher.h"
1874a628f7SDimitry Andric #include "lldb/Utility/FileSpec.h"
196f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
20f034231aSEd Maste 
21f73363f1SDimitry Andric #include "Plugins/ExpressionParser/Clang/ClangHost.h"
22706b4fc4SDimitry Andric #if LLDB_ENABLE_PYTHON
23f73363f1SDimitry Andric #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
24f73363f1SDimitry Andric #endif
25f73363f1SDimitry Andric 
26f3fbd1c0SDimitry Andric #include "llvm/ADT/SmallString.h"
2714f1b3e8SDimitry Andric #include "llvm/Support/Path.h"
28f3fbd1c0SDimitry Andric 
29f034231aSEd Maste using namespace lldb;
30f034231aSEd Maste using namespace lldb_private;
31f034231aSEd Maste 
GetProgramFileSpec()3214f1b3e8SDimitry Andric SBFileSpec SBHostOS::GetProgramFileSpec() {
336f8fc217SDimitry Andric   LLDB_INSTRUMENT();
345f29bb8aSDimitry Andric 
35f034231aSEd Maste   SBFileSpec sb_filespec;
360cac4ca3SEd Maste   sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
376f8fc217SDimitry Andric   return sb_filespec;
38f034231aSEd Maste }
39f034231aSEd Maste 
GetLLDBPythonPath()4014f1b3e8SDimitry Andric SBFileSpec SBHostOS::GetLLDBPythonPath() {
416f8fc217SDimitry Andric   LLDB_INSTRUMENT();
425f29bb8aSDimitry Andric 
436f8fc217SDimitry Andric   return GetLLDBPath(ePathTypePythonDir);
44f034231aSEd Maste }
45f034231aSEd Maste 
GetLLDBPath(lldb::PathType path_type)4614f1b3e8SDimitry Andric SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
476f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(path_type);
485f29bb8aSDimitry Andric 
490cac4ca3SEd Maste   FileSpec fspec;
50f73363f1SDimitry Andric   switch (path_type) {
51f73363f1SDimitry Andric   case ePathTypeLLDBShlibDir:
52f73363f1SDimitry Andric     fspec = HostInfo::GetShlibDir();
53f73363f1SDimitry Andric     break;
54f73363f1SDimitry Andric   case ePathTypeSupportExecutableDir:
55f73363f1SDimitry Andric     fspec = HostInfo::GetSupportExeDir();
56f73363f1SDimitry Andric     break;
57f73363f1SDimitry Andric   case ePathTypeHeaderDir:
58f73363f1SDimitry Andric     fspec = HostInfo::GetHeaderDir();
59f73363f1SDimitry Andric     break;
60f73363f1SDimitry Andric   case ePathTypePythonDir:
61706b4fc4SDimitry Andric #if LLDB_ENABLE_PYTHON
62f73363f1SDimitry Andric     fspec = ScriptInterpreterPython::GetPythonDir();
63f73363f1SDimitry Andric #endif
64f73363f1SDimitry Andric     break;
65f73363f1SDimitry Andric   case ePathTypeLLDBSystemPlugins:
66f73363f1SDimitry Andric     fspec = HostInfo::GetSystemPluginDir();
67f73363f1SDimitry Andric     break;
68f73363f1SDimitry Andric   case ePathTypeLLDBUserPlugins:
69f73363f1SDimitry Andric     fspec = HostInfo::GetUserPluginDir();
70f73363f1SDimitry Andric     break;
71f73363f1SDimitry Andric   case ePathTypeLLDBTempSystemDir:
72f73363f1SDimitry Andric     fspec = HostInfo::GetProcessTempDir();
73f73363f1SDimitry Andric     break;
74f73363f1SDimitry Andric   case ePathTypeGlobalLLDBTempSystemDir:
75f73363f1SDimitry Andric     fspec = HostInfo::GetGlobalTempDir();
76f73363f1SDimitry Andric     break;
77f73363f1SDimitry Andric   case ePathTypeClangDir:
78f73363f1SDimitry Andric     fspec = GetClangResourceDir();
79f73363f1SDimitry Andric     break;
80f73363f1SDimitry Andric   }
81f73363f1SDimitry Andric 
82f73363f1SDimitry Andric   SBFileSpec sb_fspec;
830cac4ca3SEd Maste   sb_fspec.SetFileSpec(fspec);
846f8fc217SDimitry Andric   return sb_fspec;
850cac4ca3SEd Maste }
860cac4ca3SEd Maste 
GetUserHomeDirectory()8714f1b3e8SDimitry Andric SBFileSpec SBHostOS::GetUserHomeDirectory() {
886f8fc217SDimitry Andric   LLDB_INSTRUMENT();
895f29bb8aSDimitry Andric 
90b60736ecSDimitry Andric   FileSpec homedir;
91b60736ecSDimitry Andric   FileSystem::Instance().GetHomeDirectory(homedir);
9294994d37SDimitry Andric   FileSystem::Instance().Resolve(homedir);
93f3fbd1c0SDimitry Andric 
94b60736ecSDimitry Andric   SBFileSpec sb_fspec;
95f3fbd1c0SDimitry Andric   sb_fspec.SetFileSpec(homedir);
96b60736ecSDimitry Andric 
976f8fc217SDimitry Andric   return sb_fspec;
98f3fbd1c0SDimitry Andric }
99f3fbd1c0SDimitry Andric 
ThreadCreate(const char * name,lldb::thread_func_t thread_function,void * thread_arg,SBError * error_ptr)10014f1b3e8SDimitry Andric lldb::thread_t SBHostOS::ThreadCreate(const char *name,
1010cac4ca3SEd Maste                                       lldb::thread_func_t thread_function,
10214f1b3e8SDimitry Andric                                       void *thread_arg, SBError *error_ptr) {
1036f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(name, thread_function, thread_arg, error_ptr);
1045f29bb8aSDimitry Andric   return LLDB_INVALID_HOST_THREAD;
105f034231aSEd Maste }
106f034231aSEd Maste 
ThreadCreated(const char * name)1076f8fc217SDimitry Andric void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); }
108f034231aSEd Maste 
ThreadCancel(lldb::thread_t thread,SBError * error_ptr)10914f1b3e8SDimitry Andric bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
1106f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(thread, error_ptr);
111b1c73532SDimitry Andric   return false;
112f034231aSEd Maste }
113f034231aSEd Maste 
ThreadDetach(lldb::thread_t thread,SBError * error_ptr)11414f1b3e8SDimitry Andric bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
1156f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(thread, error_ptr);
116b1c73532SDimitry Andric   return false;
117f034231aSEd Maste }
118f034231aSEd Maste 
ThreadJoin(lldb::thread_t thread,lldb::thread_result_t * result,SBError * error_ptr)11914f1b3e8SDimitry Andric bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
12014f1b3e8SDimitry Andric                           SBError *error_ptr) {
1216f8fc217SDimitry Andric   LLDB_INSTRUMENT_VA(thread, result, error_ptr);
122b1c73532SDimitry Andric   return false;
123f034231aSEd Maste }
124