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