TestAbbreviations.py revision 9d1acc179e28cf2625e66c411fb164303b6e4e4e
1""" 2Test some lldb command abbreviations. 3""" 4 5import os, time 6import unittest2 7import lldb 8from lldbtest import * 9 10class AbbreviationsTestCase(TestBase): 11 12 mydir = os.path.join("functionalities", "abbreviation") 13 14 def test_nonrunning_command_abbreviations (self): 15 self.expect("ap script", 16 startstr = "The following commands may relate to 'script':", 17 substrs = ['breakpoint command add', 18 'breakpoint command list', 19 'breakpoint list', 20 'command alias', 21 'expression', 22 'script']) 23 24 self.runCmd("com a alias com al") 25 self.runCmd("alias gurp help") 26 self.expect("gurp target create", 27 substrs = ['Syntax: target create <cmd-options> <filename>']) 28 self.runCmd("com u gurp") 29 self.expect("gurp", 30 COMMAND_FAILED_AS_EXPECTED, error = True, 31 substrs = ["error: 'gurp' is not a valid command."]) 32 33 self.expect("h", 34 startstr = "The following is a list of built-in, permanent debugger commands:") 35 36 37 self.expect("com sou ./change_prompt.lldb", 38 patterns = ["Executing commands in '.*change_prompt.lldb'"]) 39 40 self.expect("settings show prompt", 41 startstr = 'prompt (string) = "[old-oak]"') 42 43 44 self.runCmd("settings set -r prompt") 45 self.expect("settings show prompt", 46 startstr = 'prompt (string) = "(lldb) "') 47 48 49 self.expect("lo li", 50 startstr = "Logging categories for ") 51 52 self.runCmd("se se prompt Sycamore> ") 53 self.expect("se sh prompt", 54 startstr = 'prompt (string) = "Sycamore>"') 55 56 self.runCmd("se se -r prompt") 57 self.expect("set sh prompt", 58 startstr = 'prompt (string) = "(lldb) "') 59 60 # We don't want to display the stdout if not in TraceOn() mode. 61 if not self.TraceOn(): 62 self.HideStdout() 63 64 self.runCmd (r'''sc print "\n\n\tHello!\n"''') 65 66 67 @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") 68 def test_with_dsym (self): 69 self.buildDsym () 70 self.running_abbreviations () 71 72 def test_with_dwarf (self): 73 self.buildDwarf () 74 self.running_abbreviations () 75 76 def running_abbreviations (self): 77 exe = os.path.join (os.getcwd(), "a.out") 78 self.expect("fil " + exe, 79 patterns = [ "Current executable set to .*a.out.*" ]) 80 81 self.expect("_regexp-b product", 82 substrs = [ "breakpoint set --name 'product'", 83 "Breakpoint created: 1: name = 'product', locations = 1" ]) 84 85 self.expect("br s -n sum", 86 startstr = "Breakpoint created: 2: name = 'sum', locations = 1") 87 88 self.expect("br s -f main.cpp -l 32", 89 startstr = "Breakpoint created: 3: file ='main.cpp', line = 32, locations = 1") 90 91 self.runCmd("br co a -s python 1 -o 'print frame'") 92 self.expect("br co l 1", 93 substrs = [ "Breakpoint 1:", 94 "Breakpoint commands:", 95 "print frame" ]) 96 97 self.runCmd("br co del 1") 98 self.expect("breakpoint command list 1", 99 startstr = "Breakpoint 1 does not have an associated command.") 100 101 self.expect("br di", 102 startstr = 'All breakpoints disabled. (3 breakpoints)') 103 104 self.expect("bre e", 105 startstr = "All breakpoints enabled. (3 breakpoints)") 106 107 self.expect("break list", 108 substrs = ["1: name = 'product', locations = 1", 109 "2: name = 'sum', locations = 1", 110 "3: file ='main.cpp', line = 32, locations = 1"]) 111 self.expect("br cl -l 32 -f main.cpp", 112 startstr = "1 breakpoints cleared:", 113 substrs = ["3: file ='main.cpp', line = 32, locations = 1"]) 114 115 # Add a future to terminate the current process being debugged. 116 # 117 # The test framework relies on detecting either "run" or "process launch" 118 # command to automatically kill the inferior upon tear down. 119 # But we'll be using "pro la" command to launch the inferior. 120 self.addTearDownHook(lambda: self.runCmd("process kill")) 121 self.expect("pro la", 122 patterns = [ "Process .* launched: "]) 123 124 self.expect("pro st", 125 patterns = [ "Process .* stopped", 126 "thread #1:", 127 "a.out", 128 "sum\(int, int\)", 129 "at main.cpp\:25", 130 "stop reason = breakpoint 2.1" ]) 131 132 # ARCH, if not specified, defaults to x86_64. 133 if self.getArchitecture() in ["", 'x86_64', 'i386']: 134 self.expect("dis -f", 135 startstr = "a.out`sum(int, int)", 136 substrs = [' push', 137 ' mov', 138 ' addl ', 139 'ret'], 140 patterns = ['(leave|popq|popl)']) 141 142 self.expect("i d l main.cpp", 143 patterns = ["Line table for .*main.cpp in `a.out"]) 144 145 self.expect("i d se", 146 patterns = ["Dumping sections for [0-9]+ modules."]) 147 148 self.expect("i d symf", 149 patterns = ["Dumping debug symbols for [0-9]+ modules."]) 150 151 self.expect("i d symt", 152 patterns = ["Dumping symbol table for [0-9]+ modules."]) 153 154 self.expect("i li", 155 substrs = [ 'a.out', 156 '/usr/lib/dyld', 157 '/usr/lib/libstdc++', 158 '/usr/lib/libSystem.B.dylib', 159 '/usr/lib/system/libmathCommon.A.dylib']) 160 161 162if __name__ == '__main__': 163 import atexit 164 lldb.SBDebugger.Initialize() 165 atexit.register(lambda: lldb.SBDebugger.Terminate()) 166 unittest2.main() 167 168