diff options
| author | Enrico Granata <egranata@apple.com> | 2012-10-23 00:09:02 +0000 |
|---|---|---|
| committer | Enrico Granata <egranata@apple.com> | 2012-10-23 00:09:02 +0000 |
| commit | bc08ab450ac340dab4cf9fca0659cfc1f4211d48 (patch) | |
| tree | 5b33a981b67eb6c68be4ea679a4e20fb84b390ed /lldb/test/functionalities/plugins | |
| parent | c2d984c82384c6d264cc27c2dc4fbf09513912cb (diff) | |
| download | bcm5719-llvm-bc08ab450ac340dab4cf9fca0659cfc1f4211d48.tar.gz bcm5719-llvm-bc08ab450ac340dab4cf9fca0659cfc1f4211d48.zip | |
<rdar://problem/12500212> Test case for the new plugin feature
llvm-svn: 166453
Diffstat (limited to 'lldb/test/functionalities/plugins')
3 files changed, 124 insertions, 0 deletions
diff --git a/lldb/test/functionalities/plugins/commands/Makefile b/lldb/test/functionalities/plugins/commands/Makefile new file mode 100644 index 00000000000..2d79cf61c16 --- /dev/null +++ b/lldb/test/functionalities/plugins/commands/Makefile @@ -0,0 +1,11 @@ +all: foo.dylib + +CWD := $(shell pwd) + +all: foo.dylib + +foo.dylib: + clang++ -O0 -g -stdlib=libc++ -dynamiclib -o plugin.dylib plugin.cpp -framework LLDB -F $(LLDB_FRAMEWORK)/.. + +clean: + rm -rf plugin.dylib plugin.dylib.dSYM/* plugin.dylib.dSYM diff --git a/lldb/test/functionalities/plugins/commands/TestPluginCommands.py b/lldb/test/functionalities/plugins/commands/TestPluginCommands.py new file mode 100644 index 00000000000..a53edca679d --- /dev/null +++ b/lldb/test/functionalities/plugins/commands/TestPluginCommands.py @@ -0,0 +1,57 @@ +""" +Test that plugins that load commands work correctly. +""" + +import os, time +import re +import unittest2 +import lldb +from lldbtest import * +import lldbutil + +class PluginCommandTestCase(TestBase): + + mydir = os.path.join("functionalities", "plugins", "commands") + + def setUp(self): + # Call super's setUp(). + TestBase.setUp(self) + + @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") + def test_load_plugin(self): + """Test that plugins that load commands work correctly.""" + + # Invoke the default build rule. + self.buildDefault() + + debugger = lldb.SBDebugger.Create() + + retobj = lldb.SBCommandReturnObject() + + retval = debugger.GetCommandInterpreter().HandleCommand("plugin load plugin.dylib",retobj) + + retobj.Clear() + + retval = debugger.GetCommandInterpreter().HandleCommand("plugin_loaded_command child abc def ghi",retobj) + + if self.TraceOn(): + print retobj.GetOutput() + + self.expect(retobj,substrs = ['abc def ghi'], exe=False) + + retobj.Clear() + + # check that abbreviations work correctly in plugin commands. + retval = debugger.GetCommandInterpreter().HandleCommand("plugin_loaded_ ch abc def ghi",retobj) + + if self.TraceOn(): + print retobj.GetOutput() + + self.expect(retobj,substrs = ['abc def ghi'], exe=False) + + +if __name__ == '__main__': + import atexit + lldb.SBDebugger.Initialize() + atexit.register(lambda: lldb.SBDebugger.Terminate()) + unittest2.main() diff --git a/lldb/test/functionalities/plugins/commands/plugin.cpp b/lldb/test/functionalities/plugins/commands/plugin.cpp new file mode 100644 index 00000000000..7b4e46fc484 --- /dev/null +++ b/lldb/test/functionalities/plugins/commands/plugin.cpp @@ -0,0 +1,56 @@ +//===-- fooplugin.cpp -------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +/* +An example plugin for LLDB that provides a new foo command with a child subcommand +Compile this into a dylib foo.dylib and load by placing in appropriate locations on disk or +by typing plugin load foo.dylib at the LLDB command line +*/ + +#include <LLDB/SBCommandInterpreter.h> +#include <LLDB/SBCommandReturnObject.h> +#include <LLDB/SBDebugger.h> + +namespace lldb { + bool + PluginInitialize (lldb::SBDebugger debugger); +} + +class ChildCommand : public lldb::SBCommandPluginInterface +{ +public: + virtual bool + DoExecute (lldb::SBDebugger debugger, + char** command, + lldb::SBCommandReturnObject &result) + { + if (command) + { + const char* arg = *command; + while (arg) + { + result.Printf("%s ",arg); + arg = *(++command); + } + result.Printf("\n"); + return true; + } + return false; + } + +}; + +bool +lldb::PluginInitialize (lldb::SBDebugger debugger) +{ + lldb::SBCommandInterpreter interpreter = debugger.GetCommandInterpreter(); + lldb::SBCommand foo = interpreter.AddMultiwordCommand("plugin_loaded_command",NULL); + foo.AddCommand("child",new ChildCommand(),"a child of plugin_loaded_command"); + return true; +} |

