1""" 2Test that an alias can reference other aliases without crashing. 3""" 4 5 6 7import lldb 8from lldbsuite.test.lldbtest import * 9import lldbsuite.test.lldbutil as lldbutil 10 11 12class NestedAliasTestCase(TestBase): 13 NO_DEBUG_INFO_TESTCASE = True 14 15 def setUp(self): 16 # Call super's setUp(). 17 TestBase.setUp(self) 18 # Find the line number to break inside main(). 19 self.line = line_number('main.cpp', '// break here') 20 21 def test_nested_alias(self): 22 """Test that an alias can reference other aliases without crashing.""" 23 self.build() 24 exe = self.getBuildArtifact("a.out") 25 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 26 27 # Break in main() after the variables are assigned values. 28 lldbutil.run_break_set_by_file_and_line( 29 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 30 31 self.runCmd("run", RUN_SUCCEEDED) 32 33 # The stop reason of the thread should be breakpoint. 34 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 35 substrs=['stopped', 'stop reason = breakpoint']) 36 37 # The breakpoint should have a hit count of 1. 38 lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1) 39 40 # This is the function to remove the custom aliases in order to have a 41 # clean slate for the next test case. 42 def cleanup(): 43 self.runCmd('command unalias read', check=False) 44 self.runCmd('command unalias rd', check=False) 45 self.runCmd('command unalias fo', check=False) 46 self.runCmd('command unalias foself', check=False) 47 self.runCmd('command unalias add_two', check=False) 48 self.runCmd('command unalias two', check=False) 49 50 # Execute the cleanup function during test case tear down. 51 self.addTearDownHook(cleanup) 52 53 self.runCmd('command alias read memory read -f A') 54 self.runCmd('command alias rd read -c 3') 55 56 self.expect( 57 'memory read -f A -c 3 `&my_ptr[0]`', 58 substrs=[ 59 'deadbeef', 60 'main.cpp:', 61 'feedbeef']) 62 self.expect( 63 'rd `&my_ptr[0]`', 64 substrs=[ 65 'deadbeef', 66 'main.cpp:', 67 'feedbeef']) 68 69 self.expect( 70 'memory read -f A -c 3 `&my_ptr[0]`', 71 substrs=['deadfeed'], 72 matching=False) 73 self.expect('rd `&my_ptr[0]`', substrs=['deadfeed'], matching=False) 74 75 self.runCmd('command alias fo frame variable -O --') 76 self.runCmd('command alias foself fo self') 77 78 self.expect( 79 'help foself', 80 substrs=[ 81 '--show-all-children', 82 '--raw-output'], 83 matching=False) 84 self.expect( 85 'help foself', 86 substrs=[ 87 'Show variables for the current', 88 'stack frame.'], 89 matching=True) 90 91 # Check that foself was resolved and is now independent of 'fo'. 92 self.runCmd('command unalias fo') 93 self.expect( 94 'help foself', 95 substrs=[ 96 'Show variables for the current', 97 'stack frame.'], 98 matching=True) 99 100 # Check that aliases can be created for raw input commands. 101 self.expect('command alias two expr -- 2') 102 self.expect('command alias add_two two +') 103 self.expect('add_two 3', patterns=[' = 5$']) 104