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