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"
12 #include "lldb/Host/FileSpec.h"
13 #include "lldb/Core/Log.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Host/HostInfo.h"
16 #include "lldb/Host/HostNativeThread.h"
17 #include "lldb/Host/HostThread.h"
18 #include "lldb/Host/ThreadLauncher.h"
19
20 using namespace lldb;
21 using namespace lldb_private;
22
23
24
25 SBFileSpec
GetProgramFileSpec()26 SBHostOS::GetProgramFileSpec ()
27 {
28 SBFileSpec sb_filespec;
29 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
30 return sb_filespec;
31 }
32
33 SBFileSpec
GetLLDBPythonPath()34 SBHostOS::GetLLDBPythonPath ()
35 {
36 SBFileSpec sb_lldb_python_filespec;
37 FileSpec lldb_python_spec;
38 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
39 {
40 sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
41 }
42 return sb_lldb_python_filespec;
43 }
44
45
46 SBFileSpec
GetLLDBPath(lldb::PathType path_type)47 SBHostOS::GetLLDBPath (lldb::PathType path_type)
48 {
49 SBFileSpec sb_fspec;
50 FileSpec fspec;
51 if (HostInfo::GetLLDBPath(path_type, fspec))
52 sb_fspec.SetFileSpec (fspec);
53 return sb_fspec;
54 }
55
56 lldb::thread_t
ThreadCreate(const char * name,lldb::thread_func_t thread_function,void * thread_arg,SBError * error_ptr)57 SBHostOS::ThreadCreate
58 (
59 const char *name,
60 lldb::thread_func_t thread_function,
61 void *thread_arg,
62 SBError *error_ptr
63 )
64 {
65 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
66
67 if (log)
68 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
69 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
70 static_cast<void*>(thread_arg),
71 static_cast<void*>(error_ptr));
72
73 // FIXME: You should log the return value?
74
75 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
76 return thread.Release();
77 }
78
79 void
ThreadCreated(const char * name)80 SBHostOS::ThreadCreated (const char *name)
81 {
82 }
83
84 bool
ThreadCancel(lldb::thread_t thread,SBError * error_ptr)85 SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
86 {
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();
94 }
95
96 bool
ThreadDetach(lldb::thread_t thread,SBError * error_ptr)97 SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
98 {
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);
105 error = host_thread.GetNativeThread().Detach();
106 if (error_ptr)
107 error_ptr->SetError(error);
108 host_thread.Release();
109 #endif
110 return error.Success();
111 }
112
113 bool
ThreadJoin(lldb::thread_t thread,lldb::thread_result_t * result,SBError * error_ptr)114 SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
115 {
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();
123 }
124
125
126