1 //===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "lldb/Target/OperatingSystem.h"
10 #include "lldb/Core/PluginManager.h"
11 #include "lldb/Target/Thread.h"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 
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) {
25       std::unique_ptr<OperatingSystem> instance_up(
26           create_callback(process, true));
27       if (instance_up)
28         return instance_up.release();
29     }
30   } else {
31     for (uint32_t idx = 0;
32          (create_callback =
33               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
34          nullptr;
35          ++idx) {
36       std::unique_ptr<OperatingSystem> instance_up(
37           create_callback(process, false));
38       if (instance_up)
39         return instance_up.release();
40     }
41   }
42   return nullptr;
43 }
44 
45 OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
46 
47 OperatingSystem::~OperatingSystem() = default;
48 
49 bool OperatingSystem::IsOperatingSystemPluginThread(
50     const lldb::ThreadSP &thread_sp) {
51   if (thread_sp)
52     return thread_sp->IsOperatingSystemPluginThread();
53   return false;
54 }
55