14bb0738eSEd Maste //===-- OperatingSystem.cpp -------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste //                     The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste 
104bb0738eSEd Maste #include "lldb/Target/OperatingSystem.h"
11ac7ddfbfSEd Maste #include "lldb/Core/PluginManager.h"
12ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
13ac7ddfbfSEd Maste 
14ac7ddfbfSEd Maste using namespace lldb;
15ac7ddfbfSEd Maste using namespace lldb_private;
16ac7ddfbfSEd Maste 
FindPlugin(Process * process,const char * plugin_name)17435933ddSDimitry Andric OperatingSystem *OperatingSystem::FindPlugin(Process *process,
18435933ddSDimitry Andric                                              const char *plugin_name) {
194bb0738eSEd Maste   OperatingSystemCreateInstance create_callback = nullptr;
20435933ddSDimitry Andric   if (plugin_name) {
21ac7ddfbfSEd Maste     ConstString const_plugin_name(plugin_name);
22435933ddSDimitry Andric     create_callback =
23435933ddSDimitry Andric         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
24435933ddSDimitry Andric             const_plugin_name);
25435933ddSDimitry Andric     if (create_callback) {
26435933ddSDimitry Andric       std::unique_ptr<OperatingSystem> instance_ap(
27435933ddSDimitry Andric           create_callback(process, true));
284bb0738eSEd Maste       if (instance_ap)
29ac7ddfbfSEd Maste         return instance_ap.release();
30ac7ddfbfSEd Maste     }
31435933ddSDimitry Andric   } else {
32435933ddSDimitry Andric     for (uint32_t idx = 0;
33435933ddSDimitry Andric          (create_callback =
34435933ddSDimitry Andric               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
35435933ddSDimitry Andric          nullptr;
36435933ddSDimitry Andric          ++idx) {
37435933ddSDimitry Andric       std::unique_ptr<OperatingSystem> instance_ap(
38435933ddSDimitry Andric           create_callback(process, false));
394bb0738eSEd Maste       if (instance_ap)
40ac7ddfbfSEd Maste         return instance_ap.release();
41ac7ddfbfSEd Maste     }
42ac7ddfbfSEd Maste   }
434bb0738eSEd Maste   return nullptr;
44ac7ddfbfSEd Maste }
45ac7ddfbfSEd Maste 
OperatingSystem(Process * process)46435933ddSDimitry Andric OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
47ac7ddfbfSEd Maste 
484bb0738eSEd Maste OperatingSystem::~OperatingSystem() = default;
49ac7ddfbfSEd Maste 
IsOperatingSystemPluginThread(const lldb::ThreadSP & thread_sp)50435933ddSDimitry Andric bool OperatingSystem::IsOperatingSystemPluginThread(
51435933ddSDimitry Andric     const lldb::ThreadSP &thread_sp) {
52ac7ddfbfSEd Maste   if (thread_sp)
53ac7ddfbfSEd Maste     return thread_sp->IsOperatingSystemPluginThread();
54ac7ddfbfSEd Maste   return false;
55ac7ddfbfSEd Maste }
56