Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 1 | //===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===// |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 9 | #include "lldb/Target/OperatingSystem.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 10 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 11 | #include "lldb/Target/Thread.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 12 | |
| 13 | using namespace lldb; |
| 14 | using namespace lldb_private; |
| 15 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 16 | OperatingSystem *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 Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 25 | std::unique_ptr<OperatingSystem> instance_up( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | create_callback(process, true)); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 27 | if (instance_up) |
| 28 | return instance_up.release(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 29 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | } else { |
| 31 | for (uint32_t idx = 0; |
| 32 | (create_callback = |
| 33 | PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) != |
| 34 | nullptr; |
| 35 | ++idx) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 36 | std::unique_ptr<OperatingSystem> instance_up( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | create_callback(process, false)); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 38 | if (instance_up) |
| 39 | return instance_up.release(); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 40 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 41 | } |
| 42 | return nullptr; |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 43 | } |
| 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | OperatingSystem::OperatingSystem(Process *process) : m_process(process) {} |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 46 | |
Eugene Zelenko | 9394d772 | 2016-02-18 00:10:17 +0000 | [diff] [blame] | 47 | OperatingSystem::~OperatingSystem() = default; |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 48 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 49 | bool OperatingSystem::IsOperatingSystemPluginThread( |
| 50 | const lldb::ThreadSP &thread_sp) { |
| 51 | if (thread_sp) |
| 52 | return thread_sp->IsOperatingSystemPluginThread(); |
| 53 | return false; |
Greg Clayton | 160c9d8 | 2013-05-01 21:54:04 +0000 | [diff] [blame] | 54 | } |