"""
Test some expressions involving STL data types.
"""
import os, time
import unittest2
import lldb
import lldbutil
from lldbtest import *
class STLTestCase(TestBase):
mydir = os.path.join("lang", "cpp", "stl")
@unittest2.expectedFailure
@unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
@dsym_test
def test_with_dsym(self):
"""Test some expressions involving STL data types."""
self.buildDsym()
self.step_stl_exprs()
@unittest2.expectedFailure
@dwarf_test
def test_with_dwarf(self):
"""Test some expressions involving STL data types."""
self.buildDwarf()
self.step_stl_exprs()
@python_api_test
@dsym_test
def test_SBType_template_aspects_with_dsym(self):
"""Test APIs for getting template arguments from an SBType."""
self.buildDsym()
self.sbtype_template_apis()
@python_api_test
@dwarf_test
def test_SBType_template_aspects_with_dwarf(self):
"""Test APIs for getting template arguments from an SBType."""
self.buildDwarf()
self.sbtype_template_apis()
def setUp(self):
TestBase.setUp(self)
self.source = 'main.cpp'
self.line = line_number(self.source, '// Set break point at this line.')
def step_stl_exprs(self):
"""Test some expressions involving STL data types."""
exe = os.path.join(os.getcwd(), "a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
self.runCmd("run", RUN_SUCCEEDED)
self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
substrs = ['main.cpp:%d' % self.line,
'stop reason = breakpoint'])
self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
substrs = [' resolved, hit count = 1'])
self.runCmd('expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }')
self.expect('expr associative_array.size()',
substrs = [' = 3'])
self.expect('expr associative_array.count(hello_world)',
substrs = [' = 1'])
self.expect('expr associative_array[hello_world]',
substrs = [' = 1'])
self.expect('expr associative_array["hello"]',
substrs = [' = 2'])
def sbtype_template_apis(self):
"""Test APIs for getting template arguments from an SBType."""
exe = os.path.join(os.getcwd(), 'a.out')
target = self.dbg.CreateTarget(exe)
self.assertTrue(target, VALID_TARGET)
breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
self.assertTrue(breakpoint, VALID_BREAKPOINT)
process = target.LaunchSimple(None, None, os.getcwd())
self.assertTrue(process, PROCESS_IS_VALID)
self.assertTrue(process.GetState() == lldb.eStateStopped)
thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition")
frame0 = thread.GetFrameAtIndex(0)
associative_array = frame0.FindVariable('associative_array')
self.DebugSBValue(associative_array)
self.assertTrue(associative_array, VALID_VARIABLE)
map_type = associative_array.GetType()
self.DebugSBType(map_type)
self.assertTrue(map_type, VALID_TYPE)
num_template_args = map_type.GetNumberOfTemplateArguments()
self.assertTrue(num_template_args > 0)
expected_types = { 'string': False, 'int': False }
for i in range(num_template_args):
t = map_type.GetTemplateArgumentType(i)
self.DebugSBType(t)
self.assertTrue(t, VALID_TYPE)
name = t.GetName()
if 'string' in name:
expected_types['string'] = True
elif 'int' == name:
expected_types['int'] = True
self.assertTrue(all(expected_types.values()))
if __name__ == '__main__':
import atexit
lldb.SBDebugger.Initialize()
atexit.register(lambda: lldb.SBDebugger.Terminate())
unittest2.main()