def inferior_not_crashing(self): """Test lldb reloads the inferior after it was changed during the session.""" self.runCmd("process kill") self.runCmd("run", RUN_SUCCEEDED) self.runCmd("process status") # FIXME: This unexpected stop reason is Darwin-specific if 'EXC_BAD_ACCESS' in self.res.GetOutput(): self.fail("Inferior changed, but lldb did not perform a reload") # Break inside the main. lldbutil.run_break_set_by_file_and_line (self, "main2.c", self.line2, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) self.runCmd("frame variable int_ptr") self.expect("frame variable *int_ptr", substrs = ['= 7']) self.expect("expression *int_ptr", substrs = ['= 7'])
def ostype_data_formatter_commands(self): """Test the formatters we use for OSType.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, "main.mm", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type synth clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) # Now check that we use the right summary for OSType self.expect('frame variable', substrs = ["'test'","'best'"])
def test_with_run_command(self): """Test using Python synthetic children provider.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd("command script import helperfunc.py") self.runCmd('type summary add -x "^something<.*>$" -s "T is a ${script.var:helperfunc.f}"') self.expect("frame variable x", substrs = ['T is a non-pointer type']); self.expect("frame variable y", substrs = ['T is a pointer type']);
def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect('frame variable', substrs = ['(vFloat) valueFL = (1.25, 0, 0.25, 0)', '(int16_t [8]) valueI16 = (1, 0, 4, 0, 0, 1, 0, 4)', '(int32_t [4]) valueI32 = (1, 0, 4, 0)', '(vDouble) valueDL = (1.25, 2.25)', '(vUInt8) valueU8 = (0x01, 0x00, 0x04, 0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)', '(vUInt16) valueU16 = (1, 0, 4, 0, 0, 1, 0, 4)', '(vUInt32) valueU32 = (1, 2, 3, 4)', "(vSInt8) valueS8 = (1, 0, 4, 0, 0, 1, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0)", '(vSInt16) valueS16 = (1, 0, 4, 0, 0, 1, 0, 4)', '(vSInt32) valueS32 = (4, 3, 2, 1)', '(vBool32) valueBool32 = (0, 1, 0, 1)'])
def stop_hook_cmd_sequence(self): """Test a sequence of target stop-hook commands.""" 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.begl, num_expected_locations=1, loc_exact=True) lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("target stop-hook add -f main.cpp -l %d -e %d -o 'expr ptr'" % (self.begl, self.endl)) self.expect('target stop-hook list', 'Stop Hook added successfully', substrs = ['State: enabled', 'expr ptr']) self.runCmd('target stop-hook disable') self.expect('target stop-hook list', 'Stop Hook disabled successfully', substrs = ['State: disabled', 'expr ptr']) self.runCmd('target stop-hook enable') self.expect('target stop-hook list', 'Stop Hook enabled successfully', substrs = ['State: enabled', 'expr ptr']) self.runCmd("settings set auto-confirm true") self.addTearDownHook(lambda: self.runCmd("settings clear auto-confirm")) self.runCmd('target stop-hook delete') self.expect('target stop-hook list', 'Stop Hook deleted successfully', substrs = ['No stop hooks.'])
def do_my_test(self): # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd("type summary clear", check=False) self.runCmd("type synthetic clear", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) """Test expr + formatters for good interoperability.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.m", self.line, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) self.expect("expr -O -v -- foo", substrs=["(id) $", " = 0x", "1 = 2", "2 = 3;"]) self.expect("expr -O -vfull -- foo", substrs=["(id) $", " = 0x", "1 = 2", "2 = 3;"]) self.expect("expr -O -- foo", matching=False, substrs=["(id) $"]) self.expect("expr -O -- 22", matching=False, substrs=["(int) $"]) self.expect("expr -O -- 22", substrs=["22"]) self.expect("expr -O -vfull -- 22", substrs=["(int) $", " = 22"]) self.expect("expr -O -v -- 22", substrs=["(int) $", " = 22"])
def recursive_vo_commands(self): """Test that that file and class static variables display correctly.""" self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) root = self.frame().FindVariable("root") child = root.GetChildAtIndex(1) if self.TraceOn(): print root print child for i in range(0,24500): child = child.GetChildAtIndex(1) if self.TraceOn(): print child self.assertTrue(child.IsValid(),"could not retrieve the deep ValueObject") self.assertTrue(child.GetChildAtIndex(0).IsValid(),"the deep ValueObject has no value") self.assertTrue(child.GetChildAtIndex(0).GetValueAsUnsigned() != 0,"the deep ValueObject has a zero value") self.assertTrue(child.GetChildAtIndex(1).GetValueAsUnsigned() != 0, "the deep ValueObject has no next")
def test(self): """Test number of threads.""" self.build() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # This should create a breakpoint with 1 location. lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=1) # The breakpoint list should show 3 locations. self.expect("breakpoint list -f", "Breakpoint location shown correctly", substrs = ["1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" % self.line]) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # Stopped once. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ["stop reason = breakpoint 1."]) # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() # Get the number of threads num_threads = process.GetNumThreads() # Using std::thread may involve extra threads, so we assert that there are # at least 4 rather than exactly 4. self.assertTrue(num_threads >= 4, 'Number of expected threads and actual threads do not match.')
def class_types(self): """Test 'frame variable this' when stopped on a class constructor.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break on the ctor function of class C. lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The test suite sometimes shows that the process has exited without stopping. # # CC=clang ./dotest.py -v -t class_types # ... # Process 76604 exited with status = 0 (0x00000000) self.runCmd("process status") # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) # We should be stopped on the ctor function of class C. self.expect("frame variable --show-types this", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['C *', ' this = '])
def test_frame_var_after_stop_at_implementation(self): """Test that we can find the implementation for an objective C type""" if self.getArchitecture() == 'i386': self.skipTest("requires modern objc runtime") self.build() self.common_setup() line = line_number('Bar.m', '// Set breakpoint where Bar is an implementation') lldbutil.run_break_set_by_file_and_line (self, 'Bar.m', line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # Run and stop at Foo self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) self.runCmd("continue", RUN_SUCCEEDED) # Run at stop at main self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) # This should display correctly. self.expect("frame variable foo->_bar->_hidden_ivar", VARIABLES_DISPLAYED_CORRECTLY, substrs = ["(NSString *)", "foo->_bar->_hidden_ivar = 0x"])
def test(self): """Break inside a() and b() defined within libfoo.a.""" self.build() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside a() by file and line first. lldbutil.run_break_set_by_file_and_line (self, "a.c", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # Break at a(int) first. self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(int) arg = 1']) self.expect("frame variable __a_global", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(int) __a_global = 1']) # Set breakpoint for b() next. lldbutil.run_break_set_by_symbol (self, "b", num_expected_locations=1, sym_exact=True) # Continue the program, we should break at b(int) next. self.runCmd("continue") self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) self.expect("frame variable", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(int) arg = 2']) self.expect("frame variable __b_global", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(int) __b_global = 2'])
def test_step_over_load (self): """Test stepping over code that loads a shared library works correctly.""" # Invoke the default build rule. self.buildDefault() self.copy_shlibs_to_remote() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break by function name a_function (not yet loaded). lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint and at a_function. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) self.runCmd("thread step-over", "Stepping over function that loads library") # The stop reason should be step end. self.expect("thread list", "step over succeeded.", substrs = ['stopped', 'stop reason = step over'])
def test_with_run_command(self): """Test that file and class static variables display correctly.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # global variables are no longer displayed with the "frame variable" command. self.expect('target variable A::g_points', VARIABLES_DISPLAYED_CORRECTLY, patterns=['\(PointType \[[1-9]*\]\) A::g_points = {.*}']) self.expect('target variable g_points', VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(PointType [2]) g_points']) # On Mac OS X, gcc 4.2 emits the wrong debug info for A::g_points. # A::g_points is an array of two elements. if self.platformIsDarwin() or self.getPlatform() == "linux": self.expect("target variable A::g_points[1].x", VARIABLES_DISPLAYED_CORRECTLY, startstr = "(int) A::g_points[1].x = 11")
def data_formatter_commands(self): """Test that that file and class static variables display correctly.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect("frame variable vBool", substrs = ['size=49','[0] = false','[1] = true','[18] = false','[27] = true','[36] = false','[47] = true','[48] = true']) self.expect("expr vBool", substrs = ['size=49','[0] = false','[1] = true','[18] = false','[27] = true','[36] = false','[47] = true','[48] = true'])
def inferior_not_crashing(self): """Test lldb reloads the inferior after it was changed during the session.""" self.runCmd("process kill") # Prod the lldb-platform that we have a newly built inferior ready. if lldb.lldbtest_remote_sandbox: self.runCmd("file " + self.exe, CURRENT_EXECUTABLE_SET) self.runCmd("run", RUN_SUCCEEDED) self.runCmd("process status") self.assertNotEqual( len(lldbutil.get_crashed_threads(self, self.dbg.GetSelectedTarget().GetProcess())), 1, "Inferior changed, but lldb did not perform a reload") # Break inside the main. lldbutil.run_break_set_by_file_and_line (self, "main2.c", self.line2, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) self.runCmd("frame variable int_ptr") self.expect("frame variable *int_ptr", substrs = ['= 7']) self.expect("expression *int_ptr", substrs = ['= 7'])
def common_setup(self, line): # Set debugger into synchronous mode self.dbg.SetAsync(False) # Create a target exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set breakpoints inside and outside methods that take pointers to the containing struct. lldbutil.run_break_set_by_file_and_line (self, self.source, line, num_expected_locations=1, loc_exact=True) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1'])
def unsigned_types(self): """Test that variables with unsigned types display correctly.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # GCC puts a breakpoint on the last line of a multi-line expression, so # if GCC is the target compiler, we cannot rely on an exact line match. need_exact = "gcc" not in self.getCompiler() # Break on line 19 in main() aftre the variables are assigned values. lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=need_exact) self.runCmd("run", RUN_FAILED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) # Test that unsigned types display correctly. self.expect("frame variable --show-types --no-args", VARIABLES_DISPLAYED_CORRECTLY, startstr = "(unsigned char) the_unsigned_char = 'c'", patterns = ["\((short unsigned int|unsigned short)\) the_unsigned_short = 99"], substrs = ["(unsigned int) the_unsigned_int = 99", "(unsigned long) the_unsigned_long = 99", "(unsigned long long) the_unsigned_long_long = 99", "(uint32_t) the_uint32 = 99"])
def charstar_dyntype(self, exe_name): """Test that we do not attempt to make a dynamic type for a 'const char*'""" exe = os.path.join(os.getcwd(), exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, self.main_source, self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # check that we correctly see the const char*, even with dynamic types on self.expect("frame variable my_string", substrs = ['const char *']) self.expect("frame variable my_string --dynamic-type run-target", substrs = ['const char *']) # check that expr also gets it right self.expect("expr my_string", substrs = ['const char *']) self.expect("expr -d run -- my_string", substrs = ['const char *']) # but check that we get the real Foolie as such self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *']) self.expect("frame variable my_foolie --dynamic-type run-target", substrs = ['FoolMeOnce *']) # check that expr also gets it right self.expect("expr my_foolie", substrs = ['FoolMeOnce *']) self.expect("expr -d run -- my_foolie", substrs = ['FoolMeOnce *']) # now check that assigning a true string does not break anything self.runCmd("next") # check that we correctly see the const char*, even with dynamic types on self.expect("frame variable my_string", substrs = ['const char *']) self.expect("frame variable my_string --dynamic-type run-target", substrs = ['const char *']) # check that expr also gets it right self.expect("expr my_string", substrs = ['const char *']) self.expect("expr -d run -- my_string", substrs = ['const char *']) # but check that we get the real Foolie as such self.expect("frame variable my_foolie", substrs = ['FoolMeOnce *']) self.expect("frame variable my_foolie --dynamic-type run-target", substrs = ['FoolMeOnce *']) # check that expr also gets it right self.expect("expr my_foolie", substrs = ['FoolMeOnce *']) self.expect("expr -d run -- my_foolie", substrs = ['FoolMeOnce *'])
def rdar12991846(self): """Test that the expression parser returns proper Unicode strings.""" if self.getArchitecture() in ['i386']: self.skipTest("Skipping because this test is known to crash on i386") exe = os.path.join(os.getcwd(), "a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Break on the struct declration statement in main.cpp. lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple (None, None, self.get_process_working_directory()) if not process: self.fail("SBTarget.Launch() failed") self.expect('expression L"hello"', substrs = ['hello']) self.expect('expression u"hello"', substrs = ['hello']) self.expect('expression U"hello"', substrs = ['hello'])
def breakpoint_after_join_test(self): """Test breakpoint handling after a thread join.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # This should create a breakpoint in the main thread. lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1) # The breakpoint list should show 1 location. self.expect("breakpoint list -f", "Breakpoint location shown correctly", substrs = ["1: file = 'main.cpp', line = %d, locations = 1" % self.breakpoint]) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # Get the target process target = self.dbg.GetSelectedTarget() process = target.GetProcess() # The exit probably occured during breakpoint handling, but it isn't # guaranteed. The main thing we're testing here is that the debugger # handles this cleanly is some way. # Get the number of threads num_threads = process.GetNumThreads() # Make sure we see six threads self.assertTrue(num_threads == 6, 'Number of expected threads and actual threads do not match.') # Get the thread objects thread1 = process.GetThreadAtIndex(0) thread2 = process.GetThreadAtIndex(1) thread3 = process.GetThreadAtIndex(2) thread4 = process.GetThreadAtIndex(3) thread5 = process.GetThreadAtIndex(4) thread6 = process.GetThreadAtIndex(5) # Make sure all threads are stopped self.assertTrue(thread1.IsStopped(), "Thread 1 didn't stop during breakpoint") self.assertTrue(thread2.IsStopped(), "Thread 2 didn't stop during breakpoint") self.assertTrue(thread3.IsStopped(), "Thread 3 didn't stop during breakpoint") self.assertTrue(thread4.IsStopped(), "Thread 4 didn't stop during breakpoint") self.assertTrue(thread5.IsStopped(), "Thread 5 didn't stop during breakpoint") self.assertTrue(thread6.IsStopped(), "Thread 6 didn't stop during breakpoint") # Run to completion self.runCmd("continue") # If the process hasn't exited, collect some information if process.GetState() != lldb.eStateExited: self.runCmd("thread list") self.runCmd("process status") # At this point, the inferior process should have exited. self.assertTrue(process.GetState() == lldb.eStateExited, PROCESS_EXITED)
def test_expr(self): self.build() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the foo function which takes a bar_ptr argument. lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) self.runCmd("settings set target.clang-module-search-paths \"" + os.getcwd() + "\"") self.expect("expr @import myModule; 3", VARIABLES_DISPLAYED_CORRECTLY, substrs = ["int", "3"]) self.expect("expr [myObject privateMethod]", VARIABLES_DISPLAYED_CORRECTLY, substrs = ["int", "5"]) self.expect("expr MIN(2,3)", "#defined macro was found", substrs = ["int", "2"]) self.expect("expr MAX(2,3)", "#undefd macro was correcltly not found", error=True)
def inlined_breakpoints(self): """Test 'b basic_types.cpp:176' does break (where int.cpp includes basic_type.cpp).""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # With the inline-breakpoint-strategy, our file+line breakpoint should not resolve to a location. self.runCmd('settings set target.inline-breakpoint-strategy headers') # Set a breakpoint and fail because it is in an inlined source implemenation file lldbutil.run_break_set_by_file_and_line (self, "basic_type.cpp", self.line, num_expected_locations=0) # Now enable breakpoints in implementation files and see the breakpoint set succeed self.runCmd('settings set target.inline-breakpoint-strategy always') # And add hooks to restore the settings during tearDown(). self.addTearDownHook( lambda: self.runCmd("settings set target.inline-breakpoint-strategy always")) lldbutil.run_break_set_by_file_and_line (self, "basic_type.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. # And it should break at basic_type.cpp:176. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint', 'basic_type.cpp:%d' % self.line])
def sanity_check_executable(self, exe_name): """Sanity check executable compiled from the auto-generated program.""" exe = os.path.join(os.getcwd(), exe_name) self.runCmd("file %s" % exe, CURRENT_EXECUTABLE_SET) self.line_to_break = line_number(self.source, '// Set breakpoint here.') if sys.platform.startswith("darwin"): env_var = 'DYLD_FRAMEWORK_PATH' env_val = self.build_dir if sys.platform.startswith("linux"): env_var = 'LD_LIBRARY_PATH' env_val = self.build_dir env_cmd = "settings set target.env-vars %s=%s" %(env_var, env_val) if self.TraceOn(): print "Set environment to: ", env_cmd self.runCmd(env_cmd) self.addTearDownHook(lambda: self.runCmd("settings remove target.env-vars %s" % env_var)) lldbutil.run_break_set_by_file_and_line (self, self.source, self.line_to_break, num_expected_locations = -1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) self.runCmd('frame variable')
def test_with_run_command(self): """Test that a pointer/reference to a typedef is formatted as we want.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd('type summary add --cascade true -s "IntPointer" "int *"') self.runCmd('type summary add --cascade true -s "IntLRef" "int &"') self.runCmd('type summary add --cascade true -s "IntRRef" "int &&"') self.expect("frame variable x", substrs = ['(Foo *) x = 0x','IntPointer']) # note: Ubuntu 12.04 x86_64 build with gcc 4.8.2 is getting a # const after the ref that isn't showing up on FreeBSD. This # tweak changes the behavior so that the const is not part of # the match. self.expect("frame variable y", substrs = ['(Foo &', ') y = 0x','IntLRef']) self.expect("frame variable z", substrs = ['(Foo &&', ') z = 0x','IntRRef'])
def test_dyn(self): """Test that we are able to properly report a usable dynamic type.""" d = {'EXE': self.exe_name} self.build(dictionary=d) self.setTearDownCleanup(dictionary=d) exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, self.main_source, self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) v_object = self.frame().FindVariable("object").GetDynamicValue(lldb.eDynamicCanRunTarget) v_base = self.frame().FindVariable("base").GetDynamicValue(lldb.eDynamicCanRunTarget) self.assertTrue(v_object.GetTypeName() == "MyDerivedClass *", "The NSObject is properly type-named") self.assertTrue(v_base.GetTypeName() == "MyDerivedClass *", "The Base is properly type-named") object_type = v_object.GetType() base_type = v_base.GetType() self.assertTrue(object_type.GetName() == "MyDerivedClass *", "The dynamic SBType for NSObject is for the correct type") self.assertTrue(base_type.GetName() == "MyDerivedClass *", "The dynamic SBType for Base is for the correct type") object_pointee_type = object_type.GetPointeeType() base_pointee_type = base_type.GetPointeeType() self.assertTrue(object_pointee_type.GetName() == "MyDerivedClass", "The dynamic type for NSObject figures out its pointee type just fine") self.assertTrue(base_pointee_type.GetName() == "MyDerivedClass", "The dynamic type for Base figures out its pointee type just fine") self.assertTrue(object_pointee_type.GetDirectBaseClassAtIndex(0).GetName() == "MyBaseClass", "The dynamic type for NSObject can go back to its base class") self.assertTrue(base_pointee_type.GetDirectBaseClassAtIndex(0).GetName() == "MyBaseClass", "The dynamic type for Base can go back to its base class") self.assertTrue(object_pointee_type.GetDirectBaseClassAtIndex(0).GetType().GetDirectBaseClassAtIndex(0).GetName() == "NSObject", "The dynamic type for NSObject can go up the hierarchy") self.assertTrue(base_pointee_type.GetDirectBaseClassAtIndex(0).GetType().GetDirectBaseClassAtIndex(0).GetName() == "NSObject", "The dynamic type for Base can go up the hierarchy") self.assertTrue(object_pointee_type.GetNumberOfFields() == 2, "The dynamic type for NSObject has 2 fields") self.assertTrue(base_pointee_type.GetNumberOfFields() == 2, "The dynamic type for Base has 2 fields")
def rdar11106605_commands(self): """Check that Unicode characters come out of CFString summary correctly.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line (self, "main.m", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_FAILED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type synth clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect('frame variable italian', substrs = ['L\'Italia è una Repubblica democratica, fondata sul lavoro. La sovranità appartiene al popolo, che la esercita nelle forme e nei limiti della Costituzione.']) self.expect('frame variable french', substrs = ['Que veut cette horde d\'esclaves, De traîtres, de rois conjurés?']) self.expect('frame variable german', substrs = ['Über-Ich und aus den Ansprüchen der sozialen Umwelt']) self.expect('frame variable japanese', substrs = ['色は匂へど散りぬるを']) self.expect('frame variable hebrew', substrs = ['לילה טוב'])
def data_formatter_commands(self): """Test that that file and class static variables display correctly.""" self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=["stopped", "stop reason = breakpoint"]) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd("type summary clear", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd('type summary add --summary-string "SUMMARY SUCCESS ${var}" Summarize') self.expect("frame variable mine_ptr", substrs=["SUMMARY SUCCESS summarize_ptr_t @ "]) self.expect("frame variable *mine_ptr", substrs=["SUMMARY SUCCESS summarize_t @"]) self.runCmd('type summary add --summary-string "SUMMARY SUCCESS ${var.first}" Summarize') self.expect("frame variable mine_ptr", substrs=["SUMMARY SUCCESS 10"]) self.expect("frame variable *mine_ptr", substrs=["SUMMARY SUCCESS 10"])
def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+")) lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect("frame variable", substrs = ['(std::__1::wstring) s = L"hello world! מזל טוב!"', '(std::__1::wstring) S = L"!!!!"', '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"', '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"']) self.runCmd("n") TheVeryLongOne = self.frame().FindVariable("TheVeryLongOne"); summaryOptions = lldb.SBTypeSummaryOptions() summaryOptions.SetCapping(lldb.eTypeSummaryUncapped) uncappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(uncappedSummaryStream,summaryOptions) uncappedSummary = uncappedSummaryStream.GetData() self.assertTrue(uncappedSummary.find("someText") > 0, "uncappedSummary does not include the full string") summaryOptions.SetCapping(lldb.eTypeSummaryCapped) cappedSummaryStream = lldb.SBStream() TheVeryLongOne.GetSummary(cappedSummaryStream,summaryOptions) cappedSummary = cappedSummaryStream.GetData() self.assertTrue(cappedSummary.find("someText") <= 0, "cappedSummary includes the full string") self.expect("frame variable", substrs = ['(std::__1::wstring) s = L"hello world! מזל טוב!"', '(std::__1::wstring) S = L"!!!!!"', '(const wchar_t *) mazeltov = 0x','L"מזל טוב"', '(std::__1::string) q = "hello world"', '(std::__1::string) Q = "quite a long std::strin with lots of info inside it"', '(std::__1::string) IHaveEmbeddedZeros = "a\\0b\\0c\\0d"', '(std::__1::wstring) IHaveEmbeddedZerosToo = L"hello world!\\0てざ ル゜䋨ミ㠧槊 きゅへ狦穤襩 じゃ馩リョ 䤦監"'])
def test_more_expr_commands(self): """Test some more expression commands.""" self.build() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1,loc_exact=False) self.runCmd("run", RUN_SUCCEEDED) # Does static casting work? self.expect("expression (int*)argv", startstr = "(int *) $0 = 0x") # (int *) $0 = 0x00007fff5fbff258 # Do anonymous symbols work? self.expect("expression ((char**)environ)[0]", startstr = "(char *) $1 = 0x") # (char *) $1 = 0x00007fff5fbff298 "Apple_PubSub_Socket_Render=/tmp/launch-7AEsUD/Render" # Do return values containing the contents of expression locals work? self.expect("expression int i = 5; i", startstr = "(int) $2 = 5") # (int) $2 = 5 self.expect("expression $2 + 1", startstr = "(int) $3 = 6") # (int) $3 = 6 # Do return values containing the results of static expressions work? self.expect("expression 20 + 3", startstr = "(int) $4 = 23") # (int) $4 = 5 self.expect("expression $4 + 1", startstr = "(int) $5 = 24")
def common_setup(self): exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the foo function which takes a bar_ptr argument. line = line_number('main.m', '// Set breakpoint in main') lldbutil.run_break_set_by_file_and_line (self, "main.m", line, num_expected_locations=1, loc_exact=True)
def ignore_read_write_watchpoint(self): """Test watchpoint ignore count and expect to not to stop at all.""" exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint to set a watchpoint when stopped on the breakpoint. lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # We should be stopped again due to the breakpoint. # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # Now let's set a read_write-type watchpoint for 'global'. # There should be two watchpoint hits (see main.c). self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED, substrs=[ 'Watchpoint created', 'size = 4', 'type = rw', '%s:%d' % (self.source, self.decl) ]) # Set the ignore count of the watchpoint immediately. self.expect("watchpoint ignore -i 2", substrs=['All watchpoints ignored.']) # Use the '-v' option to do verbose listing of the watchpoint. # Expect to find an ignore_count of 2. self.expect("watchpoint list -v", substrs=['hit_count = 0', 'ignore_count = 2']) self.runCmd("process continue") # There should be no more watchpoint hit and the process status should # be 'exited'. self.expect("process status", substrs=['exited']) # Use the '-v' option to do verbose listing of the watchpoint. # Expect to find a hit_count of 2 as well. self.expect("watchpoint list -v", substrs=['hit_count = 2', 'ignore_count = 2'])
def kvo_data_formatter_commands(self): """Test the behavior of formatters when KVO is in use.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.m", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type synth clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) # as long as KVO is implemented by subclassing, this test should succeed # we should be able to dynamically figure out that the KVO implementor class # is a subclass of Molecule, and use the appropriate summary for it self.runCmd("type summary add -s JustAMoleculeHere Molecule") self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) self.runCmd("next") self.expect("thread list", substrs=['stopped', 'step over']) self.expect('frame variable molecule', substrs=['JustAMoleculeHere']) self.runCmd("next") # check that NSMutableDictionary's formatter is not confused when dealing with a KVO'd dictionary self.expect('frame variable newMutableDictionary', substrs=[ '(NSDictionary *) newMutableDictionary = ', ' 21 key/value pairs' ]) lldbutil.run_break_set_by_regexp(self, 'setAtoms') self.runCmd("continue") self.expect("frame variable _cmd", substrs=['setAtoms:'])
def test_with_run_command(self): """Check that vector types format properly""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): pass # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) pass # my code never fails v = self.frame().FindVariable("v") v.SetPreferSyntheticValue(True) v.SetFormat(lldb.eFormatVectorOfFloat32) if self.TraceOn(): print v self.assertTrue(v.GetNumChildren() == 4, "v as float32[] has 4 children") self.assertTrue(v.GetChildAtIndex(0).GetData().float[0] == 1.25, "child 0 == 1.25") self.assertTrue(v.GetChildAtIndex(1).GetData().float[0] == 1.25, "child 1 == 1.25") self.assertTrue(v.GetChildAtIndex(2).GetData().float[0] == 2.50, "child 2 == 2.50") self.assertTrue(v.GetChildAtIndex(3).GetData().float[0] == 2.50, "child 3 == 2.50") self.expect("expr -f int16_t[] -- v", substrs=['(0, 16288, 0, 16288, 0, 16416, 0, 16416)']) self.expect("expr -f uint128_t[] -- v", substrs=['(85236745249553456609335044694184296448)']) self.expect("expr -f float32[] -- v", substrs=['(1.25, 1.25, 2.5, 2.5)']) oldValue = v.GetChildAtIndex(0).GetValue() v.SetFormat(lldb.eFormatHex) newValue = v.GetChildAtIndex(0).GetValue() self.assertFalse(oldValue == newValue, "values did not change along with format") v.SetFormat(lldb.eFormatVectorOfFloat32) oldValueAgain = v.GetChildAtIndex(0).GetValue() self.assertTrue(oldValue == oldValueAgain, "same format but different values")
def test(self): """The expression parser's type search should be wider than the current compilation unit.""" self.build() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.m", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # Now do a NSArry type query from the 'main.m' compile uint. self.expect("expression (NSArray*)array_token", substrs=['(NSArray *) $0 = 0x'])
def call_function(self): """Test calling std::String member function.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) # Some versions of GCC encode two locations for the 'return' statement in main.cpp 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("print str", substrs = ['Hello world']) # Calling this function now succeeds, but we follow the typedef return type through to # const char *, and thus don't invoke the Summary formatter. self.expect("print str.c_str()", substrs = ['Hello world'])
def crash_during_step_inst_test(self): exe = os.path.join(os.getcwd(), "a.out") target = self.dbg.CreateTarget(exe) self.assertTrue(target and target.IsValid(), "Target is valid") self.bp_num = lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.breakpoint, num_expected_locations=1) # Run the program. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process and process.IsValid(), PROCESS_IS_VALID) # The stop reason should be breakpoint. self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) self.assertEqual(lldbutil.get_stopped_thread(process, lldb.eStopReasonBreakpoint).IsValid(), 1, STOPPED_DUE_TO_BREAKPOINT) thread = process.GetThreadAtIndex(0) self.assertTrue(thread and thread.IsValid(), "Thread is valid") # Keep stepping until the inferior crashes while process.GetState() == lldb.eStateStopped and not lldbutil.is_thread_crashed(self, thread): thread.StepInstruction(False) self.assertEqual(process.GetState(), lldb.eStateStopped, PROCESS_STOPPED) self.assertTrue(lldbutil.is_thread_crashed(self, thread), "Thread has crashed") process.Kill()
def test_expr(self): if platform.system( ) == "Darwin" and platform.release() < StrictVersion('12.0.0'): self.skipTest() self.build() exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the foo function which takes a bar_ptr argument. lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs=[' resolved, hit count = 1']) self.expect("expr @import Darwin; 3", VARIABLES_DISPLAYED_CORRECTLY, substrs=["int", "3"]) self.expect("expr *fopen(\"/dev/zero\", \"w\")", VARIABLES_DISPLAYED_CORRECTLY, substrs=["FILE", "_close", "__sclose"]) self.expect("expr *myFile", VARIABLES_DISPLAYED_CORRECTLY, substrs=["a", "5", "b", "9"]) self.expect("expr MIN((uint64_t)2, (uint64_t)3)", VARIABLES_DISPLAYED_CORRECTLY, substrs=["uint64_t", "2"]) self.expect("expr stdin", VARIABLES_DISPLAYED_CORRECTLY, substrs=["(FILE *)", "0x"])
def test_with_run_command(self): """Check that SBValue.GetValueAsSigned() does the right thing for a 32-bit -1.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format delete hex', check=False) self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.assertTrue( self.frame().FindVariable("myvar").GetValueAsSigned() == -1, "GetValueAsSigned() says -1") self.assertTrue( self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFF, "GetValueAsSigned() does not say 0xFFFFFFFF") self.assertTrue( self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFFFFFFFFFF, "GetValueAsSigned() does not say 0xFFFFFFFFFFFFFFFF") self.assertTrue( self.frame().FindVariable("myvar").GetValueAsUnsigned() != -1, "GetValueAsUnsigned() does not say -1") self.assertTrue( self.frame().FindVariable("myvar").GetValueAsUnsigned() == 0xFFFFFFFFFFFFFFFF, "GetValueAsUnsigned() says 0xFFFFFFFFFFFFFFFF") self.assertTrue( self.frame().FindVariable("myvar").GetValueAsSigned() != 0xFFFFFFFF, "GetValueAsUnsigned() does not say 0xFFFFFFFF")
def wchar_t(self): """Test that C++ supports wchar_t correctly.""" exe = os.path.join(os.getcwd(), "a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Break on the struct declration statement in main.cpp. lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) if not process: self.fail("SBTarget.Launch() failed") # Check that we correctly report templates on wchar_t self.expect("frame variable foo_y", substrs=['(Foo<wchar_t>) foo_y = ']) # Check that we correctly report templates on int self.expect("frame variable foo_x", substrs=['(Foo<int>) foo_x = ']) # Check that we correctly report wchar_t self.expect("frame variable foo_y.object", substrs=['(wchar_t) foo_y.object = ']) # Check that we correctly report int self.expect("frame variable foo_x.object", substrs=['(int) foo_x.object = ']) # Check that we can run expressions that return wchar_t self.expect("expression L'a'", substrs=['(wchar_t) $', "L'a'"]) # Mazel Tov if this works! self.expect("frame variable mazeltov", substrs=['(const wchar_t *) mazeltov = ', 'L"מזל טוב"']) self.expect("frame variable ws_NULL", substrs=['(wchar_t *) ws_NULL = 0x0']) self.expect("frame variable ws_empty", substrs=[' L""']) self.expect("frame variable array", substrs=['L"Hey, I\'m a super wchar_t string']) self.expect("frame variable array", substrs=['[0]'], matching=False)
def data_formatter_commands(self): """Test that that file and class static variables display correctly.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.runCmd("type summary add --summary-string \"JustATest\" Point") # Simply check we can get at global variables self.expect("target variable g_point", substrs=['JustATest']) self.expect("target variable g_point_pointer", substrs=['(Point *) g_point_pointer =']) # Print some information about the variables # (we ignore the actual values) self.runCmd( "type summary add --summary-string \"(x=${var.x},y=${var.y})\" Point" ) self.expect("target variable g_point", substrs=['x=', 'y=']) self.expect("target variable g_point_pointer", substrs=['(Point *) g_point_pointer =']) # Test Python code on resulting SBValue self.runCmd( "type summary add --python-script \"return 'x=' + str(valobj.GetChildMemberWithName('x').GetValue());\" Point" ) self.expect("target variable g_point", substrs=['x=']) self.expect("target variable g_point_pointer", substrs=['(Point *) g_point_pointer ='])
def array_types(self): """Test 'frame variable var_name' on some variables with array 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.c", self.line, num_expected_locations=1, loc_exact=False) self.runCmd("run", RUN_SUCCEEDED) # The test suite sometimes shows that the process has exited without stopping. # # CC=clang ./dotest.py -v -t array_types # ... # Process 76604 exited with status = 0 (0x00000000) self.runCmd("process status") # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = ['resolved, hit count = 1']) # Issue 'variable list' command on several array-type variables. self.expect("frame variable --show-types strings", VARIABLES_DISPLAYED_CORRECTLY, startstr = '(char *[4])', substrs = ['(char *) [0]', '(char *) [1]', '(char *) [2]', '(char *) [3]', 'Hello', 'Hola', 'Bonjour', 'Guten Tag']) self.expect("frame variable --show-types --raw -- char_16", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['(char) [0]', '(char) [15]']) self.expect("frame variable --show-types ushort_matrix", VARIABLES_DISPLAYED_CORRECTLY, startstr = '(unsigned short [2][3])') self.expect("frame variable --show-types long_6", VARIABLES_DISPLAYED_CORRECTLY, startstr = '(long [6])')
def global_variables(self): """Test 'frame variable --scope --no-args' which omits args and shows scopes.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the main. lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) self.runCmd("process status", "Get process status") # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1']) # Check that GLOBAL scopes are indicated for the variables. self.expect("frame variable --show-types --scope --show-globals --no-args", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['GLOBAL: (int) g_file_global_int = 42', 'GLOBAL: (const char *) g_file_global_cstr', '"g_file_global_cstr"', 'STATIC: (const char *) g_file_static_cstr', '"g_file_static_cstr"', 'GLOBAL: (int) g_common_1 = 21']) # 'frame variable' should support address-of operator. self.runCmd("frame variable &g_file_global_int") # Exercise the 'target variable' command to display globals in a.c file. self.expect("target variable g_a", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['g_a', '123']) self.expect("target variable g_marked_spot.x", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['g_marked_spot.x', '20']) # rdar://problem/9747668 # runCmd: target variable g_marked_spot.y # output: (int) g_marked_spot.y = <a.o[0x214] can't be resolved, in not currently loaded. # > self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY, substrs = ['g_marked_spot.y', '21']) self.expect("target variable g_marked_spot.y", VARIABLES_DISPLAYED_CORRECTLY, matching=False, substrs = ["can't be resolved"])
def test_with_run_command(self): """Test that deeply nested ValueObjects still work.""" self.build() self.runCmd("file a.out", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) root = self.frame().FindVariable("root") child = root.GetChildAtIndex(1) if self.TraceOn(): print root print child for i in range(0, 24500): child = child.GetChildAtIndex(1) if self.TraceOn(): print child self.assertTrue(child.IsValid(), "could not retrieve the deep ValueObject") self.assertTrue( child.GetChildAtIndex(0).IsValid(), "the deep ValueObject has no value") self.assertTrue( child.GetChildAtIndex(0).GetValueAsUnsigned() != 0, "the deep ValueObject has a zero value") self.assertTrue( child.GetChildAtIndex(1).GetValueAsUnsigned() != 0, "the deep ValueObject has no next")
def force_synth_off(self): """Test that one can have the public API return non-synthetic SBValues if desired""" self.runCmd("file no_synth", 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) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synthetic clear', check=False) self.runCmd('type category delete foobar', check=False) self.runCmd('type category delete JASSynth', check=False) self.runCmd('type category delete newbar', check=False) self.runCmd('settings set target.enable-synthetic-value true') # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) frame = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() int_vector = frame.FindVariable("int_vector") if self.TraceOn(): print int_vector self.assertTrue(int_vector.GetNumChildren() == 0, 'synthetic vector is empty') self.runCmd('settings set target.enable-synthetic-value false') frame = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() int_vector = frame.FindVariable("int_vector") if self.TraceOn(): print int_vector self.assertFalse(int_vector.GetNumChildren() == 0, '"physical" vector is not empty') self.runCmd('settings set target.enable-synthetic-value true') frame = self.dbg.GetSelectedTarget().GetProcess().GetSelectedThread().GetSelectedFrame() int_vector = frame.FindVariable("int_vector") if self.TraceOn(): print int_vector self.assertTrue(int_vector.GetNumChildren() == 0, 'synthetic vector is still empty')
def test_expr_commands_can_handle_quotes(self): """Throw some expression commands with quotes at lldb.""" self.buildDefault() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1,loc_exact=False) self.runCmd("run", RUN_SUCCEEDED) # runCmd: expression 'a' # output: (char) $0 = 'a' self.expect("expression 'a'", substrs = ['(char) $', "'a'"]) # runCmd: expression (int) printf ("\n\n\tHello there!\n") # output: (int) $1 = 16 self.expect(r'''expression (int) printf ("\n\n\tHello there!\n")''', substrs = ['(int) $', '16']) # runCmd: expression (int) printf("\t\x68\n") # output: (int) $2 = 3 self.expect(r'''expression (int) printf("\t\x68\n")''', substrs = ['(int) $', '3']) # runCmd: expression (int) printf("\"\n") # output: (int) $3 = 2 self.expect(r'''expression (int) printf("\"\n")''', substrs = ['(int) $', '2']) # runCmd: expression (int) printf("'\n") # output: (int) $4 = 2 self.expect(r'''expression (int) printf("'\n")''', substrs = ['(int) $', '2']) # runCmd: command alias print_hi expression (int) printf ("\n\tHi!\n") # output: self.runCmd(r'''command alias print_hi expression (int) printf ("\n\tHi!\n")''') # This fails currently. self.expect('print_hi', substrs = ['(int) $', '6'])
def test(self): """Test that variables with signed types display correctly.""" self.build() # Run in synchronous mode self.dbg.SetAsync(False) # Create a target by the debugger. target = self.dbg.CreateTarget("a.out") self.assertTrue(target, VALID_TARGET) lldbutil.run_break_set_by_file_and_line(self, self.source, self.line, num_expected_locations=1, loc_exact=True) # Now launch the process, and do not stop at entry point. process = target.LaunchSimple(None, None, self.get_process_working_directory()) self.assertTrue(process, PROCESS_IS_VALID) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs=[' resolved, hit count = 1']) # Execute the assignment statement. self.runCmd("thread step-over") # Test that signed types display correctly. self.expect("frame variable --show-types --no-args", VARIABLES_DISPLAYED_CORRECTLY, patterns=[ "\((short int|short)\) the_signed_short = 99", "\((signed char|char)\) the_signed_char = 'c'" ], substrs=[ "(int) the_signed_int = 99", "(long) the_signed_long = 99", "(long long) the_signed_long_long = 99" ])
def test(self): """Test a sequence of target stop-hook commands.""" self.build() 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.begl, num_expected_locations=1, loc_exact=True) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) self.runCmd( "target stop-hook add -f main.cpp -l %d -e %d -o 'expr ptr'" % (self.begl, self.endl)) self.expect('target stop-hook list', 'Stop Hook added successfully', substrs=['State: enabled', 'expr ptr']) self.runCmd('target stop-hook disable') self.expect('target stop-hook list', 'Stop Hook disabled successfully', substrs=['State: disabled', 'expr ptr']) self.runCmd('target stop-hook enable') self.expect('target stop-hook list', 'Stop Hook enabled successfully', substrs=['State: enabled', 'expr ptr']) self.runCmd("settings set auto-confirm true") self.addTearDownHook( lambda: self.runCmd("settings clear auto-confirm")) self.runCmd('target stop-hook delete') self.expect('target stop-hook list', 'Stop Hook deleted successfully', substrs=['No stop hooks.'])
def hello_multiple_threads(self): """Test that lldb watchpoint works for multiple threads.""" exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint to set a watchpoint when stopped on the breakpoint. lldbutil.run_break_set_by_file_and_line(self, None, self.first_stop, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # We should be stopped again due to the breakpoint. # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # Now let's set a write-type watchpoint for variable 'g_val'. # The main.cpp, by design, misbehaves by not following the agreed upon # protocol of using a mutex while accessing the global pool and by not # writing to the variable. self.expect("watchpoint set variable -w write g_val", WATCHPOINT_CREATED, substrs=['Watchpoint created', 'size = 4', 'type = w']) # Use the '-v' option to do verbose listing of the watchpoint. # The hit count should be 0 initially. self.expect("watchpoint list -v", substrs=['hit_count = 0']) while True: self.runCmd("process continue") self.runCmd("thread list") if "stop reason = watchpoint" in self.res.GetOutput(): # Good, we verified that the watchpoint works! self.runCmd("thread backtrace all") break else: self.fail( "The stop reason should be either break or watchpoint") # Use the '-v' option to do verbose listing of the watchpoint. # The hit count should now be 1. self.expect("watchpoint list -v", substrs=['hit_count = 1'])
def test_expr_commands(self): """The following expression commands should just work.""" self.buildDefault() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, self.main_source, self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # rdar://problem/9673664 lldb expression evaluation problem self.expect('expr char c[] = "foo"; c[0]', substrs=["'f'"])
def test_with_run_command(self): """Test that that file and class static variables display correctly.""" self.build() self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.skip_if_library_missing(self, self.target(), lldbutil.PrintableRegex("libc\+\+")) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect("frame variable vBool", substrs=[ 'size=49', '[0] = false', '[1] = true', '[18] = false', '[27] = true', '[36] = false', '[47] = true', '[48] = true' ]) self.expect("expr vBool", substrs=[ 'size=49', '[0] = false', '[1] = true', '[18] = false', '[27] = true', '[36] = false', '[47] = true', '[48] = true' ])
def test_watchpoint_cond(self): """Test watchpoint condition.""" self.build(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint to set a watchpoint when stopped on the breakpoint. lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # We should be stopped again due to the breakpoint. # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # Now let's set a write-type watchpoint for 'global'. # With a condition of 'global==5'. self.expect("watchpoint set variable -w write global", WATCHPOINT_CREATED, substrs = ['Watchpoint created', 'size = 4', 'type = w', '%s:%d' % (self.source, self.decl)]) self.runCmd("watchpoint modify -c 'global==5'") # Use the '-v' option to do verbose listing of the watchpoint. # The hit count should be 0 initially. self.expect("watchpoint list -v", substrs = ['hit_count = 0', 'global==5']) self.runCmd("process continue") # We should be stopped again due to the watchpoint (write type). # The stop reason of the thread should be watchpoint. self.expect("thread backtrace", STOPPED_DUE_TO_WATCHPOINT, substrs = ['stop reason = watchpoint']) self.expect("frame variable --show-globals global", substrs = ['(int32_t)', 'global = 5']) # Use the '-v' option to do verbose listing of the watchpoint. # The hit count should now be 2. self.expect("watchpoint list -v", substrs = ['hit_count = 5'])
def test_rw_watchpoint_delete(self): """Test delete watchpoint and expect not to stop for watchpoint.""" self.build(dictionary=self.d) self.setTearDownCleanup(dictionary=self.d) exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint to set a watchpoint when stopped on the breakpoint. lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # We should be stopped again due to the breakpoint. # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # Now let's set a read_write-type watchpoint for 'global'. # There should be two watchpoint hits (see main.c). self.expect("watchpoint set variable -w read_write global", WATCHPOINT_CREATED, substrs=[ 'Watchpoint created', 'size = 4', 'type = rw', '%s:%d' % (self.source, self.decl) ]) # Delete the watchpoint immediately, but set auto-confirm to true first. self.runCmd("settings set auto-confirm true") self.expect("watchpoint delete", substrs=['All watchpoints removed.']) # Restore the original setting of auto-confirm. self.runCmd("settings clear auto-confirm") # Use the '-v' option to do verbose listing of the watchpoint. self.runCmd("watchpoint list -v") self.runCmd("process continue") # There should be no more watchpoint hit and the process status should # be 'exited'. self.expect("process status", substrs=['exited'])
def tls_globals(self): """Test thread-local storage.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) line1 = line_number('main.c', '// thread breakpoint') lldbutil.run_break_set_by_file_and_line (self, "main.c", line1, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.runCmd("process status", "Get process status") self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # BUG: sometimes lldb doesn't change threads to the stopped thread. # (unrelated to this test). self.runCmd("thread select 2", "Change thread") # Check that TLS evaluates correctly within the thread. self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY, patterns = ["\(int\) \$.* = 88"]) self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY, patterns = ["\(int\) \$.* = 66"]) # Continue on the main thread line2 = line_number('main.c', '// main breakpoint') lldbutil.run_break_set_by_file_and_line (self, "main.c", line2, num_expected_locations=1, loc_exact=True) self.runCmd("continue", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.runCmd("process status", "Get process status") self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # BUG: sometimes lldb doesn't change threads to the stopped thread. # (unrelated to this test). self.runCmd("thread select 1", "Change thread") # Check that TLS evaluates correctly within the main thread. self.expect("expr var_static", VARIABLES_DISPLAYED_CORRECTLY, patterns = ["\(int\) \$.* = 44"]) self.expect("expr var_shared", VARIABLES_DISPLAYED_CORRECTLY, patterns = ["\(int\) \$.* = 33"])
def error_cases_with_watchpoint_set(self): """Test error cases with the 'watchpoint set' command.""" exe = os.path.join(os.getcwd(), self.exe_name) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint to set a watchpoint when stopped on the breakpoint. lldbutil.run_break_set_by_file_and_line(self, None, self.line, num_expected_locations=1) # Run the program. self.runCmd("run", RUN_SUCCEEDED) # We should be stopped again due to the breakpoint. # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # Try some error conditions: # 'watchpoint set' is now a multiword command. self.expect("watchpoint set", substrs=[ 'The following subcommands are supported:', 'expression', 'variable' ]) self.runCmd("watchpoint set variable -w read_write", check=False) # 'watchpoint set expression' with '-w' or '-s' specified now needs # an option terminator and a raw expression after that. self.expect("watchpoint set expression -w write --", error=True, startstr='error: ') # It's an error if the expression did not evaluate to an address. self.expect( "watchpoint set expression MyAggregateDataType", error=True, startstr='error: expression did not evaluate to an address') # Wrong size parameter is an error. self.expect("watchpoint set variable -s -128", error=True, substrs=['invalid enumeration value'])
def common_setup(self): exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Break inside the foo function which takes a bar_ptr argument. lldbutil.run_break_set_by_file_and_line (self, "main.c", self.line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1'])
def common_setup(self, line): exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Set breakpoints inside and outside methods that take pointers to the containing struct. lldbutil.run_break_set_by_file_and_line (self, "main.c", line, num_expected_locations=1, loc_exact=True) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs = ['stopped', 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs = [' resolved, hit count = 1'])
def test(self): """Test some expressions involving STL data types.""" self.build() exe = os.path.join(os.getcwd(), "a.out") # The following two lines, if uncommented, will enable loggings. #self.ci.HandleCommand("log enable -f /tmp/lldb.log lldb default", res) #self.assertTrue(res.Succeeded()) self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # rdar://problem/8543077 # test/stl: clang built binaries results in the breakpoint locations = 3, # is this a problem with clang generated debug info? 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) # Stop at 'std::string hello_world ("Hello World!");'. self.expect( "thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['main.cpp:%d' % self.line, 'stop reason = breakpoint']) # The breakpoint should have a hit count of 1. self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE, substrs=[' resolved, hit count = 1']) # Now try some expressions.... self.runCmd( 'expr for (int i = 0; i < hello_world.length(); ++i) { (void)printf("%c\\n", hello_world[i]); }' ) # rdar://problem/10373783 # rdar://problem/10400981 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 breakpoint_command_script_parameters(self): """Test that the frame and breakpoint location are being properly passed to the script breakpoint command function.""" exe = os.path.join(os.getcwd(), "a.out") self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) # Add a breakpoint. lldbutil.run_break_set_by_file_and_line(self, "main.c", self.line, num_expected_locations=1, loc_exact=True) # Now add callbacks for the breakpoints just created. self.runCmd( "breakpoint command add -s python -o 'here = open(\"output-2.txt\", \"w\"); print >> here, frame; print >> here, bp_loc; here.close()' 1" ) # Remove 'output-2.txt' if it already exists. if (os.path.exists('output-2.txt')): os.remove('output-2.txt') # Run program, hit breakpoint, and hopefully write out new version of 'output-2.txt' self.runCmd("run", RUN_SUCCEEDED) # Check that the file 'output.txt' exists and contains the string "lldb". # The 'output-2.txt' file should now exist. self.assertTrue( os.path.isfile("output-2.txt"), "'output-2.txt' exists due to breakpoint command for breakpoint 1." ) # Read the output file produced by running the program. with open('output-2.txt', 'r') as f: output = f.read() self.expect(output, "File 'output-2.txt' and the content matches", exe=False, startstr="frame #0:", patterns=["1.* where = .*main .* resolved, hit count = 1"]) # Now remove 'output-2.txt' os.remove('output-2.txt')
def data_formatter_commands(self): """Test that libc++ iterators format properly.""" self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) lldbutil.run_break_set_by_file_and_line(self, "main.cpp", self.line, num_expected_locations=-1) self.runCmd("run", RUN_SUCCEEDED) # The stop reason of the thread should be breakpoint. self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, substrs=['stopped', 'stop reason = breakpoint']) # This is the function to remove the custom formats in order to have a # clean slate for the next test case. def cleanup(): self.runCmd('type format clear', check=False) self.runCmd('type summary clear', check=False) self.runCmd('type filter clear', check=False) self.runCmd('type synth clear', check=False) self.runCmd("settings set target.max-children-count 256", check=False) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) self.expect('image list', substrs=['libc++.1.dylib', 'libc++abi.dylib']) self.expect('frame variable ivI', substrs=['item = 3']) self.expect('expr ivI', substrs=['item = 3']) self.expect('frame variable iimI', substrs=['first = 0', 'second = 12']) self.expect('expr iimI', substrs=['first = 0', 'second = 12']) self.expect('frame variable simI', substrs=['first = "world"', 'second = 42']) self.expect('expr simI', substrs=['first = "world"', 'second = 42']) self.expect('frame variable svI', substrs=['item = "hello"']) self.expect('expr svI', substrs=['item = "hello"'])
def char1632(self): """Test that the C++11 support for char16_t and char32_t works correctly.""" exe = os.path.join(os.getcwd(), "a.out") # Create a target by the debugger. target = self.dbg.CreateTarget(exe) self.assertTrue(target, VALID_TARGET) # Set breakpoints for line in self.lines: lldbutil.run_break_set_by_file_and_line (self, "main.cpp", line) # Now launch the process, and do not stop at entry point and stop at breakpoint1 process = target.LaunchSimple (None, None, self.get_process_working_directory()) if not process: self.fail("SBTarget.Launch() failed") if self.TraceOn(): self.runCmd("frame variable") # Check that we correctly report the const types self.expect("frame variable cs16 cs32", substrs = ['(const char16_t *) cs16 = ','(const char32_t *) cs32 = ','u"hello world ྒྙྐ"','U"hello world ྒྙྐ"']) # Check that we correctly report the non-const types self.expect("frame variable s16 s32", substrs = ['(char16_t *) s16 = ','(char32_t *) s32 = ','u"ﺸﺵۻ"','U"ЕЙРГЖО"']) self.runCmd("next") # step to after the string is nullified # check that we don't crash on NULL self.expect("frame variable s32", substrs = ['(char32_t *) s32 = 0x00000000']) # continue and hit breakpoint2 self.runCmd("continue") # check that the new strings show self.expect("frame variable s16 s32", substrs = ['(char16_t *) s16 = 0x','(char32_t *) s32 = ','"色ハ匂ヘト散リヌルヲ"','"෴"']) # Check that we can run expressions that return charN_t self.expect("expression u'a'",substrs = ['(char16_t) $',"61 u'a'"]) self.expect("expression U'a'",substrs = ['(char32_t) $',"61 U'a'"])