Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 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 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 19 | namespace { |
| 20 | class CommandStructuredData : public CommandObjectMultiword { |
| 21 | public: |
| 22 | CommandStructuredData(CommandInterpreter &interpreter) |
| 23 | : CommandObjectMultiword(interpreter, "structured-data", |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 24 | "Parent for per-plugin structured data commands", |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 25 | "plugin structured-data <plugin>") {} |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 26 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 27 | ~CommandStructuredData() {} |
| 28 | }; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 29 | } |
| 30 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 31 | StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp) |
| 32 | : PluginInterface(), m_process_wp(process_wp) {} |
| 33 | |
| 34 | StructuredDataPlugin::~StructuredDataPlugin() {} |
| 35 | |
| 36 | bool StructuredDataPlugin::GetEnabled(const ConstString &type_name) const { |
| 37 | // By default, plugins are always enabled. Plugin authors should override |
| 38 | // this if there is an enabled/disabled state for their plugin. |
| 39 | return true; |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | ProcessSP StructuredDataPlugin::GetProcess() const { |
| 43 | return m_process_wp.lock(); |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 44 | } |
| 45 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 46 | void StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) { |
| 47 | // Create our mutliword command anchor if it doesn't already exist. |
| 48 | auto &interpreter = debugger.GetCommandInterpreter(); |
| 49 | if (!interpreter.GetCommandObject("plugin structured-data")) { |
| 50 | // Find the parent command. |
| 51 | auto parent_command = |
| 52 | debugger.GetCommandInterpreter().GetCommandObject("plugin"); |
| 53 | if (!parent_command) |
| 54 | return; |
| 55 | |
| 56 | // Create the structured-data ommand object. |
| 57 | auto command_name = "structured-data"; |
| 58 | auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter)); |
| 59 | |
| 60 | // Hook it up under the top-level plugin command. |
| 61 | parent_command->LoadSubCommand(command_name, command_sp); |
| 62 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 65 | void StructuredDataPlugin::ModulesDidLoad(Process &process, |
| 66 | ModuleList &module_list) { |
| 67 | // Default implementation does nothing. |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 68 | } |