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 14 mydir = TestBase.compute_mydir(__file__) 15 NO_DEBUG_INFO_TESTCASE = True 16 17 def setUp(self): 18 # Call super's setUp(). 19 TestBase.setUp(self) 20 # Find the line number to break inside main(). 21 self.line = line_number('main.cpp', '// break here') 22 23 def test_nested_alias(self): 24 """Test that an alias can reference other aliases without crashing.""" 25 self.build() 26 exe = self.getBuildArtifact("a.out") 27 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 28 29 # Break in main() after the variables are assigned values. 30 lldbutil.run_break_set_by_file_and_line( 31 self, "main.cpp", self.line, num_expected_locations=1, loc_exact=True) 32 33 self.runCmd("run", RUN_SUCCEEDED) 34 35 # The stop reason of the thread should be breakpoint. 36 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 37 substrs=['stopped', 'stop reason = breakpoint']) 38 39 # The breakpoint should have a hit count of 1. 40 lldbutil.check_breakpoint(self, bpno = 1, expected_hit_count = 1) 41 42 # This is the function to remove the custom aliases in order to have a 43 # clean slate for the next test case. 44 def cleanup(): 45 self.runCmd('command unalias read', check=False) 46 self.runCmd('command unalias rd', check=False) 47 self.runCmd('command unalias fo', check=False) 48 self.runCmd('command unalias foself', 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