Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test SBThread APIs. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 8 | from lldbutil import get_stopped_thread, get_caller_symbol |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 9 | from lldbtest import * |
| 10 | |
| 11 | class ThreadAPITestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("python_api", "thread") |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 16 | @python_api_test |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 17 | def test_get_process_with_dsym(self): |
| 18 | """Test Python SBThread.GetProcess() API.""" |
| 19 | self.buildDsym() |
| 20 | self.get_process() |
| 21 | |
| 22 | @python_api_test |
| 23 | def test_get_process_with_dwarf(self): |
| 24 | """Test Python SBThread.GetProcess() API.""" |
| 25 | self.buildDwarf() |
| 26 | self.get_process() |
| 27 | |
| 28 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 29 | @python_api_test |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 30 | def test_get_stop_description_with_dsym(self): |
| 31 | """Test Python SBThread.GetStopDescription() API.""" |
| 32 | self.buildDsym() |
| 33 | self.get_stop_description() |
| 34 | |
| 35 | @python_api_test |
| 36 | def test_get_stop_description_with_dwarf(self): |
| 37 | """Test Python SBThread.GetStopDescription() API.""" |
| 38 | self.buildDwarf() |
| 39 | self.get_stop_description() |
| 40 | |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 41 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 42 | @python_api_test |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 43 | def test_run_to_address_with_dsym(self): |
| 44 | """Test Python SBThread.RunToAddress() API.""" |
| 45 | # We build a different executable than the default buildDwarf() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 46 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 47 | self.buildDsym(dictionary=d) |
| 48 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 49 | self.run_to_address(self.exe_name) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 50 | |
| 51 | @python_api_test |
| 52 | def test_run_to_address_with_dwarf(self): |
| 53 | """Test Python SBThread.RunToAddress() API.""" |
| 54 | # We build a different executable than the default buildDwarf() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 55 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 56 | self.buildDwarf(dictionary=d) |
| 57 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 58 | self.run_to_address(self.exe_name) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 59 | |
| 60 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 61 | @python_api_test |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 62 | def test_step_out_of_malloc_into_function_b_with_dsym(self): |
| 63 | """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" |
| 64 | # We build a different executable than the default buildDsym() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 65 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 66 | self.buildDsym(dictionary=d) |
| 67 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 68 | self.step_out_of_malloc_into_function_b(self.exe_name) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 69 | |
| 70 | @python_api_test |
| 71 | def test_step_out_of_malloc_into_function_b_with_dwarf(self): |
| 72 | """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" |
| 73 | # We build a different executable than the default buildDwarf() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 74 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 75 | self.buildDwarf(dictionary=d) |
| 76 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 77 | self.step_out_of_malloc_into_function_b(self.exe_name) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 78 | |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 79 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | 31963ce | 2011-08-19 00:54:27 +0000 | [diff] [blame] | 80 | @expectedFailureClang |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 81 | @python_api_test |
| 82 | def test_step_over_3_times_with_dsym(self): |
| 83 | """Test Python SBThread.StepOver() API.""" |
| 84 | # We build a different executable than the default buildDsym() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 85 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 86 | self.buildDsym(dictionary=d) |
| 87 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 88 | self.step_over_3_times(self.exe_name) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 89 | |
Johnny Chen | 31963ce | 2011-08-19 00:54:27 +0000 | [diff] [blame] | 90 | @expectedFailureClang |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 91 | @python_api_test |
| 92 | def test_step_over_3_times_with_dwarf(self): |
| 93 | """Test Python SBThread.StepOver() API.""" |
| 94 | # We build a different executable than the default buildDwarf() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 95 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 96 | self.buildDwarf(dictionary=d) |
| 97 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 98 | self.step_over_3_times(self.exe_name) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 99 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 100 | def setUp(self): |
| 101 | # Call super's setUp(). |
| 102 | TestBase.setUp(self) |
Johnny Chen | 792ed4c | 2011-05-26 21:50:47 +0000 | [diff] [blame] | 103 | # Find the line number within main.cpp to break inside main(). |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 104 | self.break_line = line_number("main.cpp", "// Set break point at this line and check variable 'my_char'.") |
| 105 | # Find the line numbers within main2.cpp for step_out_of_malloc_into_function_b() and step_over_3_times(). |
| 106 | self.step_out_of_malloc = line_number("main2.cpp", "// thread step-out of malloc into function b.") |
| 107 | self.after_3_step_overs = line_number("main2.cpp", "// we should reach here after 3 step-over's.") |
| 108 | |
| 109 | # We'll use the test method name as the exe_name for executable comppiled from main2.cpp. |
| 110 | self.exe_name = self.testMethodName |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 111 | |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 112 | def get_process(self): |
| 113 | """Test Python SBThread.GetProcess() API.""" |
| 114 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 115 | |
| 116 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 117 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 118 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 119 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 120 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 121 | self.runCmd("breakpoint list") |
| 122 | |
| 123 | # Launch the process, and do not stop at the entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 124 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 125 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 126 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 127 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint") |
| 128 | self.runCmd("process status") |
| 129 | |
| 130 | proc_of_thread = thread.GetProcess() |
| 131 | #print "proc_of_thread:", proc_of_thread |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 132 | self.assertTrue(proc_of_thread.GetProcessID() == process.GetProcessID()) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 133 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 134 | def get_stop_description(self): |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 135 | """Test Python SBThread.GetStopDescription() API.""" |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 136 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 137 | |
| 138 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 139 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 140 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 141 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 142 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 143 | #self.runCmd("breakpoint list") |
| 144 | |
| 145 | # Launch the process, and do not stop at the entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 146 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 147 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 148 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 149 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint") |
| 150 | #self.runCmd("process status") |
| 151 | |
| 152 | # Due to the typemap magic (see lldb.swig), we pass in an (int)length to GetStopDescription |
| 153 | # and expect to get a Python string as the result object! |
| 154 | # The 100 is just an arbitrary number specifying the buffer size. |
| 155 | stop_description = thread.GetStopDescription(100) |
| 156 | self.expect(stop_description, exe=False, |
| 157 | startstr = 'breakpoint') |
| 158 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 159 | def step_out_of_malloc_into_function_b(self, exe_name): |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 160 | """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 161 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 162 | |
| 163 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 164 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 165 | |
| 166 | breakpoint = target.BreakpointCreateByName('malloc') |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 167 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 168 | self.runCmd("breakpoint list") |
| 169 | |
| 170 | # Launch the process, and do not stop at the entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 171 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 172 | |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 173 | while True: |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 174 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 175 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint") |
| 176 | caller_symbol = get_caller_symbol(thread) |
| 177 | #print "caller symbol of malloc:", caller_symbol |
| 178 | if not caller_symbol: |
| 179 | self.fail("Test failed: could not locate the caller symbol of malloc") |
| 180 | if caller_symbol == "b(int)": |
| 181 | break |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 182 | #self.runCmd("thread backtrace") |
| 183 | #self.runCmd("process status") |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 184 | process.Continue() |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 185 | |
| 186 | thread.StepOut() |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 187 | self.runCmd("thread backtrace") |
| 188 | #self.runCmd("process status") |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 189 | self.assertTrue(thread.GetFrameAtIndex(0).GetLineEntry().GetLine() == self.step_out_of_malloc, |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 190 | "step out of malloc into function b is successful") |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 191 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 192 | def step_over_3_times(self, exe_name): |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 193 | """Test Python SBThread.StepOver() API.""" |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 194 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 195 | |
| 196 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 197 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 198 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 199 | breakpoint = target.BreakpointCreateByLocation('main2.cpp', self.step_out_of_malloc) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 200 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 201 | self.runCmd("breakpoint list") |
| 202 | |
| 203 | # Launch the process, and do not stop at the entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 204 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 205 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 206 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 207 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 208 | # Frame #0 should be on self.step_out_of_malloc. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 209 | self.assertTrue(process.GetState() == lldb.eStateStopped) |
| 210 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 211 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition") |
| 212 | self.runCmd("thread backtrace") |
| 213 | frame0 = thread.GetFrameAtIndex(0) |
| 214 | lineEntry = frame0.GetLineEntry() |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 215 | self.assertTrue(lineEntry.GetLine() == self.step_out_of_malloc) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 216 | |
| 217 | thread.StepOver() |
| 218 | thread.StepOver() |
| 219 | thread.StepOver() |
| 220 | self.runCmd("thread backtrace") |
| 221 | |
| 222 | # Verify that we are stopped at the correct source line number in main2.cpp. |
| 223 | frame0 = thread.GetFrameAtIndex(0) |
| 224 | lineEntry = frame0.GetLineEntry() |
| 225 | self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete) |
Johnny Chen | 31963ce | 2011-08-19 00:54:27 +0000 | [diff] [blame] | 226 | # Expected failure with clang as the compiler. |
| 227 | # rdar://problem/9223880 |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 228 | self.assertTrue(lineEntry.GetLine() == self.after_3_step_overs) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 229 | |
Johnny Chen | 02028fa | 2011-06-23 21:22:01 +0000 | [diff] [blame] | 230 | def run_to_address(self, exe_name): |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 231 | """Test Python SBThread.RunToAddress() API.""" |
Johnny Chen | 02028fa | 2011-06-23 21:22:01 +0000 | [diff] [blame] | 232 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 233 | |
| 234 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 235 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 236 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 237 | breakpoint = target.BreakpointCreateByLocation('main2.cpp', self.step_out_of_malloc) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 238 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 239 | self.runCmd("breakpoint list") |
| 240 | |
| 241 | # Launch the process, and do not stop at the entry point. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 242 | process = target.LaunchSimple(None, None, os.getcwd()) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 243 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 244 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 245 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 246 | # Frame #0 should be on self.step_out_of_malloc. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 247 | self.assertTrue(process.GetState() == lldb.eStateStopped) |
| 248 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 249 | self.assertTrue(thread != None, "There should be a thread stopped due to breakpoint condition") |
| 250 | self.runCmd("thread backtrace") |
| 251 | frame0 = thread.GetFrameAtIndex(0) |
| 252 | lineEntry = frame0.GetLineEntry() |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 253 | self.assertTrue(lineEntry.GetLine() == self.step_out_of_malloc) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 254 | |
| 255 | # Get the start/end addresses for this line entry. |
| 256 | start_addr = lineEntry.GetStartAddress().GetLoadAddress(target) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 257 | end_addr = lineEntry.GetEndAddress().GetLoadAddress(target) |
Johnny Chen | c1c92a2 | 2011-04-19 20:11:58 +0000 | [diff] [blame] | 258 | if self.TraceOn(): |
| 259 | print "start addr:", hex(start_addr) |
| 260 | print "end addr:", hex(end_addr) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 261 | |
| 262 | # Disable the breakpoint. |
| 263 | self.assertTrue(target.DisableAllBreakpoints()) |
| 264 | self.runCmd("breakpoint list") |
| 265 | |
| 266 | thread.StepOver() |
| 267 | thread.StepOver() |
| 268 | thread.StepOver() |
| 269 | self.runCmd("thread backtrace") |
| 270 | |
| 271 | # Now ask SBThread to run to the address 'start_addr' we got earlier, which |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 272 | # corresponds to self.step_out_of_malloc line entry's start address. |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 273 | thread.RunToAddress(start_addr) |
| 274 | self.runCmd("process status") |
| 275 | #self.runCmd("thread backtrace") |
| 276 | |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 277 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 278 | if __name__ == '__main__': |
| 279 | import atexit |
| 280 | lldb.SBDebugger.Initialize() |
| 281 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 282 | unittest2.main() |