LLDB  mainline
StructuredDataPlugin.cpp
Go to the documentation of this file.
1 //===-- StructuredDataPlugin.cpp ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 
11 #include "lldb/Core/Debugger.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 namespace {
19 class CommandStructuredData : public CommandObjectMultiword {
20 public:
21  CommandStructuredData(CommandInterpreter &interpreter)
22  : CommandObjectMultiword(interpreter, "structured-data",
23  "Parent for per-plugin structured data commands",
24  "plugin structured-data <plugin>") {}
25 
26  ~CommandStructuredData() override = default;
27 };
28 }
29 
30 StructuredDataPlugin::StructuredDataPlugin(const ProcessWP &process_wp)
31  : PluginInterface(), m_process_wp(process_wp) {}
32 
34 
36  // By default, plugins are always enabled. Plugin authors should override
37  // this if there is an enabled/disabled state for their plugin.
38  return true;
39 }
40 
42  return m_process_wp.lock();
43 }
44 
46  // Create our mutliword command anchor if it doesn't already exist.
47  auto &interpreter = debugger.GetCommandInterpreter();
48  if (!interpreter.GetCommandObject("plugin structured-data")) {
49  // Find the parent command.
50  auto parent_command =
51  debugger.GetCommandInterpreter().GetCommandObject("plugin");
52  if (!parent_command)
53  return;
54 
55  // Create the structured-data ommand object.
56  auto command_name = "structured-data";
57  auto command_sp = CommandObjectSP(new CommandStructuredData(interpreter));
58 
59  // Hook it up under the top-level plugin command.
60  parent_command->LoadSubCommand(command_name, command_sp);
61  }
62 }
63 
65  ModuleList &module_list) {
66  // Default implementation does nothing.
67 }
lldb_private::StructuredDataPlugin::m_process_wp
lldb::ProcessWP m_process_wp
Definition: StructuredDataPlugin.h:163
lldb_private::Debugger::GetCommandInterpreter
CommandInterpreter & GetCommandInterpreter()
Definition: Debugger.h:193
lldb_private::PluginInterface
Definition: PluginInterface.h:16
lldb_private::StructuredDataPlugin::InitializeBasePluginForDebugger
static void InitializeBasePluginForDebugger(Debugger &debugger)
Derived classes must call this before attempting to hook up commands to the 'plugin structured-data' ...
Definition: StructuredDataPlugin.cpp:45
lldb_private::Process
Definition: Process.h:340
lldb_private::CommandInterpreter::GetCommandObject
CommandObject * GetCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
Debugger.h
lldb_private::CommandObjectMultiword
Definition: CommandObjectMultiword.h:19
lldb_private::ModuleList
Definition: ModuleList.h:72
StructuredDataPlugin.h
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::StructuredDataPlugin::~StructuredDataPlugin
~StructuredDataPlugin() override
lldb_private::CommandInterpreter
Definition: CommandInterpreter.h:214
CommandObjectMultiword.h
lldb_private::Debugger
Definition: Debugger.h:70
lldb_private::StructuredDataPlugin::GetProcess
lldb::ProcessSP GetProcess() const
Definition: StructuredDataPlugin.cpp:41
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
CommandInterpreter.h
lldb_private::StructuredDataPlugin::GetEnabled
virtual bool GetEnabled(ConstString type_name) const
Returns whether the plugin's features are enabled.
Definition: StructuredDataPlugin.cpp:35
lldb
Definition: SBAddress.h:15
lldb_private::StructuredDataPlugin::ModulesDidLoad
virtual void ModulesDidLoad(Process &process, ModuleList &module_list)
Allow the plugin to do work related to modules that loaded in the the corresponding process.
Definition: StructuredDataPlugin.cpp:64