Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- ThreadPlanStepRange.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/ThreadPlanStepRange.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | |
| 17 | #include "lldb/lldb-private-log.h" |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 19 | #include "lldb/Breakpoint/BreakpointSite.h" |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Disassembler.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Log.h" |
| 22 | #include "lldb/Core/Stream.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/Function.h" |
| 24 | #include "lldb/Symbol/Symbol.h" |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 25 | #include "lldb/Target/ExecutionContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 26 | #include "lldb/Target/Process.h" |
| 27 | #include "lldb/Target/RegisterContext.h" |
| 28 | #include "lldb/Target/StopInfo.h" |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 29 | #include "lldb/Target/Target.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 30 | #include "lldb/Target/Thread.h" |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | |
| 33 | using namespace lldb; |
| 34 | using namespace lldb_private; |
| 35 | |
| 36 | |
| 37 | //---------------------------------------------------------------------- |
| 38 | // ThreadPlanStepRange: Step through a stack range, either stepping over or into |
| 39 | // based on the value of \a type. |
| 40 | //---------------------------------------------------------------------- |
| 41 | |
Jim Ingham | 8af1bb7 | 2011-02-08 04:27:50 +0000 | [diff] [blame] | 42 | ThreadPlanStepRange::ThreadPlanStepRange (ThreadPlanKind kind, |
| 43 | const char *name, |
| 44 | Thread &thread, |
| 45 | const AddressRange &range, |
| 46 | const SymbolContext &addr_context, |
| 47 | lldb::RunMode stop_others) : |
Jim Ingham | 5b668b5 | 2010-07-10 02:23:31 +0000 | [diff] [blame] | 48 | ThreadPlan (kind, name, thread, eVoteNoOpinion, eVoteNoOpinion), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | m_addr_context (addr_context), |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 50 | m_address_ranges (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | m_stop_others (stop_others), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | m_stack_id (), |
Greg Clayton | 54e7afa | 2010-07-09 20:39:50 +0000 | [diff] [blame] | 53 | m_no_more_plans (false), |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 54 | m_first_run_event (true), |
| 55 | m_use_fast_step(false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 56 | { |
Jim Ingham | 5e0e372 | 2013-03-13 17:58:04 +0000 | [diff] [blame] | 57 | m_use_fast_step = GetTarget().GetUseFastStepping(); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 58 | AddRange(range); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | m_stack_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
| 60 | } |
| 61 | |
| 62 | ThreadPlanStepRange::~ThreadPlanStepRange () |
| 63 | { |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 64 | ClearNextBranchBreakpoint(); |
| 65 | } |
| 66 | |
| 67 | void |
| 68 | ThreadPlanStepRange::DidPush () |
| 69 | { |
| 70 | // See if we can find a "next range" breakpoint: |
| 71 | SetNextBranchBreakpoint(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | bool |
| 75 | ThreadPlanStepRange::ValidatePlan (Stream *error) |
| 76 | { |
| 77 | return true; |
| 78 | } |
| 79 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 80 | Vote |
| 81 | ThreadPlanStepRange::ShouldReportStop (Event *event_ptr) |
| 82 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 83 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 84 | |
| 85 | const Vote vote = IsPlanComplete() ? eVoteYes : eVoteNo; |
| 86 | if (log) |
Greg Clayton | 590cce3 | 2011-01-18 21:44:45 +0000 | [diff] [blame] | 87 | log->Printf ("ThreadPlanStepRange::ShouldReportStop() returning vote %i\n", vote); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 88 | return vote; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 91 | void |
| 92 | ThreadPlanStepRange::AddRange(const AddressRange &new_range) |
| 93 | { |
| 94 | // For now I'm just adding the ranges. At some point we may want to |
| 95 | // condense the ranges if they overlap, though I don't think it is likely |
| 96 | // to be very important. |
| 97 | m_address_ranges.push_back (new_range); |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 98 | m_instruction_ranges.push_back (DisassemblerSP()); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void |
| 102 | ThreadPlanStepRange::DumpRanges(Stream *s) |
| 103 | { |
| 104 | size_t num_ranges = m_address_ranges.size(); |
| 105 | if (num_ranges == 1) |
| 106 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 107 | m_address_ranges[0].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 108 | } |
| 109 | else |
| 110 | { |
| 111 | for (size_t i = 0; i < num_ranges; i++) |
| 112 | { |
| 113 | s->PutCString("%d: "); |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 114 | m_address_ranges[i].Dump (s, m_thread.CalculateTarget().get(), Address::DumpStyleLoadAddress); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 119 | bool |
| 120 | ThreadPlanStepRange::InRange () |
| 121 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 122 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 123 | bool ret_value = false; |
| 124 | |
| 125 | lldb::addr_t pc_load_addr = m_thread.GetRegisterContext()->GetPC(); |
| 126 | |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 127 | size_t num_ranges = m_address_ranges.size(); |
| 128 | for (size_t i = 0; i < num_ranges; i++) |
| 129 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 130 | ret_value = m_address_ranges[i].ContainsLoadAddress(pc_load_addr, m_thread.CalculateTarget().get()); |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 131 | if (ret_value) |
| 132 | break; |
| 133 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 134 | |
| 135 | if (!ret_value) |
| 136 | { |
| 137 | // See if we've just stepped to another part of the same line number... |
| 138 | StackFrame *frame = m_thread.GetStackFrameAtIndex(0).get(); |
| 139 | |
| 140 | SymbolContext new_context(frame->GetSymbolContext(eSymbolContextEverything)); |
| 141 | if (m_addr_context.line_entry.IsValid() && new_context.line_entry.IsValid()) |
| 142 | { |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 143 | if (m_addr_context.line_entry.file == new_context.line_entry.file) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | { |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 145 | if (m_addr_context.line_entry.line == new_context.line_entry.line) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | { |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 147 | m_addr_context = new_context; |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 148 | AddRange(m_addr_context.line_entry.range); |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 149 | ret_value = true; |
| 150 | if (log) |
| 151 | { |
| 152 | StreamString s; |
Jim Ingham | 69f834f | 2012-09-10 23:42:44 +0000 | [diff] [blame] | 153 | m_addr_context.line_entry.Dump (&s, |
| 154 | m_thread.CalculateTarget().get(), |
| 155 | true, |
| 156 | Address::DumpStyleLoadAddress, |
| 157 | Address::DumpStyleLoadAddress, |
| 158 | true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 159 | |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 160 | log->Printf ("Step range plan stepped to another range of same line: %s", s.GetData()); |
| 161 | } |
| 162 | } |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 163 | else if (new_context.line_entry.range.GetBaseAddress().GetLoadAddress(m_thread.CalculateTarget().get()) |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 164 | != pc_load_addr) |
| 165 | { |
| 166 | // Another thing that sometimes happens here is that we step out of one line into the MIDDLE of another |
| 167 | // line. So far I mostly see this due to bugs in the debug information. |
| 168 | // But we probably don't want to be in the middle of a line range, so in that case reset the stepping |
| 169 | // range to the line we've stepped into the middle of and continue. |
| 170 | m_addr_context = new_context; |
Jim Ingham | 76e55f7 | 2011-10-15 00:24:48 +0000 | [diff] [blame] | 171 | m_address_ranges.clear(); |
| 172 | AddRange(m_addr_context.line_entry.range); |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 173 | ret_value = true; |
| 174 | if (log) |
| 175 | { |
| 176 | StreamString s; |
Jim Ingham | 69f834f | 2012-09-10 23:42:44 +0000 | [diff] [blame] | 177 | m_addr_context.line_entry.Dump (&s, |
| 178 | m_thread.CalculateTarget().get(), |
| 179 | true, |
| 180 | Address::DumpStyleLoadAddress, |
| 181 | Address::DumpStyleLoadAddress, |
| 182 | true); |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 183 | |
| 184 | log->Printf ("Step range plan stepped to the middle of new line(%d): %s, continuing to clear this line.", |
| 185 | new_context.line_entry.line, |
| 186 | s.GetData()); |
| 187 | } |
| 188 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 189 | } |
| 190 | } |
Jim Ingham | 0f4d0f3 | 2011-09-23 21:08:11 +0000 | [diff] [blame] | 191 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | } |
| 195 | |
| 196 | if (!ret_value && log) |
Daniel Malea | 5f35a4b | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 197 | log->Printf ("Step range plan out of range to 0x%" PRIx64, pc_load_addr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | |
| 199 | return ret_value; |
| 200 | } |
| 201 | |
| 202 | bool |
| 203 | ThreadPlanStepRange::InSymbol() |
| 204 | { |
| 205 | lldb::addr_t cur_pc = m_thread.GetRegisterContext()->GetPC(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 206 | if (m_addr_context.function != NULL) |
| 207 | { |
Greg Clayton | f4124de | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 208 | return m_addr_context.function->GetAddressRange().ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | } |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 210 | else if (m_addr_context.symbol) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 211 | { |
Greg Clayton | 0c31d3d | 2012-03-07 21:03:09 +0000 | [diff] [blame] | 212 | AddressRange range(m_addr_context.symbol->GetAddress(), m_addr_context.symbol->GetByteSize()); |
| 213 | return range.ContainsLoadAddress (cur_pc, m_thread.CalculateTarget().get()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 214 | } |
| 215 | return false; |
| 216 | } |
| 217 | |
| 218 | // FIXME: This should also handle inlining if we aren't going to do inlining in the |
| 219 | // main stack. |
| 220 | // |
| 221 | // Ideally we should remember the whole stack frame list, and then compare that |
| 222 | // to the current list. |
| 223 | |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 224 | lldb::FrameComparison |
| 225 | ThreadPlanStepRange::CompareCurrentFrameToStartFrame() |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 226 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 227 | FrameComparison frame_order; |
Jim Ingham | 0e81b64 | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 228 | |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 229 | StackID cur_frame_id = m_thread.GetStackFrameAtIndex(0)->GetStackID(); |
Jim Ingham | 0e81b64 | 2010-09-16 00:58:09 +0000 | [diff] [blame] | 230 | |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 231 | if (cur_frame_id == m_stack_id) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 232 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 233 | frame_order = eFrameCompareEqual; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 234 | } |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 235 | else if (cur_frame_id < m_stack_id) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 236 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 237 | frame_order = eFrameCompareYounger; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 238 | } |
| 239 | else |
| 240 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 241 | frame_order = eFrameCompareOlder; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | } |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 243 | return frame_order; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | bool |
| 247 | ThreadPlanStepRange::StopOthers () |
| 248 | { |
| 249 | if (m_stop_others == lldb::eOnlyThisThread |
| 250 | || m_stop_others == lldb::eOnlyDuringStepping) |
| 251 | return true; |
| 252 | else |
| 253 | return false; |
| 254 | } |
| 255 | |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 256 | InstructionList * |
| 257 | ThreadPlanStepRange::GetInstructionsForAddress(lldb::addr_t addr, size_t &range_index, size_t &insn_offset) |
| 258 | { |
| 259 | size_t num_ranges = m_address_ranges.size(); |
| 260 | for (size_t i = 0; i < num_ranges; i++) |
| 261 | { |
| 262 | if (m_address_ranges[i].ContainsLoadAddress(addr, &GetTarget())) |
| 263 | { |
| 264 | // Some joker added a zero size range to the stepping range... |
| 265 | if (m_address_ranges[i].GetByteSize() == 0) |
| 266 | return NULL; |
| 267 | |
| 268 | if (!m_instruction_ranges[i]) |
| 269 | { |
| 270 | //Disassemble the address range given: |
| 271 | ExecutionContext exe_ctx (m_thread.GetProcess()); |
Jim Ingham | 7d40838 | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 272 | const char *plugin_name = NULL; |
| 273 | const char *flavor = NULL; |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 274 | m_instruction_ranges[i] = Disassembler::DisassembleRange(GetTarget().GetArchitecture(), |
Jim Ingham | 7d40838 | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 275 | plugin_name, |
| 276 | flavor, |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 277 | exe_ctx, |
| 278 | m_address_ranges[i]); |
| 279 | |
| 280 | } |
| 281 | if (!m_instruction_ranges[i]) |
| 282 | return NULL; |
| 283 | else |
| 284 | { |
| 285 | // Find where we are in the instruction list as well. If we aren't at an instruction, |
| 286 | // return NULL. In this case, we're probably lost, and shouldn't try to do anything fancy. |
| 287 | |
| 288 | insn_offset = m_instruction_ranges[i]->GetInstructionList().GetIndexOfInstructionAtLoadAddress(addr, GetTarget()); |
| 289 | if (insn_offset == UINT32_MAX) |
| 290 | return NULL; |
| 291 | else |
| 292 | { |
| 293 | range_index = i; |
| 294 | return &m_instruction_ranges[i]->GetInstructionList(); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | return NULL; |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | ThreadPlanStepRange::ClearNextBranchBreakpoint() |
| 304 | { |
| 305 | if (m_next_branch_bp_sp) |
| 306 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 307 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 308 | if (log) |
| 309 | log->Printf ("Removing next branch breakpoint: %d.", m_next_branch_bp_sp->GetID()); |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 310 | GetTarget().RemoveBreakpointByID (m_next_branch_bp_sp->GetID()); |
| 311 | m_next_branch_bp_sp.reset(); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | bool |
| 316 | ThreadPlanStepRange::SetNextBranchBreakpoint () |
| 317 | { |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 318 | if (m_next_branch_bp_sp) |
| 319 | return true; |
| 320 | |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 321 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 322 | // Stepping through ranges using breakpoints doesn't work yet, but with this off we fall back to instruction |
| 323 | // single stepping. |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 324 | if (!m_use_fast_step) |
| 325 | return false; |
| 326 | |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 327 | lldb::addr_t cur_addr = GetThread().GetRegisterContext()->GetPC(); |
| 328 | // Find the current address in our address ranges, and fetch the disassembly if we haven't already: |
| 329 | size_t pc_index; |
| 330 | size_t range_index; |
| 331 | InstructionList *instructions = GetInstructionsForAddress (cur_addr, range_index, pc_index); |
| 332 | if (instructions == NULL) |
| 333 | return false; |
| 334 | else |
| 335 | { |
| 336 | uint32_t branch_index; |
| 337 | branch_index = instructions->GetIndexOfNextBranchInstruction (pc_index); |
| 338 | |
| 339 | Address run_to_address; |
| 340 | |
| 341 | // If we didn't find a branch, run to the end of the range. |
| 342 | if (branch_index == UINT32_MAX) |
| 343 | { |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 344 | branch_index = instructions->GetSize() - 1; |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 345 | } |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 346 | |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 347 | if (branch_index - pc_index > 1) |
| 348 | { |
| 349 | const bool is_internal = true; |
| 350 | run_to_address = instructions->GetInstructionAtIndex(branch_index)->GetAddress(); |
| 351 | m_next_branch_bp_sp = GetTarget().CreateBreakpoint(run_to_address, is_internal); |
Jim Ingham | 090f831 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 352 | if (m_next_branch_bp_sp) |
| 353 | { |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 354 | if (log) |
| 355 | { |
| 356 | lldb::break_id_t bp_site_id = LLDB_INVALID_BREAK_ID; |
| 357 | BreakpointLocationSP bp_loc = m_next_branch_bp_sp->GetLocationAtIndex(0); |
| 358 | if (bp_loc) |
| 359 | { |
| 360 | BreakpointSiteSP bp_site = bp_loc->GetBreakpointSite(); |
| 361 | if (bp_site) |
| 362 | { |
| 363 | bp_site_id = bp_site->GetID(); |
| 364 | } |
| 365 | } |
| 366 | log->Printf ("ThreadPlanStepRange::SetNextBranchBreakpoint - Setting breakpoint %d (site %d) to run to address 0x%" PRIx64, |
| 367 | m_next_branch_bp_sp->GetID(), |
| 368 | bp_site_id, |
| 369 | run_to_address.GetLoadAddress(&m_thread.GetProcess()->GetTarget())); |
| 370 | } |
Jim Ingham | 090f831 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 371 | m_next_branch_bp_sp->SetThreadID(m_thread.GetID()); |
| 372 | m_next_branch_bp_sp->SetBreakpointKind ("next-branch-location"); |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 373 | return true; |
Jim Ingham | 090f831 | 2013-01-26 02:19:28 +0000 | [diff] [blame] | 374 | } |
| 375 | else |
| 376 | return false; |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | return false; |
| 380 | } |
| 381 | |
| 382 | bool |
| 383 | ThreadPlanStepRange::NextRangeBreakpointExplainsStop (lldb::StopInfoSP stop_info_sp) |
| 384 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 385 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 386 | if (!m_next_branch_bp_sp) |
| 387 | return false; |
| 388 | |
| 389 | break_id_t bp_site_id = stop_info_sp->GetValue(); |
| 390 | BreakpointSiteSP bp_site_sp = m_thread.GetProcess()->GetBreakpointSiteList().FindByID(bp_site_id); |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 391 | if (!bp_site_sp) |
| 392 | return false; |
| 393 | else if (!bp_site_sp->IsBreakpointAtThisSite (m_next_branch_bp_sp->GetID())) |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 394 | return false; |
| 395 | else |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 396 | { |
| 397 | // If we've hit the next branch breakpoint, then clear it. |
| 398 | size_t num_owners = bp_site_sp->GetNumberOfOwners(); |
| 399 | bool explains_stop = true; |
| 400 | // If all the owners are internal, then we are probably just stepping over this range from multiple threads, |
| 401 | // or multiple frames, so we want to continue. If one is not internal, then we should not explain the stop, |
| 402 | // and let the user breakpoint handle the stop. |
| 403 | for (size_t i = 0; i < num_owners; i++) |
| 404 | { |
| 405 | if (!bp_site_sp->GetOwnerAtIndex(i)->GetBreakpoint().IsInternal()) |
| 406 | { |
| 407 | explains_stop = false; |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | if (log) |
| 412 | log->Printf ("ThreadPlanStepRange::NextRangeBreakpointExplainsStop - Hit next range breakpoint which has %zu owners - explains stop: %u.", |
| 413 | num_owners, |
| 414 | explains_stop); |
| 415 | ClearNextBranchBreakpoint(); |
| 416 | return explains_stop; |
| 417 | } |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | ThreadPlanStepRange::WillStop () |
| 422 | { |
| 423 | return true; |
| 424 | } |
| 425 | |
| 426 | StateType |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 427 | ThreadPlanStepRange::GetPlanRunState () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 428 | { |
Jim Ingham | b2cf58a | 2012-03-09 04:10:47 +0000 | [diff] [blame] | 429 | if (m_next_branch_bp_sp) |
| 430 | return eStateRunning; |
| 431 | else |
| 432 | return eStateStepping; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | bool |
| 436 | ThreadPlanStepRange::MischiefManaged () |
| 437 | { |
Jim Ingham | 69f834f | 2012-09-10 23:42:44 +0000 | [diff] [blame] | 438 | // If we have pushed some plans between ShouldStop & MischiefManaged, then we're not done... |
| 439 | // I do this check first because we might have stepped somewhere that will fool InRange into |
| 440 | // thinking it needs to step past the end of that line. This happens, for instance, when stepping |
| 441 | // over inlined code that is in the middle of the current line. |
| 442 | |
| 443 | if (!m_no_more_plans) |
| 444 | return false; |
| 445 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 446 | bool done = true; |
| 447 | if (!IsPlanComplete()) |
| 448 | { |
| 449 | if (InRange()) |
| 450 | { |
| 451 | done = false; |
| 452 | } |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 453 | else |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | { |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 455 | FrameComparison frame_order = CompareCurrentFrameToStartFrame(); |
| 456 | if (frame_order != eFrameCompareOlder) |
| 457 | { |
| 458 | if (m_no_more_plans) |
| 459 | done = true; |
| 460 | else |
| 461 | done = false; |
| 462 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | else |
Jim Ingham | 441e3b9 | 2012-03-01 00:50:50 +0000 | [diff] [blame] | 464 | done = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | if (done) |
| 469 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 470 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 471 | if (log) |
| 472 | log->Printf("Completed step through range plan."); |
Jim Ingham | 3aaa2c2 | 2013-03-13 01:56:41 +0000 | [diff] [blame] | 473 | ClearNextBranchBreakpoint(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 474 | ThreadPlan::MischiefManaged (); |
| 475 | return true; |
| 476 | } |
| 477 | else |
| 478 | { |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | } |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 483 | |
| 484 | bool |
| 485 | ThreadPlanStepRange::IsPlanStale () |
| 486 | { |
Greg Clayton | 952e9dc | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 487 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 88e3de2 | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 488 | FrameComparison frame_order = CompareCurrentFrameToStartFrame(); |
| 489 | |
| 490 | if (frame_order == eFrameCompareOlder) |
| 491 | { |
| 492 | if (log) |
| 493 | { |
| 494 | log->Printf("ThreadPlanStepRange::IsPlanStale returning true, we've stepped out."); |
| 495 | } |
| 496 | return true; |
| 497 | } |
| 498 | else if (frame_order == eFrameCompareEqual && InSymbol()) |
| 499 | { |
| 500 | // If we are not in a place we should step through, we've gotten stale. |
| 501 | // One tricky bit here is that some stubs don't push a frame, so we should. |
| 502 | // check that we are in the same symbol. |
| 503 | if (!InRange()) |
| 504 | { |
| 505 | return true; |
| 506 | } |
| 507 | } |
| 508 | return false; |
| 509 | } |