1""" 2Test the lldb command line completion mechanism. 3""" 4 5 6 7import os 8from multiprocessing import Process 9import lldb 10from lldbsuite.test.decorators import * 11from lldbsuite.test.lldbtest import * 12from lldbsuite.test import lldbplatform 13from lldbsuite.test import lldbutil 14 15 16class CommandLineCompletionTestCase(TestBase): 17 18 mydir = TestBase.compute_mydir(__file__) 19 20 NO_DEBUG_INFO_TESTCASE = True 21 22 @classmethod 23 def classCleanup(cls): 24 """Cleanup the test byproducts.""" 25 try: 26 os.remove("child_send.txt") 27 os.remove("child_read.txt") 28 except: 29 pass 30 31 def test_at(self): 32 """Test that 'at' completes to 'attach '.""" 33 self.complete_from_to('at', 'attach ') 34 35 def test_de(self): 36 """Test that 'de' completes to 'detach '.""" 37 self.complete_from_to('de', 'detach ') 38 39 def test_frame_variable(self): 40 self.build() 41 self.main_source = "main.cpp" 42 self.main_source_spec = lldb.SBFileSpec(self.main_source) 43 44 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 45 '// Break here', self.main_source_spec) 46 self.assertEquals(process.GetState(), lldb.eStateStopped) 47 48 # Since CommandInterpreter has been corrected to update the current execution 49 # context at the beginning of HandleCompletion, we're here explicitly testing 50 # the scenario where "frame var" is completed without any preceding commands. 51 52 self.complete_from_to('frame variable fo', 53 'frame variable fooo') 54 self.complete_from_to('frame variable fooo.', 55 'frame variable fooo.') 56 self.complete_from_to('frame variable fooo.dd', 57 'frame variable fooo.dd') 58 59 self.complete_from_to('frame variable ptr_fooo->', 60 'frame variable ptr_fooo->') 61 self.complete_from_to('frame variable ptr_fooo->dd', 62 'frame variable ptr_fooo->dd') 63 64 self.complete_from_to('frame variable cont', 65 'frame variable container') 66 self.complete_from_to('frame variable container.', 67 'frame variable container.MemberVar') 68 self.complete_from_to('frame variable container.Mem', 69 'frame variable container.MemberVar') 70 71 self.complete_from_to('frame variable ptr_cont', 72 'frame variable ptr_container') 73 self.complete_from_to('frame variable ptr_container->', 74 'frame variable ptr_container->MemberVar') 75 self.complete_from_to('frame variable ptr_container->Mem', 76 'frame variable ptr_container->MemberVar') 77 78 def test_process_attach_dash_dash_con(self): 79 """Test that 'process attach --con' completes to 'process attach --continue '.""" 80 self.complete_from_to( 81 'process attach --con', 82 'process attach --continue ') 83 84 def test_process_launch_arch(self): 85 self.complete_from_to('process launch --arch ', 86 ['mips', 87 'arm64']) 88 89 def test_process_load(self): 90 self.build() 91 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 92 self.complete_from_to('process load Makef', 'process load Makefile') 93 94 @skipUnlessPlatform(["linux"]) 95 def test_process_unload(self): 96 """Test the completion for "process unload <index>" """ 97 # This tab completion should not work without a running process. 98 self.complete_from_to('process unload ', 99 'process unload ') 100 101 self.build() 102 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 103 err = lldb.SBError() 104 self.process().LoadImage(lldb.SBFileSpec(self.getBuildArtifact("libshared.so")), err) 105 self.assertSuccess(err) 106 107 self.complete_from_to('process unload ', 108 'process unload 0') 109 110 self.process().UnloadImage(0) 111 self.complete_from_to('process unload ', 112 'process unload ') 113 114 def test_process_plugin_completion(self): 115 subcommands = ['attach -P', 'connect -p', 'launch -p'] 116 117 for subcommand in subcommands: 118 self.complete_from_to('process ' + subcommand + ' mac', 119 'process ' + subcommand + ' mach-o-core') 120 121 def completions_contain_str(self, input, needle): 122 interp = self.dbg.GetCommandInterpreter() 123 match_strings = lldb.SBStringList() 124 num_matches = interp.HandleCompletion(input, len(input), 0, -1, match_strings) 125 found_needle = False 126 for match in match_strings: 127 if needle in match: 128 found_needle = True 129 break 130 self.assertTrue(found_needle, "Returned completions: " + "\n".join(match_strings)) 131 132 133 @skipIfRemote 134 def test_common_completion_process_pid_and_name(self): 135 # The LLDB process itself and the process already attached to are both 136 # ignored by the process discovery mechanism, thus we need a process known 137 # to us here. 138 self.build() 139 server = self.spawnSubprocess( 140 self.getBuildArtifact("a.out"), 141 ["-x"], # Arg "-x" makes the subprocess wait for input thus it won't be terminated too early 142 install_remote=False) 143 self.assertIsNotNone(server) 144 pid = server.pid 145 146 self.completions_contain('process attach -p ', [str(pid)]) 147 self.completions_contain('platform process attach -p ', [str(pid)]) 148 self.completions_contain('platform process info ', [str(pid)]) 149 150 self.completions_contain_str('process attach -n ', "a.out") 151 self.completions_contain_str('platform process attach -n ', "a.out") 152 153 def test_process_signal(self): 154 # The tab completion for "process signal" won't work without a running process. 155 self.complete_from_to('process signal ', 156 'process signal ') 157 158 # Test with a running process. 159 self.build() 160 self.main_source = "main.cpp" 161 self.main_source_spec = lldb.SBFileSpec(self.main_source) 162 lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) 163 164 self.complete_from_to('process signal ', 165 'process signal SIG') 166 self.complete_from_to('process signal SIGA', 167 ['SIGABRT', 168 'SIGALRM']) 169 170 def test_ambiguous_long_opt(self): 171 self.completions_match('breakpoint modify --th', 172 ['--thread-id', 173 '--thread-index', 174 '--thread-name']) 175 176 def test_disassemble_dash_f(self): 177 self.completions_match('disassemble -F ', 178 ['default', 179 'intel', 180 'att']) 181 182 def test_plugin_load(self): 183 self.complete_from_to('plugin load ', []) 184 185 def test_log_enable(self): 186 self.complete_from_to('log enable ll', ['lldb']) 187 self.complete_from_to('log enable dw', ['dwarf']) 188 self.complete_from_to('log enable lldb al', ['all']) 189 self.complete_from_to('log enable lldb sym', ['symbol']) 190 191 def test_log_enable(self): 192 self.complete_from_to('log disable ll', ['lldb']) 193 self.complete_from_to('log disable dw', ['dwarf']) 194 self.complete_from_to('log disable lldb al', ['all']) 195 self.complete_from_to('log disable lldb sym', ['symbol']) 196 197 def test_log_list(self): 198 self.complete_from_to('log list ll', ['lldb']) 199 self.complete_from_to('log list dw', ['dwarf']) 200 self.complete_from_to('log list ll', ['lldb']) 201 self.complete_from_to('log list lldb dwa', ['dwarf']) 202 203 def test_quoted_command(self): 204 self.complete_from_to('"set', 205 ['"settings" ']) 206 207 def test_quoted_arg_with_quoted_command(self): 208 self.complete_from_to('"settings" "repl', 209 ['"replace" ']) 210 211 def test_quoted_arg_without_quoted_command(self): 212 self.complete_from_to('settings "repl', 213 ['"replace" ']) 214 215 def test_single_quote_command(self): 216 self.complete_from_to("'set", 217 ["'settings' "]) 218 219 def test_terminated_quote_command(self): 220 # This should not crash, but we don't get any 221 # reasonable completions from this. 222 self.complete_from_to("'settings'", []) 223 224 def test_process_launch_arch_arm(self): 225 self.complete_from_to('process launch --arch arm', 226 ['arm64']) 227 228 def test_target_symbols_add_shlib(self): 229 # Doesn't seem to work, but at least it shouldn't crash. 230 self.complete_from_to('target symbols add --shlib ', []) 231 232 def test_log_file(self): 233 # Complete in our source directory which contains a 'main.cpp' file. 234 src_dir = os.path.dirname(os.path.realpath(__file__)) + '/' 235 self.complete_from_to('log enable lldb expr -f ' + src_dir, 236 ['main.cpp']) 237 238 def test_log_dir(self): 239 # Complete our source directory. 240 src_dir = os.path.dirname(os.path.realpath(__file__)) 241 self.complete_from_to('log enable lldb expr -f ' + src_dir, 242 [src_dir + os.sep], turn_off_re_match=True) 243 244 # <rdar://problem/11052829> 245 def test_infinite_loop_while_completing(self): 246 """Test that 'process print hello\' completes to itself and does not infinite loop.""" 247 self.complete_from_to('process print hello\\', 'process print hello\\', 248 turn_off_re_match=True) 249 250 def test_watchpoint_co(self): 251 """Test that 'watchpoint co' completes to 'watchpoint command '.""" 252 self.complete_from_to('watchpoint co', 'watchpoint command ') 253 254 def test_watchpoint_command_space(self): 255 """Test that 'watchpoint command ' completes to ['add', 'delete', 'list'].""" 256 self.complete_from_to( 257 'watchpoint command ', [ 258 'add', 'delete', 'list']) 259 260 def test_watchpoint_command_a(self): 261 """Test that 'watchpoint command a' completes to 'watchpoint command add '.""" 262 self.complete_from_to( 263 'watchpoint command a', 264 'watchpoint command add ') 265 266 def test_watchpoint_set_ex(self): 267 """Test that 'watchpoint set ex' completes to 'watchpoint set expression '.""" 268 self.complete_from_to( 269 'watchpoint set ex', 270 'watchpoint set expression ') 271 272 def test_watchpoint_set_var(self): 273 """Test that 'watchpoint set var' completes to 'watchpoint set variable '.""" 274 self.complete_from_to('watchpoint set var', 'watchpoint set variable ') 275 276 def test_watchpoint_set_variable_foo(self): 277 self.build() 278 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 279 self.complete_from_to('watchpoint set variable fo', 'watchpoint set variable fooo') 280 # Only complete the first argument. 281 self.complete_from_to('watchpoint set variable fooo ', 'watchpoint set variable fooo ') 282 283 def test_help_fi(self): 284 """Test that 'help fi' completes to ['file', 'finish'].""" 285 self.complete_from_to( 286 'help fi', [ 287 'file', 'finish']) 288 289 def test_help_watchpoint_s(self): 290 """Test that 'help watchpoint s' completes to 'help watchpoint set '.""" 291 self.complete_from_to('help watchpoint s', 'help watchpoint set ') 292 293 def test_common_complete_watchpoint_ids(self): 294 subcommands = ['enable', 'disable', 'delete', 'modify', 'ignore'] 295 296 # Completion should not work without a target. 297 for subcommand in subcommands: 298 self.complete_from_to('watchpoint ' + subcommand + ' ', 299 'watchpoint ' + subcommand + ' ') 300 301 # Create a process to provide a target and enable watchpoint setting. 302 self.build() 303 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 304 305 self.runCmd('watchpoint set variable ptr_fooo') 306 for subcommand in subcommands: 307 self.complete_from_to('watchpoint ' + subcommand + ' ', ['1']) 308 309 def test_settings_append_target_er(self): 310 """Test that 'settings append target.er' completes to 'settings append target.error-path'.""" 311 self.complete_from_to( 312 'settings append target.er', 313 'settings append target.error-path') 314 315 def test_settings_insert_after_target_en(self): 316 """Test that 'settings insert-after target.env' completes to 'settings insert-after target.env-vars'.""" 317 self.complete_from_to( 318 'settings insert-after target.env', 319 'settings insert-after target.env-vars') 320 321 def test_settings_insert_before_target_en(self): 322 """Test that 'settings insert-before target.env' completes to 'settings insert-before target.env-vars'.""" 323 self.complete_from_to( 324 'settings insert-before target.env', 325 'settings insert-before target.env-vars') 326 327 def test_settings_replace_target_ru(self): 328 """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'.""" 329 self.complete_from_to( 330 'settings replace target.ru', 331 'settings replace target.run-args') 332 333 def test_settings_show_term(self): 334 self.complete_from_to( 335 'settings show term-', 336 'settings show term-width') 337 338 def test_settings_list_term(self): 339 self.complete_from_to( 340 'settings list term-', 341 'settings list term-width') 342 343 def test_settings_remove_term(self): 344 self.complete_from_to( 345 'settings remove term-', 346 'settings remove term-width') 347 348 def test_settings_s(self): 349 """Test that 'settings s' completes to ['set', 'show'].""" 350 self.complete_from_to( 351 'settings s', [ 352 'set', 'show']) 353 354 def test_settings_set_th(self): 355 """Test that 'settings set thread-f' completes to 'settings set thread-format'.""" 356 self.complete_from_to('settings set thread-f', 'settings set thread-format') 357 358 def test_settings_s_dash(self): 359 """Test that 'settings set --g' completes to 'settings set --global'.""" 360 self.complete_from_to('settings set --g', 'settings set --global') 361 362 def test_settings_clear_th(self): 363 """Test that 'settings clear thread-f' completes to 'settings clear thread-format'.""" 364 self.complete_from_to( 365 'settings clear thread-f', 366 'settings clear thread-format') 367 368 def test_settings_set_ta(self): 369 """Test that 'settings set ta' completes to 'settings set target.'.""" 370 self.complete_from_to( 371 'settings set target.ma', 372 'settings set target.max-') 373 374 def test_settings_set_target_exec(self): 375 """Test that 'settings set target.exec' completes to 'settings set target.exec-search-paths '.""" 376 self.complete_from_to( 377 'settings set target.exec', 378 'settings set target.exec-search-paths') 379 380 def test_settings_set_target_pr(self): 381 """Test that 'settings set target.pr' completes to [ 382 'target.prefer-dynamic-value', 'target.process.'].""" 383 self.complete_from_to('settings set target.pr', 384 ['target.prefer-dynamic-value', 385 'target.process.']) 386 387 def test_settings_set_target_process(self): 388 """Test that 'settings set target.process' completes to 'settings set target.process.'.""" 389 self.complete_from_to( 390 'settings set target.process', 391 'settings set target.process.') 392 393 def test_settings_set_target_process_dot(self): 394 """Test that 'settings set target.process.t' completes to 'settings set target.process.thread.'.""" 395 self.complete_from_to( 396 'settings set target.process.t', 397 'settings set target.process.thread.') 398 399 def test_settings_set_target_process_thread_dot(self): 400 """Test that 'settings set target.process.thread.' completes to [ 401 'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread'].""" 402 self.complete_from_to('settings set target.process.thread.', 403 ['target.process.thread.step-avoid-regexp', 404 'target.process.thread.trace-thread']) 405 406 def test_thread_plan_discard(self): 407 self.build() 408 (_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, 409 'ptr_foo', lldb.SBFileSpec("main.cpp")) 410 self.assertTrue(thread) 411 self.complete_from_to('thread plan discard ', 'thread plan discard ') 412 413 source_path = os.path.join(self.getSourceDir(), "thread_plan_script.py") 414 self.runCmd("command script import '%s'"%(source_path)) 415 self.runCmd("thread step-scripted -C thread_plan_script.PushPlanStack") 416 self.complete_from_to('thread plan discard ', 'thread plan discard 1') 417 self.runCmd('thread plan discard 1') 418 419 def test_target_space(self): 420 """Test that 'target ' completes to ['create', 'delete', 'list', 421 'modules', 'select', 'stop-hook', 'variable'].""" 422 self.complete_from_to('target ', 423 ['create', 424 'delete', 425 'list', 426 'modules', 427 'select', 428 'stop-hook', 429 'variable']) 430 431 def test_target_modules_dump_line_table(self): 432 """Tests source file completion by completing the line-table argument.""" 433 self.build() 434 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 435 self.complete_from_to('target modules dump line-table main.cp', 436 ['main.cpp']) 437 438 def test_target_modules_load_aout(self): 439 """Tests modules completion by completing the target modules load argument.""" 440 self.build() 441 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 442 self.complete_from_to('target modules load a.ou', 443 ['a.out']) 444 445 def test_target_modules_search_paths_insert(self): 446 # Completion won't work without a valid target. 447 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 448 self.build() 449 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 450 self.assertTrue(target, VALID_TARGET) 451 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 452 self.runCmd("target modules search-paths add a b") 453 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") 454 # Completion only works for the first arg. 455 self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") 456 457 def test_target_create_dash_co(self): 458 """Test that 'target create --co' completes to 'target variable --core '.""" 459 self.complete_from_to('target create --co', 'target create --core ') 460 461 def test_target_va(self): 462 """Test that 'target va' completes to 'target variable '.""" 463 self.complete_from_to('target va', 'target variable ') 464 465 def test_common_completion_thread_index(self): 466 subcommands = ['continue', 'info', 'exception', 'select', 467 'step-in', 'step-inst', 'step-inst-over', 'step-out', 'step-over', 'step-script'] 468 469 # Completion should do nothing without threads. 470 for subcommand in subcommands: 471 self.complete_from_to('thread ' + subcommand + ' ', 472 'thread ' + subcommand + ' ') 473 474 self.build() 475 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 476 477 # At least we have the thread at the index of 1 now. 478 for subcommand in subcommands: 479 self.complete_from_to('thread ' + subcommand + ' ', ['1']) 480 481 def test_common_completion_type_category_name(self): 482 subcommands = ['delete', 'list', 'enable', 'disable', 'define'] 483 for subcommand in subcommands: 484 self.complete_from_to('type category ' + subcommand + ' ', ['default']) 485 self.complete_from_to('type filter add -w ', ['default']) 486 487 def test_command_argument_completion(self): 488 """Test completion of command arguments""" 489 self.complete_from_to("watchpoint set variable -", ["-w", "-s"]) 490 self.complete_from_to('watchpoint set variable -w', 'watchpoint set variable -w ') 491 self.complete_from_to("watchpoint set variable --", ["--watch", "--size"]) 492 self.complete_from_to("watchpoint set variable --w", "watchpoint set variable --watch") 493 self.complete_from_to('watchpoint set variable -w ', ['read', 'write', 'read_write']) 494 self.complete_from_to("watchpoint set variable --watch ", ["read", "write", "read_write"]) 495 self.complete_from_to("watchpoint set variable --watch w", "watchpoint set variable --watch write") 496 self.complete_from_to('watchpoint set variable -w read_', 'watchpoint set variable -w read_write') 497 # Now try the same thing with a variable name (non-option argument) to 498 # test that getopts arg reshuffling doesn't confuse us. 499 self.complete_from_to("watchpoint set variable foo -", ["-w", "-s"]) 500 self.complete_from_to('watchpoint set variable foo -w', 'watchpoint set variable foo -w ') 501 self.complete_from_to("watchpoint set variable foo --", ["--watch", "--size"]) 502 self.complete_from_to("watchpoint set variable foo --w", "watchpoint set variable foo --watch") 503 self.complete_from_to('watchpoint set variable foo -w ', ['read', 'write', 'read_write']) 504 self.complete_from_to("watchpoint set variable foo --watch ", ["read", "write", "read_write"]) 505 self.complete_from_to("watchpoint set variable foo --watch w", "watchpoint set variable foo --watch write") 506 self.complete_from_to('watchpoint set variable foo -w read_', 'watchpoint set variable foo -w read_write') 507 508 def test_command_script_delete(self): 509 self.runCmd("command script add -h test_desc -f none -s current usercmd1") 510 self.check_completion_with_desc('command script delete ', [['usercmd1', 'test_desc']]) 511 512 def test_command_delete(self): 513 self.runCmd(r"command regex test_command s/^$/finish/ 's/([0-9]+)/frame select %1/'") 514 self.complete_from_to('command delete test_c', 'command delete test_command') 515 516 def test_command_unalias(self): 517 self.complete_from_to('command unalias ima', 'command unalias image') 518 519 def test_completion_description_commands(self): 520 """Test descriptions of top-level command completions""" 521 self.check_completion_with_desc("", [ 522 ["command", "Commands for managing custom LLDB commands."], 523 ["breakpoint", "Commands for operating on breakpoints (see 'help b' for shorthand.)"] 524 ]) 525 526 self.check_completion_with_desc("pl", [ 527 ["platform", "Commands to manage and create platforms."], 528 ["plugin", "Commands for managing LLDB plugins."] 529 ]) 530 531 # Just check that this doesn't crash. 532 self.check_completion_with_desc("comman", []) 533 self.check_completion_with_desc("non-existent-command", []) 534 535 def test_completion_description_command_options(self): 536 """Test descriptions of command options""" 537 # Short options 538 self.check_completion_with_desc("breakpoint set -", [ 539 ["-h", "Set the breakpoint on exception catcH."], 540 ["-w", "Set the breakpoint on exception throW."] 541 ]) 542 543 # Long options. 544 self.check_completion_with_desc("breakpoint set --", [ 545 ["--on-catch", "Set the breakpoint on exception catcH."], 546 ["--on-throw", "Set the breakpoint on exception throW."] 547 ]) 548 549 # Ambiguous long options. 550 self.check_completion_with_desc("breakpoint set --on-", [ 551 ["--on-catch", "Set the breakpoint on exception catcH."], 552 ["--on-throw", "Set the breakpoint on exception throW."] 553 ]) 554 555 # Unknown long option. 556 self.check_completion_with_desc("breakpoint set --Z", [ 557 ]) 558 559 def test_common_completion_frame_index(self): 560 self.build() 561 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 562 563 self.complete_from_to('frame select ', ['0']) 564 self.complete_from_to('thread backtrace -s ', ['0']) 565 566 def test_frame_recognizer_delete(self): 567 self.runCmd("frame recognizer add -l py_class -s module_name -n recognizer_name") 568 self.check_completion_with_desc('frame recognizer delete ', [['0', 'py_class, module module_name, symbol recognizer_name']]) 569 570 def test_platform_install_local_file(self): 571 self.complete_from_to('platform target-install main.cp', 'platform target-install main.cpp') 572 573 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") 574 def test_symbol_name(self): 575 self.build() 576 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 577 self.complete_from_to('breakpoint set -n Fo', 578 'breakpoint set -n Foo::Bar(int,\\ int)', 579 turn_off_re_match=True) 580 # No completion for Qu because the candidate is 581 # (anonymous namespace)::Quux(). 582 self.complete_from_to('breakpoint set -n Qu', '') 583 584 def test_completion_type_formatter_delete(self): 585 self.runCmd('type filter add --child a Aoo') 586 self.complete_from_to('type filter delete ', ['Aoo']) 587 self.runCmd('type filter add --child b -x Boo') 588 self.complete_from_to('type filter delete ', ['Boo']) 589 590 self.runCmd('type format add -f hex Coo') 591 self.complete_from_to('type format delete ', ['Coo']) 592 self.runCmd('type format add -f hex -x Doo') 593 self.complete_from_to('type format delete ', ['Doo']) 594 595 self.runCmd('type summary add -c Eoo') 596 self.complete_from_to('type summary delete ', ['Eoo']) 597 self.runCmd('type summary add -x -c Foo') 598 self.complete_from_to('type summary delete ', ['Foo']) 599 600 self.runCmd('type synthetic add Goo -l test') 601 self.complete_from_to('type synthetic delete ', ['Goo']) 602 self.runCmd('type synthetic add -x Hoo -l test') 603 self.complete_from_to('type synthetic delete ', ['Hoo']) 604 605 @skipIf(archs=no_match(['x86_64'])) 606 def test_register_read_and_write_on_x86(self): 607 """Test the completion of the commands register read and write on x86""" 608 609 # The tab completion for "register read/write" won't work without a running process. 610 self.complete_from_to('register read ', 611 'register read ') 612 self.complete_from_to('register write ', 613 'register write ') 614 615 self.build() 616 self.main_source_spec = lldb.SBFileSpec("main.cpp") 617 lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) 618 619 # test cases for register read 620 self.complete_from_to('register read ', 621 ['rax', 622 'rbx', 623 'rcx']) 624 self.complete_from_to('register read r', 625 ['rax', 626 'rbx', 627 'rcx']) 628 self.complete_from_to('register read ra', 629 'register read rax') 630 # register read can take multiple register names as arguments 631 self.complete_from_to('register read rax ', 632 ['rax', 633 'rbx', 634 'rcx']) 635 # complete with prefix '$' 636 self.completions_match('register read $rb', 637 ['$rbx', 638 '$rbp']) 639 self.completions_match('register read $ra', 640 ['$rax']) 641 self.complete_from_to('register read rax $', 642 ['\$rax', 643 '\$rbx', 644 '\$rcx']) 645 self.complete_from_to('register read $rax ', 646 ['rax', 647 'rbx', 648 'rcx']) 649 650 # test cases for register write 651 self.complete_from_to('register write ', 652 ['rax', 653 'rbx', 654 'rcx']) 655 self.complete_from_to('register write r', 656 ['rax', 657 'rbx', 658 'rcx']) 659 self.complete_from_to('register write ra', 660 'register write rax') 661 self.complete_from_to('register write rb', 662 ['rbx', 663 'rbp']) 664 # register write can only take exact one register name as argument 665 self.complete_from_to('register write rbx ', 666 []) 667 668 def test_common_completion_target_stophook_ids(self): 669 subcommands = ['delete', 'enable', 'disable'] 670 671 for subcommand in subcommands: 672 self.complete_from_to('target stop-hook ' + subcommand + ' ', 673 'target stop-hook ' + subcommand + ' ') 674 675 self.build() 676 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 677 self.runCmd('target stop-hook add test DONE') 678 679 for subcommand in subcommands: 680 self.complete_from_to('target stop-hook ' + subcommand + ' ', 681 'target stop-hook ' + subcommand + ' 1') 682 683 # Completion should work only on the first argument. 684 for subcommand in subcommands: 685 self.complete_from_to('target stop-hook ' + subcommand + ' 1 ', 686 'target stop-hook ' + subcommand + ' 1 ') 687 688 def test_common_completion_type_language(self): 689 self.complete_from_to('type category -l ', ['c']) 690 691 def test_target_modules_load_dash_u(self): 692 self.build() 693 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 694 self.complete_from_to('target modules load -u ', [target.GetModuleAtIndex(0).GetUUIDString()]) 695 696 def test_complete_breakpoint_with_ids(self): 697 """These breakpoint subcommands should be completed with a list of breakpoint ids""" 698 699 subcommands = ['enable', 'disable', 'delete', 'modify', 'name add', 'name delete', 'write'] 700 701 # The tab completion here is unavailable without a target 702 for subcommand in subcommands: 703 self.complete_from_to('breakpoint ' + subcommand + ' ', 704 'breakpoint ' + subcommand + ' ') 705 706 self.build() 707 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 708 self.assertTrue(target, VALID_TARGET) 709 710 bp = target.BreakpointCreateByName('main', 'a.out') 711 self.assertTrue(bp) 712 self.assertEqual(bp.GetNumLocations(), 1) 713 714 for subcommand in subcommands: 715 self.complete_from_to('breakpoint ' + subcommand + ' ', 716 ['1']) 717 718 bp2 = target.BreakpointCreateByName('Bar', 'a.out') 719 self.assertTrue(bp2) 720 self.assertEqual(bp2.GetNumLocations(), 1) 721 722 for subcommand in subcommands: 723 self.complete_from_to('breakpoint ' + subcommand + ' ', 724 ['1', 725 '2']) 726 727 for subcommand in subcommands: 728 self.complete_from_to('breakpoint ' + subcommand + ' 1 ', 729 ['1', 730 '2']) 731 732 def test_complete_breakpoint_with_names(self): 733 self.build() 734 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 735 self.assertTrue(target, VALID_TARGET) 736 737 # test breakpoint read dedicated 738 self.complete_from_to('breakpoint read -N ', 'breakpoint read -N ') 739 self.complete_from_to('breakpoint read -f breakpoints.json -N ', ['mm']) 740 self.complete_from_to('breakpoint read -f breakpoints.json -N n', 'breakpoint read -f breakpoints.json -N n') 741 self.complete_from_to('breakpoint read -f breakpoints_invalid.json -N ', 'breakpoint read -f breakpoints_invalid.json -N ') 742 743 # test common breapoint name completion 744 bp1 = target.BreakpointCreateByName('main', 'a.out') 745 self.assertTrue(bp1) 746 self.assertEqual(bp1.GetNumLocations(), 1) 747 self.complete_from_to('breakpoint set -N n', 'breakpoint set -N n') 748 self.assertTrue(bp1.AddNameWithErrorHandling("nn")) 749 self.complete_from_to('breakpoint set -N ', 'breakpoint set -N nn') 750