| 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" |
| 15 | #include "lldb/Host/HostNativeThread.h" |
| 16 | #include "lldb/Host/HostThread.h" |
| 17 | #include "lldb/Host/ThreadLauncher.h" |
| 18 | #include "lldb/Utility/FileSpec.h" |
| 19 | #include "lldb/Utility/Instrumentation.h" |
| 20 | |
| 21 | #include "Plugins/ExpressionParser/Clang/ClangHost.h" |
| 22 | #if LLDB_ENABLE_PYTHON |
| 23 | #include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h" |
| 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 | |
| 32 | SBFileSpec SBHostOS::GetProgramFileSpec() { |
| 33 | LLDB_INSTRUMENT(); |
| 34 | |
| 35 | SBFileSpec sb_filespec; |
| 36 | sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec()); |
| 37 | return sb_filespec; |
| 38 | } |
| 39 | |
| 40 | SBFileSpec SBHostOS::GetLLDBPythonPath() { |
| 41 | LLDB_INSTRUMENT(); |
| 42 | |
| 43 | return GetLLDBPath(path_type: ePathTypePythonDir); |
| 44 | } |
| 45 | |
| 46 | SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) { |
| 47 | LLDB_INSTRUMENT_VA(path_type); |
| 48 | |
| 49 | FileSpec fspec; |
| 50 | switch (path_type) { |
| 51 | case ePathTypeLLDBShlibDir: |
| 52 | fspec = HostInfo::GetShlibDir(); |
| 53 | break; |
| 54 | case ePathTypeSupportExecutableDir: |
| 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; |
| 65 | case ePathTypeLLDBSystemPlugins: |
| 66 | fspec = HostInfo::GetSystemPluginDir(); |
| 67 | break; |
| 68 | case ePathTypeLLDBUserPlugins: |
| 69 | fspec = HostInfo::GetUserPluginDir(); |
| 70 | break; |
| 71 | case ePathTypeLLDBTempSystemDir: |
| 72 | fspec = HostInfo::GetProcessTempDir(); |
| 73 | break; |
| 74 | case ePathTypeGlobalLLDBTempSystemDir: |
| 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 | |
| 87 | SBFileSpec SBHostOS::GetUserHomeDirectory() { |
| 88 | LLDB_INSTRUMENT(); |
| 89 | |
| 90 | FileSpec homedir; |
| 91 | FileSystem::Instance().GetHomeDirectory(file_spec&: homedir); |
| 92 | FileSystem::Instance().Resolve(file_spec&: homedir); |
| 93 | |
| 94 | SBFileSpec sb_fspec; |
| 95 | sb_fspec.SetFileSpec(homedir); |
| 96 | |
| 97 | return sb_fspec; |
| 98 | } |
| 99 | |
| 100 | lldb::thread_t SBHostOS::ThreadCreate(const char *name, |
| 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 | return LLDB_INVALID_HOST_THREAD; |
| 105 | } |
| 106 | |
| 107 | void SBHostOS::ThreadCreated(const char *name) { LLDB_INSTRUMENT_VA(name); } |
| 108 | |
| 109 | bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) { |
| 110 | LLDB_INSTRUMENT_VA(thread, error_ptr); |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) { |
| 115 | LLDB_INSTRUMENT_VA(thread, error_ptr); |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result, |
| 120 | SBError *error_ptr) { |
| 121 | LLDB_INSTRUMENT_VA(thread, result, error_ptr); |
| 122 | return false; |
| 123 | } |
| 124 | |