1cfca06d7SDimitry Andric //===-- StructuredDataPlugin.cpp ------------------------------------------===// 214f1b3e8SDimitry Andric // 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 614f1b3e8SDimitry Andric // 714f1b3e8SDimitry Andric //===----------------------------------------------------------------------===// 814f1b3e8SDimitry Andric 914f1b3e8SDimitry Andric #include "lldb/Target/StructuredDataPlugin.h" 1014f1b3e8SDimitry Andric 1114f1b3e8SDimitry Andric #include "lldb/Core/Debugger.h" 1214f1b3e8SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h" 1314f1b3e8SDimitry Andric #include "lldb/Interpreter/CommandObjectMultiword.h" 1414f1b3e8SDimitry Andric 1514f1b3e8SDimitry Andric using namespace lldb; 1614f1b3e8SDimitry Andric using namespace lldb_private; 1714f1b3e8SDimitry Andric 1814f1b3e8SDimitry Andric namespace { 1914f1b3e8SDimitry Andric class CommandStructuredData : public CommandObjectMultiword { 2014f1b3e8SDimitry Andric public: CommandStructuredData(CommandInterpreter & interpreter)2114f1b3e8SDimitry Andric CommandStructuredData(CommandInterpreter &interpreter) 2214f1b3e8SDimitry Andric : CommandObjectMultiword(interpreter, "structured-data", 2314f1b3e8SDimitry Andric "Parent for per-plugin structured data commands", 2414f1b3e8SDimitry Andric "plugin structured-data <plugin>") {} 2514f1b3e8SDimitry Andric 26344a3780SDimitry Andric ~CommandStructuredData() override = default; 2714f1b3e8SDimitry Andric }; 2814f1b3e8SDimitry Andric } 2914f1b3e8SDimitry Andric StructuredDataPlugin(const ProcessWP & process_wp)3014f1b3e8SDimitry AndricStructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp) 3114f1b3e8SDimitry Andric : PluginInterface(), m_process_wp(process_wp) {} 3214f1b3e8SDimitry Andric 33344a3780SDimitry Andric StructuredDataPlugin::~StructuredDataPlugin() = default; 3414f1b3e8SDimitry Andric GetEnabled(llvm::StringRef type_name) const357fa27ce4SDimitry Andricbool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name) const { 3614f1b3e8SDimitry Andric // By default, plugins are always enabled. Plugin authors should override 3714f1b3e8SDimitry Andric // this if there is an enabled/disabled state for their plugin. 3814f1b3e8SDimitry Andric return true; 3914f1b3e8SDimitry Andric } 4014f1b3e8SDimitry Andric GetProcess() const4114f1b3e8SDimitry AndricProcessSP StructuredDataPlugin::GetProcess() const { 4214f1b3e8SDimitry Andric return m_process_wp.lock(); 4314f1b3e8SDimitry Andric } 4414f1b3e8SDimitry Andric InitializeBasePluginForDebugger(Debugger & debugger)4514f1b3e8SDimitry Andricvoid StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) { 4614f1b3e8SDimitry Andric // Create our mutliword command anchor if it doesn't already exist. 4714f1b3e8SDimitry Andric auto &interpreter = debugger.GetCommandInterpreter(); 4814f1b3e8SDimitry Andric if (!interpreter.GetCommandObject("plugin structured-data")) { 4914f1b3e8SDimitry Andric // Find the parent command. 5014f1b3e8SDimitry Andric auto parent_command = 5114f1b3e8SDimitry Andric debugger.GetCommandInterpreter().GetCommandObject("plugin"); 5214f1b3e8SDimitry Andric if (!parent_command) 5314f1b3e8SDimitry Andric return; 5414f1b3e8SDimitry Andric 5514f1b3e8SDimitry Andric // Create the structured-data ommand object. 5614f1b3e8SDimitry Andric auto command_name = "structured-data"; 5714f1b3e8SDimitry Andric auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter)); 5814f1b3e8SDimitry Andric 5914f1b3e8SDimitry Andric // Hook it up under the top-level plugin command. 6014f1b3e8SDimitry Andric parent_command->LoadSubCommand(command_name, command_sp); 6114f1b3e8SDimitry Andric } 6214f1b3e8SDimitry Andric } 6314f1b3e8SDimitry Andric ModulesDidLoad(Process & process,ModuleList & module_list)6414f1b3e8SDimitry Andricvoid StructuredDataPlugin::ModulesDidLoad(Process &process, 6514f1b3e8SDimitry Andric ModuleList &module_list) { 6614f1b3e8SDimitry Andric // Default implementation does nothing. 6714f1b3e8SDimitry Andric } 68