[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / command / backticks / TestBackticksInAlias.py
blobc31a08ac00182fff05b520a9e7b8e206246bed32
1 """
2 Test that an alias can contain active backticks
3 """
6 import lldb
7 from lldbsuite.test.lldbtest import *
8 import lldbsuite.test.lldbutil as lldbutil
11 class TestBackticksInAlias(TestBase):
12 NO_DEBUG_INFO_TESTCASE = True
14 def test_backticks_in_alias(self):
15 """Test that an alias can contain active backticks."""
16 self.build()
17 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
18 self, "break here", lldb.SBFileSpec("main.c")
20 interp = self.dbg.GetCommandInterpreter()
21 result = lldb.SBCommandReturnObject()
22 interp.HandleCommand(
23 "command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
25 self.assertCommandReturn(result, "Made the alias")
26 interp.HandleCommand("_test-argv-cmd", result)
27 self.assertCommandReturn(result, "The alias worked")
29 # Now try a harder case where we create this using an alias:
30 interp.HandleCommand(
31 "command alias _test-argv-parray-cmd parray \`argc\` argv", result
33 self.assertCommandReturn(result, "Made the alias")
34 interp.HandleCommand("_test-argv-parray-cmd", result)
35 self.assertFalse(
36 result.Succeeded(),
37 "CommandAlias::Desugar currently fails if a alias substitutes %N arguments in another alias",
40 def test_backticks_in_parsed_cmd_argument(self):
41 """break list is a parsed command, use a variable for the breakpoint number
42 and make sure that and the direct use of the ID get the same result."""
43 self.build()
44 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
45 self, "break here", lldb.SBFileSpec("main.c")
47 # Make a second breakpoint so that if the backtick part -> nothing we'll print too much:
48 # It doesn't need to resolve to anything.
49 dummy_bkpt = target.BreakpointCreateByName("dont_really_care_if_this_exists")
51 bkpt_id = bkpt.GetID()
52 self.runCmd(f"expr int $number = {bkpt_id}")
53 direct_result = lldb.SBCommandReturnObject()
54 backtick_result = lldb.SBCommandReturnObject()
55 interp = self.dbg.GetCommandInterpreter()
56 interp.HandleCommand(f"break list {bkpt_id}", direct_result)
57 self.assertTrue(direct_result.Succeeded(), "Break list with id works")
58 interp.HandleCommand("break list `$number`", backtick_result)
59 self.assertTrue(direct_result.Succeeded(), "Break list with backtick works")
60 self.assertEqual(
61 direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same"
64 def test_backticks_in_parsed_cmd_option(self):
65 # The script interpreter is a raw command, so try that one:
66 self.build()
67 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
68 self, "break here", lldb.SBFileSpec("main.c")
71 self.runCmd(f"expr int $number = 2")
72 direct_result = lldb.SBCommandReturnObject()
73 backtick_result = lldb.SBCommandReturnObject()
74 interp = self.dbg.GetCommandInterpreter()
75 interp.HandleCommand(f"memory read --count 2 argv", direct_result)
76 self.assertTrue(
77 direct_result.Succeeded(), "memory read with direct count works"
79 interp.HandleCommand("memory read --count `$number` argv", backtick_result)
80 self.assertTrue(direct_result.Succeeded(), "memory read with backtick works")
81 self.assertEqual(
82 direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same"
85 def test_backticks_in_raw_cmd(self):
86 # The script interpreter is a raw command, so try that one:
87 self.build()
88 target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
89 self, "break here", lldb.SBFileSpec("main.c")
91 argc_valobj = thread.frames[0].FindVariable("argc")
92 self.assertTrue(argc_valobj.GetError().Success(), "Made argc valobj")
93 argc_value = argc_valobj.GetValueAsUnsigned(0)
94 self.assertNotEqual(argc_value, 0, "Got a value for argc")
95 result = lldb.SBCommandReturnObject()
96 interp = self.dbg.GetCommandInterpreter()
97 interp.HandleCommand(f"script {argc_value} - `argc`", result)
98 self.assertTrue(result.Succeeded(), "Command succeeded")
99 fixed_output = result.GetOutput().rstrip()
100 self.assertEqual("0", fixed_output, "Substitution worked")