1f3d0bda5SJim Ingham""" 2f3d0bda5SJim InghamTest that an alias can contain active backticks 3f3d0bda5SJim Ingham""" 4f3d0bda5SJim Ingham 5f3d0bda5SJim Ingham 6f3d0bda5SJim Inghamimport lldb 7f3d0bda5SJim Inghamfrom lldbsuite.test.lldbtest import * 8f3d0bda5SJim Inghamimport lldbsuite.test.lldbutil as lldbutil 9f3d0bda5SJim Ingham 10f3d0bda5SJim Ingham 11f3d0bda5SJim Inghamclass TestBackticksInAlias(TestBase): 12f3d0bda5SJim Ingham NO_DEBUG_INFO_TESTCASE = True 13f3d0bda5SJim Ingham 14f3d0bda5SJim Ingham def test_backticks_in_alias(self): 15f3d0bda5SJim Ingham """Test that an alias can contain active backticks.""" 16f3d0bda5SJim Ingham self.build() 17*2238dcc3SJonas Devlieghere (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint( 18*2238dcc3SJonas Devlieghere self, "break here", lldb.SBFileSpec("main.c") 19*2238dcc3SJonas Devlieghere ) 20*2238dcc3SJonas Devlieghere interp = self.dbg.GetCommandInterpreter() 21f3d0bda5SJim Ingham result = lldb.SBCommandReturnObject() 22*2238dcc3SJonas Devlieghere interp.HandleCommand( 23*2238dcc3SJonas Devlieghere "command alias _test-argv-cmd expression -Z \`argc\` -- argv", result 24*2238dcc3SJonas Devlieghere ) 25f3d0bda5SJim Ingham self.assertCommandReturn(result, "Made the alias") 26f3d0bda5SJim Ingham interp.HandleCommand("_test-argv-cmd", result) 27f3d0bda5SJim Ingham self.assertCommandReturn(result, "The alias worked") 28f3d0bda5SJim Ingham 29f3d0bda5SJim Ingham # Now try a harder case where we create this using an alias: 30*2238dcc3SJonas Devlieghere interp.HandleCommand( 31*2238dcc3SJonas Devlieghere "command alias _test-argv-parray-cmd parray \`argc\` argv", result 32*2238dcc3SJonas Devlieghere ) 33f3d0bda5SJim Ingham self.assertCommandReturn(result, "Made the alias") 34f3d0bda5SJim Ingham interp.HandleCommand("_test-argv-parray-cmd", result) 35*2238dcc3SJonas Devlieghere self.assertFalse( 36*2238dcc3SJonas Devlieghere result.Succeeded(), 37*2238dcc3SJonas Devlieghere "CommandAlias::Desugar currently fails if a alias substitutes %N arguments in another alias", 38*2238dcc3SJonas Devlieghere ) 39f3d0bda5SJim Ingham 4075ca15fcSJim Ingham def test_backticks_in_parsed_cmd_argument(self): 4175ca15fcSJim Ingham """break list is a parsed command, use a variable for the breakpoint number 4275ca15fcSJim Ingham and make sure that and the direct use of the ID get the same result.""" 4375ca15fcSJim Ingham self.build() 44*2238dcc3SJonas Devlieghere target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 45*2238dcc3SJonas Devlieghere self, "break here", lldb.SBFileSpec("main.c") 46*2238dcc3SJonas Devlieghere ) 4775ca15fcSJim Ingham # Make a second breakpoint so that if the backtick part -> nothing we'll print too much: 4875ca15fcSJim Ingham # It doesn't need to resolve to anything. 4975ca15fcSJim Ingham dummy_bkpt = target.BreakpointCreateByName("dont_really_care_if_this_exists") 5075ca15fcSJim Ingham 5175ca15fcSJim Ingham bkpt_id = bkpt.GetID() 5275ca15fcSJim Ingham self.runCmd(f"expr int $number = {bkpt_id}") 5375ca15fcSJim Ingham direct_result = lldb.SBCommandReturnObject() 5475ca15fcSJim Ingham backtick_result = lldb.SBCommandReturnObject() 5575ca15fcSJim Ingham interp = self.dbg.GetCommandInterpreter() 5675ca15fcSJim Ingham interp.HandleCommand(f"break list {bkpt_id}", direct_result) 5775ca15fcSJim Ingham self.assertTrue(direct_result.Succeeded(), "Break list with id works") 5875ca15fcSJim Ingham interp.HandleCommand("break list `$number`", backtick_result) 5975ca15fcSJim Ingham self.assertTrue(direct_result.Succeeded(), "Break list with backtick works") 60*2238dcc3SJonas Devlieghere self.assertEqual( 61*2238dcc3SJonas Devlieghere direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same" 62*2238dcc3SJonas Devlieghere ) 6375ca15fcSJim Ingham 6475ca15fcSJim Ingham def test_backticks_in_parsed_cmd_option(self): 6575ca15fcSJim Ingham # The script interpreter is a raw command, so try that one: 6675ca15fcSJim Ingham self.build() 67*2238dcc3SJonas Devlieghere target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 68*2238dcc3SJonas Devlieghere self, "break here", lldb.SBFileSpec("main.c") 69*2238dcc3SJonas Devlieghere ) 7075ca15fcSJim Ingham 7175ca15fcSJim Ingham self.runCmd(f"expr int $number = 2") 7275ca15fcSJim Ingham direct_result = lldb.SBCommandReturnObject() 7375ca15fcSJim Ingham backtick_result = lldb.SBCommandReturnObject() 7475ca15fcSJim Ingham interp = self.dbg.GetCommandInterpreter() 7575ca15fcSJim Ingham interp.HandleCommand(f"memory read --count 2 argv", direct_result) 76*2238dcc3SJonas Devlieghere self.assertTrue( 77*2238dcc3SJonas Devlieghere direct_result.Succeeded(), "memory read with direct count works" 78*2238dcc3SJonas Devlieghere ) 7975ca15fcSJim Ingham interp.HandleCommand("memory read --count `$number` argv", backtick_result) 8075ca15fcSJim Ingham self.assertTrue(direct_result.Succeeded(), "memory read with backtick works") 81*2238dcc3SJonas Devlieghere self.assertEqual( 82*2238dcc3SJonas Devlieghere direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same" 83*2238dcc3SJonas Devlieghere ) 8475ca15fcSJim Ingham 8575ca15fcSJim Ingham def test_backticks_in_raw_cmd(self): 8675ca15fcSJim Ingham # The script interpreter is a raw command, so try that one: 8775ca15fcSJim Ingham self.build() 88*2238dcc3SJonas Devlieghere target, process, thread, bkpt = lldbutil.run_to_source_breakpoint( 89*2238dcc3SJonas Devlieghere self, "break here", lldb.SBFileSpec("main.c") 90*2238dcc3SJonas Devlieghere ) 9175ca15fcSJim Ingham argc_valobj = thread.frames[0].FindVariable("argc") 9275ca15fcSJim Ingham self.assertTrue(argc_valobj.GetError().Success(), "Made argc valobj") 9375ca15fcSJim Ingham argc_value = argc_valobj.GetValueAsUnsigned(0) 9475ca15fcSJim Ingham self.assertNotEqual(argc_value, 0, "Got a value for argc") 9575ca15fcSJim Ingham result = lldb.SBCommandReturnObject() 9675ca15fcSJim Ingham interp = self.dbg.GetCommandInterpreter() 9775ca15fcSJim Ingham interp.HandleCommand(f"script {argc_value} - `argc`", result) 9875ca15fcSJim Ingham self.assertTrue(result.Succeeded(), "Command succeeded") 990999996fSJim Ingham fixed_output = result.GetOutput().rstrip() 1000999996fSJim Ingham self.assertEqual("0", fixed_output, "Substitution worked") 101