[docs] Fix build-docs.sh
[llvm-project.git] / lldb / examples / plugins / commands / fooplugin.cpp
blobe65fa164f0489866eaace90a7d4a5beea35da0ca
1 //===-- fooplugin.cpp -------------------------------------------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
9 /*
10 An example plugin for LLDB that provides a new foo command with a child
11 subcommand
12 Compile this into a dylib foo.dylib and load by placing in appropriate locations
13 on disk or
14 by typing plugin load foo.dylib at the LLDB command line
17 #include <LLDB/SBCommandInterpreter.h>
18 #include <LLDB/SBCommandReturnObject.h>
19 #include <LLDB/SBDebugger.h>
21 namespace lldb {
22 bool PluginInitialize(lldb::SBDebugger debugger);
25 class ChildCommand : public lldb::SBCommandPluginInterface {
26 public:
27 virtual bool DoExecute(lldb::SBDebugger debugger, char **command,
28 lldb::SBCommandReturnObject &result) {
29 if (command) {
30 const char *arg = *command;
31 while (arg) {
32 result.Printf("%s\n", arg);
33 arg = *(++command);
35 return true;
37 return false;
41 bool lldb::PluginInitialize(lldb::SBDebugger debugger) {
42 lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
43 lldb::SBCommand foo = interpreter.AddMultiwordCommand("foo", NULL);
44 foo.AddCommand("child", new ChildCommand(), "a child of foo");
45 return true;