2011-03-12 01:18:19 +00:00
|
|
|
"""
|
2011-05-03 18:40:19 +00:00
|
|
|
Test lldb target stop-hook mechanism to see whether it fires off correctly .
|
2011-03-12 01:18:19 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest2
|
|
|
|
import lldb
|
|
|
|
from lldbtest import *
|
|
|
|
|
2011-05-03 18:40:19 +00:00
|
|
|
class StopHookMechanismTestCase(TestBase):
|
2011-03-12 01:18:19 +00:00
|
|
|
|
2013-12-10 23:19:29 +00:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
2011-03-12 01:18:19 +00:00
|
|
|
|
2015-03-30 14:12:17 +00:00
|
|
|
@skipUnlessDarwin
|
2012-04-06 00:56:05 +00:00
|
|
|
@dsym_test
|
2011-03-12 01:18:19 +00:00
|
|
|
def test_with_dsym(self):
|
2011-05-03 18:40:19 +00:00
|
|
|
"""Test the stop-hook mechanism."""
|
2011-03-12 01:18:19 +00:00
|
|
|
self.buildDsym()
|
2011-05-03 18:40:19 +00:00
|
|
|
self.stop_hook_firing()
|
2011-03-12 01:18:19 +00:00
|
|
|
|
2013-11-22 13:54:58 +00:00
|
|
|
@skipIfFreeBSD # llvm.org/pr15037
|
2015-06-26 15:13:21 +00:00
|
|
|
@expectedFlakeyLinux('llvm.org/pr15037') # stop-hooks sometimes fail to fire on Linux
|
2015-01-20 22:36:03 +00:00
|
|
|
@expectedFailureWindows("llvm.org/pr22274: need a pexpect replacement for windows")
|
2012-04-06 00:56:05 +00:00
|
|
|
@dwarf_test
|
2011-03-12 01:18:19 +00:00
|
|
|
def test_with_dwarf(self):
|
2011-05-03 18:40:19 +00:00
|
|
|
"""Test the stop-hook mechanism."""
|
2011-03-12 01:18:19 +00:00
|
|
|
self.buildDwarf()
|
2011-05-03 18:40:19 +00:00
|
|
|
self.stop_hook_firing()
|
2011-03-12 01:18:19 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# Call super's setUp().
|
|
|
|
TestBase.setUp(self)
|
|
|
|
# Find the line numbers inside main.cpp.
|
|
|
|
self.begl = line_number('main.cpp', '// Set breakpoint here to test target stop-hook.')
|
|
|
|
self.endl = line_number('main.cpp', '// End of the line range for which stop-hook is to be run.')
|
2011-09-23 21:24:57 +00:00
|
|
|
self.correct_step_line = line_number ('main.cpp', '// We should stop here after stepping.')
|
2011-03-12 01:18:19 +00:00
|
|
|
self.line = line_number('main.cpp', '// Another breakpoint which is outside of the stop-hook range.')
|
|
|
|
|
2011-05-03 18:40:19 +00:00
|
|
|
def stop_hook_firing(self):
|
|
|
|
"""Test the stop-hook mechanism."""
|
2014-07-18 01:02:02 +00:00
|
|
|
import pexpect
|
2011-03-12 01:18:19 +00:00
|
|
|
exe = os.path.join(os.getcwd(), "a.out")
|
2011-05-03 17:38:06 +00:00
|
|
|
prompt = "(lldb) "
|
2014-11-18 19:45:23 +00:00
|
|
|
add_prompt = "Enter your stop hook command(s). Type 'DONE' to end."
|
|
|
|
add_prompt1 = "> "
|
2011-03-12 01:18:19 +00:00
|
|
|
|
2011-05-03 17:38:06 +00:00
|
|
|
# So that the child gets torn down after the test.
|
2015-05-18 19:39:03 +00:00
|
|
|
self.child = pexpect.spawn('%s %s %s' % (lldbtest_config.lldbExec, self.lldbOption, exe))
|
2011-05-03 17:38:06 +00:00
|
|
|
child = self.child
|
2011-03-12 01:18:19 +00:00
|
|
|
# Turn on logging for what the child sends back.
|
2011-04-20 22:01:48 +00:00
|
|
|
if self.TraceOn():
|
2011-03-12 01:18:19 +00:00
|
|
|
child.logfile_read = sys.stdout
|
|
|
|
|
|
|
|
# Set the breakpoint, followed by the target stop-hook commands.
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('breakpoint set -f main.cpp -l %d' % self.begl)
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('breakpoint set -f main.cpp -l %d' % self.line)
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('target stop-hook add -f main.cpp -l %d -e %d' % (self.begl, self.endl))
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(add_prompt)
|
2014-11-18 19:45:23 +00:00
|
|
|
child.expect_exact(add_prompt1)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('expr ptr')
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(add_prompt1)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('DONE')
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('target stop-hook list')
|
|
|
|
|
2015-06-18 05:27:05 +00:00
|
|
|
# Now run the program, expect to stop at the first breakpoint which is within the stop-hook range.
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('run')
|
2014-11-18 19:45:23 +00:00
|
|
|
# Make sure we see the stop hook text from the stop of the process from the run hitting the first breakpoint
|
|
|
|
child.expect_exact('(void *) $')
|
2011-05-03 17:38:06 +00:00
|
|
|
child.expect_exact(prompt)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('thread step-over')
|
2011-09-23 18:25:02 +00:00
|
|
|
# Expecting to find the output emitted by the firing of our stop hook.
|
|
|
|
child.expect_exact('(void *) $')
|
2011-09-23 21:24:57 +00:00
|
|
|
# This is orthogonal to the main stop hook test, but this example shows a bug in
|
|
|
|
# CLANG where the line table entry for the "return -1" actually includes some code
|
|
|
|
# from the other branch of the if/else, so we incorrectly stop at the "return -1" line.
|
|
|
|
# I fixed that in lldb and I'm sticking in a test here because I don't want to have to
|
|
|
|
# make up a whole nother test case for it.
|
|
|
|
child.sendline('frame info')
|
2014-11-18 19:45:23 +00:00
|
|
|
at_line = 'at main.cpp:%d' % (self.correct_step_line)
|
|
|
|
print 'expecting "%s"' % at_line
|
|
|
|
child.expect_exact(at_line)
|
2011-03-12 01:18:19 +00:00
|
|
|
|
|
|
|
# Now continue the inferior, we'll stop at another breakpoint which is outside the stop-hook range.
|
|
|
|
child.sendline('process continue')
|
2011-05-04 00:44:20 +00:00
|
|
|
child.expect_exact('// Another breakpoint which is outside of the stop-hook range.')
|
2011-05-03 17:38:06 +00:00
|
|
|
#self.DebugPExpect(child)
|
2011-03-12 01:18:19 +00:00
|
|
|
child.sendline('thread step-over')
|
2011-05-04 00:44:20 +00:00
|
|
|
child.expect_exact('// Another breakpoint which is outside of the stop-hook range.')
|
2011-05-03 17:38:06 +00:00
|
|
|
#self.DebugPExpect(child)
|
2011-03-12 01:18:19 +00:00
|
|
|
# Verify that the 'Stop Hooks' mechanism is NOT BEING fired off.
|
|
|
|
self.expect(child.before, exe=False, matching=False,
|
2011-05-12 21:58:22 +00:00
|
|
|
substrs = ['(void *) $'])
|
2011-03-12 01:18:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import atexit
|
|
|
|
lldb.SBDebugger.Initialize()
|
|
|
|
atexit.register(lambda: lldb.SBDebugger.Terminate())
|
|
|
|
unittest2.main()
|