blob: 33b54a4d3b41764c11a4153f99b75c0eba5e02f3 [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
Zachary Turner35d017f2015-10-23 17:04:29 +00007from __future__ import print_function
8
Zachary Turner0a0490b2015-10-27 20:12:05 +00009import use_lldb_suite
Zachary Turner77db4a82015-10-22 20:06:20 +000010
Johnny Chen8c3f9182010-07-01 00:18:39 +000011import os, time
Johnny Chenbf6ffa32010-07-03 03:41:59 +000012import lldb
Zachary Turner95c453a2015-11-03 02:06:18 +000013from lldbsuite.test.lldbtest import *
Johnny Chen9320d4a2010-06-25 23:15:47 +000014
Johnny Chencbb4be02010-09-01 19:59:58 +000015class HelpCommandTestCase(TestBase):
Johnny Chen119b53e2010-07-01 22:52:57 +000016
Greg Clayton4570d3e2013-12-10 23:19:29 +000017 mydir = TestBase.compute_mydir(__file__)
Johnny Chen9320d4a2010-06-25 23:15:47 +000018
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000019 @no_debug_info_test
Johnny Chen9320d4a2010-06-25 23:15:47 +000020 def test_simplehelp(self):
21 """A simple test of 'help' command and its output."""
Johnny Chen74f26b82010-08-20 19:17:39 +000022 self.expect("help",
Ed Maste135f6ab2015-01-20 15:13:01 +000023 startstr = 'Debugger commands:')
Johnny Chen7e363f52010-06-28 20:55:57 +000024
Ed Maste135f6ab2015-01-20 15:13:01 +000025 self.expect("help -a", matching=False,
Enrico Granata08633ee2011-09-09 17:49:36 +000026 substrs = ['next'])
27
Ed Maste135f6ab2015-01-20 15:13:01 +000028 self.expect("help", matching=True,
Enrico Granata08633ee2011-09-09 17:49:36 +000029 substrs = ['next'])
30
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000031 @no_debug_info_test
Enrico Granata08633ee2011-09-09 17:49:36 +000032 def test_help_on_help(self):
33 """Testing the help on the help facility."""
34 self.expect("help help", matching=True,
Ed Maste135f6ab2015-01-20 15:13:01 +000035 substrs = ['--hide-aliases',
Enrico Granata08633ee2011-09-09 17:49:36 +000036 '--hide-user-commands'])
37
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000038 @no_debug_info_test
Johnny Chen84939892011-01-06 00:03:01 +000039 def version_number_string(self):
40 """Helper function to find the version number string of lldb."""
Peter Collingbourned6824de2011-06-20 19:06:45 +000041 plist = os.path.join(os.environ["LLDB_SRC"], "resources", "LLDB-Info.plist")
Johnny Chen84939892011-01-06 00:03:01 +000042 try:
43 CFBundleVersionSegFound = False
44 with open(plist, 'r') as f:
45 for line in f:
46 if CFBundleVersionSegFound:
47 version_line = line.strip()
48 import re
49 m = re.match("<string>(.*)</string>", version_line)
50 if m:
51 version = m.group(1)
52 return version
53 else:
54 # Unsuccessful, let's juts break out of the for loop.
55 break
56
57 if line.find("<key>CFBundleVersion</key>") != -1:
58 # Found our match. The next line contains our version
59 # string, for example:
60 #
61 # <string>38</string>
62 CFBundleVersionSegFound = True
63
64 except:
65 # Just fallthrough...
Johnny Chenb13ee842011-01-07 00:17:44 +000066 import traceback
67 traceback.print_exc()
Johnny Chen84939892011-01-06 00:03:01 +000068 pass
69
70 # Use None to signify that we are not able to grok the version number.
71 return None
72
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000073 @no_debug_info_test
Johnny Chenca7835c2012-05-26 00:32:39 +000074 def test_help_arch(self):
75 """Test 'help arch' which should list of supported architectures."""
76 self.expect("help arch",
77 substrs = ['arm', 'x86_64', 'i386'])
78
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000079 @no_debug_info_test
Johnny Chen31c39da2010-12-23 20:21:44 +000080 def test_help_version(self):
81 """Test 'help version' and 'version' commands."""
82 self.expect("help version",
83 substrs = ['Show version of LLDB debugger.'])
Johnny Chen84939892011-01-06 00:03:01 +000084 version_str = self.version_number_string()
Johnny Chen4cd2a8e2011-08-26 23:50:10 +000085 import re
86 match = re.match('[0-9]+', version_str)
Daniel Malea3b92f002013-02-28 16:51:15 +000087 if sys.platform.startswith("darwin"):
Greg Clayton1a400cf2013-04-03 00:04:27 +000088 search_regexp = ['lldb-' + (version_str if match else '[0-9]+')]
Daniel Malea3b92f002013-02-28 16:51:15 +000089 else:
90 search_regexp = ['lldb version (\d|\.)+.*$']
91
Johnny Chen31c39da2010-12-23 20:21:44 +000092 self.expect("version",
Daniel Malea3b92f002013-02-28 16:51:15 +000093 patterns = search_regexp)
Johnny Chen31c39da2010-12-23 20:21:44 +000094
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000095 @no_debug_info_test
Johnny Chen331eff32011-07-14 22:20:12 +000096 def test_help_should_not_crash_lldb(self):
97 """Command 'help disasm' should not crash lldb."""
98 self.runCmd("help disasm", check=False)
99 self.runCmd("help unsigned-integer")
100
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000101 @no_debug_info_test
Johnny Chen7e363f52010-06-28 20:55:57 +0000102 def test_help_should_not_hang_emacsshell(self):
Johnny Chenecf9ded2010-09-07 16:19:35 +0000103 """Command 'settings set term-width 0' should not hang the help command."""
Greg Clayton67cc0632012-08-22 17:17:09 +0000104 self.expect("settings set term-width 0",
105 COMMAND_FAILED_AS_EXPECTED, error=True,
106 substrs = ['error: 0 is out of range, valid values must be between'])
107 # self.runCmd("settings set term-width 0")
Johnny Chen74f26b82010-08-20 19:17:39 +0000108 self.expect("help",
Ed Maste135f6ab2015-01-20 15:13:01 +0000109 startstr = 'Debugger commands:')
Johnny Chen9320d4a2010-06-25 23:15:47 +0000110
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000111 @no_debug_info_test
Johnny Chen5ec8fcb2012-05-07 23:04:49 +0000112 def test_help_breakpoint_set(self):
113 """Test that 'help breakpoint set' does not print out redundant lines of:
114 'breakpoint set [-s <shlib-name>] ...'."""
115 self.expect("help breakpoint set", matching=False,
116 substrs = ['breakpoint set [-s <shlib-name>]'])
117
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000118 @no_debug_info_test
Johnny Chen65045f22010-10-08 17:21:27 +0000119 def test_help_image_dump_symtab_should_not_crash(self):
120 """Command 'help image dump symtab' should not crash lldb."""
Johnny Chen24f34902011-05-03 23:55:05 +0000121 # 'image' is an alias for 'target modules'.
Johnny Chen65045f22010-10-08 17:21:27 +0000122 self.expect("help image dump symtab",
Johnny Chen5aceec32011-05-03 23:18:45 +0000123 substrs = ['dump symtab',
Johnny Chen65045f22010-10-08 17:21:27 +0000124 'sort-order'])
125
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000126 @no_debug_info_test
Johnny Chen5237e902010-12-01 19:10:59 +0000127 def test_help_image_du_sym_is_ambiguous(self):
128 """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
129 self.expect("help image du sym",
130 COMMAND_FAILED_AS_EXPECTED, error=True,
131 substrs = ['error: ambiguous command image du sym',
132 'symfile',
133 'symtab'])
134
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000135 @no_debug_info_test
Johnny Chen5237e902010-12-01 19:10:59 +0000136 def test_help_image_du_line_should_work(self):
137 """Command 'help image du line' is not ambiguous and should work."""
Johnny Chen24f34902011-05-03 23:55:05 +0000138 # 'image' is an alias for 'target modules'.
Johnny Chen5237e902010-12-01 19:10:59 +0000139 self.expect("help image du line",
Daniel Maleae7322b32013-07-03 19:29:46 +0000140 substrs = ['Dump the line table for one or more compilation units'])
Johnny Chen5237e902010-12-01 19:10:59 +0000141
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000142 @no_debug_info_test
Johnny Chen81ab3f52011-08-22 22:22:00 +0000143 def test_help_target_variable_syntax(self):
144 """Command 'help target variable' should display <variable-name> ..."""
145 self.expect("help target variable",
146 substrs = ['<variable-name> [<variable-name> [...]]'])
147
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000148 @no_debug_info_test
Johnny Chen84128e62011-09-23 17:57:49 +0000149 def test_help_watchpoint_and_its_args(self):
150 """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work."""
151 self.expect("help watchpoint",
152 substrs = ['delete', 'disable', 'enable', 'list'])
153 self.expect("help watchpt-id",
154 substrs = ['<watchpt-id>'])
155 self.expect("help watchpt-id-list",
156 substrs = ['<watchpt-id-list>'])
157
Tamas Berghammerc8fd1302015-09-30 10:12:40 +0000158 @no_debug_info_test
Johnny Chen34ddc8d2012-02-08 01:13:31 +0000159 def test_help_watchpoint_set(self):
Johnny Chen2ffa7542012-02-08 22:37:48 +0000160 """Test that 'help watchpoint set' prints out 'expression' and 'variable'
161 as the possible subcommands."""
Johnny Chen34ddc8d2012-02-08 01:13:31 +0000162 self.expect("help watchpoint set",
Johnny Chen2ffa7542012-02-08 22:37:48 +0000163 substrs = ['The following subcommands are supported:'],
164 patterns = ['expression +--',
165 'variable +--'])