1//===-- plugin.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//===----------------------------------------------------------------------===//
8
9/*
10An example plugin for LLDB that provides a new foo command with a child subcommand
11Compile this into a dylib foo.dylib and load by placing in appropriate locations on disk or
12by typing plugin load foo.dylib at the LLDB command line
13*/
14
15%include_SB_APIs%
16
17namespace lldb {
18    bool
19    PluginInitialize (lldb::SBDebugger debugger);
20}
21
22class ChildCommand : public lldb::SBCommandPluginInterface
23{
24public:
25    virtual bool
26    DoExecute (lldb::SBDebugger debugger,
27               char** command,
28               lldb::SBCommandReturnObject &result)
29    {
30        if (command)
31        {
32            const char* arg = *command;
33            while (arg)
34            {
35                result.Printf("%s ",arg);
36                arg = *(++command);
37            }
38            result.Printf("\n");
39            return true;
40        }
41        return false;
42    }
43
44};
45
46bool
47lldb::PluginInitialize (lldb::SBDebugger debugger)
48{
49    lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter();
50    lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL);
51    foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command");
52    return true;
53}
54