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