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
15using namespace lldb;
16using namespace lldb_private;
17
18namespace {
19class CommandStructuredData : public CommandObjectMultiword {
20public:
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
31 : PluginInterface(), m_process_wp(process_wp) {}
32
34
35bool StructuredDataPlugin::GetEnabled(llvm::StringRef type_name) const {
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}
CommandObject * GetCommandObject(llvm::StringRef cmd, StringList *matches=nullptr, StringList *descriptions=nullptr) const
A class to manage flag bits.
Definition: Debugger.h:79
CommandInterpreter & GetCommandInterpreter()
Definition: Debugger.h:176
A collection class for Module objects.
Definition: ModuleList.h:103
A plug-in interface definition class for debugging a process.
Definition: Process.h:341
virtual bool GetEnabled(llvm::StringRef type_name) const
Returns whether the plugin's features are enabled.
virtual void ModulesDidLoad(Process &process, ModuleList &module_list)
Allow the plugin to do work related to modules that loaded in the the corresponding process.
StructuredDataPlugin(const lldb::ProcessWP &process_wp)
static void InitializeBasePluginForDebugger(Debugger &debugger)
Derived classes must call this before attempting to hook up commands to the 'plugin structured-data' ...
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
Definition: lldb-forward.h:325
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:381
std::weak_ptr< lldb_private::Process > ProcessWP
Definition: lldb-forward.h:384