2015-08-14 06:05:54 +08:00
|
|
|
"""
|
2014-11-27 17:19:46 +08:00
|
|
|
Test that the lldb-mi driver understands MI command syntax.
|
|
|
|
"""
|
|
|
|
|
2015-10-24 01:04:29 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-11-04 03:20:39 +08:00
|
|
|
|
2015-01-28 02:03:50 +08:00
|
|
|
import lldbmi_testcase
|
2016-02-05 07:04:17 +08:00
|
|
|
from lldbsuite.test.decorators import *
|
2015-11-03 10:06:18 +08:00
|
|
|
from lldbsuite.test.lldbtest import *
|
2016-02-05 07:04:17 +08:00
|
|
|
from lldbsuite.test import lldbutil
|
2016-09-12 15:14:51 +08:00
|
|
|
from functools import reduce
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2015-01-28 02:03:50 +08:00
|
|
|
class MiSyntaxTestCase(lldbmi_testcase.MiTestCaseBase):
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2015-02-21 00:34:33 +08:00
|
|
|
mydir = TestBase.compute_mydir(__file__)
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
|
|
|
|
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
|
2017-03-04 09:48:43 +08:00
|
|
|
@skipIfRemote # We do not currently support remote debugging via the MI.
|
2018-03-20 04:50:50 +08:00
|
|
|
@skipIfDarwin
|
2014-11-27 17:19:46 +08:00
|
|
|
def test_lldbmi_tokens(self):
|
2015-02-21 00:34:33 +08:00
|
|
|
"""Test that 'lldb-mi --interpreter' prints command tokens."""
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
self.spawnLldbMi(args=None)
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2015-01-28 02:03:50 +08:00
|
|
|
# Load executable
|
|
|
|
self.runCmd("000-file-exec-and-symbols %s" % self.myexe)
|
|
|
|
self.expect("000\^done")
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2015-01-28 02:03:50 +08:00
|
|
|
# Run to main
|
2015-02-21 00:34:33 +08:00
|
|
|
self.runCmd("100000001-break-insert -f main")
|
2015-01-28 02:03:50 +08:00
|
|
|
self.expect("100000001\^done,bkpt={number=\"1\"")
|
|
|
|
self.runCmd("2-exec-run")
|
|
|
|
self.expect("2\^running")
|
|
|
|
self.expect("\*stopped,reason=\"breakpoint-hit\"")
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2015-01-28 02:03:50 +08:00
|
|
|
# Exit
|
|
|
|
self.runCmd("0000000000000000000003-exec-continue")
|
|
|
|
self.expect("0000000000000000000003\^running")
|
|
|
|
self.expect("\*stopped,reason=\"exited-normally\"")
|
2014-11-27 17:19:46 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
|
|
|
|
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
|
2017-03-04 09:48:43 +08:00
|
|
|
@skipIfRemote # We do not currently support remote debugging via the MI.
|
2018-03-20 04:50:50 +08:00
|
|
|
@skipIfDarwin
|
2015-02-05 18:35:17 +08:00
|
|
|
def test_lldbmi_specialchars(self):
|
|
|
|
"""Test that 'lldb-mi --interpreter' handles complicated strings."""
|
|
|
|
|
2015-04-14 22:12:22 +08:00
|
|
|
# Create an alias for myexe
|
2018-03-15 21:47:09 +08:00
|
|
|
complicated_myexe = self.getBuildArtifact("C--mpl-x file's`s @#$%^&*()_+-={}[]| name")
|
2015-02-05 18:35:17 +08:00
|
|
|
os.symlink(self.myexe, complicated_myexe)
|
2015-04-14 21:48:49 +08:00
|
|
|
self.addTearDownHook(lambda: os.unlink(complicated_myexe))
|
2015-02-05 18:35:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
self.spawnLldbMi(args="\"%s\"" % complicated_myexe)
|
2015-04-14 22:12:22 +08:00
|
|
|
|
|
|
|
# Test that the executable was loaded
|
2016-09-07 04:57:50 +08:00
|
|
|
self.expect(
|
|
|
|
"-file-exec-and-symbols \"%s\"" %
|
|
|
|
complicated_myexe, exactly=True)
|
2015-04-14 21:48:49 +08:00
|
|
|
self.expect("\^done")
|
|
|
|
|
|
|
|
# Check that it was loaded correctly
|
|
|
|
self.runCmd("-break-insert -f main")
|
|
|
|
self.expect("\^done,bkpt={number=\"1\"")
|
|
|
|
self.runCmd("-exec-run")
|
|
|
|
self.expect("\^running")
|
|
|
|
self.expect("\*stopped,reason=\"breakpoint-hit\"")
|
2015-02-05 18:35:17 +08:00
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
@skipIfWindows # llvm.org/pr24452: Get lldb-mi tests working on Windows
|
|
|
|
@skipIfFreeBSD # llvm.org/pr22411: Failure presumably due to known thread races
|
2018-03-20 04:50:50 +08:00
|
|
|
@skipIfDarwin
|
2017-03-04 09:48:43 +08:00
|
|
|
@skipIfRemote # We do not currently support remote debugging via the MI.
|
2016-09-12 15:14:51 +08:00
|
|
|
def test_lldbmi_output_grammar(self):
|
|
|
|
"""Test that 'lldb-mi --interpreter' uses standard output syntax."""
|
|
|
|
|
|
|
|
self.spawnLldbMi(args=None)
|
|
|
|
self.child.setecho(False)
|
|
|
|
|
|
|
|
# Run all commands simultaneously
|
|
|
|
self.runCmd("-unknown-command")
|
2017-01-05 21:23:47 +08:00
|
|
|
self.runCmd("-interpreter-exec command help")
|
2016-09-12 15:14:51 +08:00
|
|
|
self.runCmd("-file-exec-and-symbols %s" % self.myexe)
|
|
|
|
self.runCmd("-break-insert -f main")
|
|
|
|
self.runCmd("-gdb-set target-async off")
|
|
|
|
self.runCmd("-exec-run")
|
|
|
|
self.runCmd("-gdb-set target-async on")
|
|
|
|
self.runCmd("-exec-continue")
|
|
|
|
self.runCmd("-gdb-exit")
|
|
|
|
|
|
|
|
# Test that the program's output matches to the following pattern:
|
|
|
|
# ( async-record | stream-record )* [ result-record ] "(gdb)" nl
|
|
|
|
async_record = "^[0-9]*(\*|\+|=).+?\n" # 1
|
|
|
|
stream_record = "^(~|@|&).+?\n" # 2
|
|
|
|
result_record = "^[0-9]*\^.+?\n" # 3
|
|
|
|
prompt = "^\(gdb\)\r\n" # 4
|
|
|
|
command = "^\r\n" # 5 (it looks like empty line for pexpect)
|
|
|
|
error = "^.+?\n" # 6
|
|
|
|
import pexpect # 7 (EOF)
|
|
|
|
all_patterns = [
|
|
|
|
async_record,
|
|
|
|
stream_record,
|
|
|
|
result_record,
|
|
|
|
prompt,
|
|
|
|
command,
|
|
|
|
error,
|
|
|
|
pexpect.EOF]
|
|
|
|
|
|
|
|
# Routines to get a bit-mask for the specified list of patterns
|
|
|
|
def get_bit(pattern): return all_patterns.index(pattern)
|
|
|
|
def get_mask(pattern): return 1 << get_bit(pattern)
|
|
|
|
def or_op(x, y): return x | y
|
|
|
|
def get_state(*args): return reduce(or_op, map(get_mask, args))
|
|
|
|
|
|
|
|
next_state = get_state(command)
|
|
|
|
while True:
|
|
|
|
it = self.expect(all_patterns)
|
|
|
|
matched_pattern = all_patterns[it]
|
|
|
|
|
|
|
|
# Check that state is acceptable
|
|
|
|
if not (next_state & get_mask(matched_pattern)):
|
|
|
|
self.fail(
|
|
|
|
"error: inconsistent pattern '%s' for state %#x (matched string: %s)" %
|
|
|
|
(repr(matched_pattern), next_state, self.child.after))
|
|
|
|
elif matched_pattern == async_record or matched_pattern == stream_record:
|
|
|
|
next_state = get_state(
|
|
|
|
async_record,
|
|
|
|
stream_record,
|
|
|
|
result_record,
|
|
|
|
prompt)
|
|
|
|
elif matched_pattern == result_record:
|
|
|
|
# FIXME lldb-mi prints async-records out of turn
|
|
|
|
# ```
|
|
|
|
# ^done
|
|
|
|
# (gdb)
|
|
|
|
# ^running
|
|
|
|
# =thread-group-started,id="i1",pid="13875"
|
|
|
|
# (gdb)
|
|
|
|
# ```
|
|
|
|
# Therefore to pass that test I changed the grammar's rule:
|
|
|
|
# next_state = get_state(prompt)
|
|
|
|
# to:
|
|
|
|
next_state = get_state(async_record, prompt)
|
|
|
|
elif matched_pattern == prompt:
|
|
|
|
# FIXME lldb-mi prints the prompt out of turn
|
|
|
|
# ```
|
|
|
|
# ^done
|
|
|
|
# (gdb)
|
|
|
|
# ^running
|
|
|
|
# (gdb)
|
|
|
|
# (gdb)
|
|
|
|
# ```
|
|
|
|
# Therefore to pass that test I changed the grammar's rule:
|
|
|
|
# next_state = get_state(async_record, stream_record, result_record, command, pexpect.EOF)
|
|
|
|
# to:
|
|
|
|
next_state = get_state(
|
|
|
|
async_record,
|
|
|
|
stream_record,
|
|
|
|
result_record,
|
|
|
|
prompt,
|
|
|
|
command,
|
|
|
|
pexpect.EOF)
|
|
|
|
elif matched_pattern == command:
|
|
|
|
next_state = get_state(
|
|
|
|
async_record,
|
|
|
|
stream_record,
|
|
|
|
result_record)
|
|
|
|
elif matched_pattern == pexpect.EOF:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
self.fail("error: pexpect returned an unknown state")
|