2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/API/SBHostOS.h"
|
|
|
|
#include "lldb/API/SBError.h"
|
2011-02-08 13:05:52 +08:00
|
|
|
#include "lldb/Host/FileSpec.h"
|
2010-10-26 11:11:13 +08:00
|
|
|
#include "lldb/Core/Log.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Host/Host.h"
|
2014-08-22 01:29:12 +08:00
|
|
|
#include "lldb/Host/HostInfo.h"
|
2014-11-18 06:42:57 +08:00
|
|
|
#include "lldb/Host/HostNativeThread.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
#include "lldb/Host/HostThread.h"
|
|
|
|
#include "lldb/Host/ThreadLauncher.h"
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SBFileSpec
|
|
|
|
SBHostOS::GetProgramFileSpec ()
|
|
|
|
{
|
|
|
|
SBFileSpec sb_filespec;
|
2014-08-22 05:49:24 +08:00
|
|
|
sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
|
2010-06-09 00:52:24 +08:00
|
|
|
return sb_filespec;
|
|
|
|
}
|
|
|
|
|
2012-12-22 06:22:26 +08:00
|
|
|
SBFileSpec
|
|
|
|
SBHostOS::GetLLDBPythonPath ()
|
|
|
|
{
|
|
|
|
SBFileSpec sb_lldb_python_filespec;
|
|
|
|
FileSpec lldb_python_spec;
|
2014-08-22 01:29:12 +08:00
|
|
|
if (HostInfo::GetLLDBPath(ePathTypePythonDir, lldb_python_spec))
|
2012-12-22 06:22:26 +08:00
|
|
|
{
|
|
|
|
sb_lldb_python_filespec.SetFileSpec (lldb_python_spec);
|
|
|
|
}
|
|
|
|
return sb_lldb_python_filespec;
|
|
|
|
}
|
|
|
|
|
2014-07-31 01:38:47 +08:00
|
|
|
|
|
|
|
SBFileSpec
|
|
|
|
SBHostOS::GetLLDBPath (lldb::PathType path_type)
|
|
|
|
{
|
|
|
|
SBFileSpec sb_fspec;
|
|
|
|
FileSpec fspec;
|
2014-08-22 01:29:12 +08:00
|
|
|
if (HostInfo::GetLLDBPath(path_type, fspec))
|
2014-07-31 01:38:47 +08:00
|
|
|
sb_fspec.SetFileSpec (fspec);
|
|
|
|
return sb_fspec;
|
|
|
|
}
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
lldb::thread_t
|
|
|
|
SBHostOS::ThreadCreate
|
|
|
|
(
|
|
|
|
const char *name,
|
2014-03-03 23:39:47 +08:00
|
|
|
lldb::thread_func_t thread_function,
|
2010-06-09 00:52:24 +08:00
|
|
|
void *thread_arg,
|
|
|
|
SBError *error_ptr
|
|
|
|
)
|
|
|
|
{
|
2013-03-28 07:08:40 +08:00
|
|
|
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
|
|
|
if (log)
|
2014-04-04 12:06:10 +08:00
|
|
|
log->Printf ("SBHostOS::ThreadCreate (name=\"%s\", thread_function=%p, thread_arg=%p, error_ptr=%p)",
|
2014-07-23 06:00:04 +08:00
|
|
|
name, reinterpret_cast<void*>(reinterpret_cast<intptr_t>(thread_function)),
|
2014-04-04 12:06:10 +08:00
|
|
|
static_cast<void*>(thread_arg),
|
|
|
|
static_cast<void*>(error_ptr));
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2011-06-15 00:36:12 +08:00
|
|
|
// FIXME: You should log the return value?
|
2010-10-26 11:11:13 +08:00
|
|
|
|
2014-09-10 04:54:56 +08:00
|
|
|
HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL));
|
|
|
|
return thread.Release();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBHostOS::ThreadCreated (const char *name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr)
|
|
|
|
{
|
2014-09-10 04:54:56 +08:00
|
|
|
Error error;
|
|
|
|
HostThread host_thread(thread);
|
|
|
|
error = host_thread.Cancel();
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetError(error);
|
|
|
|
host_thread.Release();
|
|
|
|
return error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr)
|
|
|
|
{
|
2014-09-10 04:54:56 +08:00
|
|
|
Error error;
|
|
|
|
#if defined(_WIN32)
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
|
|
|
|
#else
|
|
|
|
HostThread host_thread(thread);
|
2014-11-18 06:42:57 +08:00
|
|
|
error = host_thread.GetNativeThread().Detach();
|
2014-09-10 04:54:56 +08:00
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetError(error);
|
|
|
|
host_thread.Release();
|
|
|
|
#endif
|
|
|
|
return error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-03 23:39:47 +08:00
|
|
|
SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2014-09-10 04:54:56 +08:00
|
|
|
Error error;
|
|
|
|
HostThread host_thread(thread);
|
|
|
|
error = host_thread.Join(result);
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetError(error);
|
|
|
|
host_thread.Release();
|
|
|
|
return error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|