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 
10ac7ddfbfSEd Maste // C Includes
11ac7ddfbfSEd Maste // C++ Includes
12ac7ddfbfSEd Maste // Other libraries and framework includes
134bb0738eSEd Maste // Project includes
144bb0738eSEd Maste #include "lldb/Target/OperatingSystem.h"
15ac7ddfbfSEd Maste #include "lldb/Core/PluginManager.h"
16ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
17ac7ddfbfSEd Maste 
18ac7ddfbfSEd Maste using namespace lldb;
19ac7ddfbfSEd Maste using namespace lldb_private;
20ac7ddfbfSEd Maste 
21ac7ddfbfSEd Maste OperatingSystem*
22ac7ddfbfSEd Maste OperatingSystem::FindPlugin (Process *process, const char *plugin_name)
23ac7ddfbfSEd Maste {
244bb0738eSEd Maste     OperatingSystemCreateInstance create_callback = nullptr;
25ac7ddfbfSEd Maste     if (plugin_name)
26ac7ddfbfSEd Maste     {
27ac7ddfbfSEd Maste         ConstString const_plugin_name(plugin_name);
28ac7ddfbfSEd Maste         create_callback  = PluginManager::GetOperatingSystemCreateCallbackForPluginName (const_plugin_name);
29ac7ddfbfSEd Maste         if (create_callback)
30ac7ddfbfSEd Maste         {
31ac7ddfbfSEd Maste             std::unique_ptr<OperatingSystem> instance_ap(create_callback(process, true));
324bb0738eSEd Maste             if (instance_ap)
33ac7ddfbfSEd Maste                 return instance_ap.release();
34ac7ddfbfSEd Maste         }
35ac7ddfbfSEd Maste     }
36ac7ddfbfSEd Maste     else
37ac7ddfbfSEd Maste     {
384bb0738eSEd Maste         for (uint32_t idx = 0; (create_callback = PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) != nullptr; ++idx)
39ac7ddfbfSEd Maste         {
40ac7ddfbfSEd Maste             std::unique_ptr<OperatingSystem> instance_ap(create_callback(process, false));
414bb0738eSEd Maste             if (instance_ap)
42ac7ddfbfSEd Maste                 return instance_ap.release();
43ac7ddfbfSEd Maste         }
44ac7ddfbfSEd Maste     }
454bb0738eSEd Maste     return nullptr;
46ac7ddfbfSEd Maste }
47ac7ddfbfSEd Maste 
48ac7ddfbfSEd Maste 
49ac7ddfbfSEd Maste OperatingSystem::OperatingSystem (Process *process) :
50ac7ddfbfSEd Maste     m_process (process)
51ac7ddfbfSEd Maste {
52ac7ddfbfSEd Maste }
53ac7ddfbfSEd Maste 
544bb0738eSEd Maste OperatingSystem::~OperatingSystem() = default;
55ac7ddfbfSEd Maste 
56ac7ddfbfSEd Maste bool
57ac7ddfbfSEd Maste OperatingSystem::IsOperatingSystemPluginThread (const lldb::ThreadSP &thread_sp)
58ac7ddfbfSEd Maste {
59ac7ddfbfSEd Maste     if (thread_sp)
60ac7ddfbfSEd Maste         return thread_sp->IsOperatingSystemPluginThread();
61ac7ddfbfSEd Maste     return false;
62ac7ddfbfSEd Maste }
63