Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test my first lldb watchpoint. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
Jim Ingham | 431d839 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 9 | import lldbutil |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 10 | |
| 11 | class HelloWatchpointTestCase(TestBase): |
| 12 | |
Jim Ingham | edc4ddb | 2013-02-26 22:51:48 +0000 | [diff] [blame] | 13 | def getCategories (self): |
| 14 | return ['basic_process'] |
| 15 | |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 16 | mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint") |
| 17 | |
Johnny Chen | a3ed7d8 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 18 | @dsym_test |
Johnny Chen | 55a2d5a | 2012-01-30 21:46:17 +0000 | [diff] [blame] | 19 | def test_hello_watchpoint_with_dsym_using_watchpoint_set(self): |
| 20 | """Test a simple sequence of watchpoint creation and watchpoint hit.""" |
| 21 | self.buildDsym(dictionary=self.d) |
| 22 | self.setTearDownCleanup(dictionary=self.d) |
Johnny Chen | 2b05e29 | 2012-02-14 22:00:40 +0000 | [diff] [blame] | 23 | self.hello_watchpoint() |
Johnny Chen | 55a2d5a | 2012-01-30 21:46:17 +0000 | [diff] [blame] | 24 | |
Ed Maste | 3bf526a | 2013-07-25 17:23:10 +0000 | [diff] [blame^] | 25 | @expectedFailureFreeBSD('llvm.org/pr16706') # Watchpoints fail on FreeBSD |
Johnny Chen | a3ed7d8 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 26 | @dwarf_test |
Johnny Chen | 55a2d5a | 2012-01-30 21:46:17 +0000 | [diff] [blame] | 27 | def test_hello_watchpoint_with_dwarf_using_watchpoint_set(self): |
| 28 | """Test a simple sequence of watchpoint creation and watchpoint hit.""" |
| 29 | self.buildDwarf(dictionary=self.d) |
| 30 | self.setTearDownCleanup(dictionary=self.d) |
Johnny Chen | 2b05e29 | 2012-02-14 22:00:40 +0000 | [diff] [blame] | 31 | self.hello_watchpoint() |
Johnny Chen | 55a2d5a | 2012-01-30 21:46:17 +0000 | [diff] [blame] | 32 | |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 33 | def setUp(self): |
| 34 | # Call super's setUp(). |
| 35 | TestBase.setUp(self) |
| 36 | # Our simple source filename. |
| 37 | self.source = 'main.c' |
| 38 | # Find the line number to break inside main(). |
| 39 | self.line = line_number(self.source, '// Set break point at this line.') |
Johnny Chen | 10b12b3 | 2011-09-16 21:41:42 +0000 | [diff] [blame] | 40 | # And the watchpoint variable declaration line number. |
| 41 | self.decl = line_number(self.source, '// Watchpoint variable declaration.') |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 42 | # Build dictionary to have unique executable names for each test method. |
| 43 | self.exe_name = self.testMethodName |
| 44 | self.d = {'C_SOURCES': self.source, 'EXE': self.exe_name} |
| 45 | |
Johnny Chen | 2b05e29 | 2012-02-14 22:00:40 +0000 | [diff] [blame] | 46 | def hello_watchpoint(self): |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 47 | """Test a simple sequence of watchpoint creation and watchpoint hit.""" |
| 48 | exe = os.path.join(os.getcwd(), self.exe_name) |
| 49 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 50 | |
| 51 | # Add a breakpoint to set a watchpoint when stopped on the breakpoint. |
Jim Ingham | 431d839 | 2012-09-22 00:05:11 +0000 | [diff] [blame] | 52 | lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1) |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 53 | |
| 54 | # Run the program. |
| 55 | self.runCmd("run", RUN_SUCCEEDED) |
| 56 | |
| 57 | # We should be stopped again due to the breakpoint. |
| 58 | # The stop reason of the thread should be breakpoint. |
| 59 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT, |
| 60 | substrs = ['stopped', |
| 61 | 'stop reason = breakpoint']) |
| 62 | |
| 63 | # Now let's set a write-type watchpoint for 'global'. |
| 64 | # There should be only one watchpoint hit (see main.c). |
Johnny Chen | 2b05e29 | 2012-02-14 22:00:40 +0000 | [diff] [blame] | 65 | self.expect("watchpoint set variable -w write global", WATCHPOINT_CREATED, |
| 66 | substrs = ['Watchpoint created', 'size = 4', 'type = w', |
| 67 | '%s:%d' % (self.source, self.decl)]) |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 68 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 69 | # Use the '-v' option to do verbose listing of the watchpoint. |
| 70 | # The hit count should be 0 initially. |
| 71 | self.expect("watchpoint list -v", |
| 72 | substrs = ['hit_count = 0']) |
| 73 | |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 74 | self.runCmd("process continue") |
| 75 | |
| 76 | # We should be stopped again due to the watchpoint (write type), but |
| 77 | # only once. The stop reason of the thread should be watchpoint. |
| 78 | self.expect("thread list", STOPPED_DUE_TO_WATCHPOINT, |
| 79 | substrs = ['stopped', |
| 80 | 'stop reason = watchpoint']) |
| 81 | |
| 82 | self.runCmd("process continue") |
| 83 | # Don't expect the read of 'global' to trigger a stop exception. |
| 84 | # The process status should be 'exited'. |
| 85 | self.expect("process status", |
| 86 | substrs = ['exited']) |
| 87 | |
Johnny Chen | 01acfa7 | 2011-09-22 18:04:58 +0000 | [diff] [blame] | 88 | # Use the '-v' option to do verbose listing of the watchpoint. |
| 89 | # The hit count should now be 1. |
| 90 | self.expect("watchpoint list -v", |
| 91 | substrs = ['hit_count = 1']) |
| 92 | |
Johnny Chen | 58c66e2 | 2011-09-15 21:09:59 +0000 | [diff] [blame] | 93 | |
| 94 | if __name__ == '__main__': |
| 95 | import atexit |
| 96 | lldb.SBDebugger.Initialize() |
| 97 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 98 | unittest2.main() |