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//===----------------------------------------------------------------------===//
8
9/*
10An example plugin for LLDB that provides a new foo command with a child
11subcommand
12Compile this into a dylib foo.dylib and load by placing in appropriate locations
13on disk or
14by typing plugin load foo.dylib at the LLDB command line
15*/
16
17#include <LLDB/SBCommandInterpreter.h>
18#include <LLDB/SBCommandReturnObject.h>
19#include <LLDB/SBDebugger.h>
20
21namespace lldb {
22bool PluginInitialize(lldb::SBDebugger debugger);
23}
24
25class ChildCommand : public lldb::SBCommandPluginInterface {
26public:
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);
34      }
35      return true;
36    }
37    return false;
38  }
39};
40
41bool 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;
46}
47