blob: 4a65eee10641f8f703bb8fedadbaf281da6ab885 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Clayton53239f02011-02-08 05:05:52 +000012#include "lldb/Host/FileSpec.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000013#include "lldb/Core/Log.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000014#include "lldb/Host/Host.h"
Zachary Turner42ff0ad2014-08-21 17:29:12 +000015#include "lldb/Host/HostInfo.h"
Zachary Turner39de3112014-09-09 20:54:56 +000016#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 Lattner30fdc8d2010-06-08 16:52:24 +000022
23using namespace lldb;
24using namespace lldb_private;
25
26
27
28SBFileSpec
29SBHostOS::GetProgramFileSpec ()
30{
31 SBFileSpec sb_filespec;
Zachary Turnera21fee02014-08-21 21:49:24 +000032 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000033 return sb_filespec;
34}
35
Jim Inghame2231ac2012-12-21 22:22:26 +000036SBFileSpec
37SBHostOS::GetLLDBPythonPath ()
38{
39 SBFileSpec sb_lldb_python_filespec;
40 FileSpec lldb_python_spec;
Zachary Turner42ff0ad2014-08-21 17:29:12 +000041 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
Jim Inghame2231ac2012-12-21 22:22:26 +000042 {
43 sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
44 }
45 return sb_lldb_python_filespec;
46}
47
Greg Clayton06357c92014-07-30 17:38:47 +000048
49SBFileSpec
50SBHostOS::GetLLDBPath (lldb::PathType path_type)
51{
52 SBFileSpec sb_fspec;
53 FileSpec fspec;
Zachary Turner42ff0ad2014-08-21 17:29:12 +000054 if (HostInfo::GetLLDBPath(path_type, fspec))
Greg Clayton06357c92014-07-30 17:38:47 +000055 sb_fspec.SetFileSpec (fspec);
56 return sb_fspec;
57}
58
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059lldb::thread_t
60SBHostOS::ThreadCreate
61(
62 const char *name,
Deepak Panickal99fbc072014-03-03 15:39:47 +000063 lldb::thread_func_t thread_function,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000064 void *thread_arg,
65 SBError *error_ptr
66)
67{
Greg Clayton5160ce52013-03-27 23:08:40 +000068 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000069
70 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000071 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
David Majnemer702c1d092014-07-22 22:00:04 +000072 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000073 static_cast<void*>(thread_arg),
74 static_cast<void*>(error_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +000075
Caroline Ticec1338e82011-06-14 16:36:12 +000076 // FIXME: You should log the return value?
Caroline Ticeceb6b132010-10-26 03:11:13 +000077
Zachary Turner39de3112014-09-09 20:54:56 +000078 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
79 return thread.Release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000080}
81
82void
83SBHostOS::ThreadCreated (const char *name)
84{
Chris Lattner30fdc8d2010-06-08 16:52:24 +000085}
86
87bool
88SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
89{
Zachary Turner39de3112014-09-09 20:54:56 +000090 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 Lattner30fdc8d2010-06-08 16:52:24 +000097}
98
99bool
100SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
101{
Zachary Turner39de3112014-09-09 20:54:56 +0000102 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 Lattner30fdc8d2010-06-08 16:52:24 +0000114}
115
116bool
Deepak Panickal99fbc072014-03-03 15:39:47 +0000117SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000118{
Zachary Turner39de3112014-09-09 20:54:56 +0000119 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 Lattner30fdc8d2010-06-08 16:52:24 +0000126}
127
128