xref: /freebsd-src/contrib/llvm-project/lldb/source/Target/OperatingSystem.cpp (revision 349cc55c9796c4596a5b9904cd3281af295f878f)
15ffd83dbSDimitry Andric //===-- OperatingSystem.cpp -----------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #include "lldb/Target/OperatingSystem.h"
100b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
110b57cec5SDimitry Andric #include "lldb/Target/Thread.h"
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric using namespace lldb;
140b57cec5SDimitry Andric using namespace lldb_private;
150b57cec5SDimitry Andric 
FindPlugin(Process * process,const char * plugin_name)160b57cec5SDimitry Andric OperatingSystem *OperatingSystem::FindPlugin(Process *process,
170b57cec5SDimitry Andric                                              const char *plugin_name) {
180b57cec5SDimitry Andric   OperatingSystemCreateInstance create_callback = nullptr;
190b57cec5SDimitry Andric   if (plugin_name) {
200b57cec5SDimitry Andric     create_callback =
210b57cec5SDimitry Andric         PluginManager::GetOperatingSystemCreateCallbackForPluginName(
22*349cc55cSDimitry Andric             plugin_name);
230b57cec5SDimitry Andric     if (create_callback) {
240b57cec5SDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
250b57cec5SDimitry Andric           create_callback(process, true));
260b57cec5SDimitry Andric       if (instance_up)
270b57cec5SDimitry Andric         return instance_up.release();
280b57cec5SDimitry Andric     }
290b57cec5SDimitry Andric   } else {
300b57cec5SDimitry Andric     for (uint32_t idx = 0;
310b57cec5SDimitry Andric          (create_callback =
320b57cec5SDimitry Andric               PluginManager::GetOperatingSystemCreateCallbackAtIndex(idx)) !=
330b57cec5SDimitry Andric          nullptr;
340b57cec5SDimitry Andric          ++idx) {
350b57cec5SDimitry Andric       std::unique_ptr<OperatingSystem> instance_up(
360b57cec5SDimitry Andric           create_callback(process, false));
370b57cec5SDimitry Andric       if (instance_up)
380b57cec5SDimitry Andric         return instance_up.release();
390b57cec5SDimitry Andric     }
400b57cec5SDimitry Andric   }
410b57cec5SDimitry Andric   return nullptr;
420b57cec5SDimitry Andric }
430b57cec5SDimitry Andric 
OperatingSystem(Process * process)440b57cec5SDimitry Andric OperatingSystem::OperatingSystem(Process *process) : m_process(process) {}
450b57cec5SDimitry Andric 
IsOperatingSystemPluginThread(const lldb::ThreadSP & thread_sp)460b57cec5SDimitry Andric bool OperatingSystem::IsOperatingSystemPluginThread(
470b57cec5SDimitry Andric     const lldb::ThreadSP &thread_sp) {
480b57cec5SDimitry Andric   if (thread_sp)
490b57cec5SDimitry Andric     return thread_sp->IsOperatingSystemPluginThread();
500b57cec5SDimitry Andric   return false;
510b57cec5SDimitry Andric }
52