199451b44SJordan Rupprecht""" 299451b44SJordan RupprechtTest the lldb command line completion mechanism. 399451b44SJordan Rupprecht""" 499451b44SJordan Rupprecht 599451b44SJordan Rupprecht 699451b44SJordan Rupprecht 799451b44SJordan Rupprechtimport os 819311f5cSGongyu Dengfrom multiprocessing import Process 999451b44SJordan Rupprechtimport lldb 1099451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 1199451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 1299451b44SJordan Rupprechtfrom lldbsuite.test import lldbplatform 1399451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 1499451b44SJordan Rupprecht 1599451b44SJordan Rupprecht 1699451b44SJordan Rupprechtclass CommandLineCompletionTestCase(TestBase): 1799451b44SJordan Rupprecht 1899451b44SJordan Rupprecht NO_DEBUG_INFO_TESTCASE = True 1999451b44SJordan Rupprecht 2099451b44SJordan Rupprecht @classmethod 2199451b44SJordan Rupprecht def classCleanup(cls): 2299451b44SJordan Rupprecht """Cleanup the test byproducts.""" 2399451b44SJordan Rupprecht try: 2499451b44SJordan Rupprecht os.remove("child_send.txt") 2599451b44SJordan Rupprecht os.remove("child_read.txt") 2699451b44SJordan Rupprecht except: 2799451b44SJordan Rupprecht pass 2899451b44SJordan Rupprecht 2999451b44SJordan Rupprecht def test_at(self): 3099451b44SJordan Rupprecht """Test that 'at' completes to 'attach '.""" 3199451b44SJordan Rupprecht self.complete_from_to('at', 'attach ') 3299451b44SJordan Rupprecht 3399451b44SJordan Rupprecht def test_de(self): 3499451b44SJordan Rupprecht """Test that 'de' completes to 'detach '.""" 3599451b44SJordan Rupprecht self.complete_from_to('de', 'detach ') 3699451b44SJordan Rupprecht 3799451b44SJordan Rupprecht def test_frame_variable(self): 3899451b44SJordan Rupprecht self.build() 3999451b44SJordan Rupprecht self.main_source = "main.cpp" 4099451b44SJordan Rupprecht self.main_source_spec = lldb.SBFileSpec(self.main_source) 4199451b44SJordan Rupprecht 4299451b44SJordan Rupprecht (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 4399451b44SJordan Rupprecht '// Break here', self.main_source_spec) 44ce825e46SJonas Devlieghere self.assertState(process.GetState(), lldb.eStateStopped) 45ec31255cSGongyu Deng 46ec31255cSGongyu Deng # Since CommandInterpreter has been corrected to update the current execution 47ec31255cSGongyu Deng # context at the beginning of HandleCompletion, we're here explicitly testing 48ec31255cSGongyu Deng # the scenario where "frame var" is completed without any preceding commands. 4999451b44SJordan Rupprecht 5099451b44SJordan Rupprecht self.complete_from_to('frame variable fo', 5199451b44SJordan Rupprecht 'frame variable fooo') 5299451b44SJordan Rupprecht self.complete_from_to('frame variable fooo.', 5399451b44SJordan Rupprecht 'frame variable fooo.') 5499451b44SJordan Rupprecht self.complete_from_to('frame variable fooo.dd', 5599451b44SJordan Rupprecht 'frame variable fooo.dd') 5699451b44SJordan Rupprecht 5799451b44SJordan Rupprecht self.complete_from_to('frame variable ptr_fooo->', 5899451b44SJordan Rupprecht 'frame variable ptr_fooo->') 5999451b44SJordan Rupprecht self.complete_from_to('frame variable ptr_fooo->dd', 6099451b44SJordan Rupprecht 'frame variable ptr_fooo->dd') 6199451b44SJordan Rupprecht 6299451b44SJordan Rupprecht self.complete_from_to('frame variable cont', 6399451b44SJordan Rupprecht 'frame variable container') 6499451b44SJordan Rupprecht self.complete_from_to('frame variable container.', 6599451b44SJordan Rupprecht 'frame variable container.MemberVar') 6699451b44SJordan Rupprecht self.complete_from_to('frame variable container.Mem', 6799451b44SJordan Rupprecht 'frame variable container.MemberVar') 6899451b44SJordan Rupprecht 6999451b44SJordan Rupprecht self.complete_from_to('frame variable ptr_cont', 7099451b44SJordan Rupprecht 'frame variable ptr_container') 7199451b44SJordan Rupprecht self.complete_from_to('frame variable ptr_container->', 7299451b44SJordan Rupprecht 'frame variable ptr_container->MemberVar') 7399451b44SJordan Rupprecht self.complete_from_to('frame variable ptr_container->Mem', 7499451b44SJordan Rupprecht 'frame variable ptr_container->MemberVar') 7599451b44SJordan Rupprecht 7699451b44SJordan Rupprecht def test_process_attach_dash_dash_con(self): 7799451b44SJordan Rupprecht """Test that 'process attach --con' completes to 'process attach --continue '.""" 7899451b44SJordan Rupprecht self.complete_from_to( 7999451b44SJordan Rupprecht 'process attach --con', 8099451b44SJordan Rupprecht 'process attach --continue ') 8199451b44SJordan Rupprecht 8299451b44SJordan Rupprecht def test_process_launch_arch(self): 8399451b44SJordan Rupprecht self.complete_from_to('process launch --arch ', 8499451b44SJordan Rupprecht ['mips', 8599451b44SJordan Rupprecht 'arm64']) 8699451b44SJordan Rupprecht 87e1cd7cacSGongyu Deng def test_process_load(self): 88e1cd7cacSGongyu Deng self.build() 89e1cd7cacSGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 90e1cd7cacSGongyu Deng self.complete_from_to('process load Makef', 'process load Makefile') 91e1cd7cacSGongyu Deng 92e1cd7cacSGongyu Deng @skipUnlessPlatform(["linux"]) 93e1cd7cacSGongyu Deng def test_process_unload(self): 94e1cd7cacSGongyu Deng """Test the completion for "process unload <index>" """ 95e1cd7cacSGongyu Deng # This tab completion should not work without a running process. 96e1cd7cacSGongyu Deng self.complete_from_to('process unload ', 97e1cd7cacSGongyu Deng 'process unload ') 98e1cd7cacSGongyu Deng 99e1cd7cacSGongyu Deng self.build() 100e1cd7cacSGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 101e1cd7cacSGongyu Deng err = lldb.SBError() 102e1cd7cacSGongyu Deng self.process().LoadImage(lldb.SBFileSpec(self.getBuildArtifact("libshared.so")), err) 103e1cd7cacSGongyu Deng self.assertSuccess(err) 104e1cd7cacSGongyu Deng 105e1cd7cacSGongyu Deng self.complete_from_to('process unload ', 106e1cd7cacSGongyu Deng 'process unload 0') 107e1cd7cacSGongyu Deng 108e1cd7cacSGongyu Deng self.process().UnloadImage(0) 109e1cd7cacSGongyu Deng self.complete_from_to('process unload ', 110e1cd7cacSGongyu Deng 'process unload ') 111e1cd7cacSGongyu Deng 112763bc230SGongyu Deng def test_process_plugin_completion(self): 113763bc230SGongyu Deng subcommands = ['attach -P', 'connect -p', 'launch -p'] 114763bc230SGongyu Deng 115763bc230SGongyu Deng for subcommand in subcommands: 116763bc230SGongyu Deng self.complete_from_to('process ' + subcommand + ' mac', 117763bc230SGongyu Deng 'process ' + subcommand + ' mach-o-core') 118763bc230SGongyu Deng 1192501e911SRaphael Isemann def completions_contain_str(self, input, needle): 1202501e911SRaphael Isemann interp = self.dbg.GetCommandInterpreter() 1212501e911SRaphael Isemann match_strings = lldb.SBStringList() 1222501e911SRaphael Isemann num_matches = interp.HandleCompletion(input, len(input), 0, -1, match_strings) 1232501e911SRaphael Isemann found_needle = False 1242501e911SRaphael Isemann for match in match_strings: 1252501e911SRaphael Isemann if needle in match: 1262501e911SRaphael Isemann found_needle = True 1272501e911SRaphael Isemann break 1282501e911SRaphael Isemann self.assertTrue(found_needle, "Returned completions: " + "\n".join(match_strings)) 1292501e911SRaphael Isemann 1302501e911SRaphael Isemann 13119311f5cSGongyu Deng @skipIfRemote 13219311f5cSGongyu Deng def test_common_completion_process_pid_and_name(self): 13319311f5cSGongyu Deng # The LLDB process itself and the process already attached to are both 13419311f5cSGongyu Deng # ignored by the process discovery mechanism, thus we need a process known 13519311f5cSGongyu Deng # to us here. 13619311f5cSGongyu Deng self.build() 13719311f5cSGongyu Deng server = self.spawnSubprocess( 13819311f5cSGongyu Deng self.getBuildArtifact("a.out"), 13919311f5cSGongyu Deng ["-x"], # Arg "-x" makes the subprocess wait for input thus it won't be terminated too early 14019311f5cSGongyu Deng install_remote=False) 14119311f5cSGongyu Deng self.assertIsNotNone(server) 14219311f5cSGongyu Deng pid = server.pid 14319311f5cSGongyu Deng 144b51321ccSRaphael Isemann self.completions_contain('process attach -p ', [str(pid)]) 145b51321ccSRaphael Isemann self.completions_contain('platform process attach -p ', [str(pid)]) 146b51321ccSRaphael Isemann self.completions_contain('platform process info ', [str(pid)]) 14719311f5cSGongyu Deng 1482501e911SRaphael Isemann self.completions_contain_str('process attach -n ', "a.out") 1492501e911SRaphael Isemann self.completions_contain_str('platform process attach -n ', "a.out") 15019311f5cSGongyu Deng 1512bba1c22SRaphael Isemann def test_process_signal(self): 1522bba1c22SRaphael Isemann # The tab completion for "process signal" won't work without a running process. 1532bba1c22SRaphael Isemann self.complete_from_to('process signal ', 1542bba1c22SRaphael Isemann 'process signal ') 1552bba1c22SRaphael Isemann 1562bba1c22SRaphael Isemann # Test with a running process. 1572bba1c22SRaphael Isemann self.build() 1582bba1c22SRaphael Isemann self.main_source = "main.cpp" 1592bba1c22SRaphael Isemann self.main_source_spec = lldb.SBFileSpec(self.main_source) 1602bba1c22SRaphael Isemann lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) 1612bba1c22SRaphael Isemann 1622bba1c22SRaphael Isemann self.complete_from_to('process signal ', 1632bba1c22SRaphael Isemann 'process signal SIG') 164eb61ffbcSRaphael Isemann self.complete_from_to('process signal SIGPIP', 165eb61ffbcSRaphael Isemann 'process signal SIGPIPE') 1662bba1c22SRaphael Isemann self.complete_from_to('process signal SIGA', 1672bba1c22SRaphael Isemann ['SIGABRT', 1682bba1c22SRaphael Isemann 'SIGALRM']) 1692bba1c22SRaphael Isemann 17099451b44SJordan Rupprecht def test_ambiguous_long_opt(self): 17199451b44SJordan Rupprecht self.completions_match('breakpoint modify --th', 17299451b44SJordan Rupprecht ['--thread-id', 17399451b44SJordan Rupprecht '--thread-index', 17499451b44SJordan Rupprecht '--thread-name']) 17599451b44SJordan Rupprecht 1768a5e2969SGongyu Deng def test_disassemble_dash_f(self): 1778a5e2969SGongyu Deng self.completions_match('disassemble -F ', 1788a5e2969SGongyu Deng ['default', 1798a5e2969SGongyu Deng 'intel', 1808a5e2969SGongyu Deng 'att']) 1818a5e2969SGongyu Deng 18299451b44SJordan Rupprecht def test_plugin_load(self): 18399451b44SJordan Rupprecht self.complete_from_to('plugin load ', []) 18499451b44SJordan Rupprecht 18599451b44SJordan Rupprecht def test_log_enable(self): 18699451b44SJordan Rupprecht self.complete_from_to('log enable ll', ['lldb']) 18799451b44SJordan Rupprecht self.complete_from_to('log enable dw', ['dwarf']) 18899451b44SJordan Rupprecht self.complete_from_to('log enable lldb al', ['all']) 18999451b44SJordan Rupprecht self.complete_from_to('log enable lldb sym', ['symbol']) 19099451b44SJordan Rupprecht 19199451b44SJordan Rupprecht def test_log_enable(self): 19299451b44SJordan Rupprecht self.complete_from_to('log disable ll', ['lldb']) 19399451b44SJordan Rupprecht self.complete_from_to('log disable dw', ['dwarf']) 19499451b44SJordan Rupprecht self.complete_from_to('log disable lldb al', ['all']) 19599451b44SJordan Rupprecht self.complete_from_to('log disable lldb sym', ['symbol']) 19699451b44SJordan Rupprecht 19799451b44SJordan Rupprecht def test_log_list(self): 19899451b44SJordan Rupprecht self.complete_from_to('log list ll', ['lldb']) 19999451b44SJordan Rupprecht self.complete_from_to('log list dw', ['dwarf']) 20099451b44SJordan Rupprecht self.complete_from_to('log list ll', ['lldb']) 20199451b44SJordan Rupprecht self.complete_from_to('log list lldb dwa', ['dwarf']) 20299451b44SJordan Rupprecht 20399451b44SJordan Rupprecht def test_quoted_command(self): 20499451b44SJordan Rupprecht self.complete_from_to('"set', 20599451b44SJordan Rupprecht ['"settings" ']) 20699451b44SJordan Rupprecht 20799451b44SJordan Rupprecht def test_quoted_arg_with_quoted_command(self): 20899451b44SJordan Rupprecht self.complete_from_to('"settings" "repl', 20999451b44SJordan Rupprecht ['"replace" ']) 21099451b44SJordan Rupprecht 21199451b44SJordan Rupprecht def test_quoted_arg_without_quoted_command(self): 21299451b44SJordan Rupprecht self.complete_from_to('settings "repl', 21399451b44SJordan Rupprecht ['"replace" ']) 21499451b44SJordan Rupprecht 21599451b44SJordan Rupprecht def test_single_quote_command(self): 21699451b44SJordan Rupprecht self.complete_from_to("'set", 21799451b44SJordan Rupprecht ["'settings' "]) 21899451b44SJordan Rupprecht 21999451b44SJordan Rupprecht def test_terminated_quote_command(self): 22099451b44SJordan Rupprecht # This should not crash, but we don't get any 22199451b44SJordan Rupprecht # reasonable completions from this. 22299451b44SJordan Rupprecht self.complete_from_to("'settings'", []) 22399451b44SJordan Rupprecht 22499451b44SJordan Rupprecht def test_process_launch_arch_arm(self): 22599451b44SJordan Rupprecht self.complete_from_to('process launch --arch arm', 22699451b44SJordan Rupprecht ['arm64']) 22799451b44SJordan Rupprecht 22899451b44SJordan Rupprecht def test_target_symbols_add_shlib(self): 22999451b44SJordan Rupprecht # Doesn't seem to work, but at least it shouldn't crash. 23099451b44SJordan Rupprecht self.complete_from_to('target symbols add --shlib ', []) 23199451b44SJordan Rupprecht 23299451b44SJordan Rupprecht def test_log_file(self): 23399451b44SJordan Rupprecht # Complete in our source directory which contains a 'main.cpp' file. 234633ac517SPavel Labath src_dir = self.getSourceDir() + '/' 23599451b44SJordan Rupprecht self.complete_from_to('log enable lldb expr -f ' + src_dir, 23699451b44SJordan Rupprecht ['main.cpp']) 23799451b44SJordan Rupprecht 23899451b44SJordan Rupprecht def test_log_dir(self): 23999451b44SJordan Rupprecht # Complete our source directory. 24099451b44SJordan Rupprecht src_dir = os.path.dirname(os.path.realpath(__file__)) 24199451b44SJordan Rupprecht self.complete_from_to('log enable lldb expr -f ' + src_dir, 24299451b44SJordan Rupprecht [src_dir + os.sep], turn_off_re_match=True) 24399451b44SJordan Rupprecht 24499451b44SJordan Rupprecht # <rdar://problem/11052829> 24599451b44SJordan Rupprecht def test_infinite_loop_while_completing(self): 24699451b44SJordan Rupprecht """Test that 'process print hello\' completes to itself and does not infinite loop.""" 24799451b44SJordan Rupprecht self.complete_from_to('process print hello\\', 'process print hello\\', 24899451b44SJordan Rupprecht turn_off_re_match=True) 24999451b44SJordan Rupprecht 25099451b44SJordan Rupprecht def test_watchpoint_co(self): 25199451b44SJordan Rupprecht """Test that 'watchpoint co' completes to 'watchpoint command '.""" 25299451b44SJordan Rupprecht self.complete_from_to('watchpoint co', 'watchpoint command ') 25399451b44SJordan Rupprecht 25499451b44SJordan Rupprecht def test_watchpoint_command_space(self): 25599451b44SJordan Rupprecht """Test that 'watchpoint command ' completes to ['add', 'delete', 'list'].""" 25699451b44SJordan Rupprecht self.complete_from_to( 25799451b44SJordan Rupprecht 'watchpoint command ', [ 25899451b44SJordan Rupprecht 'add', 'delete', 'list']) 25999451b44SJordan Rupprecht 26099451b44SJordan Rupprecht def test_watchpoint_command_a(self): 26199451b44SJordan Rupprecht """Test that 'watchpoint command a' completes to 'watchpoint command add '.""" 26299451b44SJordan Rupprecht self.complete_from_to( 26399451b44SJordan Rupprecht 'watchpoint command a', 26499451b44SJordan Rupprecht 'watchpoint command add ') 26599451b44SJordan Rupprecht 26699451b44SJordan Rupprecht def test_watchpoint_set_ex(self): 26799451b44SJordan Rupprecht """Test that 'watchpoint set ex' completes to 'watchpoint set expression '.""" 26899451b44SJordan Rupprecht self.complete_from_to( 26999451b44SJordan Rupprecht 'watchpoint set ex', 27099451b44SJordan Rupprecht 'watchpoint set expression ') 27199451b44SJordan Rupprecht 27299451b44SJordan Rupprecht def test_watchpoint_set_var(self): 27399451b44SJordan Rupprecht """Test that 'watchpoint set var' completes to 'watchpoint set variable '.""" 27499451b44SJordan Rupprecht self.complete_from_to('watchpoint set var', 'watchpoint set variable ') 27599451b44SJordan Rupprecht 2762e653327SGongyu Deng def test_watchpoint_set_variable_foo(self): 2772e653327SGongyu Deng self.build() 2782e653327SGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 2792e653327SGongyu Deng self.complete_from_to('watchpoint set variable fo', 'watchpoint set variable fooo') 2802e653327SGongyu Deng # Only complete the first argument. 2812e653327SGongyu Deng self.complete_from_to('watchpoint set variable fooo ', 'watchpoint set variable fooo ') 2822e653327SGongyu Deng 28399451b44SJordan Rupprecht def test_help_fi(self): 28499451b44SJordan Rupprecht """Test that 'help fi' completes to ['file', 'finish'].""" 28599451b44SJordan Rupprecht self.complete_from_to( 28699451b44SJordan Rupprecht 'help fi', [ 28799451b44SJordan Rupprecht 'file', 'finish']) 28899451b44SJordan Rupprecht 28999451b44SJordan Rupprecht def test_help_watchpoint_s(self): 29099451b44SJordan Rupprecht """Test that 'help watchpoint s' completes to 'help watchpoint set '.""" 29199451b44SJordan Rupprecht self.complete_from_to('help watchpoint s', 'help watchpoint set ') 29299451b44SJordan Rupprecht 29399562332SMichał Górny @expectedFailureNetBSD 294*7b69843fSMuhammad Omair Javaid @add_test_categories(["watchpoint"]) 2954f3559dbSGongyu Deng def test_common_complete_watchpoint_ids(self): 2964f3559dbSGongyu Deng subcommands = ['enable', 'disable', 'delete', 'modify', 'ignore'] 2974f3559dbSGongyu Deng 2984f3559dbSGongyu Deng # Completion should not work without a target. 2994f3559dbSGongyu Deng for subcommand in subcommands: 3004f3559dbSGongyu Deng self.complete_from_to('watchpoint ' + subcommand + ' ', 3014f3559dbSGongyu Deng 'watchpoint ' + subcommand + ' ') 3024f3559dbSGongyu Deng 3034f3559dbSGongyu Deng # Create a process to provide a target and enable watchpoint setting. 3044f3559dbSGongyu Deng self.build() 3054f3559dbSGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 3064f3559dbSGongyu Deng 3074f3559dbSGongyu Deng self.runCmd('watchpoint set variable ptr_fooo') 3084f3559dbSGongyu Deng for subcommand in subcommands: 3094f3559dbSGongyu Deng self.complete_from_to('watchpoint ' + subcommand + ' ', ['1']) 3104f3559dbSGongyu Deng 31199451b44SJordan Rupprecht def test_settings_append_target_er(self): 31299451b44SJordan Rupprecht """Test that 'settings append target.er' completes to 'settings append target.error-path'.""" 31399451b44SJordan Rupprecht self.complete_from_to( 31499451b44SJordan Rupprecht 'settings append target.er', 31599451b44SJordan Rupprecht 'settings append target.error-path') 31699451b44SJordan Rupprecht 31799451b44SJordan Rupprecht def test_settings_insert_after_target_en(self): 31899451b44SJordan Rupprecht """Test that 'settings insert-after target.env' completes to 'settings insert-after target.env-vars'.""" 31999451b44SJordan Rupprecht self.complete_from_to( 32099451b44SJordan Rupprecht 'settings insert-after target.env', 32199451b44SJordan Rupprecht 'settings insert-after target.env-vars') 32299451b44SJordan Rupprecht 32399451b44SJordan Rupprecht def test_settings_insert_before_target_en(self): 32499451b44SJordan Rupprecht """Test that 'settings insert-before target.env' completes to 'settings insert-before target.env-vars'.""" 32599451b44SJordan Rupprecht self.complete_from_to( 32699451b44SJordan Rupprecht 'settings insert-before target.env', 32799451b44SJordan Rupprecht 'settings insert-before target.env-vars') 32899451b44SJordan Rupprecht 32999451b44SJordan Rupprecht def test_settings_replace_target_ru(self): 33099451b44SJordan Rupprecht """Test that 'settings replace target.ru' completes to 'settings replace target.run-args'.""" 33199451b44SJordan Rupprecht self.complete_from_to( 33299451b44SJordan Rupprecht 'settings replace target.ru', 33399451b44SJordan Rupprecht 'settings replace target.run-args') 33499451b44SJordan Rupprecht 33599451b44SJordan Rupprecht def test_settings_show_term(self): 33699451b44SJordan Rupprecht self.complete_from_to( 33799451b44SJordan Rupprecht 'settings show term-', 33899451b44SJordan Rupprecht 'settings show term-width') 33999451b44SJordan Rupprecht 34099451b44SJordan Rupprecht def test_settings_list_term(self): 34199451b44SJordan Rupprecht self.complete_from_to( 34299451b44SJordan Rupprecht 'settings list term-', 34399451b44SJordan Rupprecht 'settings list term-width') 34499451b44SJordan Rupprecht 34599451b44SJordan Rupprecht def test_settings_remove_term(self): 34699451b44SJordan Rupprecht self.complete_from_to( 34799451b44SJordan Rupprecht 'settings remove term-', 34899451b44SJordan Rupprecht 'settings remove term-width') 34999451b44SJordan Rupprecht 35099451b44SJordan Rupprecht def test_settings_s(self): 35199451b44SJordan Rupprecht """Test that 'settings s' completes to ['set', 'show'].""" 35299451b44SJordan Rupprecht self.complete_from_to( 35399451b44SJordan Rupprecht 'settings s', [ 35499451b44SJordan Rupprecht 'set', 'show']) 35599451b44SJordan Rupprecht 35699451b44SJordan Rupprecht def test_settings_set_th(self): 35799451b44SJordan Rupprecht """Test that 'settings set thread-f' completes to 'settings set thread-format'.""" 35899451b44SJordan Rupprecht self.complete_from_to('settings set thread-f', 'settings set thread-format') 35999451b44SJordan Rupprecht 36099451b44SJordan Rupprecht def test_settings_s_dash(self): 36199451b44SJordan Rupprecht """Test that 'settings set --g' completes to 'settings set --global'.""" 36299451b44SJordan Rupprecht self.complete_from_to('settings set --g', 'settings set --global') 36399451b44SJordan Rupprecht 36499451b44SJordan Rupprecht def test_settings_clear_th(self): 36599451b44SJordan Rupprecht """Test that 'settings clear thread-f' completes to 'settings clear thread-format'.""" 36699451b44SJordan Rupprecht self.complete_from_to( 36799451b44SJordan Rupprecht 'settings clear thread-f', 36899451b44SJordan Rupprecht 'settings clear thread-format') 36999451b44SJordan Rupprecht 37099451b44SJordan Rupprecht def test_settings_set_ta(self): 37199451b44SJordan Rupprecht """Test that 'settings set ta' completes to 'settings set target.'.""" 37299451b44SJordan Rupprecht self.complete_from_to( 37399451b44SJordan Rupprecht 'settings set target.ma', 37499451b44SJordan Rupprecht 'settings set target.max-') 37599451b44SJordan Rupprecht 37699451b44SJordan Rupprecht def test_settings_set_target_exec(self): 37799451b44SJordan Rupprecht """Test that 'settings set target.exec' completes to 'settings set target.exec-search-paths '.""" 37899451b44SJordan Rupprecht self.complete_from_to( 37999451b44SJordan Rupprecht 'settings set target.exec', 38099451b44SJordan Rupprecht 'settings set target.exec-search-paths') 38199451b44SJordan Rupprecht 38299451b44SJordan Rupprecht def test_settings_set_target_pr(self): 38399451b44SJordan Rupprecht """Test that 'settings set target.pr' completes to [ 38499451b44SJordan Rupprecht 'target.prefer-dynamic-value', 'target.process.'].""" 38599451b44SJordan Rupprecht self.complete_from_to('settings set target.pr', 38699451b44SJordan Rupprecht ['target.prefer-dynamic-value', 38799451b44SJordan Rupprecht 'target.process.']) 38899451b44SJordan Rupprecht 38999451b44SJordan Rupprecht def test_settings_set_target_process(self): 39099451b44SJordan Rupprecht """Test that 'settings set target.process' completes to 'settings set target.process.'.""" 39199451b44SJordan Rupprecht self.complete_from_to( 39299451b44SJordan Rupprecht 'settings set target.process', 39399451b44SJordan Rupprecht 'settings set target.process.') 39499451b44SJordan Rupprecht 39599451b44SJordan Rupprecht def test_settings_set_target_process_dot(self): 39699451b44SJordan Rupprecht """Test that 'settings set target.process.t' completes to 'settings set target.process.thread.'.""" 39799451b44SJordan Rupprecht self.complete_from_to( 398ff4c98c0SRaphael Isemann 'settings set target.process.thr', 39999451b44SJordan Rupprecht 'settings set target.process.thread.') 40099451b44SJordan Rupprecht 40199451b44SJordan Rupprecht def test_settings_set_target_process_thread_dot(self): 40299451b44SJordan Rupprecht """Test that 'settings set target.process.thread.' completes to [ 40399451b44SJordan Rupprecht 'target.process.thread.step-avoid-regexp', 'target.process.thread.trace-thread'].""" 40499451b44SJordan Rupprecht self.complete_from_to('settings set target.process.thread.', 40599451b44SJordan Rupprecht ['target.process.thread.step-avoid-regexp', 40699451b44SJordan Rupprecht 'target.process.thread.trace-thread']) 40799451b44SJordan Rupprecht 408f99a18bbSGongyu Deng def test_thread_plan_discard(self): 409f99a18bbSGongyu Deng self.build() 410f99a18bbSGongyu Deng (_, _, thread, _) = lldbutil.run_to_source_breakpoint(self, 411f99a18bbSGongyu Deng 'ptr_foo', lldb.SBFileSpec("main.cpp")) 412f99a18bbSGongyu Deng self.assertTrue(thread) 413f99a18bbSGongyu Deng self.complete_from_to('thread plan discard ', 'thread plan discard ') 414f99a18bbSGongyu Deng 415f99a18bbSGongyu Deng source_path = os.path.join(self.getSourceDir(), "thread_plan_script.py") 416f99a18bbSGongyu Deng self.runCmd("command script import '%s'"%(source_path)) 417f99a18bbSGongyu Deng self.runCmd("thread step-scripted -C thread_plan_script.PushPlanStack") 418f99a18bbSGongyu Deng self.complete_from_to('thread plan discard ', 'thread plan discard 1') 419f99a18bbSGongyu Deng self.runCmd('thread plan discard 1') 420f99a18bbSGongyu Deng 42199451b44SJordan Rupprecht def test_target_space(self): 42299451b44SJordan Rupprecht """Test that 'target ' completes to ['create', 'delete', 'list', 42399451b44SJordan Rupprecht 'modules', 'select', 'stop-hook', 'variable'].""" 42499451b44SJordan Rupprecht self.complete_from_to('target ', 42599451b44SJordan Rupprecht ['create', 42699451b44SJordan Rupprecht 'delete', 42799451b44SJordan Rupprecht 'list', 42899451b44SJordan Rupprecht 'modules', 42999451b44SJordan Rupprecht 'select', 43099451b44SJordan Rupprecht 'stop-hook', 43199451b44SJordan Rupprecht 'variable']) 43299451b44SJordan Rupprecht 4338888992dSRaphael Isemann def test_target_modules_dump_line_table(self): 4348888992dSRaphael Isemann """Tests source file completion by completing the line-table argument.""" 4358888992dSRaphael Isemann self.build() 4368888992dSRaphael Isemann self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 4378888992dSRaphael Isemann self.complete_from_to('target modules dump line-table main.cp', 4388888992dSRaphael Isemann ['main.cpp']) 4398888992dSRaphael Isemann 440f65f9d3bSRaphael Isemann def test_target_modules_load_aout(self): 441f65f9d3bSRaphael Isemann """Tests modules completion by completing the target modules load argument.""" 442f65f9d3bSRaphael Isemann self.build() 443f65f9d3bSRaphael Isemann self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 444f65f9d3bSRaphael Isemann self.complete_from_to('target modules load a.ou', 445f65f9d3bSRaphael Isemann ['a.out']) 446f65f9d3bSRaphael Isemann 44724bc8afdSGongyu Deng def test_target_modules_search_paths_insert(self): 44824bc8afdSGongyu Deng # Completion won't work without a valid target. 44924bc8afdSGongyu Deng self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 45024bc8afdSGongyu Deng self.build() 45124bc8afdSGongyu Deng target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 45224bc8afdSGongyu Deng self.assertTrue(target, VALID_TARGET) 45324bc8afdSGongyu Deng self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert ") 45424bc8afdSGongyu Deng self.runCmd("target modules search-paths add a b") 45524bc8afdSGongyu Deng self.complete_from_to("target modules search-paths insert ", "target modules search-paths insert 0") 45624bc8afdSGongyu Deng # Completion only works for the first arg. 45724bc8afdSGongyu Deng self.complete_from_to("target modules search-paths insert 0 ", "target modules search-paths insert 0 ") 45824bc8afdSGongyu Deng 45999451b44SJordan Rupprecht def test_target_create_dash_co(self): 46099451b44SJordan Rupprecht """Test that 'target create --co' completes to 'target variable --core '.""" 46199451b44SJordan Rupprecht self.complete_from_to('target create --co', 'target create --core ') 46299451b44SJordan Rupprecht 46399451b44SJordan Rupprecht def test_target_va(self): 46499451b44SJordan Rupprecht """Test that 'target va' completes to 'target variable '.""" 46599451b44SJordan Rupprecht self.complete_from_to('target va', 'target variable ') 46699451b44SJordan Rupprecht 467a952fe23SGongyu Deng def test_common_completion_thread_index(self): 468a952fe23SGongyu Deng subcommands = ['continue', 'info', 'exception', 'select', 469a952fe23SGongyu Deng 'step-in', 'step-inst', 'step-inst-over', 'step-out', 'step-over', 'step-script'] 470a952fe23SGongyu Deng 471a952fe23SGongyu Deng # Completion should do nothing without threads. 472a952fe23SGongyu Deng for subcommand in subcommands: 473a952fe23SGongyu Deng self.complete_from_to('thread ' + subcommand + ' ', 474a952fe23SGongyu Deng 'thread ' + subcommand + ' ') 475a952fe23SGongyu Deng 476a952fe23SGongyu Deng self.build() 477a952fe23SGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 478a952fe23SGongyu Deng 479a952fe23SGongyu Deng # At least we have the thread at the index of 1 now. 480a952fe23SGongyu Deng for subcommand in subcommands: 481a952fe23SGongyu Deng self.complete_from_to('thread ' + subcommand + ' ', ['1']) 482a952fe23SGongyu Deng 483188f1ac3SGongyu Deng def test_common_completion_type_category_name(self): 484188f1ac3SGongyu Deng subcommands = ['delete', 'list', 'enable', 'disable', 'define'] 485188f1ac3SGongyu Deng for subcommand in subcommands: 486188f1ac3SGongyu Deng self.complete_from_to('type category ' + subcommand + ' ', ['default']) 487188f1ac3SGongyu Deng self.complete_from_to('type filter add -w ', ['default']) 488188f1ac3SGongyu Deng 48999451b44SJordan Rupprecht def test_command_argument_completion(self): 49099451b44SJordan Rupprecht """Test completion of command arguments""" 49199451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable -", ["-w", "-s"]) 49299451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable -w', 'watchpoint set variable -w ') 49399451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable --", ["--watch", "--size"]) 49499451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable --w", "watchpoint set variable --watch") 49599451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable -w ', ['read', 'write', 'read_write']) 49699451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable --watch ", ["read", "write", "read_write"]) 49799451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable --watch w", "watchpoint set variable --watch write") 49899451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable -w read_', 'watchpoint set variable -w read_write') 49999451b44SJordan Rupprecht # Now try the same thing with a variable name (non-option argument) to 50099451b44SJordan Rupprecht # test that getopts arg reshuffling doesn't confuse us. 50199451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable foo -", ["-w", "-s"]) 50299451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable foo -w', 'watchpoint set variable foo -w ') 50399451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable foo --", ["--watch", "--size"]) 50499451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable foo --w", "watchpoint set variable foo --watch") 50599451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable foo -w ', ['read', 'write', 'read_write']) 50699451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable foo --watch ", ["read", "write", "read_write"]) 50799451b44SJordan Rupprecht self.complete_from_to("watchpoint set variable foo --watch w", "watchpoint set variable foo --watch write") 50899451b44SJordan Rupprecht self.complete_from_to('watchpoint set variable foo -w read_', 'watchpoint set variable foo -w read_write') 50999451b44SJordan Rupprecht 5102e8f304fSGongyu Deng def test_command_script_delete(self): 5112e8f304fSGongyu Deng self.runCmd("command script add -h test_desc -f none -s current usercmd1") 512c5011aedSJim Ingham self.check_completion_with_desc('command script delete ', [['usercmd1', '']]) 5132e8f304fSGongyu Deng 51431fd64acSGongyu Deng def test_command_delete(self): 51531fd64acSGongyu Deng self.runCmd(r"command regex test_command s/^$/finish/ 's/([0-9]+)/frame select %1/'") 51631fd64acSGongyu Deng self.complete_from_to('command delete test_c', 'command delete test_command') 51731fd64acSGongyu Deng 51831fd64acSGongyu Deng def test_command_unalias(self): 51931fd64acSGongyu Deng self.complete_from_to('command unalias ima', 'command unalias image') 52031fd64acSGongyu Deng 52199451b44SJordan Rupprecht def test_completion_description_commands(self): 52299451b44SJordan Rupprecht """Test descriptions of top-level command completions""" 52399451b44SJordan Rupprecht self.check_completion_with_desc("", [ 52499451b44SJordan Rupprecht ["command", "Commands for managing custom LLDB commands."], 52599451b44SJordan Rupprecht ["breakpoint", "Commands for operating on breakpoints (see 'help b' for shorthand.)"] 52699451b44SJordan Rupprecht ]) 52799451b44SJordan Rupprecht 52899451b44SJordan Rupprecht self.check_completion_with_desc("pl", [ 52999451b44SJordan Rupprecht ["platform", "Commands to manage and create platforms."], 53099451b44SJordan Rupprecht ["plugin", "Commands for managing LLDB plugins."] 53199451b44SJordan Rupprecht ]) 53299451b44SJordan Rupprecht 53399451b44SJordan Rupprecht # Just check that this doesn't crash. 53499451b44SJordan Rupprecht self.check_completion_with_desc("comman", []) 53599451b44SJordan Rupprecht self.check_completion_with_desc("non-existent-command", []) 53699451b44SJordan Rupprecht 53799451b44SJordan Rupprecht def test_completion_description_command_options(self): 53899451b44SJordan Rupprecht """Test descriptions of command options""" 53999451b44SJordan Rupprecht # Short options 54099451b44SJordan Rupprecht self.check_completion_with_desc("breakpoint set -", [ 541742fb134SDavid Spickett ["-h", "Set the breakpoint on exception catcH."], 542742fb134SDavid Spickett ["-w", "Set the breakpoint on exception throW."] 54399451b44SJordan Rupprecht ]) 54499451b44SJordan Rupprecht 54599451b44SJordan Rupprecht # Long options. 54699451b44SJordan Rupprecht self.check_completion_with_desc("breakpoint set --", [ 547742fb134SDavid Spickett ["--on-catch", "Set the breakpoint on exception catcH."], 548742fb134SDavid Spickett ["--on-throw", "Set the breakpoint on exception throW."] 54999451b44SJordan Rupprecht ]) 55099451b44SJordan Rupprecht 55199451b44SJordan Rupprecht # Ambiguous long options. 55299451b44SJordan Rupprecht self.check_completion_with_desc("breakpoint set --on-", [ 553742fb134SDavid Spickett ["--on-catch", "Set the breakpoint on exception catcH."], 554742fb134SDavid Spickett ["--on-throw", "Set the breakpoint on exception throW."] 55599451b44SJordan Rupprecht ]) 55699451b44SJordan Rupprecht 55799451b44SJordan Rupprecht # Unknown long option. 55899451b44SJordan Rupprecht self.check_completion_with_desc("breakpoint set --Z", [ 55999451b44SJordan Rupprecht ]) 56099451b44SJordan Rupprecht 56166fa73faSGongyu Deng def test_common_completion_frame_index(self): 56280eb4228SGongyu Deng self.build() 56366fa73faSGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', lldb.SBFileSpec("main.cpp")) 56480eb4228SGongyu Deng 56580eb4228SGongyu Deng self.complete_from_to('frame select ', ['0']) 56666fa73faSGongyu Deng self.complete_from_to('thread backtrace -s ', ['0']) 567c37d25f0SGongyu Deng 568c37d25f0SGongyu Deng def test_frame_recognizer_delete(self): 569c37d25f0SGongyu Deng self.runCmd("frame recognizer add -l py_class -s module_name -n recognizer_name") 570c37d25f0SGongyu Deng self.check_completion_with_desc('frame recognizer delete ', [['0', 'py_class, module module_name, symbol recognizer_name']]) 57180eb4228SGongyu Deng 572e3820570SGongyu Deng def test_platform_install_local_file(self): 573e3820570SGongyu Deng self.complete_from_to('platform target-install main.cp', 'platform target-install main.cpp') 574e3820570SGongyu Deng 57599451b44SJordan Rupprecht @expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr24489") 57699451b44SJordan Rupprecht def test_symbol_name(self): 57799451b44SJordan Rupprecht self.build() 57899451b44SJordan Rupprecht self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 57999451b44SJordan Rupprecht self.complete_from_to('breakpoint set -n Fo', 58099451b44SJordan Rupprecht 'breakpoint set -n Foo::Bar(int,\\ int)', 58199451b44SJordan Rupprecht turn_off_re_match=True) 58299451b44SJordan Rupprecht # No completion for Qu because the candidate is 58399451b44SJordan Rupprecht # (anonymous namespace)::Quux(). 58499451b44SJordan Rupprecht self.complete_from_to('breakpoint set -n Qu', '') 585a14f4a75SGongyu Deng 5861cd99fe9SGongyu Deng def test_completion_type_formatter_delete(self): 5871cd99fe9SGongyu Deng self.runCmd('type filter add --child a Aoo') 5881cd99fe9SGongyu Deng self.complete_from_to('type filter delete ', ['Aoo']) 5891cd99fe9SGongyu Deng self.runCmd('type filter add --child b -x Boo') 5901cd99fe9SGongyu Deng self.complete_from_to('type filter delete ', ['Boo']) 5911cd99fe9SGongyu Deng 5921cd99fe9SGongyu Deng self.runCmd('type format add -f hex Coo') 5931cd99fe9SGongyu Deng self.complete_from_to('type format delete ', ['Coo']) 5941cd99fe9SGongyu Deng self.runCmd('type format add -f hex -x Doo') 5951cd99fe9SGongyu Deng self.complete_from_to('type format delete ', ['Doo']) 5961cd99fe9SGongyu Deng 5971cd99fe9SGongyu Deng self.runCmd('type summary add -c Eoo') 5981cd99fe9SGongyu Deng self.complete_from_to('type summary delete ', ['Eoo']) 5991cd99fe9SGongyu Deng self.runCmd('type summary add -x -c Foo') 6001cd99fe9SGongyu Deng self.complete_from_to('type summary delete ', ['Foo']) 6011cd99fe9SGongyu Deng 6021cd99fe9SGongyu Deng self.runCmd('type synthetic add Goo -l test') 6031cd99fe9SGongyu Deng self.complete_from_to('type synthetic delete ', ['Goo']) 6041cd99fe9SGongyu Deng self.runCmd('type synthetic add -x Hoo -l test') 6051cd99fe9SGongyu Deng self.complete_from_to('type synthetic delete ', ['Hoo']) 6061cd99fe9SGongyu Deng 607a14f4a75SGongyu Deng @skipIf(archs=no_match(['x86_64'])) 608a14f4a75SGongyu Deng def test_register_read_and_write_on_x86(self): 609a14f4a75SGongyu Deng """Test the completion of the commands register read and write on x86""" 610a14f4a75SGongyu Deng 611a14f4a75SGongyu Deng # The tab completion for "register read/write" won't work without a running process. 612a14f4a75SGongyu Deng self.complete_from_to('register read ', 613a14f4a75SGongyu Deng 'register read ') 614a14f4a75SGongyu Deng self.complete_from_to('register write ', 615a14f4a75SGongyu Deng 'register write ') 616a14f4a75SGongyu Deng 617a14f4a75SGongyu Deng self.build() 618a14f4a75SGongyu Deng self.main_source_spec = lldb.SBFileSpec("main.cpp") 619a14f4a75SGongyu Deng lldbutil.run_to_source_breakpoint(self, '// Break here', self.main_source_spec) 620a14f4a75SGongyu Deng 621a14f4a75SGongyu Deng # test cases for register read 622a14f4a75SGongyu Deng self.complete_from_to('register read ', 623a14f4a75SGongyu Deng ['rax', 624a14f4a75SGongyu Deng 'rbx', 625a14f4a75SGongyu Deng 'rcx']) 626a14f4a75SGongyu Deng self.complete_from_to('register read r', 627a14f4a75SGongyu Deng ['rax', 628a14f4a75SGongyu Deng 'rbx', 629a14f4a75SGongyu Deng 'rcx']) 630a14f4a75SGongyu Deng self.complete_from_to('register read ra', 631a14f4a75SGongyu Deng 'register read rax') 632a14f4a75SGongyu Deng # register read can take multiple register names as arguments 633a14f4a75SGongyu Deng self.complete_from_to('register read rax ', 634a14f4a75SGongyu Deng ['rax', 635a14f4a75SGongyu Deng 'rbx', 636a14f4a75SGongyu Deng 'rcx']) 637a14f4a75SGongyu Deng # complete with prefix '$' 638a14f4a75SGongyu Deng self.completions_match('register read $rb', 639a14f4a75SGongyu Deng ['$rbx', 640a14f4a75SGongyu Deng '$rbp']) 641a14f4a75SGongyu Deng self.completions_match('register read $ra', 642a14f4a75SGongyu Deng ['$rax']) 643a14f4a75SGongyu Deng self.complete_from_to('register read rax $', 644a14f4a75SGongyu Deng ['\$rax', 645a14f4a75SGongyu Deng '\$rbx', 646a14f4a75SGongyu Deng '\$rcx']) 647a14f4a75SGongyu Deng self.complete_from_to('register read $rax ', 648a14f4a75SGongyu Deng ['rax', 649a14f4a75SGongyu Deng 'rbx', 650a14f4a75SGongyu Deng 'rcx']) 651a14f4a75SGongyu Deng 652a14f4a75SGongyu Deng # test cases for register write 653a14f4a75SGongyu Deng self.complete_from_to('register write ', 654a14f4a75SGongyu Deng ['rax', 655a14f4a75SGongyu Deng 'rbx', 656a14f4a75SGongyu Deng 'rcx']) 657a14f4a75SGongyu Deng self.complete_from_to('register write r', 658a14f4a75SGongyu Deng ['rax', 659a14f4a75SGongyu Deng 'rbx', 660a14f4a75SGongyu Deng 'rcx']) 661a14f4a75SGongyu Deng self.complete_from_to('register write ra', 662a14f4a75SGongyu Deng 'register write rax') 663a14f4a75SGongyu Deng self.complete_from_to('register write rb', 664a14f4a75SGongyu Deng ['rbx', 665a14f4a75SGongyu Deng 'rbp']) 666a14f4a75SGongyu Deng # register write can only take exact one register name as argument 667a14f4a75SGongyu Deng self.complete_from_to('register write rbx ', 668a14f4a75SGongyu Deng []) 6690e50b9a4SGongyu Deng 670b2b7dbb4SGongyu Deng def test_common_completion_target_stophook_ids(self): 671b2b7dbb4SGongyu Deng subcommands = ['delete', 'enable', 'disable'] 672b2b7dbb4SGongyu Deng 673b2b7dbb4SGongyu Deng for subcommand in subcommands: 674b2b7dbb4SGongyu Deng self.complete_from_to('target stop-hook ' + subcommand + ' ', 675b2b7dbb4SGongyu Deng 'target stop-hook ' + subcommand + ' ') 676b2b7dbb4SGongyu Deng 677b2b7dbb4SGongyu Deng self.build() 678b2b7dbb4SGongyu Deng self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 679c1b07d61SJim Ingham self.runCmd('target stop-hook add -o test') 680b2b7dbb4SGongyu Deng 681b2b7dbb4SGongyu Deng for subcommand in subcommands: 682b2b7dbb4SGongyu Deng self.complete_from_to('target stop-hook ' + subcommand + ' ', 683b2b7dbb4SGongyu Deng 'target stop-hook ' + subcommand + ' 1') 684b2b7dbb4SGongyu Deng 685b2b7dbb4SGongyu Deng # Completion should work only on the first argument. 686b2b7dbb4SGongyu Deng for subcommand in subcommands: 687b2b7dbb4SGongyu Deng self.complete_from_to('target stop-hook ' + subcommand + ' 1 ', 688b2b7dbb4SGongyu Deng 'target stop-hook ' + subcommand + ' 1 ') 689b2b7dbb4SGongyu Deng 6903ce57e01SGongyu Deng def test_common_completion_type_language(self): 6913ce57e01SGongyu Deng self.complete_from_to('type category -l ', ['c']) 6923ce57e01SGongyu Deng 693419f1be7SGongyu Deng def test_target_modules_load_dash_u(self): 694419f1be7SGongyu Deng self.build() 695419f1be7SGongyu Deng target = self.dbg.CreateTarget(self.getBuildArtifact("a.out")) 696419f1be7SGongyu Deng self.complete_from_to('target modules load -u ', [target.GetModuleAtIndex(0).GetUUIDString()]) 697419f1be7SGongyu Deng 698e87362e6SGongyu Deng def test_complete_breakpoint_with_ids(self): 699e87362e6SGongyu Deng """These breakpoint subcommands should be completed with a list of breakpoint ids""" 7000e50b9a4SGongyu Deng 701e87362e6SGongyu Deng subcommands = ['enable', 'disable', 'delete', 'modify', 'name add', 'name delete', 'write'] 7020e50b9a4SGongyu Deng 7030e50b9a4SGongyu Deng # The tab completion here is unavailable without a target 7040e50b9a4SGongyu Deng for subcommand in subcommands: 7050e50b9a4SGongyu Deng self.complete_from_to('breakpoint ' + subcommand + ' ', 7060e50b9a4SGongyu Deng 'breakpoint ' + subcommand + ' ') 7070e50b9a4SGongyu Deng 7080e50b9a4SGongyu Deng self.build() 7090e50b9a4SGongyu Deng target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 7100e50b9a4SGongyu Deng self.assertTrue(target, VALID_TARGET) 7110e50b9a4SGongyu Deng 7120e50b9a4SGongyu Deng bp = target.BreakpointCreateByName('main', 'a.out') 7130e50b9a4SGongyu Deng self.assertTrue(bp) 7140e50b9a4SGongyu Deng self.assertEqual(bp.GetNumLocations(), 1) 7150e50b9a4SGongyu Deng 7160e50b9a4SGongyu Deng for subcommand in subcommands: 7170e50b9a4SGongyu Deng self.complete_from_to('breakpoint ' + subcommand + ' ', 7180e50b9a4SGongyu Deng ['1']) 7190e50b9a4SGongyu Deng 7200e50b9a4SGongyu Deng bp2 = target.BreakpointCreateByName('Bar', 'a.out') 7210e50b9a4SGongyu Deng self.assertTrue(bp2) 7220e50b9a4SGongyu Deng self.assertEqual(bp2.GetNumLocations(), 1) 7230e50b9a4SGongyu Deng 7240e50b9a4SGongyu Deng for subcommand in subcommands: 7250e50b9a4SGongyu Deng self.complete_from_to('breakpoint ' + subcommand + ' ', 7260e50b9a4SGongyu Deng ['1', 7270e50b9a4SGongyu Deng '2']) 7280e50b9a4SGongyu Deng 7290e50b9a4SGongyu Deng for subcommand in subcommands: 7300e50b9a4SGongyu Deng self.complete_from_to('breakpoint ' + subcommand + ' 1 ', 7310e50b9a4SGongyu Deng ['1', 7320e50b9a4SGongyu Deng '2']) 7330e50b9a4SGongyu Deng 73422e63cbaSGongyu Deng def test_complete_breakpoint_with_names(self): 73522e63cbaSGongyu Deng self.build() 73622e63cbaSGongyu Deng target = self.dbg.CreateTarget(self.getBuildArtifact('a.out')) 73722e63cbaSGongyu Deng self.assertTrue(target, VALID_TARGET) 73822e63cbaSGongyu Deng 73922e63cbaSGongyu Deng # test breakpoint read dedicated 74022e63cbaSGongyu Deng self.complete_from_to('breakpoint read -N ', 'breakpoint read -N ') 74122e63cbaSGongyu Deng self.complete_from_to('breakpoint read -f breakpoints.json -N ', ['mm']) 74222e63cbaSGongyu Deng self.complete_from_to('breakpoint read -f breakpoints.json -N n', 'breakpoint read -f breakpoints.json -N n') 74322e63cbaSGongyu Deng self.complete_from_to('breakpoint read -f breakpoints_invalid.json -N ', 'breakpoint read -f breakpoints_invalid.json -N ') 74422e63cbaSGongyu Deng 74522e63cbaSGongyu Deng # test common breapoint name completion 74622e63cbaSGongyu Deng bp1 = target.BreakpointCreateByName('main', 'a.out') 74722e63cbaSGongyu Deng self.assertTrue(bp1) 74822e63cbaSGongyu Deng self.assertEqual(bp1.GetNumLocations(), 1) 74922e63cbaSGongyu Deng self.complete_from_to('breakpoint set -N n', 'breakpoint set -N n') 75022e63cbaSGongyu Deng self.assertTrue(bp1.AddNameWithErrorHandling("nn")) 75122e63cbaSGongyu Deng self.complete_from_to('breakpoint set -N ', 'breakpoint set -N nn') 752