def testBreakpointByLine(self): self.build() main_c = lldb.SBFileSpec("main.c") _, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, main_c, 19) self.expect("fr v did_call", substrs='0') in_condition = False for i in range(breakpoint.GetNumLocations()): b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry() self.assertEqual(b_loc.GetLine(), 19) in_condition |= b_loc.GetColumn() < 30 self.assertTrue(in_condition)
def testBreakpointByLine(self): self.build() main_c = lldb.SBFileSpec("main.c") _, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, main_c, 11) self.expect("fr v did_call", substrs='0') in_condition = False for i in range(breakpoint.GetNumLocations()): b_loc = breakpoint.GetLocationAtIndex( i).GetAddress().GetLineEntry() self.assertEqual(b_loc.GetLine(), 11) in_condition |= b_loc.GetColumn() < 30 self.assertTrue(in_condition)
def testBreakpointByLine(self): self.build() src_file = lldb.SBFileSpec("main.cpp") line = line_number("main.cpp", "At the beginning of a function name (col:50)") + 1 # Next line after comment _, _, _, breakpoint = lldbutil.run_to_line_breakpoint(self, src_file, line) self.expect("fr v did_call", substrs=['0']) in_condition = False for i in range(breakpoint.GetNumLocations()): b_loc = breakpoint.GetLocationAtIndex(i).GetAddress().GetLineEntry() self.assertEqual(b_loc.GetLine(), line) in_condition |= b_loc.GetColumn() < 30 self.assertTrue(in_condition)
def test_on_sane_process(self): """Test that lldb doesn't fetch the extended crash information dictionnary from a 'sane' stopped process.""" self.build() target, _, _, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec(self.source), self.line) stream = lldb.SBStream() self.assertTrue(stream) crash_info = target.GetExtendedCrashInformation() error = crash_info.GetAsJSON(stream) self.assertFalse(error.Success()) self.assertIn("No structured data.", error.GetCString())
def test_step_until(self): """Test stepping until when hardware breakpoints are required.""" self.build() _, _, thread, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec("main.c"), 7) self.runCmd("settings set target.require-hardware-breakpoint true") self.expect("thread until 5", error=True) # Ensure we fail when stepping through the API. error = thread.StepOverUntil(lldb.SBFrame(), lldb.SBFileSpec(), 5) self.assertTrue(error.Fail()) self.assertTrue("Could not create hardware breakpoint for thread plan" in error.GetCString())
def test_step_over(self): """Test stepping over when hardware breakpoints are required.""" self.build() _, _, thread, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec("main.c"), 7) self.runCmd("settings set target.require-hardware-breakpoint true") # Step over doesn't fail immediately but fails later on. self.expect( "thread step-over", error=True, substrs=[ 'error: Could not create hardware breakpoint for thread plan.' ])
def test_step_over(self): """Test stepping over when hardware breakpoints are required.""" self.build() _, _, thread, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec("main.c"), 7) self.runCmd("settings set target.require-hardware-breakpoint true") # Step over doesn't fail immediately but fails later on. self.expect("thread step-over") self.expect( "process status", substrs=[ 'step over failed', 'Could not create hardware breakpoint for thread plan' ])
def test_step_out(self): """Test stepping out when hardware breakpoints are required.""" self.build() _, _, thread, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec("main.c"), 1) self.runCmd("settings set target.require-hardware-breakpoint true") # Ensure this fails in the command interpreter. self.expect("thread step-out", error=True) # Ensure we fail when stepping through the API. error = lldb.SBError() thread.StepOut(error) self.assertTrue(error.Fail()) self.assertTrue("Could not create hardware breakpoint for thread plan" in error.GetCString())
def data_formatter_commands(self): """Test using Python synthetic children provider.""" _, process, thread, _ = lldbutil.run_to_line_breakpoint( self, lldb.SBFileSpec("main.cpp"), self.line) # 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) # print the f00_1 variable without a synth self.expect("frame variable f00_1", substrs=['a = 1', 'b = 2', 'r = 34']) # now set up the synth self.runCmd("script from fooSynthProvider import *") self.runCmd("type synth add -l fooSynthProvider foo") self.runCmd("type synth add -l wrapfooSynthProvider wrapfoo") self.expect("type synthetic list foo", substrs=['fooSynthProvider']) # note that the value of fake_a depends on target byte order if process.GetByteOrder() == lldb.eByteOrderLittle: fake_a_val = 0x02000000 else: fake_a_val = 0x00000100 # check that we get the two real vars and the fake_a variables self.expect("frame variable f00_1", substrs=[ 'a = 1', 'fake_a = %d' % fake_a_val, 'r = 34', ]) # check that we do not get the extra vars self.expect("frame variable f00_1", matching=False, substrs=['b = 2']) # check access to members by name self.expect('frame variable f00_1.fake_a', substrs=['%d' % fake_a_val]) # check access to members by index self.expect('frame variable f00_1[1]', substrs=['%d' % fake_a_val]) # put synthetic children in summary in several combinations self.runCmd( "type summary add --summary-string \"fake_a=${svar.fake_a}\" foo") self.expect('frame variable f00_1', substrs=['fake_a=%d' % fake_a_val]) self.runCmd( "type summary add --summary-string \"fake_a=${svar[1]}\" foo") self.expect('frame variable f00_1', substrs=['fake_a=%d' % fake_a_val]) # clear the summary self.runCmd("type summary delete foo") # check that the caching does not span beyond the stopoint self.runCmd("n") if process.GetByteOrder() == lldb.eByteOrderLittle: fake_a_val = 0x02000000 else: fake_a_val = 0x00000200 self.expect("frame variable f00_1", substrs=[ 'a = 2', 'fake_a = %d' % fake_a_val, 'r = 34', ]) # check that altering the object also alters fake_a self.runCmd("expr f00_1.a = 280") if process.GetByteOrder() == lldb.eByteOrderLittle: fake_a_val = 0x02000001 else: fake_a_val = 0x00011800 self.expect("frame variable f00_1", substrs=[ 'a = 280', 'fake_a = %d' % fake_a_val, 'r = 34', ]) # check that expanding a pointer does the right thing if process.GetByteOrder() == lldb.eByteOrderLittle: fake_a_val = 0x0d000000 else: fake_a_val = 0x00000c00 self.expect("frame variable --ptr-depth 1 f00_ptr", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) self.expect("frame variable --ptr-depth 1 wrapper", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) # now add a filter.. it should fail self.expect("type filter add foo --child b --child j", error=True, substrs=['cannot add']) # we get the synth again.. self.expect('frame variable f00_1', matching=False, substrs=['b = 1', 'j = 17']) self.expect("frame variable --ptr-depth 1 f00_ptr", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) self.expect("frame variable --ptr-depth 1 wrapper", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) # Test that the custom dereference operator for `wrapfoo` works through # the Python API. The synthetic children provider gets queried at # slightly different times in this case. wrapper_var = thread.GetSelectedFrame().FindVariable('wrapper') foo_var = wrapper_var.Dereference() self.assertEqual(foo_var.GetNumChildren(), 3) self.assertEqual(foo_var.GetChildAtIndex(0).GetName(), 'a') self.assertEqual(foo_var.GetChildAtIndex(1).GetName(), 'fake_a') self.assertEqual(foo_var.GetChildAtIndex(2).GetName(), 'r') # now delete the synth and add the filter self.runCmd("type synth delete foo") self.runCmd("type synth delete wrapfoo") self.runCmd("type filter add foo --child b --child j") self.expect('frame variable f00_1', substrs=['b = 2', 'j = 18']) self.expect("frame variable --ptr-depth 1 f00_ptr", matching=False, substrs=['r = 45', 'fake_a = %d' % fake_a_val, 'a = 12']) self.expect("frame variable --ptr-depth 1 wrapper", matching=False, substrs=['r = 45', 'fake_a = %d' % fake_a_val, 'a = 12']) # now add the synth and it should fail self.expect("type synth add -l fooSynthProvider foo", error=True, substrs=['cannot add']) # check the listing self.expect('type synth list', matching=False, substrs=['foo', 'Python class fooSynthProvider']) self.expect('type filter list', substrs=['foo', '.b', '.j']) # delete the filter, add the synth self.runCmd("type filter delete foo") self.runCmd("type synth add -l fooSynthProvider foo") self.expect('frame variable f00_1', matching=False, substrs=['b = 2', 'j = 18']) self.expect("frame variable --ptr-depth 1 f00_ptr", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) self.expect("frame variable --ptr-depth 1 wrapper", substrs=[ 'a = 12', 'fake_a = %d' % fake_a_val, 'r = 45', ]) # check the listing self.expect('type synth list', substrs=['foo', 'Python class fooSynthProvider']) self.expect('type filter list', matching=False, substrs=['foo', '.b', '.j']) # delete the synth and check that we get good output self.runCmd("type synth delete foo") self.expect("frame variable f00_1", substrs=['a = 280', 'b = 2', 'j = 18']) self.expect("frame variable f00_1", matching=False, substrs=['fake_a = '])