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