TestWatchpointSetErrorCases.py revision e4b5ec026712d56f3cc259900f13158c47cb4d73
1""" 2Test error cases for the 'watchpoint set' command to make sure it errors out when necessary. 3""" 4 5import os, time 6import unittest2 7import lldb 8from lldbtest import * 9 10class WatchpointSetErrorTestCase(TestBase): 11 12 mydir = os.path.join("functionalities", "watchpoint", "watchpoint_set_command") 13 14 def test_error_cases_with_watchpoint_set(self): 15 """Test error cases with the 'watchpoint set' command.""" 16 self.buildDwarf(dictionary=self.d) 17 self.setTearDownCleanup(dictionary=self.d) 18 self.error_cases_with_watchpoint_set() 19 20 def setUp(self): 21 # Call super's setUp(). 22 TestBase.setUp(self) 23 # Our simple source filename. 24 self.source = 'main.cpp' 25 # Find the line number to break inside main(). 26 self.line = line_number(self.source, '// Set break point at this line.') 27 # Build dictionary to have unique executable names for each test method. 28 self.exe_name = self.testMethodName 29 self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name} 30 31 def error_cases_with_watchpoint_set(self): 32 """Test error cases with the 'watchpoint set' command.""" 33 exe = os.path.join(os.getcwd(), self.exe_name) 34 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 35 36 # Add a breakpoint to set a watchpoint when stopped on the breakpoint. 37 self.expect("breakpoint set -l %d" % self.line, BREAKPOINT_CREATED, 38 startstr = "Breakpoint created: 1: file ='%s', line = %d, locations = 1" % 39 (self.source, self.line)) 40 41 # Run the program. 42 self.runCmd("run", RUN_SUCCEEDED) 43 44 # We should be stopped again due to the breakpoint. 45 # The stop reason of the thread should be breakpoint. 46 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, 47 substrs = ['stopped', 48 'stop reason = breakpoint']) 49 50 # Try some error conditions: 51 52 # 'watchpoint set' is now a multiword command. 53 self.expect("watchpoint set", 54 substrs = ['The following subcommands are supported:', 55 'expression', 56 'variable']) 57 self.runCmd("watchpoint set variable -w read_write", check=False) 58 59 # 'watchpoint set expression' with '-w' or '-x' specified now needs 60 # an option terminator and a raw expression after that. 61 self.expect("watchpoint set expression -w write --", error=True, 62 startstr = 'error: required argument missing; specify an expression to evaulate into the addres to watch for') 63 64 # It's an error if the expression did not evaluate to an address. 65 self.expect("watchpoint set expression MyAggregateDataType", error=True, 66 startstr = 'error: expression did not evaluate to an address') 67 68 # Check for missing option terminator '--'. 69 self.expect("watchpoint set expression -w write -x 1 g_char_ptr", error=True, 70 startstr = 'error: did you forget to enter the option terminator string "--"?') 71 72 # Wrong size parameter is an error. 73 self.expect("watchpoint set variable -x -128", error=True, 74 substrs = ['invalid enumeration value']) 75 76 77if __name__ == '__main__': 78 import atexit 79 lldb.SBDebugger.Initialize() 80 atexit.register(lambda: lldb.SBDebugger.Terminate()) 81 unittest2.main() 82