blob: 57e67362fae30eacb7604cf1ff4b74104c02b84b [file] [log] [blame]
Johnny Chen7f5f2802010-08-02 21:26:00 +00001"""
Johnny Chen65045f22010-10-08 17:21:27 +00002Test some lldb help commands.
Johnny Chen7f5f2802010-08-02 21:26:00 +00003
4See also CommandInterpreter::OutputFormattedHelpText().
5"""
Johnny Chen9320d4a2010-06-25 23:15:47 +00006
Johnny Chen8c3f9182010-07-01 00:18:39 +00007import os, time
Johnny Chen73258832010-08-05 23:42:46 +00008import unittest2
Johnny Chenbf6ffa32010-07-03 03:41:59 +00009import lldb
Johnny Chen17941842010-08-09 23:44:24 +000010from lldbtest import *
Johnny Chen9320d4a2010-06-25 23:15:47 +000011
Johnny Chencbb4be02010-09-01 19:59:58 +000012class HelpCommandTestCase(TestBase):
Johnny Chen119b53e2010-07-01 22:52:57 +000013
Johnny Chenbf6ffa32010-07-03 03:41:59 +000014 mydir = "help"
Johnny Chen9320d4a2010-06-25 23:15:47 +000015
16 def test_simplehelp(self):
17 """A simple test of 'help' command and its output."""
Johnny Chen74f26b82010-08-20 19:17:39 +000018 self.expect("help",
19 startstr = 'The following is a list of built-in, permanent debugger commands')
Johnny Chen7e363f52010-06-28 20:55:57 +000020
Enrico Granata08633ee2011-09-09 17:49:36 +000021 self.expect("help", matching=False,
22 substrs = ['next'])
23
24 self.expect("help -a", matching=True,
25 substrs = ['next'])
26
27 def test_help_on_help(self):
28 """Testing the help on the help facility."""
29 self.expect("help help", matching=True,
30 substrs = ['--show-aliases',
31 '--hide-user-commands'])
32
Johnny Chen84939892011-01-06 00:03:01 +000033 def version_number_string(self):
34 """Helper function to find the version number string of lldb."""
Peter Collingbourned6824de2011-06-20 19:06:45 +000035 plist = os.path.join(os.environ["LLDB_SRC"], "resources", "LLDB-Info.plist")
Johnny Chen84939892011-01-06 00:03:01 +000036 try:
37 CFBundleVersionSegFound = False
38 with open(plist, 'r') as f:
39 for line in f:
40 if CFBundleVersionSegFound:
41 version_line = line.strip()
42 import re
43 m = re.match("<string>(.*)</string>", version_line)
44 if m:
45 version = m.group(1)
46 return version
47 else:
48 # Unsuccessful, let's juts break out of the for loop.
49 break
50
51 if line.find("<key>CFBundleVersion</key>") != -1:
52 # Found our match. The next line contains our version
53 # string, for example:
54 #
55 # <string>38</string>
56 CFBundleVersionSegFound = True
57
58 except:
59 # Just fallthrough...
Johnny Chenb13ee842011-01-07 00:17:44 +000060 import traceback
61 traceback.print_exc()
Johnny Chen84939892011-01-06 00:03:01 +000062 pass
63
64 # Use None to signify that we are not able to grok the version number.
65 return None
66
67
Johnny Chen31c39da2010-12-23 20:21:44 +000068 def test_help_version(self):
69 """Test 'help version' and 'version' commands."""
70 self.expect("help version",
71 substrs = ['Show version of LLDB debugger.'])
Johnny Chen84939892011-01-06 00:03:01 +000072 version_str = self.version_number_string()
Johnny Chen4cd2a8e2011-08-26 23:50:10 +000073 import re
74 match = re.match('[0-9]+', version_str)
Johnny Chen31c39da2010-12-23 20:21:44 +000075 self.expect("version",
Johnny Chen4cd2a8e2011-08-26 23:50:10 +000076 patterns = ['LLDB-' + (version_str if match else '[0-9]+')])
Johnny Chen31c39da2010-12-23 20:21:44 +000077
Johnny Chen331eff32011-07-14 22:20:12 +000078 def test_help_should_not_crash_lldb(self):
79 """Command 'help disasm' should not crash lldb."""
80 self.runCmd("help disasm", check=False)
81 self.runCmd("help unsigned-integer")
82
Johnny Chen7e363f52010-06-28 20:55:57 +000083 def test_help_should_not_hang_emacsshell(self):
Johnny Chenecf9ded2010-09-07 16:19:35 +000084 """Command 'settings set term-width 0' should not hang the help command."""
85 self.runCmd("settings set term-width 0")
Johnny Chen74f26b82010-08-20 19:17:39 +000086 self.expect("help",
87 startstr = 'The following is a list of built-in, permanent debugger commands')
Johnny Chen9320d4a2010-06-25 23:15:47 +000088
Johnny Chen65045f22010-10-08 17:21:27 +000089 def test_help_image_dump_symtab_should_not_crash(self):
90 """Command 'help image dump symtab' should not crash lldb."""
Johnny Chen24f34902011-05-03 23:55:05 +000091 # 'image' is an alias for 'target modules'.
Johnny Chen65045f22010-10-08 17:21:27 +000092 self.expect("help image dump symtab",
Johnny Chen5aceec32011-05-03 23:18:45 +000093 substrs = ['dump symtab',
Johnny Chen65045f22010-10-08 17:21:27 +000094 'sort-order'])
95
Johnny Chen5237e902010-12-01 19:10:59 +000096 def test_help_image_du_sym_is_ambiguous(self):
97 """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
98 self.expect("help image du sym",
99 COMMAND_FAILED_AS_EXPECTED, error=True,
100 substrs = ['error: ambiguous command image du sym',
101 'symfile',
102 'symtab'])
103
104 def test_help_image_du_line_should_work(self):
105 """Command 'help image du line' is not ambiguous and should work."""
Johnny Chen24f34902011-05-03 23:55:05 +0000106 # 'image' is an alias for 'target modules'.
Johnny Chen5237e902010-12-01 19:10:59 +0000107 self.expect("help image du line",
Johnny Chen5aceec32011-05-03 23:18:45 +0000108 substrs = ['Dump the debug symbol file for one or more target modules'])
Johnny Chen5237e902010-12-01 19:10:59 +0000109
Johnny Chen81ab3f52011-08-22 22:22:00 +0000110 def test_help_target_variable_syntax(self):
111 """Command 'help target variable' should display <variable-name> ..."""
112 self.expect("help target variable",
113 substrs = ['<variable-name> [<variable-name> [...]]'])
114
Johnny Chen84128e62011-09-23 17:57:49 +0000115 def test_help_watchpoint_and_its_args(self):
116 """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work."""
117 self.expect("help watchpoint",
118 substrs = ['delete', 'disable', 'enable', 'list'])
119 self.expect("help watchpt-id",
120 substrs = ['<watchpt-id>'])
121 self.expect("help watchpt-id-list",
122 substrs = ['<watchpt-id-list>'])
123
Johnny Chen34ddc8d2012-02-08 01:13:31 +0000124 def test_help_watchpoint_set(self):
Johnny Chen2ffa7542012-02-08 22:37:48 +0000125 """Test that 'help watchpoint set' prints out 'expression' and 'variable'
126 as the possible subcommands."""
Johnny Chen34ddc8d2012-02-08 01:13:31 +0000127 self.expect("help watchpoint set",
Johnny Chen2ffa7542012-02-08 22:37:48 +0000128 substrs = ['The following subcommands are supported:'],
129 patterns = ['expression +--',
130 'variable +--'])
Johnny Chen34ddc8d2012-02-08 01:13:31 +0000131
Johnny Chen9320d4a2010-06-25 23:15:47 +0000132
133if __name__ == '__main__':
Johnny Chena2124952010-08-05 21:23:45 +0000134 import atexit
Johnny Chen4657be62010-06-29 19:44:16 +0000135 lldb.SBDebugger.Initialize()
Johnny Chena2124952010-08-05 21:23:45 +0000136 atexit.register(lambda: lldb.SBDebugger.Terminate())
Johnny Chen73258832010-08-05 23:42:46 +0000137 unittest2.main()