blob: 6c172997bdc8120ec9e9b76c24745c8d38a41dda [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
Jason Molenda878ae012016-02-19 00:05:17 +000020#include "llvm/Support/Path.h"
Pavel Labath7eafdce2016-04-18 12:18:35 +000021#include "llvm/ADT/SmallString.h"
Jason Molenda878ae012016-02-19 00:05:17 +000022
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023using 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
Jason Molenda878ae012016-02-19 00:05:17 +000059SBFileSpec
60SBHostOS::GetUserHomeDirectory ()
61{
62 SBFileSpec sb_fspec;
63
64 llvm::SmallString<64> home_dir_path;
65 llvm::sys::path::home_directory (home_dir_path);
66 FileSpec homedir (home_dir_path.c_str(), true);
67
68 sb_fspec.SetFileSpec (homedir);
69 return sb_fspec;
70}
71
Chris Lattner30fdc8d2010-06-08 16:52:24 +000072lldb::thread_t
73SBHostOS::ThreadCreate
74(
75 const char *name,
Deepak Panickal99fbc072014-03-03 15:39:47 +000076 lldb::thread_func_t thread_function,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077 void *thread_arg,
78 SBError *error_ptr
79)
80{
Greg Clayton5160ce52013-03-27 23:08:40 +000081 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +000082
83 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000084 log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
David Majnemer702c1d092014-07-22 22:00:04 +000085 name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +000086 static_cast<void*>(thread_arg),
87 static_cast<void*>(error_ptr));
Caroline Ticeceb6b132010-10-26 03:11:13 +000088
Caroline Ticec1338e82011-06-14 16:36:12 +000089 // FIXME: You should log the return value?
Caroline Ticeceb6b132010-10-26 03:11:13 +000090
Zachary Turner39de3112014-09-09 20:54:56 +000091 HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
92 return thread.Release();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000093}
94
95void
96SBHostOS::ThreadCreated (const char *name)
97{
Chris Lattner30fdc8d2010-06-08 16:52:24 +000098}
99
100bool
101SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
102{
Zachary Turner39de3112014-09-09 20:54:56 +0000103 Error error;
104 HostThread host_thread(thread);
105 error = host_thread.Cancel();
106 if (error_ptr)
107 error_ptr->SetError(error);
108 host_thread.Release();
109 return error.Success();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000110}
111
112bool
113SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
114{
Zachary Turner39de3112014-09-09 20:54:56 +0000115 Error error;
116#if defined(_WIN32)
117 if (error_ptr)
118 error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
119#else
120 HostThread host_thread(thread);
Zachary Turnerc3018992014-11-17 22:42:57 +0000121 error = host_thread.GetNativeThread().Detach();
Zachary Turner39de3112014-09-09 20:54:56 +0000122 if (error_ptr)
123 error_ptr->SetError(error);
124 host_thread.Release();
125#endif
126 return error.Success();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000127}
128
129bool
Deepak Panickal99fbc072014-03-03 15:39:47 +0000130SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131{
Zachary Turner39de3112014-09-09 20:54:56 +0000132 Error error;
133 HostThread host_thread(thread);
134 error = host_thread.Join(result);
135 if (error_ptr)
136 error_ptr->SetError(error);
137 host_thread.Release();
138 return error.Success();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000139}
140
141