brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · ab0e9f0 Raw
94 lines · python
1"""2Use lldb Python SBWatchpoint API to set the ignore count.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class WatchpointIgnoreCountTestCase(TestBase):12    NO_DEBUG_INFO_TESTCASE = True13 14    def setUp(self):15        # Call super's setUp().16        TestBase.setUp(self)17        # Our simple source filename.18        self.source = "main.c"19        # Find the line number to break inside main().20        self.line = line_number(self.source, "// Set break point at this line.")21 22    # on arm64 targets, lldb has incorrect hit-count / ignore-counts23    # for watchpoints when they are hit with multiple threads at24    # the same time.  Tracked as llvm.org/pr4943325    # or rdar://93863107 inside Apple.26    def affected_by_radar_93863107(self):27        return (28            self.getArchitecture() in ["arm64", "arm64e"]29        ) and self.platformIsDarwin()30 31    # Read-write watchpoints not supported on SystemZ32    @expectedFailureAll(archs=["s390x"])33    def test_set_watch_ignore_count(self):34        """Test SBWatchpoint.SetIgnoreCount() API."""35        self.build()36        exe = self.getBuildArtifact("a.out")37 38        # Create a target by the debugger.39        target = self.dbg.CreateTarget(exe)40        self.assertTrue(target, VALID_TARGET)41 42        # Create a breakpoint on main.c in order to set our watchpoint later.43        breakpoint = target.BreakpointCreateByLocation(self.source, self.line)44        self.assertTrue(45            breakpoint and breakpoint.GetNumLocations() == 1, VALID_BREAKPOINT46        )47 48        # Now launch the process, and do not stop at the entry point.49        process = target.LaunchSimple(None, None, self.get_process_working_directory())50 51        # We should be stopped due to the breakpoint.  Get frame #0.52        process = target.GetProcess()53        self.assertState(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED)54        thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)55        frame0 = thread.GetFrameAtIndex(0)56 57        # Watch 'global' for read and write.58        value = frame0.FindValue("global", lldb.eValueTypeVariableGlobal)59        error = lldb.SBError()60        watchpoint = value.Watch(True, True, True, error)61        self.assertTrue(62            value and watchpoint, "Successfully found the variable and set a watchpoint"63        )64        self.DebugSBValue(value)65 66        # Hide stdout if not running with '-t' option.67        if not self.TraceOn():68            self.HideStdout()69 70        # There should be only 1 watchpoint location under the target.71        self.assertEqual(target.GetNumWatchpoints(), 1)72        watchpoint = target.GetWatchpointAtIndex(0)73        self.assertTrue(watchpoint.IsEnabled())74        self.assertEqual(watchpoint.GetIgnoreCount(), 0)75        watch_id = watchpoint.GetID()76        self.assertNotEqual(watch_id, 0)77        print(watchpoint)78 79        # Now immediately set the ignore count to 2.  When we continue, expect the80        # inferior to run to its completion without stopping due to watchpoint.81        watchpoint.SetIgnoreCount(2)82        print(watchpoint)83        process.Continue()84 85        # At this point, the inferior process should have exited.86        self.assertState(process.GetState(), lldb.eStateExited, PROCESS_EXITED)87 88        # Verify some vital statistics.89        self.assertTrue(watchpoint)90        self.assertEqual(watchpoint.GetWatchSize(), 4)91        if not self.affected_by_radar_93863107():92            self.assertEqual(watchpoint.GetHitCount(), 2)93        print(watchpoint)94