1""" 2Test some lldb command abbreviations. 3""" 4 5 6import lldb 7import os 8import sys 9import json 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbtest import * 12from lldbsuite.test import lldbutil 13from lldbsuite.test import lldbplatformutil 14 15 16class TestPaths(TestBase): 17 18 mydir = TestBase.compute_mydir(__file__) 19 20 @no_debug_info_test 21 def test_paths(self): 22 '''Test to make sure no file names are set in the lldb.SBFileSpec objects returned by lldb.SBHostOS.GetLLDBPath() for paths that are directories''' 23 dir_path_types = [lldb.ePathTypeLLDBShlibDir, 24 lldb.ePathTypeSupportExecutableDir, 25 lldb.ePathTypeHeaderDir, 26 lldb.ePathTypePythonDir, 27 lldb.ePathTypeLLDBSystemPlugins, 28 lldb.ePathTypeLLDBUserPlugins, 29 lldb.ePathTypeLLDBTempSystemDir, 30 lldb.ePathTypeClangDir] 31 32 for path_type in dir_path_types: 33 f = lldb.SBHostOS.GetLLDBPath(path_type) 34 # No directory path types should have the filename set 35 self.assertIsNone(f.GetFilename()) 36 37 shlib_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeLLDBShlibDir).GetDirectory() 38 if lldbplatformutil.getHostPlatform() == 'windows': 39 filenames = ['liblldb.dll'] 40 elif lldbplatformutil.getHostPlatform() == 'darwin': 41 filenames = ['LLDB', 'liblldb.dylib'] 42 else: 43 filenames = ['liblldb.so'] 44 self.assertTrue(any([os.path.exists(os.path.join(shlib_dir, f)) for f in 45 filenames]), "shlib_dir = " + shlib_dir) 46 47 @no_debug_info_test 48 def test_interpreter_info(self): 49 info_sd = self.dbg.GetScriptInterpreterInfo(self.dbg.GetScriptingLanguage("python")) 50 self.assertTrue(info_sd.IsValid()) 51 stream = lldb.SBStream() 52 self.assertTrue(info_sd.GetAsJSON(stream).Success()) 53 info = json.loads(stream.GetData()) 54 prefix = info['prefix'] 55 self.assertEqual(os.path.realpath(sys.prefix), os.path.realpath(prefix)) 56 self.assertEqual( 57 os.path.realpath(os.path.join(info['lldb-pythonpath'], 'lldb')), 58 os.path.realpath(os.path.dirname(lldb.__file__))) 59 self.assertTrue(os.path.exists(info['executable'])) 60 self.assertEqual(info['language'], 'python') 61 62 63 @no_debug_info_test 64 def test_directory_doesnt_end_with_slash(self): 65 current_directory_spec = lldb.SBFileSpec(os.path.curdir) 66 current_directory_string = current_directory_spec.GetDirectory() 67 self.assertNotEqual(current_directory_string[-1:], '/') 68 69 @skipUnlessPlatform(["windows"]) 70 @no_debug_info_test 71 def test_windows_double_slash(self): 72 '''Test to check the path with double slash is handled correctly ''' 73 # Create a path and see if lldb gets the directory and file right 74 fspec = lldb.SBFileSpec("C:\\dummy1\\dummy2//unknown_file", True) 75 self.assertEqual( 76 os.path.normpath( 77 fspec.GetDirectory()), 78 os.path.normpath("C:/dummy1/dummy2")) 79 self.assertEqual(fspec.GetFilename(), "unknown_file") 80