TestAliases.py revision 025bcc0c90325b36dc3cbaf644bebc77ff758a7c
1""" 2Test lldb command aliases. 3""" 4 5import os, time 6import unittest2 7import lldb 8from lldbtest import * 9import lldbutil 10 11class AliasTestCase(TestBase): 12 13 mydir = os.path.join("functionalities", "alias") 14 15 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 16 @dsym_test 17 def test_with_dsym (self): 18 self.buildDsym () 19 self.alias_tests () 20 21 @dwarf_test 22 def test_with_dwarf (self): 23 self.buildDwarf () 24 self.alias_tests () 25 26 def alias_tests (self): 27 exe = os.path.join (os.getcwd(), "a.out") 28 self.expect("file " + exe, 29 patterns = [ "Current executable set to .*a.out" ]) 30 31 32 def cleanup(): 33 self.runCmd('command unalias hello', check=False) 34 self.runCmd('command unalias python', check=False) 35 self.runCmd('command unalias pp', check=False) 36 self.runCmd('command unalias alias', check=False) 37 self.runCmd('command unalias unalias', check=False) 38 self.runCmd('command unalias myrun', check=False) 39 self.runCmd('command unalias bp', check=False) 40 self.runCmd('command unalias bpa', check=False) 41 self.runCmd('command unalias bpi', check=False) 42 self.runCmd('command unalias bfl', check=False) 43 self.runCmd('command unalias exprf', check=False) 44 self.runCmd('command unalias exprf2', check=False) 45 46 # Execute the cleanup function during test case tear down. 47 self.addTearDownHook(cleanup) 48 49 self.runCmd (r'''command alias hello expr (int) printf ("\n\nHello, anybody!\n\n")''') 50 51 self.runCmd ("command alias python script") 52 53 # We don't want to display the stdout if not in TraceOn() mode. 54 if not self.TraceOn(): 55 self.HideStdout() 56 57 self.runCmd (r'''python print "\n\n\nWhoopee!\n\n\n"''') 58# self.expect (r'''python print "\n\n\nWhoopee!\n\n\n"''', 59# substrs = [ "Whoopee!" ]) 60 61 self.runCmd (r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') 62# self.expect (r'''python print "\n\t\x68\x65\x6c\x6c\x6f\n"''', 63# substrs = [ "hello" ]) 64 65 self.runCmd (r'''command alias pp python print "\n\t\x68\x65\x6c\x6c\x6f\n"''') 66 self.runCmd ("pp") 67# self.expect ("pp", 68# substrs = [ "hello" ]) 69 70 71 self.runCmd ("command alias alias command alias") 72 self.runCmd ("command alias unalias command unalias") 73 74 self.runCmd ("alias myrun process launch -t %1 --") 75 self.runCmd ("alias bp breakpoint") 76 77 self.expect ("alias bpa bp add", 78 COMMAND_FAILED_AS_EXPECTED, error = True, 79 substrs = [ "'add' is not a valid sub-command of 'bp'" ]) 80 81 self.runCmd ("alias bpa bp command add") 82 self.runCmd ("alias bpi bp list") 83 84 break_results = lldbutil.run_break_set_command (self, "bp set -n foo") 85 lldbutil.check_breakpoint_result (self, break_results, num_locations=1, symbol_name='foo', symbol_match_exact=False) 86 87 break_results = lldbutil.run_break_set_command (self, "bp set -n sum") 88 lldbutil.check_breakpoint_result (self, break_results, num_locations=1, symbol_name='sum', symbol_match_exact=False) 89 90 self.runCmd ("alias bfl bp set -f %1 -l %2") 91 92 break_results = lldbutil.run_break_set_command (self, "bfl main.cpp 32") 93 lldbutil.check_breakpoint_result (self, break_results, num_locations=1, file_name='main.cpp', line_number=32) 94 95 self.expect ("bpi", 96 startstr = "Current breakpoints:", 97 substrs = [ "1: name = 'foo', locations = 1", 98 "2: name = 'sum', locations = 1", 99 "3: file = 'main.cpp', line = 32, locations = 1" ]) 100 101 self.runCmd ("bpa -s python 1 -o 'print frame; print bp_loc'") 102 self.runCmd ("bpa -s command 2 -o 'frame variable b'") 103 self.expect ("bpi -f", 104 substrs = [ "Current breakpoints:", 105 "1: name = 'foo', locations = 1", 106 "print frame; print bp_loc", 107 "2: name = 'sum', locations = 1", 108 "frame variable b" ]) 109 110 111 self.expect ("help run", 112 substrs = [ "'run' is an abbreviation for 'process launch -c /bin/bash --'" ]) 113 114 self.expect ("help -a run", 115 substrs = [ "'run' is an abbreviation for 'process launch -c /bin/bash --'" ]) 116 117 self.expect ("help -a", 118 substrs = [ 'run', 'process launch -c /bin/bash' ]) 119 120 self.expect ("help", matching=False, 121 substrs = [ "'run'", 'process launch -c /bin/bash' ]) 122 123 self.expect ("run", 124 patterns = [ "Process .* launched: .*a.out" ]) 125 126 self.expect (r'''expression (int) printf("\x68\x65\x6c\x6c\x6f\n")''', 127 substrs = [ "(int) $", 128 "= 6" ]) 129 130 self.expect ("hello", 131 substrs = [ "(int) $", 132 "= 19" ]) 133 134 self.expect ("expr -f x -- 68", 135 substrs = [ "(int) $", 136 "= 0x00000044" ]) 137 138 self.runCmd ("alias exprf expr -f %1") 139 self.runCmd ("alias exprf2 expr --raw -f %1 --") 140 self.expect ("exprf x -- 1234", 141 substrs = [ "(int) $", 142 "= 0x000004d2" ]) 143 144 self.expect ('exprf2 c "Hi there!"', 145 substrs = [ "[0] = 'H'", 146 "[1] = 'i'", 147 "[2] = ' '", 148 "[3] = 't'", 149 "[4] = 'h'", 150 "[5] = 'e'", 151 "[6] = 'r'", 152 "[7] = 'e'", 153 "[8] = '!'", 154 "[9] = '\\0'" ]) 155 156 157 self.expect ("exprf x 1234", 158 COMMAND_FAILED_AS_EXPECTED, error = True, 159 substrs = [ "use of undeclared identifier 'f'", 160 "1 errors parsing expression" ]) 161 162if __name__ == '__main__': 163 import atexit 164 lldb.SBDebugger.Initialize() 165 atexit.register(lambda: lldb.SBDebugger.Terminate()) 166 unittest2.main() 167 168