175930019STodd Fiala //===-- StructuredDataPlugin.cpp --------------------------------*- C++ -*-===//
275930019STodd Fiala //
375930019STodd Fiala //                     The LLVM Compiler Infrastructure
475930019STodd Fiala //
575930019STodd Fiala // This file is distributed under the University of Illinois Open Source
675930019STodd Fiala // License. See LICENSE.TXT for details.
775930019STodd Fiala //
875930019STodd Fiala //===----------------------------------------------------------------------===//
975930019STodd Fiala 
1075930019STodd Fiala #include "lldb/Target/StructuredDataPlugin.h"
1175930019STodd Fiala 
1275930019STodd Fiala #include "lldb/Core/Debugger.h"
1375930019STodd Fiala #include "lldb/Interpreter/CommandInterpreter.h"
1475930019STodd Fiala #include "lldb/Interpreter/CommandObjectMultiword.h"
1575930019STodd Fiala 
1675930019STodd Fiala using namespace lldb;
1775930019STodd Fiala using namespace lldb_private;
1875930019STodd Fiala 
19*b9c1b51eSKate Stone namespace {
20*b9c1b51eSKate Stone class CommandStructuredData : public CommandObjectMultiword {
2175930019STodd Fiala public:
22*b9c1b51eSKate Stone   CommandStructuredData(CommandInterpreter &interpreter)
23*b9c1b51eSKate Stone       : CommandObjectMultiword(interpreter, "structured-data",
2475930019STodd Fiala                                "Parent for per-plugin structured data commands",
25*b9c1b51eSKate Stone                                "plugin structured-data <plugin>") {}
2675930019STodd Fiala 
27*b9c1b51eSKate Stone   ~CommandStructuredData() {}
2875930019STodd Fiala };
2975930019STodd Fiala }
3075930019STodd Fiala 
31*b9c1b51eSKate Stone StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp)
32*b9c1b51eSKate Stone     : PluginInterface(), m_process_wp(process_wp) {}
3375930019STodd Fiala 
34*b9c1b51eSKate Stone StructuredDataPlugin::~StructuredDataPlugin() {}
3575930019STodd Fiala 
36*b9c1b51eSKate Stone bool StructuredDataPlugin::GetEnabled(const ConstString &type_name) const {
3775930019STodd Fiala   // By default, plugins are always enabled.  Plugin authors should override
3875930019STodd Fiala   // this if there is an enabled/disabled state for their plugin.
3975930019STodd Fiala   return true;
4075930019STodd Fiala }
4175930019STodd Fiala 
42*b9c1b51eSKate Stone ProcessSP StructuredDataPlugin::GetProcess() const {
4375930019STodd Fiala   return m_process_wp.lock();
4475930019STodd Fiala }
4575930019STodd Fiala 
46*b9c1b51eSKate Stone void StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger) {
4775930019STodd Fiala   // Create our mutliword command anchor if it doesn't already exist.
4875930019STodd Fiala   auto &interpreter = debugger.GetCommandInterpreter();
49*b9c1b51eSKate Stone   if (!interpreter.GetCommandObject("plugin structured-data")) {
5075930019STodd Fiala     // Find the parent command.
5175930019STodd Fiala     auto parent_command =
5275930019STodd Fiala         debugger.GetCommandInterpreter().GetCommandObject("plugin");
5375930019STodd Fiala     if (!parent_command)
5475930019STodd Fiala       return;
5575930019STodd Fiala 
5675930019STodd Fiala     // Create the structured-data ommand object.
5775930019STodd Fiala     auto command_name = "structured-data";
58*b9c1b51eSKate Stone     auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter));
5975930019STodd Fiala 
6075930019STodd Fiala     // Hook it up under the top-level plugin command.
61*b9c1b51eSKate Stone     parent_command->LoadSubCommand(command_name, command_sp);
6275930019STodd Fiala   }
6375930019STodd Fiala }
6475930019STodd Fiala 
65*b9c1b51eSKate Stone void StructuredDataPlugin::ModulesDidLoad(Process &process,
66*b9c1b51eSKate Stone                                           ModuleList &module_list) {
6775930019STodd Fiala   // Default implementation does nothing.
6875930019STodd Fiala }
69