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