1""" 2Test that plugins that load commands work correctly. 3""" 4 5import lldb 6from lldbsuite.test.decorators import * 7from lldbsuite.test.lldbtest import * 8from lldbsuite.test import lldbutil 9 10 11class PluginCommandTestCase(TestBase): 12 13 def setUp(self): 14 TestBase.setUp(self) 15 self.generateSource('plugin.cpp') 16 17 @skipIfNoSBHeaders 18 # Requires a compatible arch and platform to link against the host's built 19 # lldb lib. 20 @skipIfHostIncompatibleWithRemote 21 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24778") 22 @no_debug_info_test 23 def test_load_plugin(self): 24 """Test that plugins that load commands work correctly.""" 25 26 plugin_name = "plugin" 27 if sys.platform.startswith("darwin"): 28 plugin_lib_name = "lib%s.dylib" % plugin_name 29 else: 30 plugin_lib_name = "lib%s.so" % plugin_name 31 32 # Invoke the library build rule. 33 self.buildLibrary("plugin.cpp", plugin_name) 34 35 retobj = lldb.SBCommandReturnObject() 36 37 retval = self.dbg.GetCommandInterpreter().HandleCommand( 38 "plugin load %s" % self.getBuildArtifact(plugin_lib_name), retobj) 39 40 retobj.Clear() 41 42 retval = self.dbg.GetCommandInterpreter().HandleCommand( 43 "plugin_loaded_command child abc def ghi", retobj) 44 45 if self.TraceOn(): 46 print(retobj.GetOutput()) 47 48 self.expect(retobj, substrs=['abc def ghi'], exe=False) 49 50 retobj.Clear() 51 52 # check that abbreviations work correctly in plugin commands. 53 retval = self.dbg.GetCommandInterpreter().HandleCommand( 54 "plugin_loaded_ ch abc def ghi", retobj) 55 56 if self.TraceOn(): 57 print(retobj.GetOutput()) 58 59 self.expect(retobj, substrs=['abc def ghi'], exe=False) 60 61 @no_debug_info_test 62 def test_invalid_plugin_invocation(self): 63 self.expect("plugin load a b", 64 error=True, startstr="error: 'plugin load' requires one argument") 65 self.expect("plugin load", 66 error=True, startstr="error: 'plugin load' requires one argument") 67 68 @no_debug_info_test 69 def test_invalid_plugin_target(self): 70 self.expect("plugin load ThisIsNotAValidPluginName", 71 error=True, startstr="error: no such file") 72