brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · b1ab0a1 Raw
122 lines · python
1"""2Test the iteration protocol for some lldb container objects.3"""4 5import lldb6from lldbsuite.test.decorators import *7from lldbsuite.test.lldbtest import *8from lldbsuite.test import lldbutil9 10 11class LLDBIteratorTestCase(TestBase):12    def setUp(self):13        # Call super's setUp().14        TestBase.setUp(self)15        # Find the line numbers to break inside main().16        self.line1 = line_number("main.cpp", "// Set break point at this line.")17        self.line2 = line_number("main.cpp", "// And that line.")18 19    def test_lldb_iter_module(self):20        """Test module_iter works correctly for SBTarget -> SBModule."""21        self.build()22        exe = self.getBuildArtifact("a.out")23 24        target = self.dbg.CreateTarget(exe)25        self.assertTrue(target, VALID_TARGET)26 27        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)28        self.assertTrue(breakpoint, VALID_BREAKPOINT)29 30        # Now launch the process, and do not stop at entry point.31        process = target.LaunchSimple(None, None, self.get_process_working_directory())32 33        if not process:34            self.fail("SBTarget.LaunchProcess() failed")35 36        from lldbsuite.test.lldbutil import get_description37 38        yours = []39        for i in range(target.GetNumModules()):40            yours.append(target.GetModuleAtIndex(i))41        mine = []42        for m in target.module_iter():43            mine.append(m)44 45        self.assertEqual(len(yours), len(mine))46        for i in range(len(yours)):47            if self.TraceOn():48                print("yours[%d]='%s'" % (i, get_description(yours[i])))49                print("mine[%d]='%s'" % (i, get_description(mine[i])))50            self.assertEqual(51                yours[i],52                mine[i],53                "UUID+FileSpec of yours[{0}] and mine[{0}] matches".format(i),54            )55 56    def test_lldb_iter_breakpoint(self):57        """Test breakpoint_iter works correctly for SBTarget -> SBBreakpoint."""58        self.build()59        exe = self.getBuildArtifact("a.out")60 61        target = self.dbg.CreateTarget(exe)62        self.assertTrue(target, VALID_TARGET)63 64        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)65        self.assertTrue(breakpoint, VALID_BREAKPOINT)66        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line2)67        self.assertTrue(breakpoint, VALID_BREAKPOINT)68 69        self.assertEqual(target.GetNumBreakpoints(), 2)70 71        from lldbsuite.test.lldbutil import get_description72 73        yours = []74        for i in range(target.GetNumBreakpoints()):75            yours.append(target.GetBreakpointAtIndex(i))76        mine = []77        for b in target.breakpoint_iter():78            mine.append(b)79 80        self.assertEqual(len(yours), len(mine))81        for i in range(len(yours)):82            if self.TraceOn():83                print("yours[%d]='%s'" % (i, get_description(yours[i])))84                print("mine[%d]='%s'" % (i, get_description(mine[i])))85            self.assertEqual(86                yours[i], mine[i], "ID of yours[{0}] and mine[{0}] matches".format(i)87            )88 89    @skipIfWindows  # This test is flaky on Windows90    def test_lldb_iter_frame(self):91        """Test iterator works correctly for SBProcess->SBThread->SBFrame."""92        self.build()93        exe = self.getBuildArtifact("a.out")94 95        target = self.dbg.CreateTarget(exe)96        self.assertTrue(target, VALID_TARGET)97 98        breakpoint = target.BreakpointCreateByLocation("main.cpp", self.line1)99        self.assertTrue(breakpoint, VALID_BREAKPOINT)100 101        # Now launch the process, and do not stop at entry point.102        process = target.LaunchSimple(None, None, self.get_process_working_directory())103 104        if not process:105            self.fail("SBTarget.LaunchProcess() failed")106 107        from lldbsuite.test.lldbutil import print_stacktrace108 109        stopped_due_to_breakpoint = False110        for thread in process:111            if self.TraceOn():112                print_stacktrace(thread)113            ID = thread.GetThreadID()114            if thread.GetStopReason() == lldb.eStopReasonBreakpoint:115                stopped_due_to_breakpoint = True116            for frame in thread:117                self.assertEqual(frame.GetThread().GetThreadID(), ID)118                if self.TraceOn():119                    print(frame)120 121        self.assertTrue(stopped_due_to_breakpoint)122