1dda28197Spatrick //===-- StructuredDataPlugin.cpp ------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "lldb/Target/StructuredDataPlugin.h"
10061da546Spatrick 
11061da546Spatrick #include "lldb/Core/Debugger.h"
12061da546Spatrick #include "lldb/Interpreter/CommandInterpreter.h"
13061da546Spatrick #include "lldb/Interpreter/CommandObjectMultiword.h"
14061da546Spatrick 
15061da546Spatrick using namespace lldb;
16061da546Spatrick using namespace lldb_private;
17061da546Spatrick 
18061da546Spatrick namespace {
19061da546Spatrick class CommandStructuredData : public CommandObjectMultiword {
20061da546Spatrick public:
CommandStructuredData(CommandInterpreter & interpreter)21061da546Spatrick   CommandStructuredData(CommandInterpreter &interpreter)
22061da546Spatrick       : CommandObjectMultiword(interpreter, "structured-data",
23061da546Spatrick                                "Parent for per-plugin structured data commands",
24061da546Spatrick                                "plugin structured-data <plugin>") {}
25061da546Spatrick 
26*be691f3bSpatrick   ~CommandStructuredData() override = default;
27061da546Spatrick };
28061da546Spatrick }
29061da546Spatrick 
StructuredDataPlugin(const ProcessWP & process_wp)30061da546Spatrick StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp)
31061da546Spatrick     : PluginInterface(), m_process_wp(process_wp) {}
32061da546Spatrick 
33*be691f3bSpatrick StructuredDataPlugin::~StructuredDataPlugin() = default;
34061da546Spatrick 
GetEnabled(ConstString type_name) const35061da546Spatrick bool StructuredDataPlugin::GetEnabled(ConstString type_name) const {
36061da546Spatrick   // By default, plugins are always enabled.  Plugin authors should override
37061da546Spatrick   // this if there is an enabled/disabled state for their plugin.
38061da546Spatrick   return true;
39061da546Spatrick }
40061da546Spatrick 
GetProcess() const41061da546Spatrick ProcessSP StructuredDataPlugin::GetProcess() const {
42061da546Spatrick   return m_process_wp.lock();
43061da546Spatrick }
44061da546Spatrick 
InitializeBasePluginForDebugger(Debugger & debugger)45061da546Spatrick void StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) {
46061da546Spatrick   // Create our mutliword command anchor if it doesn't already exist.
47061da546Spatrick   auto &interpreter = debugger.GetCommandInterpreter();
48061da546Spatrick   if (!interpreter.GetCommandObject("plugin structured-data")) {
49061da546Spatrick     // Find the parent command.
50061da546Spatrick     auto parent_command =
51061da546Spatrick         debugger.GetCommandInterpreter().GetCommandObject("plugin");
52061da546Spatrick     if (!parent_command)
53061da546Spatrick       return;
54061da546Spatrick 
55061da546Spatrick     // Create the structured-data ommand object.
56061da546Spatrick     auto command_name = "structured-data";
57061da546Spatrick     auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter));
58061da546Spatrick 
59061da546Spatrick     // Hook it up under the top-level plugin command.
60061da546Spatrick     parent_command->LoadSubCommand(command_name, command_sp);
61061da546Spatrick   }
62061da546Spatrick }
63061da546Spatrick 
ModulesDidLoad(Process & process,ModuleList & module_list)64061da546Spatrick void StructuredDataPlugin::ModulesDidLoad(Process &process,
65061da546Spatrick                                           ModuleList &module_list) {
66061da546Spatrick   // Default implementation does nothing.
67061da546Spatrick }
68