• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /*
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
15 */
16 
17 #include <LLDB/SBCommandInterpreter.h>
18 #include <LLDB/SBCommandReturnObject.h>
19 #include <LLDB/SBDebugger.h>
20 
21 namespace lldb {
22 bool PluginInitialize(lldb::SBDebugger debugger);
23 }
24 
25 class ChildCommand : public lldb::SBCommandPluginInterface {
26 public:
DoExecute(lldb::SBDebugger debugger,char ** command,lldb::SBCommandReturnObject & result)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 
PluginInitialize(lldb::SBDebugger debugger)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;
46 }
47