blob: 008ca4d9672ee7c0ba7fc9212e8959cdee93ac29 [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 Turnerc3018992014-11-17 22:42:57 +000016#include "lldb/Host/HostNativeThread.h"
Zachary Turner39de3112014-09-09 20:54:56 +000017#include "lldb/Host/HostThread.h"
18#include "lldb/Host/ThreadLauncher.h"
19
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020using namespace lldb;
21using namespace lldb_private;
22
23
24
25SBFileSpec
26SBHostOS::GetProgramFileSpec ()
27{
28 SBFileSpec sb_filespec;
Zachary Turnera21fee02014-08-21 21:49:24 +000029 sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
Chris Lattner30fdc8d2010-06-08 16:52:24 +000030 return sb_filespec;
31}
32
Jim Inghame2231ac2012-12-21 22:22:26 +000033SBFileSpec
34SBHostOS::GetLLDBPythonPath ()
35{
36 SBFileSpec sb_lldb_python_filespec;
37 FileSpec lldb_python_spec;
Zachary Turner42ff0ad2014-08-21 17:29:12 +000038 if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
Jim Inghame2231ac2012-12-21 22:22:26 +000039 {
40 sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
41 }
42 return sb_lldb_python_filespec;
43}
44
Greg Clayton06357c92014-07-30 17:38:47 +000045
46SBFileSpec
47SBHostOS::GetLLDBPath (lldb::PathType path_type)
48{
49 SBFileSpec sb_fspec;
50 FileSpec fspec;
Zachary Turner42ff0ad2014-08-21 17:29:12 +000051 if (HostInfo::GetLLDBPath(path_type, fspec))
Greg Clayton06357c92014-07-30 17:38:47 +000052 sb_fspec.SetFileSpec (fspec);
53 return sb_fspec;
54}
55
Chris Lattner30fdc8d2010-06-08 16:52:24 +000056lldb::thread_t
57SBHostOS::ThreadCreate
58(
59 const char *name,
Deepak Panickal99fbc072014-03-03 15:39:47 +000060 lldb::thread_func_t thread_function,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000061 void *thread_arg,
62 SBError *error_ptr
63)
64{
Greg Clayton5160ce52013-03-27 23:08:40 +000065 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000066
67 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000068 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
David Majnemer702c1d092014-07-22 22:00:04 +000069 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000070 static_cast<void*>(thread_arg),
71 static_cast<void*>(error_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +000072
Caroline Ticec1338e82011-06-14 16:36:12 +000073 // FIXME: You should log the return value?
Caroline Ticeceb6b132010-10-26 03:11:13 +000074
Zachary Turner39de3112014-09-09 20:54:56 +000075 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
76 return thread.Release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077}
78
79void
80SBHostOS::ThreadCreated (const char *name)
81{
Chris Lattner30fdc8d2010-06-08 16:52:24 +000082}
83
84bool
85SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
86{
Zachary Turner39de3112014-09-09 20:54:56 +000087 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 Lattner30fdc8d2010-06-08 16:52:24 +000094}
95
96bool
97SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
98{
Zachary Turner39de3112014-09-09 20:54:56 +000099 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 Turnerc3018992014-11-17 22:42:57 +0000105 error = host_thread.GetNativeThread().Detach();
Zachary Turner39de3112014-09-09 20:54:56 +0000106 if (error_ptr)
107 error_ptr->SetError(error);
108 host_thread.Release();
109#endif
110 return error.Success();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000111}
112
113bool
Deepak Panickal99fbc072014-03-03 15:39:47 +0000114SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115{
Zachary Turner39de3112014-09-09 20:54:56 +0000116 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 Lattner30fdc8d2010-06-08 16:52:24 +0000123}
124
125