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 }
54 
55 ProcessSP
56 StructuredDataPlugin::GetProcess() const
57 {
58     return m_process_wp.lock();
59 }
60 
61 void
62 StructuredDataPlugin::InitializeBasePluginForDebugger(Debugger &debugger)
63 {
64     // Create our mutliword command anchor if it doesn't already exist.
65     auto &interpreter = debugger.GetCommandInterpreter();
66     if (!interpreter.GetCommandObject("plugin structured-data"))
67     {
68         // Find the parent command.
69         auto parent_command =
70             debugger.GetCommandInterpreter().GetCommandObject("plugin");
71         if (!parent_command)
72             return;
73 
74         // Create the structured-data ommand object.
75         auto command_name = "structured-data";
76         auto command_sp =
77             CommandObjectSP(new CommandStructuredData(interpreter));
78 
79         // Hook it up under the top-level plugin command.
80         parent_command->LoadSubCommand(command_name,
81                                        command_sp);
82     }
83 }
84 
85 void
86 StructuredDataPlugin::ModulesDidLoad(Process &process, ModuleList &module_list)
87 {
88     // Default implementation does nothing.
89 }
90