1 //===-- StructuredDataPlugin.cpp ------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/StructuredDataPlugin.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Interpreter/CommandInterpreter.h"
13 #include "lldb/Interpreter/CommandObjectMultiword.h"
16 using namespace lldb_private
;
19 class CommandStructuredData
: public CommandObjectMultiword
{
21 CommandStructuredData(CommandInterpreter
&interpreter
)
22 : CommandObjectMultiword(interpreter
, "structured-data",
23 "Parent for per-plugin structured data commands",
24 "plugin structured-data <plugin>") {}
26 ~CommandStructuredData() override
= default;
30 StructuredDataPlugin::StructuredDataPlugin(const ProcessWP
&process_wp
)
31 : PluginInterface(), m_process_wp(process_wp
) {}
33 StructuredDataPlugin::~StructuredDataPlugin() = default;
35 bool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name
) const {
36 // By default, plugins are always enabled. Plugin authors should override
37 // this if there is an enabled/disabled state for their plugin.
41 ProcessSP
StructuredDataPlugin::GetProcess() const {
42 return m_process_wp
.lock();
45 void StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger
&debugger
) {
46 // Create our mutliword command anchor if it doesn't already exist.
47 auto &interpreter
= debugger
.GetCommandInterpreter();
48 if (!interpreter
.GetCommandObject("plugin structured-data")) {
49 // Find the parent command.
51 debugger
.GetCommandInterpreter().GetCommandObject("plugin");
55 // Create the structured-data ommand object.
56 auto command_name
= "structured-data";
57 auto command_sp
= CommandObjectSP(new CommandStructuredData(interpreter
));
59 // Hook it up under the top-level plugin command.
60 parent_command
->LoadSubCommand(command_name
, command_sp
);
64 void StructuredDataPlugin::ModulesDidLoad(Process
&process
,
65 ModuleList
&module_list
) {
66 // Default implementation does nothing.