1 //===-- StructuredDataPlugin.cpp --------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/Target/StructuredDataPlugin.h" 11 12 #include "lldb/Core/Debugger.h" 13 #include "lldb/Interpreter/CommandInterpreter.h" 14 #include "lldb/Interpreter/CommandObjectMultiword.h" 15 16 using namespace lldb; 17 using namespace lldb_private; 18 19 namespace 20 { 21 class CommandStructuredData : public CommandObjectMultiword 22 { 23 public: 24 CommandStructuredData(CommandInterpreter &interpreter) : 25 CommandObjectMultiword(interpreter, 26 "structured-data", 27 "Parent for per-plugin structured data commands", 28 "plugin structured-data <plugin>") 29 { 30 } 31 32 ~CommandStructuredData() 33 { 34 } 35 }; 36 } 37 38 StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp) : 39 PluginInterface(), 40 m_process_wp(process_wp) 41 { 42 } 43 44 StructuredDataPlugin::~StructuredDataPlugin() 45 { 46 } 47 48 bool 49 StructuredDataPlugin::GetEnabled(const ConstString &type_name) const 50 { 51 // By default, plugins are always enabled. Plugin authors should override 52 // this if there is an enabled/disabled state for their plugin. 53 return true; 54 } 55 56 ProcessSP 57 StructuredDataPlugin::GetProcess() const 58 { 59 return m_process_wp.lock(); 60 } 61 62 void 63 StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) 64 { 65 // Create our mutliword command anchor if it doesn't already exist. 66 auto &interpreter = debugger.GetCommandInterpreter(); 67 if (!interpreter.GetCommandObject("plugin structured-data")) 68 { 69 // Find the parent command. 70 auto parent_command = 71 debugger.GetCommandInterpreter().GetCommandObject("plugin"); 72 if (!parent_command) 73 return; 74 75 // Create the structured-data ommand object. 76 auto command_name = "structured-data"; 77 auto command_sp = 78 CommandObjectSP(new CommandStructuredData(interpreter)); 79 80 // Hook it up under the top-level plugin command. 81 parent_command->LoadSubCommand(command_name, 82 command_sp); 83 } 84 } 85 86 void 87 StructuredDataPlugin::ModulesDidLoad(Process &process, ModuleList &module_list) 88 { 89 // Default implementation does nothing. 90 } 91