Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanStepOut.cpp -----------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Breakpoint/Breakpoint.h" |
| 17 | #include "lldb/lldb-private-log.h" |
| 18 | #include "lldb/Core/Log.h" |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 19 | #include "lldb/Core/Value.h" |
| 20 | #include "lldb/Core/ValueObjectConstResult.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Process.h" |
| 22 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StopInfo.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 25 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace lldb; |
| 28 | using namespace lldb_private; |
| 29 | |
| 30 | //---------------------------------------------------------------------- |
| 31 | // ThreadPlanStepOut: Step out of the current frame |
| 32 | //---------------------------------------------------------------------- |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 33 | ThreadPlanStepOut::ThreadPlanStepOut |
| 34 | ( |
| 35 | Thread &thread, |
| 36 | SymbolContext *context, |
| 37 | bool first_insn, |
| 38 | bool stop_others, |
| 39 | Vote stop_vote, |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 40 | Vote run_vote, |
| 41 | uint32_t frame_idx |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 42 | ) : |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 43 | ThreadPlan (ThreadPlan::eKindStepOut, "Step out", thread, stop_vote, run_vote), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 44 | m_step_from_context (context), |
| 45 | m_step_from_insn (LLDB_INVALID_ADDRESS), |
Benjamin Kramer | 36a0810 | 2010-07-16 12:32:33 +0000 | [diff] [blame] | 46 | m_return_bp_id (LLDB_INVALID_BREAK_ID), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 47 | m_return_addr (LLDB_INVALID_ADDRESS), |
| 48 | m_first_insn (first_insn), |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 49 | m_stop_others (stop_others), |
| 50 | m_step_through_inline_plan_sp(), |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 51 | m_step_out_plan_sp (), |
| 52 | m_immediate_step_from_function(NULL) |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 53 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 54 | { |
| 55 | m_step_from_insn = m_thread.GetRegisterContext()->GetPC(0); |
| 56 | |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 57 | StackFrameSP return_frame_sp (m_thread.GetStackFrameAtIndex(frame_idx + 1)); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 58 | StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (frame_idx)); |
| 59 | |
Sean Callanan | cebfad1 | 2012-03-13 16:34:56 +0000 | [diff] [blame] | 60 | if (!return_frame_sp || !immediate_return_from_sp) |
| 61 | return; // we can't do anything here. ValidatePlan() will return false. |
| 62 | |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 63 | m_step_out_to_id = return_frame_sp->GetStackID(); |
| 64 | m_immediate_step_from_id = immediate_return_from_sp->GetStackID(); |
| 65 | |
| 66 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 67 | |
| 68 | // If the frame directly below the one we are returning to is inlined, we have to be |
| 69 | // a little more careful. It is non-trivial to determine the real "return code address" for |
| 70 | // an inlined frame, so we have to work our way to that frame and then step out. |
| 71 | if (immediate_return_from_sp && immediate_return_from_sp->IsInlined()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 73 | if (frame_idx > 0) |
| 74 | { |
| 75 | // First queue a plan that gets us to this inlined frame, and when we get there we'll queue a second |
| 76 | // plan that walks us out of this frame. |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 77 | m_step_out_plan_sp.reset (new ThreadPlanStepOut(m_thread, |
| 78 | NULL, |
| 79 | false, |
| 80 | stop_others, |
| 81 | eVoteNoOpinion, |
| 82 | eVoteNoOpinion, |
| 83 | frame_idx - 1)); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 84 | } |
| 85 | else |
| 86 | { |
| 87 | // If we're already at the inlined frame we're stepping through, then just do that now. |
| 88 | QueueInlinedStepPlan(false); |
| 89 | } |
| 90 | |
| 91 | } |
| 92 | else if (return_frame_sp) |
| 93 | { |
| 94 | // Find the return address and set a breakpoint there: |
| 95 | // FIXME - can we do this more securely if we know first_insn? |
| 96 | |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 97 | m_return_addr = return_frame_sp->GetFrameCodeAddress().GetLoadAddress(&m_thread.GetProcess()->GetTarget()); |
| 98 | Breakpoint *return_bp = m_thread.CalculateTarget()->CreateBreakpoint (m_return_addr, true).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 99 | if (return_bp != NULL) |
| 100 | { |
| 101 | return_bp->SetThreadID(m_thread.GetID()); |
| 102 | m_return_bp_id = return_bp->GetID(); |
| 103 | } |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 104 | |
| 105 | if (immediate_return_from_sp) |
| 106 | { |
| 107 | const SymbolContext &sc = immediate_return_from_sp->GetSymbolContext(eSymbolContextFunction); |
| 108 | if (sc.function) |
| 109 | { |
| 110 | m_immediate_step_from_function = sc.function; |
| 111 | } |
| 112 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void |
| 118 | ThreadPlanStepOut::DidPush() |
| 119 | { |
| 120 | if (m_step_out_plan_sp) |
| 121 | m_thread.QueueThreadPlan(m_step_out_plan_sp, false); |
| 122 | else if (m_step_through_inline_plan_sp) |
| 123 | m_thread.QueueThreadPlan(m_step_through_inline_plan_sp, false); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | ThreadPlanStepOut::~ThreadPlanStepOut () |
| 127 | { |
| 128 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 129 | m_thread.CalculateTarget()->RemoveBreakpointByID(m_return_bp_id); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | void |
| 133 | ThreadPlanStepOut::GetDescription (Stream *s, lldb::DescriptionLevel level) |
| 134 | { |
| 135 | if (level == lldb::eDescriptionLevelBrief) |
| 136 | s->Printf ("step out"); |
| 137 | else |
| 138 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 139 | if (m_step_out_plan_sp) |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 140 | s->Printf ("Stepping out to inlined frame so we can walk through it."); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 141 | else if (m_step_through_inline_plan_sp) |
| 142 | s->Printf ("Stepping out by stepping through inlined function."); |
| 143 | else |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 144 | s->Printf ("Stepping out from address 0x%llx to return address 0x%llx using breakpoint site %d", |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 145 | (uint64_t)m_step_from_insn, |
| 146 | (uint64_t)m_return_addr, |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 147 | m_return_bp_id); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
| 151 | bool |
| 152 | ThreadPlanStepOut::ValidatePlan (Stream *error) |
| 153 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 154 | if (m_step_out_plan_sp) |
| 155 | return m_step_out_plan_sp->ValidatePlan (error); |
| 156 | else if (m_step_through_inline_plan_sp) |
| 157 | return m_step_through_inline_plan_sp->ValidatePlan (error); |
| 158 | else if (m_return_bp_id == LLDB_INVALID_BREAK_ID) |
| 159 | { |
| 160 | error->PutCString("Could not create return address breakpoint."); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | return false; |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 162 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | else |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | bool |
| 168 | ThreadPlanStepOut::PlanExplainsStop () |
| 169 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 170 | // If one of our child plans just finished, then we do explain the stop. |
| 171 | if (m_step_out_plan_sp) |
| 172 | { |
| 173 | if (m_step_out_plan_sp->MischiefManaged()) |
| 174 | { |
| 175 | // If this one is done, then we are all done. |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 176 | CalculateReturnValue(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 177 | SetPlanComplete(); |
| 178 | return true; |
| 179 | } |
| 180 | else |
| 181 | return false; |
| 182 | } |
| 183 | else if (m_step_through_inline_plan_sp) |
| 184 | { |
| 185 | if (m_step_through_inline_plan_sp->MischiefManaged()) |
| 186 | return true; |
| 187 | else |
| 188 | return false; |
| 189 | } |
| 190 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | // We don't explain signals or breakpoints (breakpoints that handle stepping in or |
| 192 | // out will be handled by a child plan. |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 193 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 194 | StopInfoSP stop_info_sp = GetPrivateStopReason(); |
| 195 | if (stop_info_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 196 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 197 | StopReason reason = stop_info_sp->GetStopReason(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | switch (reason) |
| 199 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 200 | case eStopReasonBreakpoint: |
| 201 | { |
| 202 | // If this is OUR breakpoint, we're fine, otherwise we don't know why this happened... |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 203 | BreakpointSiteSP site_sp (m_thread.GetProcess()->GetBreakpointSiteList().FindByID (stop_info_sp->GetValue())); |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 204 | if (site_sp && site_sp->IsBreakpointAtThisSite (m_return_bp_id)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 206 | bool done; |
| 207 | |
| 208 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
| 209 | |
| 210 | if (m_step_out_to_id == frame_zero_id) |
| 211 | done = true; |
| 212 | else if (m_step_out_to_id < frame_zero_id) |
| 213 | { |
| 214 | // Either we stepped past the breakpoint, or the stack ID calculation |
| 215 | // was incorrect and we should probably stop. |
| 216 | done = true; |
| 217 | } |
| 218 | else |
| 219 | { |
| 220 | if (m_immediate_step_from_id < frame_zero_id) |
| 221 | done = true; |
| 222 | else |
| 223 | done = false; |
| 224 | } |
| 225 | |
| 226 | if (done) |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 227 | { |
| 228 | CalculateReturnValue(); |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 229 | SetPlanComplete(); |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 230 | } |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 231 | |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 232 | // If there was only one owner, then we're done. But if we also hit some |
| 233 | // user breakpoint on our way out, we should mark ourselves as done, but |
| 234 | // also not claim to explain the stop, since it is more important to report |
| 235 | // the user breakpoint than the step out completion. |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 237 | if (site_sp->GetNumberOfOwners() == 1) |
| 238 | return true; |
| 239 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 240 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 241 | return false; |
| 242 | } |
| 243 | case eStopReasonWatchpoint: |
| 244 | case eStopReasonSignal: |
| 245 | case eStopReasonException: |
| 246 | return false; |
| 247 | |
| 248 | default: |
| 249 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | return true; |
| 253 | } |
| 254 | |
| 255 | bool |
| 256 | ThreadPlanStepOut::ShouldStop (Event *event_ptr) |
| 257 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 258 | if (IsPlanComplete()) |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 259 | return true; |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 260 | |
| 261 | bool done; |
| 262 | |
| 263 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
| 264 | if (frame_zero_id < m_step_out_to_id) |
| 265 | done = false; |
| 266 | else |
| 267 | done = true; |
| 268 | |
| 269 | if (done) |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 270 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 271 | CalculateReturnValue(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 272 | SetPlanComplete(); |
| 273 | return true; |
| 274 | } |
| 275 | else |
| 276 | { |
| 277 | if (m_step_out_plan_sp) |
| 278 | { |
| 279 | if (m_step_out_plan_sp->MischiefManaged()) |
| 280 | { |
| 281 | // Now step through the inlined stack we are in: |
| 282 | if (QueueInlinedStepPlan(true)) |
| 283 | { |
| 284 | return false; |
| 285 | } |
| 286 | else |
| 287 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 288 | CalculateReturnValue(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 289 | SetPlanComplete (); |
| 290 | return true; |
| 291 | } |
| 292 | } |
| 293 | else |
| 294 | return m_step_out_plan_sp->ShouldStop(event_ptr); |
| 295 | } |
| 296 | else if (m_step_through_inline_plan_sp) |
| 297 | { |
| 298 | if (m_step_through_inline_plan_sp->MischiefManaged()) |
| 299 | { |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 300 | // We don't calculate the return value here because we don't know how to. |
| 301 | // But in case we had a return value sitting around from our process in |
| 302 | // getting here, let's clear it out. |
| 303 | m_return_valobj_sp.reset(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 304 | SetPlanComplete(); |
| 305 | return true; |
| 306 | } |
| 307 | else |
| 308 | return m_step_through_inline_plan_sp->ShouldStop(event_ptr); |
| 309 | } |
| 310 | else |
| 311 | return false; |
| 312 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | bool |
| 316 | ThreadPlanStepOut::StopOthers () |
| 317 | { |
| 318 | return m_stop_others; |
| 319 | } |
| 320 | |
| 321 | StateType |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 322 | ThreadPlanStepOut::GetPlanRunState () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 323 | { |
| 324 | return eStateRunning; |
| 325 | } |
| 326 | |
| 327 | bool |
| 328 | ThreadPlanStepOut::WillResume (StateType resume_state, bool current_plan) |
| 329 | { |
| 330 | ThreadPlan::WillResume (resume_state, current_plan); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 331 | if (m_step_out_plan_sp || m_step_through_inline_plan_sp) |
| 332 | return true; |
| 333 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | if (m_return_bp_id == LLDB_INVALID_BREAK_ID) |
| 335 | return false; |
| 336 | |
| 337 | if (current_plan) |
| 338 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 339 | Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | if (return_bp != NULL) |
| 341 | return_bp->SetEnabled (true); |
| 342 | } |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | bool |
| 347 | ThreadPlanStepOut::WillStop () |
| 348 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 349 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
| 350 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 351 | Breakpoint *return_bp = m_thread.CalculateTarget()->GetBreakpointByID(m_return_bp_id).get(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 352 | if (return_bp != NULL) |
| 353 | return_bp->SetEnabled (false); |
| 354 | } |
| 355 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | return true; |
| 357 | } |
| 358 | |
| 359 | bool |
| 360 | ThreadPlanStepOut::MischiefManaged () |
| 361 | { |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 362 | if (IsPlanComplete()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 363 | { |
| 364 | // Did I reach my breakpoint? If so I'm done. |
| 365 | // |
| 366 | // I also check the stack depth, since if we've blown past the breakpoint for some |
| 367 | // reason and we're now stopping for some other reason altogether, then we're done |
| 368 | // with this step out operation. |
| 369 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 370 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | if (log) |
| 372 | log->Printf("Completed step out plan."); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 373 | if (m_return_bp_id != LLDB_INVALID_BREAK_ID) |
| 374 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 375 | m_thread.CalculateTarget()->RemoveBreakpointByID (m_return_bp_id); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 376 | m_return_bp_id = LLDB_INVALID_BREAK_ID; |
| 377 | } |
| 378 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 379 | ThreadPlan::MischiefManaged (); |
| 380 | return true; |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | } |
| 387 | |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 388 | bool |
| 389 | ThreadPlanStepOut::QueueInlinedStepPlan (bool queue_now) |
| 390 | { |
| 391 | // Now figure out the range of this inlined block, and set up a "step through range" |
| 392 | // plan for that. If we've been provided with a context, then use the block in that |
| 393 | // context. |
| 394 | StackFrameSP immediate_return_from_sp (m_thread.GetStackFrameAtIndex (0)); |
| 395 | if (!immediate_return_from_sp) |
| 396 | return false; |
| 397 | |
| 398 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
| 399 | if (log) |
| 400 | { |
| 401 | StreamString s; |
| 402 | immediate_return_from_sp->Dump(&s, true, false); |
| 403 | log->Printf("Queuing inlined frame to step past: %s.", s.GetData()); |
| 404 | } |
| 405 | |
| 406 | Block *from_block = immediate_return_from_sp->GetFrameBlock(); |
| 407 | if (from_block) |
| 408 | { |
| 409 | Block *inlined_block = from_block->GetContainingInlinedBlock(); |
| 410 | if (inlined_block) |
| 411 | { |
| 412 | size_t num_ranges = inlined_block->GetNumRanges(); |
| 413 | AddressRange inline_range; |
| 414 | if (inlined_block->GetRangeAtIndex(0, inline_range)) |
| 415 | { |
| 416 | SymbolContext inlined_sc; |
| 417 | inlined_block->CalculateSymbolContext(&inlined_sc); |
Jim Ingham | c3ba2af | 2012-07-26 18:23:21 +0000 | [diff] [blame] | 418 | inlined_sc.target_sp = GetTarget().shared_from_this(); |
Jim Ingham | 43d3906 | 2011-10-15 00:57:28 +0000 | [diff] [blame] | 419 | RunMode run_mode = m_stop_others ? lldb::eOnlyThisThread : lldb::eAllThreads; |
| 420 | ThreadPlanStepOverRange *step_through_inline_plan_ptr = new ThreadPlanStepOverRange(m_thread, |
| 421 | inline_range, |
| 422 | inlined_sc, |
| 423 | run_mode); |
| 424 | step_through_inline_plan_ptr->SetOkayToDiscard(true); |
| 425 | StreamString errors; |
| 426 | if (!step_through_inline_plan_ptr->ValidatePlan(&errors)) |
| 427 | { |
| 428 | //FIXME: Log this failure. |
| 429 | delete step_through_inline_plan_ptr; |
| 430 | return false; |
| 431 | } |
| 432 | |
| 433 | for (size_t i = 1; i < num_ranges; i++) |
| 434 | { |
| 435 | if (inlined_block->GetRangeAtIndex (i, inline_range)) |
| 436 | step_through_inline_plan_ptr->AddRange (inline_range); |
| 437 | } |
| 438 | m_step_through_inline_plan_sp.reset (step_through_inline_plan_ptr); |
| 439 | if (queue_now) |
| 440 | m_thread.QueueThreadPlan (m_step_through_inline_plan_sp, false); |
| 441 | return true; |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | return false; |
| 447 | } |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 448 | |
| 449 | void |
| 450 | ThreadPlanStepOut::CalculateReturnValue () |
| 451 | { |
| 452 | if (m_return_valobj_sp) |
| 453 | return; |
| 454 | |
| 455 | if (m_immediate_step_from_function != NULL) |
| 456 | { |
| 457 | Type *return_type = m_immediate_step_from_function->GetType(); |
| 458 | lldb::clang_type_t return_clang_type = m_immediate_step_from_function->GetReturnClangType(); |
| 459 | if (return_type && return_clang_type) |
| 460 | { |
| 461 | ClangASTType ast_type (return_type->GetClangAST(), return_clang_type); |
| 462 | |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 463 | lldb::ABISP abi_sp = m_thread.GetProcess()->GetABI(); |
Jim Ingham | 1586d97 | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 464 | if (abi_sp) |
| 465 | { |
| 466 | m_return_valobj_sp = abi_sp->GetReturnValueObject(m_thread, ast_type); |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | } |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 471 | |
| 472 | bool |
| 473 | ThreadPlanStepOut::IsPlanStale() |
| 474 | { |
| 475 | // If we are still lower on the stack than the frame we are returning to, then |
| 476 | // there's something for us to do. Otherwise, we're stale. |
| 477 | |
| 478 | StackID frame_zero_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
| 479 | if (frame_zero_id < m_step_out_to_id) |
| 480 | return false; |
| 481 | else |
| 482 | return true; |
| 483 | } |
| 484 | |