]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/linux/thread/create_during_instruction_step/TestCreateDuringInstructionStep.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / linux / thread / create_during_instruction_step / TestCreateDuringInstructionStep.py
1 """
2 This tests that we do not lose control of the inferior, while doing an instruction-level step
3 over a thread creation instruction.
4 """
5
6 from __future__ import print_function
7
8
9 import os
10 import lldb
11 from lldbsuite.test.decorators import *
12 from lldbsuite.test.lldbtest import *
13 from lldbsuite.test import lldbutil
14
15
16 class CreateDuringInstructionStepTestCase(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     def setUp(self):
21         # Call super's setUp().
22         TestBase.setUp(self)
23
24     @skipUnlessPlatform(['linux'])
25     @expectedFailureAndroid('llvm.org/pr24737', archs=['arm'])
26     @expectedFailureAll(
27         oslist=["linux"],
28         archs=["arm"],
29         bugnumber="llvm.org/pr24737")
30     def test_step_inst(self):
31         self.build(dictionary=self.getBuildFlags())
32         exe = os.path.join(os.getcwd(), "a.out")
33         target = self.dbg.CreateTarget(exe)
34         self.assertTrue(target and target.IsValid(), "Target is valid")
35
36         # This should create a breakpoint in the stepping thread.
37         breakpoint = target.BreakpointCreateByName("main")
38         self.assertTrue(
39             breakpoint and breakpoint.IsValid(),
40             "Breakpoint is valid")
41
42         # Run the program.
43         process = target.LaunchSimple(
44             None, None, self.get_process_working_directory())
45         self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
46
47         # The stop reason of the thread should be breakpoint.
48         self.assertEqual(
49             process.GetState(),
50             lldb.eStateStopped,
51             PROCESS_STOPPED)
52
53         threads = lldbutil.get_threads_stopped_at_breakpoint(
54             process, breakpoint)
55         self.assertEqual(len(threads), 1, STOPPED_DUE_TO_BREAKPOINT)
56
57         thread = threads[0]
58         self.assertTrue(thread and thread.IsValid(), "Thread is valid")
59
60         # Make sure we see only one threads
61         self.assertEqual(
62             process.GetNumThreads(),
63             1,
64             'Number of expected threads and actual threads do not match.')
65
66         # Keep stepping until we see the thread creation
67         while process.GetNumThreads() < 2:
68             thread.StepInstruction(False)
69             self.assertEqual(
70                 process.GetState(),
71                 lldb.eStateStopped,
72                 PROCESS_STOPPED)
73             self.assertEqual(
74                 thread.GetStopReason(),
75                 lldb.eStopReasonPlanComplete,
76                 "Step operation succeeded")
77             if self.TraceOn():
78                 self.runCmd("disassemble --pc")
79
80         if self.TraceOn():
81             self.runCmd("thread list")
82
83         # We have successfully caught thread creation. Now just run to
84         # completion
85         process.Continue()
86
87         # At this point, the inferior process should have exited.
88         self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)