xref: /src/contrib/llvm-project/lldb/source/Target/OperatingSystem.cpp (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
1cfca06d7SDimitry Andric //===-- OperatingSystem.cpp -----------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
9f3fbd1c0SDimitry Andric #include "lldb/Target/OperatingSystem.h"
10f034231aSEd Maste #include "lldb/Core/PluginManager.h"
11f034231aSEd Maste #include "lldb/Target/Thread.h"
12f034231aSEd Maste 
13f034231aSEd Maste using namespace lldb;
14f034231aSEd Maste using namespace lldb_private;
15f034231aSEd Maste 
FindPlugin(Process * process,const char * plugin_name)1614f1b3e8SDimitry Andric OperatingSystem *OperatingSystem::FindPlugin(Process *process,
1714f1b3e8SDimitry Andric                                              const char *plugin_name) {
18f3fbd1c0SDimitry Andric   OperatingSystemCreateInstance create_callback = nullptr;
1914f1b3e8SDimitry Andric   if (plugin_name) {
2014f1b3e8SDimitry Andric     create_callback =
2114f1b3e8SDimitry Andric         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
22c0981da4SDimitry Andric             plugin_name);
2314f1b3e8SDimitry Andric     if (create_callback) {
245f29bb8aSDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
2514f1b3e8SDimitry Andric           create_callback(process, true));
265f29bb8aSDimitry Andric       if (instance_up)
275f29bb8aSDimitry Andric         return instance_up.release();
28f034231aSEd Maste     }
2914f1b3e8SDimitry Andric   } else {
3014f1b3e8SDimitry Andric     for (uint32_t idx = 0;
3114f1b3e8SDimitry Andric          (create_callback =
3214f1b3e8SDimitry Andric               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
3314f1b3e8SDimitry Andric          nullptr;
3414f1b3e8SDimitry Andric          ++idx) {
355f29bb8aSDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
3614f1b3e8SDimitry Andric           create_callback(process, false));
375f29bb8aSDimitry Andric       if (instance_up)
385f29bb8aSDimitry Andric         return instance_up.release();
39f034231aSEd Maste     }
40f034231aSEd Maste   }
41f3fbd1c0SDimitry Andric   return nullptr;
42f034231aSEd Maste }
43f034231aSEd Maste 
OperatingSystem(Process * process)4414f1b3e8SDimitry Andric OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
45f034231aSEd Maste 
IsOperatingSystemPluginThread(const lldb::ThreadSP & thread_sp)4614f1b3e8SDimitry Andric bool OperatingSystem::IsOperatingSystemPluginThread(
4714f1b3e8SDimitry Andric     const lldb::ThreadSP &thread_sp) {
48f034231aSEd Maste   if (thread_sp)
49f034231aSEd Maste     return thread_sp->IsOperatingSystemPluginThread();
50f034231aSEd Maste   return false;
51f034231aSEd Maste }
52