xref: /llvm-project/lldb/test/API/commands/help/TestHelp.py (revision 9a7672ac4980bca8829814e1e49e1c201a5bf9b6)
1"""
2Test some lldb help commands.
3
4See also CommandInterpreter::OutputFormattedHelpText().
5"""
6
7
8
9import os
10import lldb
11from lldbsuite.test.decorators import *
12from lldbsuite.test.lldbtest import *
13from lldbsuite.test import lldbutil
14
15
16class HelpCommandTestCase(TestBase):
17
18    mydir = TestBase.compute_mydir(__file__)
19
20    @no_debug_info_test
21    def test_simplehelp(self):
22        """A simple test of 'help' command and its output."""
23        self.expect("help",
24                    startstr='Debugger commands:')
25
26        self.expect("help -a", matching=False,
27                    substrs=['next'])
28
29        self.expect("help", matching=True,
30                    substrs=['next'])
31
32    @no_debug_info_test
33    def test_help_on_help(self):
34        """Testing the help on the help facility."""
35        self.expect("help help", matching=True,
36                    substrs=['--hide-aliases',
37                             '--hide-user-commands'])
38
39    @no_debug_info_test
40    def test_help_arch(self):
41        """Test 'help arch' which should list of supported architectures."""
42        self.expect("help arch",
43                    substrs=['arm', 'i386', 'x86_64'])
44
45    @no_debug_info_test
46    def test_help_version(self):
47        """Test 'help version' and 'version' commands."""
48        self.expect("help version",
49                    substrs=['Show the LLDB debugger version.'])
50        self.expect("version",
51                    patterns=['lldb( version|-[0-9]+).*\n'])
52
53    @no_debug_info_test
54    def test_help_should_not_crash_lldb(self):
55        """Command 'help disasm' should not crash lldb."""
56        self.runCmd("help disasm", check=False)
57        self.runCmd("help unsigned-integer")
58
59    @no_debug_info_test
60    def test_help_memory_read_should_not_crash_lldb(self):
61        """Command 'help memory read' should not crash lldb."""
62        self.runCmd("help memory read", check=False)
63
64    @no_debug_info_test
65    def test_help_should_not_hang_emacsshell(self):
66        """Command 'settings set term-width 0' should not hang the help command."""
67        self.expect(
68            "settings set term-width 0",
69            COMMAND_FAILED_AS_EXPECTED,
70            error=True,
71            substrs=['error: 0 is out of range, valid values must be between'])
72        # self.runCmd("settings set term-width 0")
73        self.expect("help",
74                    startstr='Debugger commands:')
75
76    @no_debug_info_test
77    def test_help_breakpoint_set(self):
78        """Test that 'help breakpoint set' does not print out redundant lines of:
79        'breakpoint set [-s <shlib-name>] ...'."""
80        self.expect("help breakpoint set", matching=False,
81                    substrs=['breakpoint set [-s <shlib-name>]'])
82
83    @no_debug_info_test
84    def test_help_image_dump_symtab_should_not_crash(self):
85        """Command 'help image dump symtab' should not crash lldb."""
86        # 'image' is an alias for 'target modules'.
87        self.expect("help image dump symtab",
88                    substrs=['dump symtab',
89                             'sort-order'])
90
91    @no_debug_info_test
92    def test_help_image_du_sym_is_ambiguous(self):
93        """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
94        self.expect("help image du sym",
95                    COMMAND_FAILED_AS_EXPECTED, error=True,
96                    substrs=['error: ambiguous command image du sym',
97                             'symfile',
98                             'symtab'])
99
100    @no_debug_info_test
101    def test_help_image_du_line_should_work(self):
102        """Command 'help image du line-table' is not ambiguous and should work."""
103        # 'image' is an alias for 'target modules'.
104        self.expect("help image du line", substrs=[
105                    'Dump the line table for one or more compilation units'])
106
107    @no_debug_info_test
108    def test_help_target_variable_syntax(self):
109        """Command 'help target variable' should display <variable-name> ..."""
110        self.expect("help target variable",
111                    substrs=['<variable-name> [<variable-name> [...]]'])
112
113    @no_debug_info_test
114    def test_help_watchpoint_and_its_args(self):
115        """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work."""
116        self.expect("help watchpoint",
117                    substrs=['delete', 'disable', 'enable', 'list'])
118        self.expect("help watchpt-id",
119                    substrs=['<watchpt-id>'])
120        self.expect("help watchpt-id-list",
121                    substrs=['<watchpt-id-list>'])
122
123    @no_debug_info_test
124    def test_help_watchpoint_set(self):
125        """Test that 'help watchpoint set' prints out 'expression' and 'variable'
126        as the possible subcommands."""
127        self.expect("help watchpoint set",
128                    substrs=['The following subcommands are supported:'],
129                    patterns=['expression +--',
130                              'variable +--'])
131
132    @no_debug_info_test
133    def test_help_po_hides_options(self):
134        """Test that 'help po' does not show all the options for expression"""
135        self.expect(
136            "help po",
137            substrs=[
138                '--show-all-children',
139                '--object-description'],
140            matching=False)
141
142    @no_debug_info_test
143    def test_help_run_hides_options(self):
144        """Test that 'help run' does not show all the options for process launch"""
145        self.expect("help run",
146                    substrs=['--arch', '--environment'], matching=False)
147
148    @no_debug_info_test
149    def test_help_next_shows_options(self):
150        """Test that 'help next' shows all the options for thread step-over"""
151        self.expect("help next",
152                    substrs=['--step-out-avoids-no-debug', '--run-mode'], matching=True)
153
154    @no_debug_info_test
155    def test_help_provides_alternatives(self):
156        """Test that help on commands that don't exist provides information on additional help avenues"""
157        self.expect(
158            "help thisisnotadebuggercommand",
159            substrs=[
160                "'thisisnotadebuggercommand' is not a known command.",
161                "Try 'help' to see a current list of commands.",
162                "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
163                "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."],
164            error=True)
165
166        self.expect(
167            "help process thisisnotadebuggercommand",
168            substrs=[
169                "'process thisisnotadebuggercommand' is not a known command.",
170                "Try 'help' to see a current list of commands.",
171                "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
172                "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."])
173
174    @no_debug_info_test
175    def test_custom_help_alias(self):
176        """Test that aliases pick up custom help text."""
177        def cleanup():
178            self.runCmd('command unalias afriendlyalias', check=False)
179            self.runCmd('command unalias averyfriendlyalias', check=False)
180
181        self.addTearDownHook(cleanup)
182        self.runCmd(
183            'command alias --help "I am a friendly alias" -- afriendlyalias help')
184        self.expect(
185            "help afriendlyalias",
186            matching=True,
187            substrs=['I am a friendly alias'])
188        self.runCmd(
189            'command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help')
190        self.expect("help averyfriendlyalias", matching=True,
191                    substrs=['I am a very friendly alias'])
192    @no_debug_info_test
193    def test_alias_prints_origin(self):
194        """Test that 'help <unique_match_to_alias>' prints the alias origin."""
195        def cleanup():
196            self.runCmd('command unalias alongaliasname', check=False)
197
198        self.addTearDownHook(cleanup)
199        self.runCmd('command alias alongaliasname help')
200        self.expect("help alongaliasna", matching=True,
201                    substrs=["'alongaliasna' is an abbreviation for 'help'"])
202
203    @no_debug_info_test
204    def test_hidden_help(self):
205        self.expect("help -h",
206                    substrs=["_regexp-bt"])
207
208    @no_debug_info_test
209    def test_help_ambiguous(self):
210        self.expect("help g",
211                    substrs=["Help requested with ambiguous command name, possible completions:",
212                             "gdb-remote", "gui"])
213
214    @no_debug_info_test
215    def test_help_unknown_flag(self):
216        self.expect("help -z", error=True,
217                    substrs=["unknown or ambiguous option"])
218
219    @no_debug_info_test
220    def test_help_format_output(self):
221        """Test that help output reaches TerminalWidth."""
222        self.runCmd(
223            'settings set term-width 108')
224        self.expect(
225            "help format",
226            matching=True,
227            substrs=['<format> -- One of the format names'])
228