]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/lang/cpp/trivial_abi/TestTrivialABI.py
Vendor import of lldb trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / lang / cpp / trivial_abi / TestTrivialABI.py
1 """
2 Test that we work properly with classes with the trivial_abi attribute
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import re
11 import lldb
12 from lldbsuite.test.decorators import *
13 from lldbsuite.test.lldbtest import *
14 from lldbsuite.test import lldbutil
15
16
17 class TestTrivialABI(TestBase):
18
19     mydir = TestBase.compute_mydir(__file__)
20     NO_DEBUG_INFO_TESTCASE = True
21
22     @skipUnlessSupportedTypeAttribute("trivial_abi")
23     @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr37995")
24     def test_call_trivial(self):
25         """Test that we can print a variable & call a function with a trivial ABI class."""
26         self.build()
27         self.main_source_file = lldb.SBFileSpec("main.cpp")
28         self.expr_test(True)
29
30     @skipUnlessSupportedTypeAttribute("trivial_abi")
31     @expectedFailureAll(bugnumber="llvm.org/pr36870")
32     def test_call_nontrivial(self):
33         """Test that we can print a variable & call a function on the same class w/o the trivial ABI marker."""
34         self.build()
35         self.main_source_file = lldb.SBFileSpec("main.cpp")
36         self.expr_test(False)
37
38     def setUp(self):
39         # Call super's setUp().
40         TestBase.setUp(self)
41
42     def check_value(self, test_var, ivar_value):
43         self.assertTrue(test_var.GetError().Success(), "Invalid valobj: %s"%(test_var.GetError().GetCString()))
44         ivar = test_var.GetChildMemberWithName("ivar")
45         self.assertTrue(test_var.GetError().Success(), "Failed to fetch ivar")
46         self.assertEqual(ivar_value, ivar.GetValueAsSigned(), "Got the right value for ivar")
47
48     def check_frame(self, thread):
49         frame = thread.frames[0]
50         inVal_var = frame.FindVariable("inVal")
51         self.check_value(inVal_var, 10)
52
53         options = lldb.SBExpressionOptions()
54         inVal_expr = frame.EvaluateExpression("inVal", options)
55         self.check_value(inVal_expr, 10)
56
57         thread.StepOut()
58         outVal_ret = thread.GetStopReturnValue()
59         self.check_value(outVal_ret, 30)
60
61     def expr_test(self, trivial):
62         (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
63                                    "Set a breakpoint here", self.main_source_file)
64
65         # Stop in a function that takes a trivial value, and try both frame var & expr to get its value:
66         if trivial:
67             self.check_frame(thread)
68             return
69
70         # Now continue to the same thing without the trivial_abi and see if we get that right:
71         threads = lldbutil.continue_to_breakpoint(process, bkpt)
72         self.assertEqual(len(threads), 1, "Hit my breakpoint the second time.")
73
74         self.check_frame(threads[0])