2 Test lldb data formatter subsystem.
7 from lldbsuite.test.decorators import *
8 from lldbsuite.test.lldbtest import *
9 from lldbsuite.test import lldbutil
12 class StdUniquePtrDataFormatterTestCase(TestBase):
13 mydir = TestBase.compute_mydir(__file__)
15 @add_test_categories(["libstdcxx"])
16 def test_with_run_command(self):
18 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
20 lldbutil.run_break_set_by_source_regexp(
21 self, "Set break point at this line.")
22 self.runCmd("run", RUN_SUCCEEDED)
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'])
29 self.assertTrue(frame.IsValid())
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'])
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'])
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())
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())
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())
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())
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())
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.
72 self.runCmd("file " + self.getBuildArtifact("a.out"), CURRENT_EXECUTABLE_SET)
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'])
80 self.expect("frame variable f1->fp",
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'])
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())