1""" 2Test breakpoint command with AT_comp_dir set to symbolic link. 3""" 4 5 6import os 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13_EXE_NAME = "CompDirSymLink" # Must match Makefile 14_SRC_FILE = "relative.cpp" 15_COMP_DIR_SYM_LINK_PROP = "symbols.debug-info-symlink-paths" 16 17 18class CompDirSymLinkTestCase(TestBase): 19 def setUp(self): 20 # Call super's setUp(). 21 TestBase.setUp(self) 22 # Find the line number to break inside main(). 23 self.line = line_number( 24 os.path.join(self.getSourceDir(), "main.cpp"), 25 "// Set break point at this line.", 26 ) 27 28 @skipIf(hostoslist=["windows"]) 29 def test_symlink_paths_set(self): 30 pwd_symlink = self.create_src_symlink() 31 self.doBuild(pwd_symlink, pwd_symlink) 32 src_path = self.getBuildArtifact(_SRC_FILE) 33 lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) 34 35 @skipIf(hostoslist=no_match(["linux"])) 36 def test_symlink_paths_set_procselfcwd(self): 37 os.chdir(self.getBuildDir()) 38 pwd_symlink = "/proc/self/cwd" 39 self.doBuild(pwd_symlink, pwd_symlink) 40 src_path = self.getBuildArtifact(_SRC_FILE) 41 # /proc/self/cwd points to a realpath form of current directory. 42 src_path = os.path.realpath(src_path) 43 lldbutil.run_break_set_by_file_and_line(self, src_path, self.line) 44 45 @skipIf(hostoslist=["windows"]) 46 def test_symlink_paths_unset(self): 47 pwd_symlink = self.create_src_symlink() 48 self.doBuild(pwd_symlink, None) 49 src_path = self.getBuildArtifact(_SRC_FILE) 50 self.assertRaises( 51 AssertionError, 52 lldbutil.run_break_set_by_file_and_line, 53 self, 54 src_path, 55 self.line, 56 ) 57 58 @skipIf(hostoslist=["windows"]) 59 def test_symlink_paths_empty(self): 60 pwd_symlink = self.create_src_symlink() 61 self.doBuild(pwd_symlink, "") 62 src_path = self.getBuildArtifact(_SRC_FILE) 63 self.assertRaises( 64 AssertionError, 65 lldbutil.run_break_set_by_file_and_line, 66 self, 67 src_path, 68 self.line, 69 ) 70 71 def create_src_symlink(self): 72 pwd_symlink = self.getBuildArtifact("pwd_symlink") 73 if os.path.exists(pwd_symlink): 74 os.unlink(pwd_symlink) 75 os.symlink(self.getBuildDir(), pwd_symlink) 76 self.addTearDownHook(lambda: os.remove(pwd_symlink)) 77 return pwd_symlink 78 79 def doBuild(self, pwd_symlink, setting_value): 80 self.build(dictionary={"PWD": pwd_symlink}) 81 82 if setting_value: 83 cmd = "settings set %s '%s'" % (_COMP_DIR_SYM_LINK_PROP, setting_value) 84 else: 85 cmd = "settings clear %s" % _COMP_DIR_SYM_LINK_PROP 86 self.runCmd(cmd) 87 88 exe = self.getBuildArtifact(_EXE_NAME) 89 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 90