blob: c78c197db5be9b48a8fe90264f75bbf371d4de99 [file] [log] [blame]
Eugene Zelenko9394d7722016-02-18 00:10:17 +00001//===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===//
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Greg Clayton56d9a1b2011-08-22 02:49:39 +00006//
7//===----------------------------------------------------------------------===//
8
Eugene Zelenko9394d7722016-02-18 00:10:17 +00009#include "lldb/Target/OperatingSystem.h"
Greg Clayton56d9a1b2011-08-22 02:49:39 +000010#include "lldb/Core/PluginManager.h"
Greg Clayton160c9d82013-05-01 21:54:04 +000011#include "lldb/Target/Thread.h"
Greg Clayton56d9a1b2011-08-22 02:49:39 +000012
13using namespace lldb;
14using namespace lldb_private;
15
Kate Stoneb9c1b512016-09-06 20:57:50 +000016OperatingSystem *OperatingSystem::FindPlugin(Process *process,
17 const char *plugin_name) {
18 OperatingSystemCreateInstance create_callback = nullptr;
19 if (plugin_name) {
20 ConstString const_plugin_name(plugin_name);
21 create_callback =
22 PluginManager::GetOperatingSystemCreateCallbackForPluginName(
23 const_plugin_name);
24 if (create_callback) {
Jonas Devlieghered5b44032019-02-13 06:25:41 +000025 std::unique_ptr<OperatingSystem> instance_up(
Kate Stoneb9c1b512016-09-06 20:57:50 +000026 create_callback(process, true));
Jonas Devlieghered5b44032019-02-13 06:25:41 +000027 if (instance_up)
28 return instance_up.release();
Greg Clayton56d9a1b2011-08-22 02:49:39 +000029 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000030 } else {
31 for (uint32_t idx = 0;
32 (create_callback =
33 PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
34 nullptr;
35 ++idx) {
Jonas Devlieghered5b44032019-02-13 06:25:41 +000036 std::unique_ptr<OperatingSystem> instance_up(
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 create_callback(process, false));
Jonas Devlieghered5b44032019-02-13 06:25:41 +000038 if (instance_up)
39 return instance_up.release();
Greg Clayton56d9a1b2011-08-22 02:49:39 +000040 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 }
42 return nullptr;
Greg Clayton56d9a1b2011-08-22 02:49:39 +000043}
44
Kate Stoneb9c1b512016-09-06 20:57:50 +000045OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
Greg Clayton56d9a1b2011-08-22 02:49:39 +000046
Eugene Zelenko9394d7722016-02-18 00:10:17 +000047OperatingSystem::~OperatingSystem() = default;
Greg Clayton160c9d82013-05-01 21:54:04 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049bool OperatingSystem::IsOperatingSystemPluginThread(
50 const lldb::ThreadSP &thread_sp) {
51 if (thread_sp)
52 return thread_sp->IsOperatingSystemPluginThread();
53 return false;
Greg Clayton160c9d82013-05-01 21:54:04 +000054}