180814287SRaphael Isemann //===-- StructuredDataPlugin.cpp ------------------------------------------===//
275930019STodd Fiala //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
675930019STodd Fiala //
775930019STodd Fiala //===----------------------------------------------------------------------===//
875930019STodd Fiala 
975930019STodd Fiala #include "lldb/Target/StructuredDataPlugin.h"
1075930019STodd Fiala 
1175930019STodd Fiala #include "lldb/Core/Debugger.h"
1275930019STodd Fiala #include "lldb/Interpreter/CommandInterpreter.h"
1375930019STodd Fiala #include "lldb/Interpreter/CommandObjectMultiword.h"
1475930019STodd Fiala 
1575930019STodd Fiala using namespace lldb;
1675930019STodd Fiala using namespace lldb_private;
1775930019STodd Fiala 
18b9c1b51eSKate Stone namespace {
19b9c1b51eSKate Stone class CommandStructuredData : public CommandObjectMultiword {
2075930019STodd Fiala public:
CommandStructuredData(CommandInterpreter & interpreter)21b9c1b51eSKate Stone   CommandStructuredData(CommandInterpreter &interpreter)
22b9c1b51eSKate Stone       : CommandObjectMultiword(interpreter, "structured-data",
2375930019STodd Fiala                                "Parent for per-plugin structured data commands",
24b9c1b51eSKate Stone                                "plugin structured-data <plugin>") {}
2575930019STodd Fiala 
26*fd2433e1SJonas Devlieghere   ~CommandStructuredData() override = default;
2775930019STodd Fiala };
2875930019STodd Fiala }
2975930019STodd Fiala 
StructuredDataPlugin(const ProcessWP & process_wp)30b9c1b51eSKate Stone StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp)
31b9c1b51eSKate Stone     : PluginInterface(), m_process_wp(process_wp) {}
3275930019STodd Fiala 
33*fd2433e1SJonas Devlieghere StructuredDataPlugin::~StructuredDataPlugin() = default;
3475930019STodd Fiala 
GetEnabled(ConstString type_name) const350e4c4821SAdrian Prantl bool StructuredDataPlugin::GetEnabled(ConstString type_name) const {
3675930019STodd Fiala   // By default, plugins are always enabled.  Plugin authors should override
3775930019STodd Fiala   // this if there is an enabled/disabled state for their plugin.
3875930019STodd Fiala   return true;
3975930019STodd Fiala }
4075930019STodd Fiala 
GetProcess() const41b9c1b51eSKate Stone ProcessSP StructuredDataPlugin::GetProcess() const {
4275930019STodd Fiala   return m_process_wp.lock();
4375930019STodd Fiala }
4475930019STodd Fiala 
InitializeBasePluginForDebugger(Debugger & debugger)45b9c1b51eSKate Stone void StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) {
4675930019STodd Fiala   // Create our mutliword command anchor if it doesn't already exist.
4775930019STodd Fiala   auto &interpreter = debugger.GetCommandInterpreter();
48b9c1b51eSKate Stone   if (!interpreter.GetCommandObject("plugin structured-data")) {
4975930019STodd Fiala     // Find the parent command.
5075930019STodd Fiala     auto parent_command =
5175930019STodd Fiala         debugger.GetCommandInterpreter().GetCommandObject("plugin");
5275930019STodd Fiala     if (!parent_command)
5375930019STodd Fiala       return;
5475930019STodd Fiala 
5575930019STodd Fiala     // Create the structured-data ommand object.
5675930019STodd Fiala     auto command_name = "structured-data";
57b9c1b51eSKate Stone     auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter));
5875930019STodd Fiala 
5975930019STodd Fiala     // Hook it up under the top-level plugin command.
60b9c1b51eSKate Stone     parent_command->LoadSubCommand(command_name, command_sp);
6175930019STodd Fiala   }
6275930019STodd Fiala }
6375930019STodd Fiala 
ModulesDidLoad(Process & process,ModuleList & module_list)64b9c1b51eSKate Stone void StructuredDataPlugin::ModulesDidLoad(Process &process,
65b9c1b51eSKate Stone                                           ModuleList &module_list) {
6675930019STodd Fiala   // Default implementation does nothing.
6775930019STodd Fiala }
68