1 //===-- fooplugin.cpp -------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 /* 11 An example plugin for LLDB that provides a new foo command with a child 12 subcommand 13 Compile this into a dylib foo.dylib and load by placing in appropriate locations 14 on disk or 15 by typing plugin load foo.dylib at the LLDB command line 16 */ 17 18 #include <LLDB/SBCommandInterpreter.h> 19 #include <LLDB/SBCommandReturnObject.h> 20 #include <LLDB/SBDebugger.h> 21 22 namespace lldb { 23 bool PluginInitialize(lldb::SBDebugger debugger); 24 } 25 26 class ChildCommand : public lldb::SBCommandPluginInterface { 27 public: 28 virtual bool DoExecute(lldb::SBDebugger debugger, char **command, 29 lldb::SBCommandReturnObject &result) { 30 if (command) { 31 const char *arg = *command; 32 while (arg) { 33 result.Printf("%s\n", arg); 34 arg = *(++command); 35 } 36 return true; 37 } 38 return false; 39 } 40 }; 41 42 bool lldb::PluginInitialize(lldb::SBDebugger debugger) { 43 lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); 44 lldb::SBCommand foo = interpreter.AddMultiwordCommand("foo", NULL); 45 foo.AddCommand("child", new ChildCommand(), "a child of foo"); 46 return true; 47 } 48