2 Test some lldb help commands.
4 See also CommandInterpreter::OutputFormattedHelpText().
10 from lldbsuite
.test
.decorators
import *
11 from lldbsuite
.test
.lldbtest
import *
12 from lldbsuite
.test
import lldbutil
15 class HelpCommandTestCase(TestBase
):
17 def test_simplehelp(self
):
18 """A simple test of 'help' command and its output."""
19 self
.expect("help", startstr
="Debugger commands:")
21 self
.expect("help -a", matching
=False, substrs
=["next"])
23 self
.expect("help", matching
=True, substrs
=["next"])
26 def test_help_on_help(self
):
27 """Testing the help on the help facility."""
31 substrs
=["--hide-aliases", "--hide-user-commands"],
35 def test_help_arch(self
):
36 """Test 'help arch' which should list of supported architectures."""
37 self
.expect("help arch", substrs
=["arm", "i386", "x86_64"])
40 def test_help_version(self
):
41 """Test 'help version' and 'version' commands."""
42 self
.expect("help version", substrs
=["Show the LLDB debugger version."])
43 self
.expect("version", patterns
=["lldb( version|-[0-9]+).*\n"])
46 def test_help_should_not_crash_lldb(self
):
47 """Command 'help disasm' should not crash lldb."""
48 self
.runCmd("help disasm", check
=False)
49 self
.runCmd("help unsigned-integer")
52 def test_help_memory_read_should_not_crash_lldb(self
):
53 """Command 'help memory read' should not crash lldb."""
54 self
.runCmd("help memory read", check
=False)
57 def test_help_should_not_hang_emacsshell(self
):
58 """Command 'settings set term-width 0' should not hang the help command."""
60 "settings set term-width 0",
61 COMMAND_FAILED_AS_EXPECTED
,
63 substrs
=["error: 0 is out of range, valid values must be between"],
65 # self.runCmd("settings set term-width 0")
66 self
.expect("help", startstr
="Debugger commands:")
69 def test_help_breakpoint_set(self
):
70 """Test that 'help breakpoint set' does not print out redundant lines of:
71 'breakpoint set [-s <shlib-name>] ...'."""
73 "help breakpoint set",
75 substrs
=["breakpoint set [-s <shlib-name>]"],
79 def test_help_image_dump_symtab_should_not_crash(self
):
80 """Command 'help image dump symtab' should not crash lldb."""
81 # 'image' is an alias for 'target modules'.
82 self
.expect("help image dump symtab", substrs
=["dump symtab", "sort-order"])
85 def test_help_image_du_sym_is_ambiguous(self
):
86 """Command 'help image du sym' is ambiguous and spits out the list of candidates."""
89 COMMAND_FAILED_AS_EXPECTED
,
91 substrs
=["error: ambiguous command image du sym", "symfile", "symtab"],
95 def test_help_image_du_line_should_work(self
):
96 """Command 'help image du line-table' is not ambiguous and should work."""
97 # 'image' is an alias for 'target modules'.
100 substrs
=["Dump the line table for one or more compilation units"],
104 def test_help_image_list_shows_positional_args(self
):
105 """Command 'help image list' should describe positional args."""
106 # 'image' is an alias for 'target modules'.
107 self
.expect("help image list", substrs
=["<module> [...]"])
110 def test_help_target_variable_syntax(self
):
111 """Command 'help target variable' should display <variable-name> ..."""
113 "help target variable", substrs
=["<variable-name> [<variable-name> [...]]"]
117 def test_help_watchpoint_and_its_args(self
):
118 """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work."""
119 self
.expect("help watchpoint", substrs
=["delete", "disable", "enable", "list"])
120 self
.expect("help watchpt-id", substrs
=["<watchpt-id>"])
121 self
.expect("help watchpt-id-list", substrs
=["<watchpt-id-list>"])
124 def test_help_watchpoint_set(self
):
125 """Test that 'help watchpoint set' prints out 'expression' and 'variable'
126 as the possible subcommands."""
128 "help watchpoint set",
129 substrs
=["The following subcommands are supported:"],
130 patterns
=["expression +--", "variable +--"],
134 def test_help_po_hides_options(self
):
135 """Test that 'help po' does not show all the options for expression"""
138 substrs
=["--show-all-children", "--object-description"],
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", substrs
=["--arch", "--environment"], matching
=False)
148 def test_help_next_shows_options(self
):
149 """Test that 'help next' shows all the options for thread step-over"""
152 substrs
=["--step-out-avoids-no-debug", "--run-mode"],
157 def test_help_provides_alternatives(self
):
158 """Test that help on commands that don't exist provides information on additional help avenues"""
160 "help thisisnotadebuggercommand",
162 "'thisisnotadebuggercommand' is not a known command.",
163 "Try 'help' to see a current list of commands.",
164 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
165 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc.",
171 "help process thisisnotadebuggercommand",
173 "'process thisisnotadebuggercommand' is not a known command.",
174 "Try 'help' to see a current list of commands.",
175 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.",
176 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc.",
181 def test_custom_help_alias(self
):
182 """Test that aliases pick up custom help text."""
185 self
.runCmd("command unalias afriendlyalias", check
=False)
186 self
.runCmd("command unalias averyfriendlyalias", check
=False)
188 self
.addTearDownHook(cleanup
)
190 'command alias --help "I am a friendly alias" -- afriendlyalias help'
193 "help afriendlyalias", matching
=True, substrs
=["I am a friendly alias"]
196 'command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help'
199 "help averyfriendlyalias",
201 substrs
=["I am a very friendly alias"],
205 def test_alias_prints_origin(self
):
206 """Test that 'help <unique_match_to_alias>' prints the alias origin."""
209 self
.runCmd("command unalias alongaliasname", check
=False)
211 self
.addTearDownHook(cleanup
)
212 self
.runCmd("command alias alongaliasname help")
216 substrs
=["'alongaliasna' is an abbreviation for 'help'"],
220 def test_hidden_help(self
):
221 self
.expect("help -h", substrs
=["_regexp-bt"])
224 def test_help_ambiguous(self
):
228 "Help requested with ambiguous command name, possible completions:",
235 def test_help_unknown_flag(self
):
236 self
.expect("help -z", error
=True, substrs
=["unknown or ambiguous option"])
239 def test_help_format_output(self
):
240 """Test that help output reaches TerminalWidth."""
241 self
.runCmd("settings set term-width 108")
245 substrs
=["<format> -- One of the format names"],
249 def test_help_option_group_format_options_usage(self
):
250 """Test that help on commands that use OptionGroupFormat options provide relevant help specific to that command."""
255 "-f <format> ( --format <format> )",
256 "Specify a format to be used for display.",
257 "-s <byte-size> ( --size <byte-size> )",
258 "The size in bytes to use when displaying with the selected format.",
266 "-f <format> ( --format <format> )",
267 "The format to use for each of the value to be written.",
268 "-s <byte-size> ( --size <byte-size> )",
269 "The size in bytes to write from input file or each value.",
274 def test_help_shows_optional_short_options(self
):
275 """Test that optional short options are printed and that they are in
276 alphabetical order with upper case options first."""
278 "help memory read", substrs
=["memory read [-br]", "memory read [-AFLORTr]"]
281 "help target modules lookup", substrs
=["target modules lookup [-Airv]"]
285 def test_help_shows_command_options_usage(self
):
286 """Test that we start the usage section with a specific line."""
288 "help memory read", substrs
=["Command Options Usage:\n memory read"]
292 def test_help_detailed_information_spacing(self
):
293 """Test that we put a break between the usage and the options help lines,
294 and between the options themselves."""
298 "[<address-expression>]\n\n -A ( --show-all-children )",
299 # Starts with the end of the show-all-children line
305 def test_help_detailed_information_ordering(self
):
306 """Test that we order options alphabetically, upper case first."""
307 # You could test this with a simple regex like:
308 # <upper case>.*<later upper case>.*<lower case>.*<later lower case>
309 # Except that that could pass sometimes even with shuffled output.
310 # This makes sure that doesn't happen.
312 self
.runCmd("help memory read")
313 got
= self
.res
.GetOutput()
314 _
, options_lines
= got
.split("Command Options Usage:")
315 options_lines
= options_lines
.lstrip().splitlines()
317 # Skip over "memory read [-xyz] lines.
318 while "memory read" in options_lines
[0]:
320 # Plus the newline after that.
324 for line
in options_lines
:
325 # Ignore line breaks and descriptions.
326 # (not stripping the line here in case some line of the descriptions
327 # happens to start with "-")
328 if not line
or not line
.startswith(" -"):
330 # This apears at the end after the options.
331 if "This command takes options and free form arguments." in line
:
334 # The order of -- only options is not enforced so ignore their position.
335 if not line
.startswith("--"):
336 # Save its short char name.
337 short_options
.append(line
[1])
340 sorted(short_options
),
342 "Short option help displayed in an incorrect order!",
346 def test_help_show_tags(self
):
347 """Check that memory find and memory read have the --show-tags option
348 but only memory read mentions binary output."""
352 "--show-tags\n\s+Include memory tags in output "
353 "\(does not apply to binary output\)."
358 patterns
=["--show-tags\n\s+Include memory tags in output."],
362 def test_help_show_enum_values(self
):
363 """Check the help output for a argument type contains the enum values
364 and their descriptions."""
366 "help <log-handler>",
368 "The log handle that will be used to write out log messages.",
370 "Use the default (stream) log handler",
372 "Write log messages to the debugger output stream",
374 "Write log messages to a fixed size circular buffer",
376 "Write log messages to the operating system log",