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 ",arg); 39 arg = *(++command); 40 } 41 result.Printf("\n"); 42 return true; 43 } 44 return false; 45 } 46 47 }; 48 49 bool PluginInitialize(lldb::SBDebugger debugger)50lldb::PluginInitialize (lldb::SBDebugger debugger) 51 { 52 lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); 53 lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL); 54 foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command"); 55 return true; 56 } 57