2ead4fab5593e85f12ffb893443ea3984785c09d
[openbsd] /
1 """
2 Test lldb data formatter subsystem.
3 """
4
5
6 import lldb
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
10
11
12 class StdUniquePtrDataFormatterTestCase(TestBase):
13     mydir = TestBase.compute_mydir(__file__)
14
15     @add_test_categories(["libstdcxx"])
16     def test_with_run_command(self):
17         self.build()
18         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
19
20         lldbutil.run_break_set_by_source_regexp(
21             self, "Set break point at this line.")
22         self.runCmd("run", RUN_SUCCEEDED)
23
24         # The stop reason of the thread should be breakpoint.
25         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
26                     substrs=['stopped', 'stop reason = breakpoint'])
27
28         frame = self.frame()
29         self.assertTrue(frame.IsValid())
30
31         self.expect("frame variable nup", substrs=['nup = nullptr'])
32         self.expect("frame variable iup", substrs=['iup = 0x'])
33         self.expect("frame variable sup", substrs=['sup = 0x'])
34
35         self.expect("frame variable ndp", substrs=['ndp = nullptr'])
36         self.expect("frame variable idp", substrs=['idp = 0x', 'deleter = ', 'a = 1', 'b = 2'])
37         self.expect("frame variable sdp", substrs=['sdp = 0x', 'deleter = ', 'a = 3', 'b = 4'])
38
39         self.assertEqual(123, frame.GetValueForVariablePath("iup.object").GetValueAsUnsigned())
40         self.assertEqual(123, frame.GetValueForVariablePath("*iup").GetValueAsUnsigned())
41         self.assertFalse(frame.GetValueForVariablePath("iup.deleter").IsValid())
42
43         self.assertEqual('"foobar"', frame.GetValueForVariablePath("sup.object").GetSummary())
44         self.assertEqual('"foobar"', frame.GetValueForVariablePath("*sup").GetSummary())
45         self.assertFalse(frame.GetValueForVariablePath("sup.deleter").IsValid())
46
47         self.assertEqual(456, frame.GetValueForVariablePath("idp.object").GetValueAsUnsigned())
48         self.assertEqual(456, frame.GetValueForVariablePath("*idp").GetValueAsUnsigned())
49         self.assertEqual('"baz"', frame.GetValueForVariablePath("sdp.object").GetSummary())
50         self.assertEqual('"baz"', frame.GetValueForVariablePath("*sdp").GetSummary())
51
52         idp_deleter = frame.GetValueForVariablePath("idp.deleter")
53         self.assertTrue(idp_deleter.IsValid())
54         self.assertEqual(1, idp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
55         self.assertEqual(2, idp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())
56
57         sdp_deleter = frame.GetValueForVariablePath("sdp.deleter")
58         self.assertTrue(sdp_deleter.IsValid())
59         self.assertEqual(3, sdp_deleter.GetChildMemberWithName("a").GetValueAsUnsigned())
60         self.assertEqual(4, sdp_deleter.GetChildMemberWithName("b").GetValueAsUnsigned())
61
62     @skipIfFreeBSD
63     @skipIfWindows  # libstdcpp not ported to Windows
64     @skipIfDarwin  # doesn't compile on Darwin
65     @skipIfwatchOS  # libstdcpp not ported to watchos
66     @add_test_categories(["libstdcxx"])
67     def test_recursive_unique_ptr(self):
68         # Tests that LLDB can handle when we have a loop in the unique_ptr
69         # reference chain and that it correctly handles the different options
70         # for the frame variable command in this case.
71         self.build()
72         self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
73
74         lldbutil.run_break_set_by_source_regexp(
75             self, "Set break point at this line.")
76         self.runCmd("run", RUN_SUCCEEDED)
77         self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
78                     substrs=['stopped', 'stop reason = breakpoint'])
79
80         self.expect("frame variable f1->fp",
81                     substrs=['fp = 0x'])
82         self.expect("frame variable --ptr-depth=1 f1->fp",
83                     substrs=['data = 2', 'fp = 0x'])
84         self.expect("frame variable --ptr-depth=2 f1->fp",
85                     substrs=['data = 2', 'fp = 0x', 'data = 1'])
86
87         frame = self.frame()
88         self.assertTrue(frame.IsValid())
89         self.assertEqual(2, frame.GetValueForVariablePath("f1->fp.object.data").GetValueAsUnsigned())
90         self.assertEqual(2, frame.GetValueForVariablePath("f1->fp->data").GetValueAsUnsigned())
91         self.assertEqual(1, frame.GetValueForVariablePath("f1->fp.object.fp.object.data").GetValueAsUnsigned())
92         self.assertEqual(1, frame.GetValueForVariablePath("f1->fp->fp->data").GetValueAsUnsigned())
93