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 version_number_string(self): 41 """Helper function to find the version number string of lldb.""" 42 plist = os.path.join( 43 os.environ["LLDB_SRC"], 44 "resources", 45 "LLDB-Info.plist") 46 try: 47 CFBundleVersionSegFound = False 48 with open(plist, 'r') as f: 49 for line in f: 50 if CFBundleVersionSegFound: 51 version_line = line.strip() 52 import re 53 m = re.match("<string>(.*)</string>", version_line) 54 if m: 55 version = m.group(1) 56 return version 57 else: 58 # Unsuccessful, let's juts break out of the for 59 # loop. 60 break 61 62 if line.find("<key>CFBundleVersion</key>") != -1: 63 # Found our match. The next line contains our version 64 # string, for example: 65 # 66 # <string>38</string> 67 CFBundleVersionSegFound = True 68 69 except: 70 # Just fallthrough... 71 import traceback 72 traceback.print_exc() 73 74 # Use None to signify that we are not able to grok the version number. 75 return None 76 77 @no_debug_info_test 78 def test_help_arch(self): 79 """Test 'help arch' which should list of supported architectures.""" 80 self.expect("help arch", 81 substrs=['arm', 'i386', 'x86_64']) 82 83 @no_debug_info_test 84 def test_help_version(self): 85 """Test 'help version' and 'version' commands.""" 86 self.expect("help version", 87 substrs=['Show the LLDB debugger version.']) 88 import re 89 version_str = self.version_number_string() 90 match = re.match('[0-9]+', version_str) 91 search_regexp = ['lldb( version|-' + (version_str if match else '[0-9]+') + ').*\n'] 92 93 self.expect("version", 94 patterns=search_regexp) 95 96 @no_debug_info_test 97 def test_help_should_not_crash_lldb(self): 98 """Command 'help disasm' should not crash lldb.""" 99 self.runCmd("help disasm", check=False) 100 self.runCmd("help unsigned-integer") 101 102 @no_debug_info_test 103 def test_help_should_not_hang_emacsshell(self): 104 """Command 'settings set term-width 0' should not hang the help command.""" 105 self.expect( 106 "settings set term-width 0", 107 COMMAND_FAILED_AS_EXPECTED, 108 error=True, 109 substrs=['error: 0 is out of range, valid values must be between']) 110 # self.runCmd("settings set term-width 0") 111 self.expect("help", 112 startstr='Debugger commands:') 113 114 @no_debug_info_test 115 def test_help_breakpoint_set(self): 116 """Test that 'help breakpoint set' does not print out redundant lines of: 117 'breakpoint set [-s <shlib-name>] ...'.""" 118 self.expect("help breakpoint set", matching=False, 119 substrs=['breakpoint set [-s <shlib-name>]']) 120 121 @no_debug_info_test 122 def test_help_image_dump_symtab_should_not_crash(self): 123 """Command 'help image dump symtab' should not crash lldb.""" 124 # 'image' is an alias for 'target modules'. 125 self.expect("help image dump symtab", 126 substrs=['dump symtab', 127 'sort-order']) 128 129 @no_debug_info_test 130 def test_help_image_du_sym_is_ambiguous(self): 131 """Command 'help image du sym' is ambiguous and spits out the list of candidates.""" 132 self.expect("help image du sym", 133 COMMAND_FAILED_AS_EXPECTED, error=True, 134 substrs=['error: ambiguous command image du sym', 135 'symfile', 136 'symtab']) 137 138 @no_debug_info_test 139 def test_help_image_du_line_should_work(self): 140 """Command 'help image du line-table' is not ambiguous and should work.""" 141 # 'image' is an alias for 'target modules'. 142 self.expect("help image du line", substrs=[ 143 'Dump the line table for one or more compilation units']) 144 145 @no_debug_info_test 146 def test_help_target_variable_syntax(self): 147 """Command 'help target variable' should display <variable-name> ...""" 148 self.expect("help target variable", 149 substrs=['<variable-name> [<variable-name> [...]]']) 150 151 @no_debug_info_test 152 def test_help_watchpoint_and_its_args(self): 153 """Command 'help watchpoint', 'help watchpt-id', and 'help watchpt-id-list' should work.""" 154 self.expect("help watchpoint", 155 substrs=['delete', 'disable', 'enable', 'list']) 156 self.expect("help watchpt-id", 157 substrs=['<watchpt-id>']) 158 self.expect("help watchpt-id-list", 159 substrs=['<watchpt-id-list>']) 160 161 @no_debug_info_test 162 def test_help_watchpoint_set(self): 163 """Test that 'help watchpoint set' prints out 'expression' and 'variable' 164 as the possible subcommands.""" 165 self.expect("help watchpoint set", 166 substrs=['The following subcommands are supported:'], 167 patterns=['expression +--', 168 'variable +--']) 169 170 @no_debug_info_test 171 def test_help_po_hides_options(self): 172 """Test that 'help po' does not show all the options for expression""" 173 self.expect( 174 "help po", 175 substrs=[ 176 '--show-all-children', 177 '--object-description'], 178 matching=False) 179 180 @no_debug_info_test 181 def test_help_run_hides_options(self): 182 """Test that 'help run' does not show all the options for process launch""" 183 self.expect("help run", 184 substrs=['--arch', '--environment'], matching=False) 185 186 @no_debug_info_test 187 def test_help_next_shows_options(self): 188 """Test that 'help next' shows all the options for thread step-over""" 189 self.expect("help next", 190 substrs=['--step-out-avoids-no-debug', '--run-mode'], matching=True) 191 192 @no_debug_info_test 193 def test_help_provides_alternatives(self): 194 """Test that help on commands that don't exist provides information on additional help avenues""" 195 self.expect( 196 "help thisisnotadebuggercommand", 197 substrs=[ 198 "'thisisnotadebuggercommand' is not a known command.", 199 "Try 'help' to see a current list of commands.", 200 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", 201 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."], 202 error=True) 203 204 self.expect( 205 "help process thisisnotadebuggercommand", 206 substrs=[ 207 "'process thisisnotadebuggercommand' is not a known command.", 208 "Try 'help' to see a current list of commands.", 209 "Try 'apropos thisisnotadebuggercommand' for a list of related commands.", 210 "Try 'type lookup thisisnotadebuggercommand' for information on types, methods, functions, modules, etc."]) 211 212 @no_debug_info_test 213 def test_custom_help_alias(self): 214 """Test that aliases pick up custom help text.""" 215 def cleanup(): 216 self.runCmd('command unalias afriendlyalias', check=False) 217 self.runCmd('command unalias averyfriendlyalias', check=False) 218 219 self.addTearDownHook(cleanup) 220 self.runCmd( 221 'command alias --help "I am a friendly alias" -- afriendlyalias help') 222 self.expect( 223 "help afriendlyalias", 224 matching=True, 225 substrs=['I am a friendly alias']) 226 self.runCmd( 227 'command alias --long-help "I am a very friendly alias" -- averyfriendlyalias help') 228 self.expect("help averyfriendlyalias", matching=True, 229 substrs=['I am a very friendly alias']) 230 @no_debug_info_test 231 def test_alias_prints_origin(self): 232 """Test that 'help <unique_match_to_alias>' prints the alias origin.""" 233 def cleanup(): 234 self.runCmd('command unalias alongaliasname', check=False) 235 236 self.addTearDownHook(cleanup) 237 self.runCmd('command alias alongaliasname help') 238 self.expect("help alongaliasna", matching=True, 239 substrs=["'alongaliasna' is an abbreviation for 'help'"]) 240 241 @no_debug_info_test 242 def test_hidden_help(self): 243 self.expect("help -h", 244 substrs=["_regexp-bt"]) 245 246 @no_debug_info_test 247 def test_help_ambiguous(self): 248 self.expect("help g", 249 substrs=["Help requested with ambiguous command name, possible completions:", 250 "gdb-remote", "gui"]) 251 252 @no_debug_info_test 253 def test_help_unknown_flag(self): 254 self.expect("help -z", error=True, 255 substrs=["unknown or ambiguous option"]) 256 257 @no_debug_info_test 258 def test_help_format_output(self): 259 """Test that help output reaches TerminalWidth.""" 260 self.runCmd( 261 'settings set term-width 108') 262 self.expect( 263 "help format", 264 matching=True, 265 substrs=['<format> -- One of the format names']) 266