• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20    mydir = TestBase.compute_mydir(__file__)
21
22    def setUp(self):
23        # Call super's setUp().
24        TestBase.setUp(self)
25        # Find the line number to break inside main().
26        self.line = line_number(
27            os.path.join(self.getSourceDir(), "main.cpp"),
28            '// Set break point at this line.')
29
30    @skipIf(hostoslist=["windows"])
31    def test_symlink_paths_set(self):
32        pwd_symlink = self.create_src_symlink()
33        self.doBuild(pwd_symlink, pwd_symlink)
34        src_path = self.getBuildArtifact(_SRC_FILE)
35        lldbutil.run_break_set_by_file_and_line(self, src_path, self.line)
36
37    @skipIf(hostoslist=no_match(["linux"]))
38    def test_symlink_paths_set_procselfcwd(self):
39        os.chdir(self.getBuildDir())
40        pwd_symlink = '/proc/self/cwd'
41        self.doBuild(pwd_symlink, pwd_symlink)
42        src_path = self.getBuildArtifact(_SRC_FILE)
43        # /proc/self/cwd points to a realpath form of current directory.
44        src_path = os.path.realpath(src_path)
45        lldbutil.run_break_set_by_file_and_line(self, src_path, self.line)
46
47    @skipIf(hostoslist=["windows"])
48    def test_symlink_paths_unset(self):
49        pwd_symlink = self.create_src_symlink()
50        self.doBuild(pwd_symlink, None)
51        src_path = self.getBuildArtifact(_SRC_FILE)
52        self.assertRaises(
53            AssertionError,
54            lldbutil.run_break_set_by_file_and_line,
55            self,
56            src_path,
57            self.line)
58
59    @skipIf(hostoslist=["windows"])
60    def test_symlink_paths_empty(self):
61        pwd_symlink = self.create_src_symlink()
62        self.doBuild(pwd_symlink, "")
63        src_path = self.getBuildArtifact(_SRC_FILE)
64        self.assertRaises(
65            AssertionError,
66            lldbutil.run_break_set_by_file_and_line,
67            self,
68            src_path,
69            self.line)
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(None, None, {'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