blob: 4a65baad5e41669e5babc306e694cc2e834fcc2b [file] [log] [blame]
Johnny Chen58c66e22011-09-15 21:09:59 +00001"""
2Test my first lldb watchpoint.
3"""
4
5import os, time
6import unittest2
7import lldb
8from lldbtest import *
Jim Ingham431d8392012-09-22 00:05:11 +00009import lldbutil
Johnny Chen58c66e22011-09-15 21:09:59 +000010
11class HelloWatchpointTestCase(TestBase):
12
Jim Inghamedc4ddb2013-02-26 22:51:48 +000013 def getCategories (self):
14 return ['basic_process']
15
Johnny Chen58c66e22011-09-15 21:09:59 +000016 mydir = os.path.join("functionalities", "watchpoint", "hello_watchpoint")
17
Johnny Chena3ed7d82012-04-06 00:56:05 +000018 @dsym_test
Johnny Chen55a2d5a2012-01-30 21:46:17 +000019 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 Chen2b05e292012-02-14 22:00:40 +000023 self.hello_watchpoint()
Johnny Chen55a2d5a2012-01-30 21:46:17 +000024
Ed Maste3bf526a2013-07-25 17:23:10 +000025 @expectedFailureFreeBSD('llvm.org/pr16706') # Watchpoints fail on FreeBSD
Johnny Chena3ed7d82012-04-06 00:56:05 +000026 @dwarf_test
Johnny Chen55a2d5a2012-01-30 21:46:17 +000027 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 Chen2b05e292012-02-14 22:00:40 +000031 self.hello_watchpoint()
Johnny Chen55a2d5a2012-01-30 21:46:17 +000032
Johnny Chen58c66e22011-09-15 21:09:59 +000033 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 Chen10b12b32011-09-16 21:41:42 +000040 # And the watchpoint variable declaration line number.
41 self.decl = line_number(self.source, '// Watchpoint variable declaration.')
Johnny Chen58c66e22011-09-15 21:09:59 +000042 # 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 Chen2b05e292012-02-14 22:00:40 +000046 def hello_watchpoint(self):
Johnny Chen58c66e22011-09-15 21:09:59 +000047 """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 Ingham431d8392012-09-22 00:05:11 +000052 lldbutil.run_break_set_by_file_and_line (self, None, self.line, num_expected_locations=1)
Johnny Chen58c66e22011-09-15 21:09:59 +000053
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 Chen2b05e292012-02-14 22:00:40 +000065 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 Chen58c66e22011-09-15 21:09:59 +000068
Johnny Chen01acfa72011-09-22 18:04:58 +000069 # 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 Chen58c66e22011-09-15 21:09:59 +000074 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 Chen01acfa72011-09-22 18:04:58 +000088 # 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 Chen58c66e22011-09-15 21:09:59 +000093
94if __name__ == '__main__':
95 import atexit
96 lldb.SBDebugger.Initialize()
97 atexit.register(lambda: lldb.SBDebugger.Terminate())
98 unittest2.main()