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
|
|
|
"""
|
|
|
|
|
2015-10-23 17:04:29 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-03 19:20:39 +00:00
|
|
|
|
2015-10-22 20:06:20 +00:00
|
|
|
|
2011-03-12 01:18:19 +00:00
|
|
|
import os
|
|
|
|
import lldb
|
2015-12-08 01:15:30 +00:00
|
|
|
from lldbsuite.test import configuration
|
2015-11-03 02:06:18 +00:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2011-03-12 01:18:19 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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.')
|
|
|
|
|
2015-09-30 10:12:40 +00:00
|
|
|
@skipIfFreeBSD # llvm.org/pr15037
|
|
|
|
@expectedFlakeyLinux('llvm.org/pr15037') # stop-hooks sometimes fail to fire on Linux
|
|
|
|
@expectedFailureHostWindows("llvm.org/pr22274: need a pexpect replacement for windows")
|
|
|
|
def test(self):
|
2011-05-03 18:40:19 +00:00
|
|
|
"""Test the stop-hook mechanism."""
|
2015-09-30 10:12:40 +00:00
|
|
|
self.build()
|
|
|
|
|
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-07-06 10:46:34 +00:00
|
|
|
self.child = pexpect.spawn('%s %s' % (lldbtest_config.lldbExec, self.lldbOption))
|
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
|
|
|
|
|
2015-07-06 10:46:34 +00:00
|
|
|
if lldb.remote_platform:
|
|
|
|
child.expect_exact(prompt)
|
|
|
|
child.sendline('platform select %s' % lldb.remote_platform.GetName())
|
|
|
|
child.expect_exact(prompt)
|
2015-12-08 01:15:30 +00:00
|
|
|
child.sendline('platform connect %s' % configuration.lldb_platform_url)
|
2015-07-06 10:46:34 +00:00
|
|
|
child.expect_exact(prompt)
|
2015-12-08 01:15:30 +00:00
|
|
|
child.sendline('platform settings -w %s' % configuration.lldb_platform_working_dir)
|
2015-07-06 10:46:34 +00:00
|
|
|
|
|
|
|
child.expect_exact(prompt)
|
|
|
|
child.sendline('target create %s' % exe)
|
|
|
|
|
2011-03-12 01:18:19 +00:00
|
|
|
# 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)
|
2015-10-23 17:04:29 +00:00
|
|
|
print('expecting "%s"' % at_line)
|
2014-11-18 19:45:23 +00:00
|
|
|
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 *) $'])
|