Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/API/SBHostOS.h" |
| 11 | #include "lldb/API/SBError.h" |
Greg Clayton | 53239f0 | 2011-02-08 05:05:52 +0000 | [diff] [blame] | 12 | #include "lldb/Host/FileSpec.h" |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 14 | #include "lldb/Host/Host.h" |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 15 | #include "lldb/Host/HostInfo.h" |
Zachary Turner | c301899 | 2014-11-17 22:42:57 +0000 | [diff] [blame] | 16 | #include "lldb/Host/HostNativeThread.h" |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 17 | #include "lldb/Host/HostThread.h" |
| 18 | #include "lldb/Host/ThreadLauncher.h" |
| 19 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
| 23 | |
| 24 | |
| 25 | SBFileSpec |
| 26 | SBHostOS::GetProgramFileSpec () |
| 27 | { |
| 28 | SBFileSpec sb_filespec; |
Zachary Turner | a21fee0 | 2014-08-21 21:49:24 +0000 | [diff] [blame] | 29 | sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 30 | return sb_filespec; |
| 31 | } |
| 32 | |
Jim Ingham | e2231ac | 2012-12-21 22:22:26 +0000 | [diff] [blame] | 33 | SBFileSpec |
| 34 | SBHostOS::GetLLDBPythonPath () |
| 35 | { |
| 36 | SBFileSpec sb_lldb_python_filespec; |
| 37 | FileSpec lldb_python_spec; |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 38 | if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec)) |
Jim Ingham | e2231ac | 2012-12-21 22:22:26 +0000 | [diff] [blame] | 39 | { |
| 40 | sb_lldb_python_filespec.SetFileSpec (lldb_python_spec); |
| 41 | } |
| 42 | return sb_lldb_python_filespec; |
| 43 | } |
| 44 | |
Greg Clayton | 06357c9 | 2014-07-30 17:38:47 +0000 | [diff] [blame] | 45 | |
| 46 | SBFileSpec |
| 47 | SBHostOS::GetLLDBPath (lldb::PathType path_type) |
| 48 | { |
| 49 | SBFileSpec sb_fspec; |
| 50 | FileSpec fspec; |
Zachary Turner | 42ff0ad | 2014-08-21 17:29:12 +0000 | [diff] [blame] | 51 | if (HostInfo::GetLLDBPath(path_type, fspec)) |
Greg Clayton | 06357c9 | 2014-07-30 17:38:47 +0000 | [diff] [blame] | 52 | sb_fspec.SetFileSpec (fspec); |
| 53 | return sb_fspec; |
| 54 | } |
| 55 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | lldb::thread_t |
| 57 | SBHostOS::ThreadCreate |
| 58 | ( |
| 59 | const char *name, |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 60 | lldb::thread_func_t thread_function, |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | void *thread_arg, |
| 62 | SBError *error_ptr |
| 63 | ) |
| 64 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 65 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 66 | |
| 67 | if (log) |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 68 | log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)", |
David Majnemer | 702c1d09 | 2014-07-22 22:00:04 +0000 | [diff] [blame] | 69 | name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)), |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 70 | static_cast<void*>(thread_arg), |
| 71 | static_cast<void*>(error_ptr)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 72 | |
Caroline Tice | c1338e8 | 2011-06-14 16:36:12 +0000 | [diff] [blame] | 73 | // FIXME: You should log the return value? |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 74 | |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 75 | HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL)); |
| 76 | return thread.Release(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void |
| 80 | SBHostOS::ThreadCreated (const char *name) |
| 81 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | bool |
| 85 | SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr) |
| 86 | { |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 87 | Error error; |
| 88 | HostThread host_thread(thread); |
| 89 | error = host_thread.Cancel(); |
| 90 | if (error_ptr) |
| 91 | error_ptr->SetError(error); |
| 92 | host_thread.Release(); |
| 93 | return error.Success(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | bool |
| 97 | SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr) |
| 98 | { |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 99 | Error error; |
| 100 | #if defined(_WIN32) |
| 101 | if (error_ptr) |
| 102 | error_ptr->SetErrorString("ThreadDetach is not supported on this platform"); |
| 103 | #else |
| 104 | HostThread host_thread(thread); |
Zachary Turner | c301899 | 2014-11-17 22:42:57 +0000 | [diff] [blame] | 105 | error = host_thread.GetNativeThread().Detach(); |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 106 | if (error_ptr) |
| 107 | error_ptr->SetError(error); |
| 108 | host_thread.Release(); |
| 109 | #endif |
| 110 | return error.Success(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | bool |
Deepak Panickal | 99fbc07 | 2014-03-03 15:39:47 +0000 | [diff] [blame] | 114 | SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | { |
Zachary Turner | 39de311 | 2014-09-09 20:54:56 +0000 | [diff] [blame] | 116 | Error error; |
| 117 | HostThread host_thread(thread); |
| 118 | error = host_thread.Join(result); |
| 119 | if (error_ptr) |
| 120 | error_ptr->SetError(error); |
| 121 | host_thread.Release(); |
| 122 | return error.Success(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | |