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