2015-08-19 06:46:57 +08:00
|
|
|
"""
|
|
|
|
Test scopes in C++.
|
|
|
|
"""
|
|
|
|
import lldb
|
2016-02-05 07:04:17 +08:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 10:06:18 +08:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-05 07:04:17 +08:00
|
|
|
from lldbsuite.test import lldbutil
|
2015-08-19 06:46:57 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
class TestCppScopes(TestBase):
|
2015-08-19 12:08:56 +08:00
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2015-08-19 12:08:56 +08:00
|
|
|
|
2016-02-09 03:34:59 +08:00
|
|
|
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24764")
|
2016-10-05 09:19:15 +08:00
|
|
|
def test_all_but_c(self):
|
|
|
|
self.do_test(False)
|
|
|
|
|
|
|
|
# There's a global symbol in libsystem on Darwin that messes up
|
|
|
|
# the lookup of class C. Breaking that test out from the others
|
|
|
|
# since that is a odd failure, and I don't want it to mask the
|
|
|
|
# real purpose of this test.
|
|
|
|
@expectedFailureDarwin(bugnumber="<rdar://problem/28623427>")
|
2016-10-06 04:47:17 +08:00
|
|
|
@expectedFailureAll(oslist=["windows"])
|
2016-10-05 09:19:15 +08:00
|
|
|
def test_c(self):
|
|
|
|
self.do_test(True)
|
|
|
|
|
|
|
|
def do_test(self, test_c):
|
2015-09-30 18:12:40 +08:00
|
|
|
self.build()
|
2015-08-19 06:46:57 +08:00
|
|
|
|
|
|
|
# Get main source file
|
|
|
|
src_file = "main.cpp"
|
|
|
|
src_file_spec = lldb.SBFileSpec(src_file)
|
|
|
|
self.assertTrue(src_file_spec.IsValid(), "Main source file")
|
2015-08-19 12:08:56 +08:00
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
# Get the path of the executable
|
2015-08-19 12:08:56 +08:00
|
|
|
cwd = os.getcwd()
|
2015-08-19 06:46:57 +08:00
|
|
|
exe_file = "a.out"
|
2016-09-07 04:57:50 +08:00
|
|
|
exe_path = os.path.join(cwd, exe_file)
|
2015-08-19 12:08:56 +08:00
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
# Load the executable
|
|
|
|
target = self.dbg.CreateTarget(exe_path)
|
|
|
|
self.assertTrue(target.IsValid(), VALID_TARGET)
|
|
|
|
|
|
|
|
# Break on main function
|
2016-09-07 04:57:50 +08:00
|
|
|
main_breakpoint = target.BreakpointCreateBySourceRegex(
|
|
|
|
"// break here", src_file_spec)
|
|
|
|
self.assertTrue(
|
|
|
|
main_breakpoint.IsValid() and main_breakpoint.GetNumLocations() >= 1,
|
|
|
|
VALID_BREAKPOINT)
|
2015-08-19 06:46:57 +08:00
|
|
|
|
|
|
|
# Launch the process
|
|
|
|
args = None
|
|
|
|
env = None
|
2016-09-07 04:57:50 +08:00
|
|
|
process = target.LaunchSimple(
|
|
|
|
args, env, self.get_process_working_directory())
|
2015-08-19 06:46:57 +08:00
|
|
|
self.assertTrue(process.IsValid(), PROCESS_IS_VALID)
|
|
|
|
|
|
|
|
# Get the thread of the process
|
2016-09-07 04:57:50 +08:00
|
|
|
self.assertTrue(
|
|
|
|
process.GetState() == lldb.eStateStopped,
|
|
|
|
PROCESS_STOPPED)
|
|
|
|
thread = lldbutil.get_stopped_thread(
|
|
|
|
process, lldb.eStopReasonBreakpoint)
|
2015-08-19 06:46:57 +08:00
|
|
|
|
2015-08-19 12:08:56 +08:00
|
|
|
# Get current fream of the thread at the breakpoint
|
2015-08-19 06:46:57 +08:00
|
|
|
frame = thread.GetSelectedFrame()
|
|
|
|
|
2015-08-19 12:08:56 +08:00
|
|
|
# Test result for scopes of variables
|
2015-08-19 06:46:57 +08:00
|
|
|
|
|
|
|
global_variables = frame.GetVariables(True, True, True, False)
|
2015-08-19 12:08:56 +08:00
|
|
|
global_variables_assert = {
|
2015-08-19 06:46:57 +08:00
|
|
|
'A::a': 1111,
|
|
|
|
'B::a': 2222,
|
|
|
|
'C::a': 3333,
|
|
|
|
'::a': 4444,
|
|
|
|
'a': 4444
|
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
self.assertTrue(
|
|
|
|
global_variables.GetSize() == 4,
|
|
|
|
"target variable returns all variables")
|
2015-08-19 06:46:57 +08:00
|
|
|
for variable in global_variables:
|
2015-08-19 12:08:56 +08:00
|
|
|
name = variable.GetName()
|
2016-09-07 04:57:50 +08:00
|
|
|
self.assertTrue(
|
|
|
|
name in global_variables_assert,
|
|
|
|
"target variable returns wrong variable " + name)
|
2015-08-19 06:46:57 +08:00
|
|
|
|
|
|
|
for name in global_variables_assert:
|
2016-10-05 09:19:15 +08:00
|
|
|
if name is "C::a" and not test_c:
|
|
|
|
continue
|
|
|
|
if name is not "C::a" and test_c:
|
|
|
|
continue
|
|
|
|
|
2015-08-19 06:46:57 +08:00
|
|
|
value = frame.EvaluateExpression(name)
|
|
|
|
assert_value = global_variables_assert[name]
|
2016-09-07 04:57:50 +08:00
|
|
|
self.assertTrue(
|
|
|
|
value.IsValid() and value.GetValueAsSigned() == assert_value,
|
|
|
|
name + " = " + str(assert_value))
|