1""" 2Test Debugger APIs. 3""" 4 5import lldb 6 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9from lldbsuite.test import lldbutil 10 11 12class DebuggerAPITestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 NO_DEBUG_INFO_TESTCASE = True 16 17 @add_test_categories(['pyapi']) 18 def test_debugger_api_boundary_condition(self): 19 """Exercise SBDebugger APIs with boundary conditions.""" 20 self.dbg.HandleCommand(None) 21 self.dbg.SetDefaultArchitecture(None) 22 self.dbg.GetScriptingLanguage(None) 23 self.dbg.CreateTarget(None) 24 self.dbg.CreateTarget(None, None, None, True, lldb.SBError()) 25 self.dbg.CreateTargetWithFileAndTargetTriple(None, None) 26 self.dbg.CreateTargetWithFileAndArch(None, None) 27 self.dbg.FindTargetWithFileAndArch(None, None) 28 self.dbg.SetInternalVariable(None, None, None) 29 self.dbg.GetInternalVariableValue(None, None) 30 # FIXME (filcab): We must first allow for the swig bindings to know if 31 # a Python callback is set. (Check python-typemaps.swig) 32 # self.dbg.SetLoggingCallback(None) 33 self.dbg.SetPrompt(None) 34 self.dbg.SetCurrentPlatform(None) 35 self.dbg.SetCurrentPlatformSDKRoot(None) 36 37 fresh_dbg = lldb.SBDebugger() 38 self.assertEquals(len(fresh_dbg), 0) 39 40 @add_test_categories(['pyapi']) 41 def test_debugger_delete_invalid_target(self): 42 """SBDebugger.DeleteTarget() should not crash LLDB given and invalid target.""" 43 target = lldb.SBTarget() 44 self.assertFalse(target.IsValid()) 45 self.dbg.DeleteTarget(target) 46 47 def test_debugger_internal_variable(self): 48 """Ensure that SBDebugger reachs the same instance of properties 49 regardless CommandInterpreter's context initialization""" 50 self.build() 51 exe = self.getBuildArtifact("a.out") 52 53 # Create a target by the debugger. 54 target = self.dbg.CreateTarget(exe) 55 self.assertTrue(target, VALID_TARGET) 56 57 property_name = "target.process.memory-cache-line-size" 58 59 def get_cache_line_size(): 60 value_list = lldb.SBStringList() 61 value_list = self.dbg.GetInternalVariableValue(property_name, 62 self.dbg.GetInstanceName()) 63 64 self.assertEqual(value_list.GetSize(), 1) 65 try: 66 return int(value_list.GetStringAtIndex(0)) 67 except ValueError as error: 68 self.fail("Value is not a number: " + error) 69 70 # Get global property value while there are no processes. 71 global_cache_line_size = get_cache_line_size() 72 73 # Run a process via SB interface. CommandInterpreter's execution context 74 # remains empty. 75 error = lldb.SBError() 76 launch_info = lldb.SBLaunchInfo(None) 77 launch_info.SetLaunchFlags(lldb.eLaunchFlagStopAtEntry) 78 process = target.Launch(launch_info, error) 79 self.assertTrue(process, PROCESS_IS_VALID) 80 81 # This should change the value of a process's local property. 82 new_cache_line_size = global_cache_line_size + 512 83 error = self.dbg.SetInternalVariable(property_name, 84 str(new_cache_line_size), 85 self.dbg.GetInstanceName()) 86 self.assertTrue(error.Success(), 87 property_name + " value was changed successfully") 88 89 # Check that it was set actually. 90 self.assertEqual(get_cache_line_size(), new_cache_line_size) 91 92 # Run any command to initialize CommandInterpreter's execution context. 93 self.runCmd("target list") 94 95 # Test the local property again, is it set to new_cache_line_size? 96 self.assertEqual(get_cache_line_size(), new_cache_line_size) 97