2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBHostOS.cpp --------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
#include "SBReproducerPrivate.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/API/SBError.h"
|
2018-11-02 05:05:36 +08:00
|
|
|
#include "lldb/API/SBHostOS.h"
|
|
|
|
#include "lldb/Host/FileSystem.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"
|
2017-03-23 02:40:07 +08:00
|
|
|
#include "lldb/Utility/FileSpec.h"
|
2014-09-10 04:54:56 +08:00
|
|
|
|
2018-06-05 01:41:00 +08:00
|
|
|
#include "Plugins/ExpressionParser/Clang/ClangHost.h"
|
2018-06-20 17:00:30 +08:00
|
|
|
#ifndef LLDB_DISABLE_PYTHON
|
2018-06-20 16:35:45 +08:00
|
|
|
#include "Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.h"
|
2018-06-20 17:00:30 +08:00
|
|
|
#endif
|
2018-06-05 01:41:00 +08:00
|
|
|
|
2016-04-18 20:18:35 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2016-02-19 08:05:17 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec SBHostOS::GetProgramFileSpec() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBFileSpec, SBHostOS,
|
|
|
|
GetProgramFileSpec);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec sb_filespec;
|
|
|
|
sb_filespec.SetFileSpec(HostInfo::GetProgramFileSpec());
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_filespec);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec SBHostOS::GetLLDBPythonPath() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBFileSpec, SBHostOS,
|
|
|
|
GetLLDBPythonPath);
|
|
|
|
|
|
|
|
return LLDB_RECORD_RESULT(GetLLDBPath(ePathTypePythonDir));
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec SBHostOS::GetLLDBPath(lldb::PathType path_type) {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD(lldb::SBFileSpec, SBHostOS, GetLLDBPath,
|
|
|
|
(lldb::PathType), path_type);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
FileSpec fspec;
|
2018-06-19 23:09:07 +08:00
|
|
|
switch (path_type) {
|
|
|
|
case ePathTypeLLDBShlibDir:
|
|
|
|
fspec = HostInfo::GetShlibDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeSupportExecutableDir:
|
|
|
|
fspec = HostInfo::GetSupportExeDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeHeaderDir:
|
|
|
|
fspec = HostInfo::GetHeaderDir();
|
|
|
|
break;
|
|
|
|
case ePathTypePythonDir:
|
2018-06-20 17:00:30 +08:00
|
|
|
#ifndef LLDB_DISABLE_PYTHON
|
2018-06-20 16:35:45 +08:00
|
|
|
fspec = ScriptInterpreterPython::GetPythonDir();
|
2018-06-20 17:00:30 +08:00
|
|
|
#endif
|
2018-06-19 23:09:07 +08:00
|
|
|
break;
|
|
|
|
case ePathTypeLLDBSystemPlugins:
|
|
|
|
fspec = HostInfo::GetSystemPluginDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeLLDBUserPlugins:
|
|
|
|
fspec = HostInfo::GetUserPluginDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeLLDBTempSystemDir:
|
|
|
|
fspec = HostInfo::GetProcessTempDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeGlobalLLDBTempSystemDir:
|
|
|
|
fspec = HostInfo::GetGlobalTempDir();
|
|
|
|
break;
|
|
|
|
case ePathTypeClangDir:
|
2018-06-05 01:41:00 +08:00
|
|
|
fspec = GetClangResourceDir();
|
2018-06-19 23:09:07 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SBFileSpec sb_fspec;
|
|
|
|
sb_fspec.SetFileSpec(fspec);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_fspec);
|
2012-12-22 06:22:26 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec SBHostOS::GetUserHomeDirectory() {
|
2019-03-06 08:06:00 +08:00
|
|
|
LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBFileSpec, SBHostOS,
|
|
|
|
GetUserHomeDirectory);
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
SBFileSpec sb_fspec;
|
2014-07-31 01:38:47 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
llvm::SmallString<64> home_dir_path;
|
|
|
|
llvm::sys::path::home_directory(home_dir_path);
|
2018-11-02 05:05:36 +08:00
|
|
|
FileSpec homedir(home_dir_path.c_str());
|
|
|
|
FileSystem::Instance().Resolve(homedir);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
|
|
|
sb_fspec.SetFileSpec(homedir);
|
2019-03-06 08:06:00 +08:00
|
|
|
return LLDB_RECORD_RESULT(sb_fspec);
|
2014-07-31 01:38:47 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
lldb::thread_t SBHostOS::ThreadCreate(const char *name,
|
|
|
|
lldb::thread_func_t thread_function,
|
|
|
|
void *thread_arg, SBError *error_ptr) {
|
2019-03-09 01:50:27 +08:00
|
|
|
LLDB_RECORD_DUMMY(lldb::thread_t, SBHostOS, ThreadCreate,
|
|
|
|
(lldb::thread_func_t, void *, SBError *), name,
|
|
|
|
thread_function, thread_arg, error_ptr);
|
[lldb] NFC modernize codebase with modernize-use-nullptr
Summary:
NFC = [[ https://llvm.org/docs/Lexicon.html#nfc | Non functional change ]]
This commit is the result of modernizing the LLDB codebase by using
`nullptr` instread of `0` or `NULL`. See
https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-nullptr.html
for more information.
This is the command I ran and I to fix and format the code base:
```
run-clang-tidy.py \
-header-filter='.*' \
-checks='-*,modernize-use-nullptr' \
-fix ~/dev/llvm-project/lldb/.* \
-format \
-style LLVM \
-p ~/llvm-builds/debug-ninja-gcc
```
NOTE: There were also changes to `llvm/utils/unittest` but I did not
include them because I felt that maybe this library shall be updated in
isolation somehow.
NOTE: I know this is a rather large commit but it is a nobrainer in most
parts.
Reviewers: martong, espindola, shafik, #lldb, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: arsenm, jvesely, nhaehnle, hiraditya, JDevlieghere, teemperor, rnkovacs, emaste, kubamracek, nemanjai, ki.stfu, javed.absar, arichardson, kbarton, jrtc27, MaskRay, atanasyan, dexonsmith, arphaman, jfb, jsji, jdoerfert, lldb-commits, llvm-commits
Tags: #lldb, #llvm
Differential Revision: https://reviews.llvm.org/D61847
llvm-svn: 361484
2019-05-23 19:14:47 +08:00
|
|
|
HostThread thread(
|
|
|
|
ThreadLauncher::LaunchThread(name, thread_function, thread_arg,
|
|
|
|
error_ptr ? error_ptr->get() : nullptr));
|
2016-09-07 04:57:50 +08:00
|
|
|
return thread.Release();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2019-03-06 08:06:00 +08:00
|
|
|
void SBHostOS::ThreadCreated(const char *name) {
|
|
|
|
LLDB_RECORD_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *),
|
|
|
|
name);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBHostOS::ThreadCancel(lldb::thread_t thread, SBError *error_ptr) {
|
2019-03-09 01:50:27 +08:00
|
|
|
LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadCancel,
|
2019-03-06 08:06:00 +08:00
|
|
|
(lldb::thread_t, lldb::SBError *), thread,
|
|
|
|
error_ptr);
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBHostOS::ThreadDetach(lldb::thread_t thread, SBError *error_ptr) {
|
2019-03-09 01:50:27 +08:00
|
|
|
LLDB_RECORD_DUMMY(bool, SBHostOS, ThreadDetach,
|
2019-03-06 08:06:00 +08:00
|
|
|
(lldb::thread_t, lldb::SBError *), thread,
|
|
|
|
error_ptr);
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2014-09-10 04:54:56 +08:00
|
|
|
#if defined(_WIN32)
|
2016-09-07 04:57:50 +08:00
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetErrorString("ThreadDetach is not supported on this platform");
|
2014-09-10 04:54:56 +08:00
|
|
|
#else
|
2016-09-07 04:57:50 +08:00
|
|
|
HostThread host_thread(thread);
|
|
|
|
error = host_thread.GetNativeThread().Detach();
|
|
|
|
if (error_ptr)
|
|
|
|
error_ptr->SetError(error);
|
|
|
|
host_thread.Release();
|
2014-09-10 04:54:56 +08:00
|
|
|
#endif
|
2016-09-07 04:57:50 +08:00
|
|
|
return error.Success();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
bool SBHostOS::ThreadJoin(lldb::thread_t thread, lldb::thread_result_t *result,
|
|
|
|
SBError *error_ptr) {
|
2019-03-09 01:50:27 +08:00
|
|
|
LLDB_RECORD_DUMMY(
|
2019-03-06 08:06:00 +08:00
|
|
|
bool, SBHostOS, ThreadJoin,
|
|
|
|
(lldb::thread_t, lldb::thread_result_t *, lldb::SBError *), thread,
|
|
|
|
result, error_ptr);
|
|
|
|
|
2017-05-12 12:51:55 +08:00
|
|
|
Status error;
|
2016-09-07 04:57:50 +08:00
|
|
|
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
|
|
|
}
|
2019-03-20 01:13:13 +08:00
|
|
|
|
|
|
|
namespace lldb_private {
|
|
|
|
namespace repro {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void RegisterMethods<SBHostOS>(Registry &R) {
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(lldb::SBFileSpec, SBHostOS, GetProgramFileSpec,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(lldb::SBFileSpec, SBHostOS, GetLLDBPythonPath,
|
|
|
|
());
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(lldb::SBFileSpec, SBHostOS, GetLLDBPath,
|
|
|
|
(lldb::PathType));
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(lldb::SBFileSpec, SBHostOS,
|
|
|
|
GetUserHomeDirectory, ());
|
|
|
|
LLDB_REGISTER_STATIC_METHOD(void, SBHostOS, ThreadCreated, (const char *));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|