Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test SBThread APIs. |
| 3 | """ |
| 4 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 5 | import lldb_shared |
| 6 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 7 | import os, time |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 8 | import lldb |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 9 | from lldbutil import get_stopped_thread, get_caller_symbol |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 10 | from lldbtest import * |
| 11 | |
| 12 | class ThreadAPITestCase(TestBase): |
| 13 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 14 | mydir = TestBase.compute_mydir(__file__) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 15 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 16 | @python_api_test |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 17 | def test_get_process(self): |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 18 | """Test Python SBThread.GetProcess() API.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 19 | self.build() |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 20 | self.get_process() |
| 21 | |
| 22 | @python_api_test |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 23 | def test_get_stop_description(self): |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 24 | """Test Python SBThread.GetStopDescription() API.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 25 | self.build() |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 26 | self.get_stop_description() |
| 27 | |
| 28 | @python_api_test |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 29 | def test_run_to_address(self): |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 30 | """Test Python SBThread.RunToAddress() API.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 31 | # We build a different executable than the default build() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 32 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 33 | self.build(dictionary=d) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 34 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 35 | self.run_to_address(self.exe_name) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 36 | |
| 37 | @python_api_test |
Ed Maste | 362f5de | 2014-08-01 17:04:31 +0000 | [diff] [blame] | 38 | @expectedFailureFreeBSD # llvm.org/pr20476 |
Zachary Turner | 4a58dd3 | 2015-09-16 18:08:33 +0000 | [diff] [blame] | 39 | @expectedFailureWindows # Test crashes |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 40 | def test_step_out_of_malloc_into_function_b(self): |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 41 | """Test Python SBThread.StepOut() API to step out of a malloc call where the call site is at function b().""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 42 | # We build a different executable than the default build() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 43 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 44 | self.build(dictionary=d) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 45 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 46 | self.step_out_of_malloc_into_function_b(self.exe_name) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 47 | |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 48 | @python_api_test |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 49 | def test_step_over_3_times(self): |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 50 | """Test Python SBThread.StepOver() API.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 51 | # We build a different executable than the default build() does. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 52 | d = {'CXX_SOURCES': 'main2.cpp', 'EXE': self.exe_name} |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 53 | self.build(dictionary=d) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 54 | self.setTearDownCleanup(dictionary=d) |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 55 | self.step_over_3_times(self.exe_name) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 56 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 57 | def setUp(self): |
| 58 | # Call super's setUp(). |
| 59 | TestBase.setUp(self) |
Johnny Chen | 792ed4c | 2011-05-26 21:50:47 +0000 | [diff] [blame] | 60 | # Find the line number within main.cpp to break inside main(). |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 61 | self.break_line = line_number("main.cpp", "// Set break point at this line and check variable 'my_char'.") |
| 62 | # Find the line numbers within main2.cpp for step_out_of_malloc_into_function_b() and step_over_3_times(). |
| 63 | self.step_out_of_malloc = line_number("main2.cpp", "// thread step-out of malloc into function b.") |
| 64 | self.after_3_step_overs = line_number("main2.cpp", "// we should reach here after 3 step-over's.") |
| 65 | |
| 66 | # We'll use the test method name as the exe_name for executable comppiled from main2.cpp. |
| 67 | self.exe_name = self.testMethodName |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 68 | |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 69 | def get_process(self): |
| 70 | """Test Python SBThread.GetProcess() API.""" |
| 71 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 72 | |
| 73 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 74 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 75 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 76 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 77 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 78 | self.runCmd("breakpoint list") |
| 79 | |
| 80 | # Launch the process, and do not stop at the entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 81 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 82 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 83 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Greg Clayton | 53c5ddf | 2013-03-19 17:59:30 +0000 | [diff] [blame] | 84 | self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint") |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 85 | self.runCmd("process status") |
| 86 | |
| 87 | proc_of_thread = thread.GetProcess() |
| 88 | #print "proc_of_thread:", proc_of_thread |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 89 | self.assertTrue(proc_of_thread.GetProcessID() == process.GetProcessID()) |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 90 | |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 91 | def get_stop_description(self): |
Johnny Chen | fdc94ff | 2011-03-11 01:16:03 +0000 | [diff] [blame] | 92 | """Test Python SBThread.GetStopDescription() API.""" |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 93 | exe = os.path.join(os.getcwd(), "a.out") |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 94 | |
| 95 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 96 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 97 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 98 | breakpoint = target.BreakpointCreateByLocation("main.cpp", self.break_line) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 99 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 100 | #self.runCmd("breakpoint list") |
| 101 | |
| 102 | # Launch the process, and do not stop at the entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 103 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 104 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 105 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Greg Clayton | 53c5ddf | 2013-03-19 17:59:30 +0000 | [diff] [blame] | 106 | self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint") |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 107 | #self.runCmd("process status") |
| 108 | |
| 109 | # Due to the typemap magic (see lldb.swig), we pass in an (int)length to GetStopDescription |
Johnny Chen | cdd7e8b | 2011-12-19 19:38:09 +0000 | [diff] [blame] | 110 | # and expect to get a Python string as the return object! |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 111 | # The 100 is just an arbitrary number specifying the buffer size. |
| 112 | stop_description = thread.GetStopDescription(100) |
| 113 | self.expect(stop_description, exe=False, |
| 114 | startstr = 'breakpoint') |
| 115 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 116 | def step_out_of_malloc_into_function_b(self, exe_name): |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 117 | """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] | 118 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 119 | |
| 120 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 121 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 122 | |
| 123 | breakpoint = target.BreakpointCreateByName('malloc') |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 124 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 125 | |
| 126 | # Launch the process, and do not stop at the entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 127 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 128 | |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 129 | while True: |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 130 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Greg Clayton | 53c5ddf | 2013-03-19 17:59:30 +0000 | [diff] [blame] | 131 | self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint") |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 132 | caller_symbol = get_caller_symbol(thread) |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 133 | if not caller_symbol: |
| 134 | self.fail("Test failed: could not locate the caller symbol of malloc") |
Ed Maste | 49f359a | 2014-03-07 19:02:20 +0000 | [diff] [blame] | 135 | |
| 136 | # Our top frame may be an inlined function in malloc() (e.g., on |
| 137 | # FreeBSD). Apply a simple heuristic of stepping out until we find |
| 138 | # a non-malloc caller |
| 139 | while caller_symbol.startswith("malloc"): |
| 140 | thread.StepOut() |
| 141 | self.assertTrue(thread.IsValid(), "Thread valid after stepping to outer malloc") |
| 142 | caller_symbol = get_caller_symbol(thread) |
| 143 | |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 144 | if caller_symbol == "b(int)": |
| 145 | break |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 146 | process.Continue() |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 147 | |
Tamas Berghammer | 09d74b7 | 2015-06-25 15:19:22 +0000 | [diff] [blame] | 148 | # On Linux malloc calls itself in some case. Remove the breakpoint because we don't want |
| 149 | # to hit it during step-out. |
| 150 | target.BreakpointDelete(breakpoint.GetID()) |
| 151 | |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 152 | thread.StepOut() |
Johnny Chen | d9f2c08 | 2011-03-10 19:18:04 +0000 | [diff] [blame] | 153 | self.runCmd("thread backtrace") |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 154 | self.assertTrue(thread.GetFrameAtIndex(0).GetLineEntry().GetLine() == self.step_out_of_malloc, |
Johnny Chen | a460316 | 2011-03-09 23:45:56 +0000 | [diff] [blame] | 155 | "step out of malloc into function b is successful") |
Johnny Chen | 2f6f7ba | 2011-03-07 21:28:57 +0000 | [diff] [blame] | 156 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 157 | def step_over_3_times(self, exe_name): |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 158 | """Test Python SBThread.StepOver() API.""" |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 159 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 160 | |
| 161 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 162 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 163 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 164 | breakpoint = target.BreakpointCreateByLocation('main2.cpp', self.step_out_of_malloc) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 165 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 166 | self.runCmd("breakpoint list") |
| 167 | |
| 168 | # Launch the process, and do not stop at the entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 169 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 170 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 171 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 172 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 173 | # Frame #0 should be on self.step_out_of_malloc. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 174 | self.assertTrue(process.GetState() == lldb.eStateStopped) |
| 175 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Greg Clayton | 53c5ddf | 2013-03-19 17:59:30 +0000 | [diff] [blame] | 176 | self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 177 | self.runCmd("thread backtrace") |
| 178 | frame0 = thread.GetFrameAtIndex(0) |
| 179 | lineEntry = frame0.GetLineEntry() |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 180 | self.assertTrue(lineEntry.GetLine() == self.step_out_of_malloc) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 181 | |
| 182 | thread.StepOver() |
| 183 | thread.StepOver() |
| 184 | thread.StepOver() |
| 185 | self.runCmd("thread backtrace") |
| 186 | |
| 187 | # Verify that we are stopped at the correct source line number in main2.cpp. |
| 188 | frame0 = thread.GetFrameAtIndex(0) |
| 189 | lineEntry = frame0.GetLineEntry() |
| 190 | self.assertTrue(thread.GetStopReason() == lldb.eStopReasonPlanComplete) |
Johnny Chen | 31963ce | 2011-08-19 00:54:27 +0000 | [diff] [blame] | 191 | # Expected failure with clang as the compiler. |
| 192 | # rdar://problem/9223880 |
Johnny Chen | 7da349d | 2011-09-26 19:05:08 +0000 | [diff] [blame] | 193 | # |
| 194 | # Which has been fixed on the lldb by compensating for inaccurate line |
| 195 | # table information with r140416. |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 196 | self.assertTrue(lineEntry.GetLine() == self.after_3_step_overs) |
Johnny Chen | f93286f | 2011-03-10 22:32:47 +0000 | [diff] [blame] | 197 | |
Johnny Chen | 02028fa | 2011-06-23 21:22:01 +0000 | [diff] [blame] | 198 | def run_to_address(self, exe_name): |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 199 | """Test Python SBThread.RunToAddress() API.""" |
Johnny Chen | 02028fa | 2011-06-23 21:22:01 +0000 | [diff] [blame] | 200 | exe = os.path.join(os.getcwd(), exe_name) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 201 | |
| 202 | target = self.dbg.CreateTarget(exe) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 203 | self.assertTrue(target, VALID_TARGET) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 204 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 205 | breakpoint = target.BreakpointCreateByLocation('main2.cpp', self.step_out_of_malloc) |
Johnny Chen | 4ebd019 | 2011-05-24 18:22:45 +0000 | [diff] [blame] | 206 | self.assertTrue(breakpoint, VALID_BREAKPOINT) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 207 | self.runCmd("breakpoint list") |
| 208 | |
| 209 | # Launch the process, and do not stop at the entry point. |
Greg Clayton | c694751 | 2013-12-13 19:18:59 +0000 | [diff] [blame] | 210 | process = target.LaunchSimple (None, None, self.get_process_working_directory()) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 211 | |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 212 | self.assertTrue(process, PROCESS_IS_VALID) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 213 | |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 214 | # Frame #0 should be on self.step_out_of_malloc. |
Johnny Chen | 5a0bee7 | 2011-06-15 22:14:12 +0000 | [diff] [blame] | 215 | self.assertTrue(process.GetState() == lldb.eStateStopped) |
| 216 | thread = get_stopped_thread(process, lldb.eStopReasonBreakpoint) |
Greg Clayton | 53c5ddf | 2013-03-19 17:59:30 +0000 | [diff] [blame] | 217 | self.assertTrue(thread.IsValid(), "There should be a thread stopped due to breakpoint condition") |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 218 | self.runCmd("thread backtrace") |
| 219 | frame0 = thread.GetFrameAtIndex(0) |
| 220 | lineEntry = frame0.GetLineEntry() |
Johnny Chen | b7373c9 | 2011-06-23 22:11:20 +0000 | [diff] [blame] | 221 | self.assertTrue(lineEntry.GetLine() == self.step_out_of_malloc) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 222 | |
| 223 | # Get the start/end addresses for this line entry. |
| 224 | start_addr = lineEntry.GetStartAddress().GetLoadAddress(target) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 225 | end_addr = lineEntry.GetEndAddress().GetLoadAddress(target) |
Johnny Chen | c1c92a2 | 2011-04-19 20:11:58 +0000 | [diff] [blame] | 226 | if self.TraceOn(): |
| 227 | print "start addr:", hex(start_addr) |
| 228 | print "end addr:", hex(end_addr) |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 229 | |
| 230 | # Disable the breakpoint. |
| 231 | self.assertTrue(target.DisableAllBreakpoints()) |
| 232 | self.runCmd("breakpoint list") |
| 233 | |
| 234 | thread.StepOver() |
| 235 | thread.StepOver() |
| 236 | thread.StepOver() |
| 237 | self.runCmd("thread backtrace") |
| 238 | |
| 239 | # 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] | 240 | # corresponds to self.step_out_of_malloc line entry's start address. |
Johnny Chen | 2d799cc | 2011-03-11 00:00:15 +0000 | [diff] [blame] | 241 | thread.RunToAddress(start_addr) |
| 242 | self.runCmd("process status") |
| 243 | #self.runCmd("thread backtrace") |