2 Test some expressions involving STL data types.
5 from __future__ import print_function
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
15 class STLTestCase(TestBase):
17 mydir = TestBase.compute_mydir(__file__)
20 # Call super's setUp().
22 # Find the line number to break inside main().
23 self.source = 'main.cpp'
24 self.line = line_number(self.source, '// Set break point at this line.')
26 # rdar://problem/10400981
27 @unittest2.expectedFailure
29 """Test some expressions involving STL data types."""
31 exe = os.path.join(os.getcwd(), "a.out")
33 # The following two lines, if uncommented, will enable loggings.
34 #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res)
35 #self.assertTrue(res.Succeeded())
37 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
39 # rdar://problem/8543077
40 # test/stl: clang built binaries results in the breakpoint locations = 3,
41 # is this a problem with clang generated debug info?
42 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True)
44 self.runCmd("run", RUN_SUCCEEDED)
46 # Stop at 'std::string hello_world ("Hello World!");'.
47 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
48 substrs = ['main.cpp:%d' % self.line,
49 'stop reason = breakpoint'])
51 # The breakpoint should have a hit count of 1.
52 self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
53 substrs = [' resolved, hit count = 1'])
55 # Now try some expressions....
57 self.runCmd('expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }')
59 # rdar://problem/10373783
60 # rdar://problem/10400981
61 self.expect('expr associative_array.size()',
63 self.expect('expr associative_array.count(hello_world)',
65 self.expect('expr associative_array[hello_world]',
67 self.expect('expr associative_array["hello"]',
70 @expectedFailureIcc # icc 13.1 and 14-beta do not emit DW_TAG_template_type_parameter
71 @add_test_categories(['pyapi'])
72 def test_SBType_template_aspects(self):
73 """Test APIs for getting template arguments from an SBType."""
75 exe = os.path.join(os.getcwd(), 'a.out')
77 # Create a target by the debugger.
78 target = self.dbg.CreateTarget(exe)
79 self.assertTrue(target, VALID_TARGET)
81 # Create the breakpoint inside function 'main'.
82 breakpoint = target.BreakpointCreateByLocation(self.source, self.line)
83 self.assertTrue(breakpoint, VALID_BREAKPOINT)
85 # Now launch the process, and do not stop at entry point.
86 process = target.LaunchSimple (None, None, self.get_process_working_directory())
87 self.assertTrue(process, PROCESS_IS_VALID)
90 self.assertTrue(process.GetState() == lldb.eStateStopped)
91 thread = lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint)
92 self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition")
93 frame0 = thread.GetFrameAtIndex(0)
95 # Get the type for variable 'associative_array'.
96 associative_array = frame0.FindVariable('associative_array')
97 self.DebugSBValue(associative_array)
98 self.assertTrue(associative_array, VALID_VARIABLE)
99 map_type = associative_array.GetType()
100 self.DebugSBType(map_type)
101 self.assertTrue(map_type, VALID_TYPE)
102 num_template_args = map_type.GetNumberOfTemplateArguments()
103 self.assertTrue(num_template_args > 0)
105 # We expect the template arguments to contain at least 'string' and 'int'.
106 expected_types = { 'string': False, 'int': False }
107 for i in range(num_template_args):
108 t = map_type.GetTemplateArgumentType(i)
110 self.assertTrue(t, VALID_TYPE)
113 expected_types['string'] = True
115 expected_types['int'] = True
117 # Check that both entries of the dictionary have 'True' as the value.
118 self.assertTrue(all(expected_types.values()))