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