b8281e9c85bdf8750db103a41e3f8fcbc3cf5dd8
[openbsd] /
1 from __future__ import print_function
2
3
4 import unittest2
5 import lldb
6 from lldbsuite.test.lldbtest import *
7 import lldbsuite.test.lldbutil as lldbutil
8
9
10 class TestMoveNearest(TestBase):
11
12     mydir = TestBase.compute_mydir(__file__)
13     NO_DEBUG_INFO_TESTCASE = True
14
15     def setUp(self):
16         # Call super's setUp().
17         TestBase.setUp(self)
18         # Find the line number to break inside main().
19         self.line1 = line_number('foo.h', '// !BR1')
20         self.line2 = line_number('foo.h', '// !BR2')
21         self.line_between = line_number('main.cpp', "// BR_Between")
22         print("BR_Between found at", self.line_between)
23         self.line_main = line_number('main.cpp', '// !BR_main')
24
25     def test(self):
26         """Test target.move-to-nearest logic"""
27
28         self.build()
29         target = self.dbg.CreateTarget(self.getBuildArtifact("a.out"))
30         self.assertTrue(target, VALID_TARGET)
31
32         lldbutil.run_break_set_by_symbol(self, 'main', sym_exact=True)
33         environment = self.registerSharedLibrariesWithTarget(target, ["foo"])
34         process = target.LaunchSimple(None, environment, self.get_process_working_directory())
35         self.assertEquals(process.GetState(), lldb.eStateStopped)
36
37         # Regardless of the -m value the breakpoint should have exactly one
38         # location on the foo functions
39         self.runCmd("settings set target.move-to-nearest-code true")
40         lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1,
41                 loc_exact=True, extra_options="-m 1")
42         lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2,
43                 loc_exact=True, extra_options="-m 1")
44
45         self.runCmd("settings set target.move-to-nearest-code false")
46         lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line1,
47                 loc_exact=True, extra_options="-m 0")
48         lldbutil.run_break_set_by_file_and_line(self, 'foo.h', self.line2,
49                 loc_exact=True, extra_options="-m 0")
50
51
52         # Make sure we set a breakpoint in main with -m 1 for various lines in
53         # the function declaration
54         # "int"
55         lldbutil.run_break_set_by_file_and_line(self, 'main.cpp',
56                 self.line_main-1, extra_options="-m 1")
57         # "main()"
58         lldbutil.run_break_set_by_file_and_line(self, 'main.cpp',
59                 self.line_main, extra_options="-m 1")
60         # "{"
61         lldbutil.run_break_set_by_file_and_line(self, 'main.cpp',
62                 self.line_main+1, extra_options="-m 1")
63         # "return .."
64         lldbutil.run_break_set_by_file_and_line(self, 'main.cpp',
65                 self.line_main+2, extra_options="-m 1")
66
67         # Make sure we don't put move the breakpoint if it is set between two functions:
68         lldbutil.run_break_set_by_file_and_line(self, 'main.cpp',
69                 self.line_between, extra_options="-m 1", num_expected_locations=0)