15ffd83dbSDimitry Andric //===-- StructuredDataPlugin.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/StructuredDataPlugin.h" 100b57cec5SDimitry Andric 110b57cec5SDimitry Andric #include "lldb/Core/Debugger.h" 120b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h" 130b57cec5SDimitry Andric #include "lldb/Interpreter/CommandObjectMultiword.h" 140b57cec5SDimitry Andric 150b57cec5SDimitry Andric using namespace lldb; 160b57cec5SDimitry Andric using namespace lldb_private; 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric namespace { 190b57cec5SDimitry Andric class CommandStructuredData : public CommandObjectMultiword { 200b57cec5SDimitry Andric public: CommandStructuredData(CommandInterpreter & interpreter)210b57cec5SDimitry Andric CommandStructuredData(CommandInterpreter &interpreter) 220b57cec5SDimitry Andric : CommandObjectMultiword(interpreter, "structured-data", 230b57cec5SDimitry Andric "Parent for per-plugin structured data commands", 240b57cec5SDimitry Andric "plugin structured-data <plugin>") {} 250b57cec5SDimitry Andric 26fe6060f1SDimitry Andric ~CommandStructuredData() override = default; 270b57cec5SDimitry Andric }; 280b57cec5SDimitry Andric } 290b57cec5SDimitry Andric StructuredDataPlugin(const ProcessWP & process_wp)300b57cec5SDimitry AndricStructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp) 310b57cec5SDimitry Andric : PluginInterface(), m_process_wp(process_wp) {} 320b57cec5SDimitry Andric 33fe6060f1SDimitry Andric StructuredDataPlugin::~StructuredDataPlugin() = default; 340b57cec5SDimitry Andric GetEnabled(llvm::StringRef type_name) const35*fe013be4SDimitry Andricbool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name) const { 360b57cec5SDimitry Andric // By default, plugins are always enabled. Plugin authors should override 370b57cec5SDimitry Andric // this if there is an enabled/disabled state for their plugin. 380b57cec5SDimitry Andric return true; 390b57cec5SDimitry Andric } 400b57cec5SDimitry Andric GetProcess() const410b57cec5SDimitry AndricProcessSP StructuredDataPlugin::GetProcess() const { 420b57cec5SDimitry Andric return m_process_wp.lock(); 430b57cec5SDimitry Andric } 440b57cec5SDimitry Andric InitializeBasePluginForDebugger(Debugger & debugger)450b57cec5SDimitry Andricvoid StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) { 460b57cec5SDimitry Andric // Create our mutliword command anchor if it doesn't already exist. 470b57cec5SDimitry Andric auto &interpreter = debugger.GetCommandInterpreter(); 480b57cec5SDimitry Andric if (!interpreter.GetCommandObject("plugin structured-data")) { 490b57cec5SDimitry Andric // Find the parent command. 500b57cec5SDimitry Andric auto parent_command = 510b57cec5SDimitry Andric debugger.GetCommandInterpreter().GetCommandObject("plugin"); 520b57cec5SDimitry Andric if (!parent_command) 530b57cec5SDimitry Andric return; 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric // Create the structured-data ommand object. 560b57cec5SDimitry Andric auto command_name = "structured-data"; 570b57cec5SDimitry Andric auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter)); 580b57cec5SDimitry Andric 590b57cec5SDimitry Andric // Hook it up under the top-level plugin command. 600b57cec5SDimitry Andric parent_command->LoadSubCommand(command_name, command_sp); 610b57cec5SDimitry Andric } 620b57cec5SDimitry Andric } 630b57cec5SDimitry Andric ModulesDidLoad(Process & process,ModuleList & module_list)640b57cec5SDimitry Andricvoid StructuredDataPlugin::ModulesDidLoad(Process &process, 650b57cec5SDimitry Andric ModuleList &module_list) { 660b57cec5SDimitry Andric // Default implementation does nothing. 670b57cec5SDimitry Andric } 68