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