]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/list/loop/TestDataFormatterLibcxxListLoop.py
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / data-formatter / data-formatter-stl / libcxx / list / loop / TestDataFormatterLibcxxListLoop.py
1 """
2 Test that the debugger handles loops in std::list (which can appear as a result of e.g. memory
3 corruption).
4 """
5
6 from __future__ import print_function
7
8
9 import os
10 import time
11 import re
12 import lldb
13 from lldbsuite.test.decorators import *
14 from lldbsuite.test.lldbtest import *
15 from lldbsuite.test import lldbutil
16
17
18 class LibcxxListDataFormatterTestCase(TestBase):
19
20     mydir = TestBase.compute_mydir(__file__)
21
22     @skipIf(compiler="gcc")
23     @skipIfWindows  # libc++ not ported to Windows yet
24     @add_test_categories(["pyapi"])
25     @skipIfDarwin  # rdar://25499635
26     def test_with_run_command(self):
27         self.build()
28         exe = os.path.join(os.getcwd(), "a.out")
29         target = self.dbg.CreateTarget(exe)
30         self.assertTrue(target and target.IsValid(), "Target is valid")
31
32         file_spec = lldb.SBFileSpec("main.cpp", False)
33         breakpoint1 = target.BreakpointCreateBySourceRegex(
34             '// Set break point at this line.', file_spec)
35         self.assertTrue(breakpoint1 and breakpoint1.IsValid())
36         breakpoint2 = target.BreakpointCreateBySourceRegex(
37             '// Set second break point at this line.', file_spec)
38         self.assertTrue(breakpoint2 and breakpoint2.IsValid())
39
40         # Run the program, it should stop at breakpoint 1.
41         process = target.LaunchSimple(
42             None, None, self.get_process_working_directory())
43         lldbutil.skip_if_library_missing(
44             self, target, lldbutil.PrintableRegex("libc\+\+"))
45         self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
46         self.assertEqual(
47             len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint1)), 1)
48
49         # verify our list is displayed correctly
50         self.expect(
51             "frame variable *numbers_list",
52             substrs=[
53                 '[0] = 1',
54                 '[1] = 2',
55                 '[2] = 3',
56                 '[3] = 4',
57                 '[5] = 6'])
58
59         # Continue to breakpoint 2.
60         process.Continue()
61         self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID)
62         self.assertEqual(
63             len(lldbutil.get_threads_stopped_at_breakpoint(process, breakpoint2)), 1)
64
65         # The list is now inconsistent. However, we should be able to get the first three
66         # elements at least (and most importantly, not crash).
67         self.expect(
68             "frame variable *numbers_list",
69             substrs=[
70                 '[0] = 1',
71                 '[1] = 2',
72                 '[2] = 3'])
73
74         # Run to completion.
75         process.Continue()
76         self.assertEqual(process.GetState(), lldb.eStateExited, PROCESS_EXITED)