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