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 SIGPIP', 167 'process signal SIGPIPE') 168 self.complete_from_to('process signal SIGA', 169 ['SIGABRT', 170 'SIGALRM']) 171 172 def test_ambiguous_long_opt(self): 173 self.completions_match('breakpoint modify --th', 174 ['--thread-id', 175 '--thread-index', 176 '--thread-name']) 177 178 def test_disassemble_dash_f(self): 179 self.completions_match('disassemble -F ', 180 ['default', 181 'intel', 182 'att']) 183 184 def test_plugin_load(self): 185 self.complete_from_to('plugin load ', []) 186 187 def test_log_enable(self): 188 self.complete_from_to('log enable ll', ['lldb']) 189 self.complete_from_to('log enable dw', ['dwarf']) 190 self.complete_from_to('log enable lldb al', ['all']) 191 self.complete_from_to('log enable lldb sym', ['symbol']) 192 193 def test_log_enable(self): 194 self.complete_from_to('log disable ll', ['lldb']) 195 self.complete_from_to('log disable dw', ['dwarf']) 196 self.complete_from_to('log disable lldb al', ['all']) 197 self.complete_from_to('log disable lldb sym', ['symbol']) 198 199 def test_log_list(self): 200 self.complete_from_to('log list ll', ['lldb']) 201 self.complete_from_to('log list dw', ['dwarf']) 202 self.complete_from_to('log list ll', ['lldb']) 203 self.complete_from_to('log list lldb dwa', ['dwarf']) 204 205 def test_quoted_command(self): 206 self.complete_from_to('"set', 207 ['"settings" ']) 208 209 def test_quoted_arg_with_quoted_command(self): 210 self.complete_from_to('"settings" "repl', 211 ['"replace" ']) 212 213 def test_quoted_arg_without_quoted_command(self): 214 self.complete_from_to('settings "repl', 215 ['"replace" ']) 216 217 def test_single_quote_command(self): 218 self.complete_from_to("'set", 219 ["'settings' "]) 220 221 def test_terminated_quote_command(self): 222 # This should not crash, but we don't get any 223 # reasonable completions from this. 224 self.complete_from_to("'settings'", []) 225 226 def test_process_launch_arch_arm(self): 227 self.complete_from_to('process launch --arch arm', 228 ['arm64']) 229 230 def test_target_symbols_add_shlib(self): 231 # Doesn't seem to work, but at least it shouldn't crash. 232 self.complete_from_to('target symbols add --shlib ', []) 233 234 def test_log_file(self): 235 # Complete in our source directory which contains a 'main.cpp' file. 236 src_dir = self.getSourceDir() + '/' 237 self.complete_from_to('log enable lldb expr -f ' + src_dir, 238 ['main.cpp']) 239 240 def test_log_dir(self): 241 # Complete our source directory. 242 src_dir = os.path.dirname(os.path.realpath(__file__)) 243 self.complete_from_to('log enable lldb expr -f ' + src_dir, 244 [src_dir + os.sep], turn_off_re_match=True) 245 246 # <rdar://problem/11052829> 247 def test_infinite_loop_while_completing(self): 248 """Test that 'process print hello\' completes to itself and does not infinite loop.""" 249 self.complete_from_to('process print hello\\', 'process print hello\\', 250 turn_off_re_match=True) 251 252 def test_watchpoint_co(self): 253 """Test that 'watchpoint co' completes to 'watchpoint command '.""" 254 self.complete_from_to('watchpoint co', 'watchpoint command ') 255 256 def test_watchpoint_command_space(self): 257 """Test that 'watchpoint command ' completes to ['add', 'delete', 'list'].""" 258 self.complete_from_to( 259 'watchpoint command ', [ 260 'add', 'delete', 'list']) 261 262 def test_watchpoint_command_a(self): 263 """Test that 'watchpoint command a' completes to 'watchpoint command add '.""" 264 self.complete_from_to( 265 'watchpoint command a', 266 'watchpoint command add ') 267 268 def test_watchpoint_set_ex(self): 269 """Test that 'watchpoint set ex' completes to 'watchpoint set expression '.""" 270 self.complete_from_to( 271 'watchpoint set ex', 272 'watchpoint set expression ') 273 274 def test_watchpoint_set_var(self): 275 """Test that 'watchpoint set var' completes to 'watchpoint set variable '.""" 276 self.complete_from_to('watchpoint set var', 'watchpoint set variable ') 277 278 def test_watchpoint_set_variable_foo(self): 279 self.build() 280 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 281 self.complete_from_to('watchpoint set variable fo', 'watchpoint set variable fooo') 282 # Only complete the first argument. 283 self.complete_from_to('watchpoint set variable fooo ', 'watchpoint set variable fooo ') 284 285 def test_help_fi(self): 286 """Test that 'help fi' completes to ['file', 'finish'].""" 287 self.complete_from_to( 288 'help fi', [ 289 'file', 'finish']) 290 291 def test_help_watchpoint_s(self): 292 """Test that 'help watchpoint s' completes to 'help watchpoint set '.""" 293 self.complete_from_to('help watchpoint s', 'help watchpoint set ') 294 295 @expectedFailureNetBSD 296 def test_common_complete_watchpoint_ids(self): 297 subcommands = ['enable', 'disable', 'delete', 'modify', 'ignore'] 298 299 # Completion should not work without a target. 300 for subcommand in subcommands: 301 self.complete_from_to('watchpoint ' + subcommand + ' ', 302 'watchpoint ' + subcommand + ' ') 303 304 # Create a process to provide a target and enable watchpoint setting. 305 self.build() 306 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 307 308 self.runCmd('watchpoint set variable ptr_fooo') 309 for subcommand in subcommands: 310 self.complete_from_to('watchpoint ' + subcommand + ' ', ['1']) 311 312 def test_settings_append_target_er(self): 313 """Test that 'settings append target.er' completes to 'settings append target.error-path'.""" 314 self.complete_from_to( 315 'settings append target.er', 316 'settings append target.error-path') 317 318 def test_settings_insert_after_target_en(self): 319 """Test that 'settings insert-after target.env' completes to 'settings insert-after target.env-vars'.""" 320 self.complete_from_to( 321 'settings insert-after target.env', 322 'settings insert-after target.env-vars') 323 324 def test_settings_insert_before_target_en(self): 325 """Test that 'settings insert-before target.env' completes to 'settings insert-before target.env-vars'.""" 326 self.complete_from_to( 327 'settings insert-before target.env', 328 'settings insert-before target.env-vars') 329 330 def test_settings_replace_target_ru(self): 331 """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'.""" 332 self.complete_from_to( 333 'settings replace target.ru', 334 'settings replace target.run-args') 335 336 def test_settings_show_term(self): 337 self.complete_from_to( 338 'settings show term-', 339 'settings show term-width') 340 341 def test_settings_list_term(self): 342 self.complete_from_to( 343 'settings list term-', 344 'settings list term-width') 345 346 def test_settings_remove_term(self): 347 self.complete_from_to( 348 'settings remove term-', 349 'settings remove term-width') 350 351 def test_settings_s(self): 352 """Test that 'settings s' completes to ['set', 'show'].""" 353 self.complete_from_to( 354 'settings s', [ 355 'set', 'show']) 356 357 def test_settings_set_th(self): 358 """Test that 'settings set thread-f' completes to 'settings set thread-format'.""" 359 self.complete_from_to('settings set thread-f', 'settings set thread-format') 360 361 def test_settings_s_dash(self): 362 """Test that 'settings set --g' completes to 'settings set --global'.""" 363 self.complete_from_to('settings set --g', 'settings set --global') 364 365 def test_settings_clear_th(self): 366 """Test that 'settings clear thread-f' completes to 'settings clear thread-format'.""" 367 self.complete_from_to( 368 'settings clear thread-f', 369 'settings clear thread-format') 370 371 def test_settings_set_ta(self): 372 """Test that 'settings set ta' completes to 'settings set target.'.""" 373 self.complete_from_to( 374 'settings set target.ma', 375 'settings set target.max-') 376 377 def test_settings_set_target_exec(self): 378 """Test that 'settings set target.exec' completes to 'settings set target.exec-search-paths '.""" 379 self.complete_from_to( 380 'settings set target.exec', 381 'settings set target.exec-search-paths') 382 383 def test_settings_set_target_pr(self): 384 """Test that 'settings set target.pr' completes to [ 385 'target.prefer-dynamic-value', 'target.process.'].""" 386 self.complete_from_to('settings set target.pr', 387 ['target.prefer-dynamic-value', 388 'target.process.']) 389 390 def test_settings_set_target_process(self): 391 """Test that 'settings set target.process' completes to 'settings set target.process.'.""" 392 self.complete_from_to( 393 'settings set target.process', 394 'settings set target.process.') 395 396 def test_settings_set_target_process_dot(self): 397 """Test that 'settings set target.process.t' completes to 'settings set target.process.thread.'.""" 398 self.complete_from_to( 399 'settings set target.process.thr', 400 'settings set target.process.thread.') 401 402 def test_settings_set_target_process_thread_dot(self): 403 """Test that 'settings set target.process.thread.' completes to [ 404 'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread'].""" 405 self.complete_from_to('settings set target.process.thread.', 406 ['target.process.thread.step-avoid-regexp', 407 'target.process.thread.trace-thread']) 408 409 def test_thread_plan_discard(self): 410 self.build() 411 (_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, 412 'ptr_foo', lldb.SBFileSpec("main.cpp")) 413 self.assertTrue(thread) 414 self.complete_from_to('thread plan discard ', 'thread plan discard ') 415 416 source_path = os.path.join(self.getSourceDir(), "thread_plan_script.py") 417 self.runCmd("command script import '%s'"%(source_path)) 418 self.runCmd("thread step-scripted -C thread_plan_script.PushPlanStack") 419 self.complete_from_to('thread plan discard ', 'thread plan discard 1') 420 self.runCmd('thread plan discard 1') 421 422 def test_target_space(self): 423 """Test that 'target ' completes to ['create', 'delete', 'list', 424 'modules', 'select', 'stop-hook', 'variable'].""" 425 self.complete_from_to('target ', 426 ['create', 427 'delete', 428 'list', 429 'modules', 430 'select', 431 'stop-hook', 432 'variable']) 433 434 def test_target_modules_dump_line_table(self): 435 """Tests source file completion by completing the line-table argument.""" 436 self.build() 437 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 438 self.complete_from_to('target modules dump line-table main.cp', 439 ['main.cpp']) 440 441 def test_target_modules_load_aout(self): 442 """Tests modules completion by completing the target modules load argument.""" 443 self.build() 444 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 445 self.complete_from_to('target modules load a.ou', 446 ['a.out']) 447 448 def test_target_modules_search_paths_insert(self): 449 # Completion won't work without a valid target. 450 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 451 self.build() 452 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 453 self.assertTrue(target, VALID_TARGET) 454 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 455 self.runCmd("target modules search-paths add a b") 456 self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") 457 # Completion only works for the first arg. 458 self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") 459 460 def test_target_create_dash_co(self): 461 """Test that 'target create --co' completes to 'target variable --core '.""" 462 self.complete_from_to('target create --co', 'target create --core ') 463 464 def test_target_va(self): 465 """Test that 'target va' completes to 'target variable '.""" 466 self.complete_from_to('target va', 'target variable ') 467 468 def test_common_completion_thread_index(self): 469 subcommands = ['continue', 'info', 'exception', 'select', 470 'step-in', 'step-inst', 'step-inst-over', 'step-out', 'step-over', 'step-script'] 471 472 # Completion should do nothing without threads. 473 for subcommand in subcommands: 474 self.complete_from_to('thread ' + subcommand + ' ', 475 'thread ' + subcommand + ' ') 476 477 self.build() 478 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 479 480 # At least we have the thread at the index of 1 now. 481 for subcommand in subcommands: 482 self.complete_from_to('thread ' + subcommand + ' ', ['1']) 483 484 def test_common_completion_type_category_name(self): 485 subcommands = ['delete', 'list', 'enable', 'disable', 'define'] 486 for subcommand in subcommands: 487 self.complete_from_to('type category ' + subcommand + ' ', ['default']) 488 self.complete_from_to('type filter add -w ', ['default']) 489 490 def test_command_argument_completion(self): 491 """Test completion of command arguments""" 492 self.complete_from_to("watchpoint set variable -", ["-w", "-s"]) 493 self.complete_from_to('watchpoint set variable -w', 'watchpoint set variable -w ') 494 self.complete_from_to("watchpoint set variable --", ["--watch", "--size"]) 495 self.complete_from_to("watchpoint set variable --w", "watchpoint set variable --watch") 496 self.complete_from_to('watchpoint set variable -w ', ['read', 'write', 'read_write']) 497 self.complete_from_to("watchpoint set variable --watch ", ["read", "write", "read_write"]) 498 self.complete_from_to("watchpoint set variable --watch w", "watchpoint set variable --watch write") 499 self.complete_from_to('watchpoint set variable -w read_', 'watchpoint set variable -w read_write') 500 # Now try the same thing with a variable name (non-option argument) to 501 # test that getopts arg reshuffling doesn't confuse us. 502 self.complete_from_to("watchpoint set variable foo -", ["-w", "-s"]) 503 self.complete_from_to('watchpoint set variable foo -w', 'watchpoint set variable foo -w ') 504 self.complete_from_to("watchpoint set variable foo --", ["--watch", "--size"]) 505 self.complete_from_to("watchpoint set variable foo --w", "watchpoint set variable foo --watch") 506 self.complete_from_to('watchpoint set variable foo -w ', ['read', 'write', 'read_write']) 507 self.complete_from_to("watchpoint set variable foo --watch ", ["read", "write", "read_write"]) 508 self.complete_from_to("watchpoint set variable foo --watch w", "watchpoint set variable foo --watch write") 509 self.complete_from_to('watchpoint set variable foo -w read_', 'watchpoint set variable foo -w read_write') 510 511 def test_command_script_delete(self): 512 self.runCmd("command script add -h test_desc -f none -s current usercmd1") 513 self.check_completion_with_desc('command script delete ', [['usercmd1', '']]) 514 515 def test_command_delete(self): 516 self.runCmd(r"command regex test_command s/^$/finish/ 's/([0-9]+)/frame select %1/'") 517 self.complete_from_to('command delete test_c', 'command delete test_command') 518 519 def test_command_unalias(self): 520 self.complete_from_to('command unalias ima', 'command unalias image') 521 522 def test_completion_description_commands(self): 523 """Test descriptions of top-level command completions""" 524 self.check_completion_with_desc("", [ 525 ["command", "Commands for managing custom LLDB commands."], 526 ["breakpoint", "Commands for operating on breakpoints (see 'help b' for shorthand.)"] 527 ]) 528 529 self.check_completion_with_desc("pl", [ 530 ["platform", "Commands to manage and create platforms."], 531 ["plugin", "Commands for managing LLDB plugins."] 532 ]) 533 534 # Just check that this doesn't crash. 535 self.check_completion_with_desc("comman", []) 536 self.check_completion_with_desc("non-existent-command", []) 537 538 def test_completion_description_command_options(self): 539 """Test descriptions of command options""" 540 # Short options 541 self.check_completion_with_desc("breakpoint set -", [ 542 ["-h", "Set the breakpoint on exception catcH."], 543 ["-w", "Set the breakpoint on exception throW."] 544 ]) 545 546 # Long options. 547 self.check_completion_with_desc("breakpoint set --", [ 548 ["--on-catch", "Set the breakpoint on exception catcH."], 549 ["--on-throw", "Set the breakpoint on exception throW."] 550 ]) 551 552 # Ambiguous long options. 553 self.check_completion_with_desc("breakpoint set --on-", [ 554 ["--on-catch", "Set the breakpoint on exception catcH."], 555 ["--on-throw", "Set the breakpoint on exception throW."] 556 ]) 557 558 # Unknown long option. 559 self.check_completion_with_desc("breakpoint set --Z", [ 560 ]) 561 562 def test_common_completion_frame_index(self): 563 self.build() 564 lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 565 566 self.complete_from_to('frame select ', ['0']) 567 self.complete_from_to('thread backtrace -s ', ['0']) 568 569 def test_frame_recognizer_delete(self): 570 self.runCmd("frame recognizer add -l py_class -s module_name -n recognizer_name") 571 self.check_completion_with_desc('frame recognizer delete ', [['0', 'py_class, module module_name, symbol recognizer_name']]) 572 573 def test_platform_install_local_file(self): 574 self.complete_from_to('platform target-install main.cp', 'platform target-install main.cpp') 575 576 @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") 577 def test_symbol_name(self): 578 self.build() 579 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 580 self.complete_from_to('breakpoint set -n Fo', 581 'breakpoint set -n Foo::Bar(int,\\ int)', 582 turn_off_re_match=True) 583 # No completion for Qu because the candidate is 584 # (anonymous namespace)::Quux(). 585 self.complete_from_to('breakpoint set -n Qu', '') 586 587 def test_completion_type_formatter_delete(self): 588 self.runCmd('type filter add --child a Aoo') 589 self.complete_from_to('type filter delete ', ['Aoo']) 590 self.runCmd('type filter add --child b -x Boo') 591 self.complete_from_to('type filter delete ', ['Boo']) 592 593 self.runCmd('type format add -f hex Coo') 594 self.complete_from_to('type format delete ', ['Coo']) 595 self.runCmd('type format add -f hex -x Doo') 596 self.complete_from_to('type format delete ', ['Doo']) 597 598 self.runCmd('type summary add -c Eoo') 599 self.complete_from_to('type summary delete ', ['Eoo']) 600 self.runCmd('type summary add -x -c Foo') 601 self.complete_from_to('type summary delete ', ['Foo']) 602 603 self.runCmd('type synthetic add Goo -l test') 604 self.complete_from_to('type synthetic delete ', ['Goo']) 605 self.runCmd('type synthetic add -x Hoo -l test') 606 self.complete_from_to('type synthetic delete ', ['Hoo']) 607 608 @skipIf(archs=no_match(['x86_64'])) 609 def test_register_read_and_write_on_x86(self): 610 """Test the completion of the commands register read and write on x86""" 611 612 # The tab completion for "register read/write" won't work without a running process. 613 self.complete_from_to('register read ', 614 'register read ') 615 self.complete_from_to('register write ', 616 'register write ') 617 618 self.build() 619 self.main_source_spec = lldb.SBFileSpec("main.cpp") 620 lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) 621 622 # test cases for register read 623 self.complete_from_to('register read ', 624 ['rax', 625 'rbx', 626 'rcx']) 627 self.complete_from_to('register read r', 628 ['rax', 629 'rbx', 630 'rcx']) 631 self.complete_from_to('register read ra', 632 'register read rax') 633 # register read can take multiple register names as arguments 634 self.complete_from_to('register read rax ', 635 ['rax', 636 'rbx', 637 'rcx']) 638 # complete with prefix '$' 639 self.completions_match('register read $rb', 640 ['$rbx', 641 '$rbp']) 642 self.completions_match('register read $ra', 643 ['$rax']) 644 self.complete_from_to('register read rax $', 645 ['\$rax', 646 '\$rbx', 647 '\$rcx']) 648 self.complete_from_to('register read $rax ', 649 ['rax', 650 'rbx', 651 'rcx']) 652 653 # test cases for register write 654 self.complete_from_to('register write ', 655 ['rax', 656 'rbx', 657 'rcx']) 658 self.complete_from_to('register write r', 659 ['rax', 660 'rbx', 661 'rcx']) 662 self.complete_from_to('register write ra', 663 'register write rax') 664 self.complete_from_to('register write rb', 665 ['rbx', 666 'rbp']) 667 # register write can only take exact one register name as argument 668 self.complete_from_to('register write rbx ', 669 []) 670 671 def test_common_completion_target_stophook_ids(self): 672 subcommands = ['delete', 'enable', 'disable'] 673 674 for subcommand in subcommands: 675 self.complete_from_to('target stop-hook ' + subcommand + ' ', 676 'target stop-hook ' + subcommand + ' ') 677 678 self.build() 679 self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 680 self.runCmd('target stop-hook add test DONE') 681 682 for subcommand in subcommands: 683 self.complete_from_to('target stop-hook ' + subcommand + ' ', 684 'target stop-hook ' + subcommand + ' 1') 685 686 # Completion should work only on the first argument. 687 for subcommand in subcommands: 688 self.complete_from_to('target stop-hook ' + subcommand + ' 1 ', 689 'target stop-hook ' + subcommand + ' 1 ') 690 691 def test_common_completion_type_language(self): 692 self.complete_from_to('type category -l ', ['c']) 693 694 def test_target_modules_load_dash_u(self): 695 self.build() 696 target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 697 self.complete_from_to('target modules load -u ', [target.GetModuleAtIndex(0).GetUUIDString()]) 698 699 def test_complete_breakpoint_with_ids(self): 700 """These breakpoint subcommands should be completed with a list of breakpoint ids""" 701 702 subcommands = ['enable', 'disable', 'delete', 'modify', 'name add', 'name delete', 'write'] 703 704 # The tab completion here is unavailable without a target 705 for subcommand in subcommands: 706 self.complete_from_to('breakpoint ' + subcommand + ' ', 707 'breakpoint ' + subcommand + ' ') 708 709 self.build() 710 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 711 self.assertTrue(target, VALID_TARGET) 712 713 bp = target.BreakpointCreateByName('main', 'a.out') 714 self.assertTrue(bp) 715 self.assertEqual(bp.GetNumLocations(), 1) 716 717 for subcommand in subcommands: 718 self.complete_from_to('breakpoint ' + subcommand + ' ', 719 ['1']) 720 721 bp2 = target.BreakpointCreateByName('Bar', 'a.out') 722 self.assertTrue(bp2) 723 self.assertEqual(bp2.GetNumLocations(), 1) 724 725 for subcommand in subcommands: 726 self.complete_from_to('breakpoint ' + subcommand + ' ', 727 ['1', 728 '2']) 729 730 for subcommand in subcommands: 731 self.complete_from_to('breakpoint ' + subcommand + ' 1 ', 732 ['1', 733 '2']) 734 735 def test_complete_breakpoint_with_names(self): 736 self.build() 737 target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 738 self.assertTrue(target, VALID_TARGET) 739 740 # test breakpoint read dedicated 741 self.complete_from_to('breakpoint read -N ', 'breakpoint read -N ') 742 self.complete_from_to('breakpoint read -f breakpoints.json -N ', ['mm']) 743 self.complete_from_to('breakpoint read -f breakpoints.json -N n', 'breakpoint read -f breakpoints.json -N n') 744 self.complete_from_to('breakpoint read -f breakpoints_invalid.json -N ', 'breakpoint read -f breakpoints_invalid.json -N ') 745 746 # test common breapoint name completion 747 bp1 = target.BreakpointCreateByName('main', 'a.out') 748 self.assertTrue(bp1) 749 self.assertEqual(bp1.GetNumLocations(), 1) 750 self.complete_from_to('breakpoint set -N n', 'breakpoint set -N n') 751 self.assertTrue(bp1.AddNameWithErrorHandling("nn")) 752 self.complete_from_to('breakpoint set -N ', 'breakpoint set -N nn') 753