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