2 Test that global operators are found and evaluated.
5 from lldbsuite
.test
.decorators
import *
6 from lldbsuite
.test
.lldbtest
import *
7 from lldbsuite
.test
import lldbutil
10 class TestCppGlobalOperators(TestBase
):
11 def prepare_executable_and_get_frame(self
):
14 # Get main source file
16 src_file_spec
= lldb
.SBFileSpec(src_file
)
17 self
.assertTrue(src_file_spec
.IsValid(), "Main source file")
19 # Get the path of the executable
20 exe_path
= self
.getBuildArtifact("a.out")
23 target
= self
.dbg
.CreateTarget(exe_path
)
24 self
.assertTrue(target
.IsValid(), VALID_TARGET
)
26 # Break on main function
27 main_breakpoint
= target
.BreakpointCreateBySourceRegex(
28 "// break here", src_file_spec
31 main_breakpoint
.IsValid() and main_breakpoint
.GetNumLocations() >= 1,
38 process
= target
.LaunchSimple(args
, env
, self
.get_process_working_directory())
39 self
.assertTrue(process
.IsValid(), PROCESS_IS_VALID
)
41 # Get the thread of the process
42 self
.assertEqual(process
.GetState(), lldb
.eStateStopped
, PROCESS_STOPPED
)
43 thread
= lldbutil
.get_stopped_thread(process
, lldb
.eStopReasonBreakpoint
)
45 return thread
.GetSelectedFrame()
47 def test_equals_operator(self
):
48 frame
= self
.prepare_executable_and_get_frame()
50 test_result
= frame
.EvaluateExpression("operator==(s1, s2)")
52 test_result
.IsValid() and test_result
.GetValue() == "false",
53 "operator==(s1, s2) = false",
56 test_result
= frame
.EvaluateExpression("operator==(s1, s3)")
58 test_result
.IsValid() and test_result
.GetValue() == "true",
59 "operator==(s1, s3) = true",
62 test_result
= frame
.EvaluateExpression("operator==(s2, s3)")
64 test_result
.IsValid() and test_result
.GetValue() == "false",
65 "operator==(s2, s3) = false",
68 def do_new_test(self
, frame
, expr
, expected_value_name
):
69 """Evaluate a new expression, and check its result"""
71 expected_value
= frame
.FindValue(
72 expected_value_name
, lldb
.eValueTypeVariableGlobal
74 self
.assertTrue(expected_value
.IsValid())
76 expected_value_addr
= expected_value
.AddressOf()
77 self
.assertTrue(expected_value_addr
.IsValid())
79 got
= frame
.EvaluateExpression(expr
)
80 self
.assertTrue(got
.IsValid())
82 got
.GetValueAsUnsigned(), expected_value_addr
.GetValueAsUnsigned()
84 got_type
= got
.GetType()
85 self
.assertTrue(got_type
.IsPointerType())
86 self
.assertEqual(got_type
.GetPointeeType().GetName(), "Struct")
88 def test_operator_new(self
):
89 frame
= self
.prepare_executable_and_get_frame()
91 self
.do_new_test(frame
, "new Struct()", "global_new_buf")
92 self
.do_new_test(frame
, "new(new_tag) Struct()", "tagged_new_buf")