Alexander Shaposhnikov | 696bd63 | 2016-11-26 05:23:44 +0000 | [diff] [blame] | 1 | //===-- SBThreadPlan.cpp ----------------------------------------*- C++ -*-===// |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 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 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBThread.h" |
| 11 | |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBFileSpec.h" |
| 13 | #include "lldb/API/SBStream.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBSymbolContext.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 15 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 16 | #include "lldb/Core/Debugger.h" |
| 17 | #include "lldb/Core/State.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 18 | #include "lldb/Core/StreamFile.h" |
| 19 | #include "lldb/Core/StructuredData.h" |
| 20 | #include "lldb/Interpreter/CommandInterpreter.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/CompileUnit.h" |
| 22 | #include "lldb/Symbol/SymbolContext.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 23 | #include "lldb/Target/Process.h" |
| 24 | #include "lldb/Target/Queue.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 25 | #include "lldb/Target/StopInfo.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 26 | #include "lldb/Target/SystemRuntime.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 28 | #include "lldb/Target/Thread.h" |
| 29 | #include "lldb/Target/ThreadPlan.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 30 | #include "lldb/Target/ThreadPlan.h" |
| 31 | #include "lldb/Target/ThreadPlanPython.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ThreadPlanStepInRange.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 33 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 34 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 35 | #include "lldb/Target/ThreadPlanStepRange.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame^] | 36 | #include "lldb/Utility/Stream.h" |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 37 | |
| 38 | #include "lldb/API/SBAddress.h" |
| 39 | #include "lldb/API/SBDebugger.h" |
| 40 | #include "lldb/API/SBEvent.h" |
| 41 | #include "lldb/API/SBFrame.h" |
| 42 | #include "lldb/API/SBProcess.h" |
| 43 | #include "lldb/API/SBThreadPlan.h" |
| 44 | #include "lldb/API/SBValue.h" |
| 45 | |
| 46 | using namespace lldb; |
| 47 | using namespace lldb_private; |
| 48 | |
| 49 | //---------------------------------------------------------------------- |
| 50 | // Constructors |
| 51 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 52 | SBThreadPlan::SBThreadPlan() {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 53 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 54 | SBThreadPlan::SBThreadPlan(const ThreadPlanSP &lldb_object_sp) |
| 55 | : m_opaque_sp(lldb_object_sp) {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 56 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 57 | SBThreadPlan::SBThreadPlan(const SBThreadPlan &rhs) |
| 58 | : m_opaque_sp(rhs.m_opaque_sp) {} |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 59 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 60 | SBThreadPlan::SBThreadPlan(lldb::SBThread &sb_thread, const char *class_name) { |
| 61 | Thread *thread = sb_thread.get(); |
| 62 | if (thread) |
| 63 | m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name)); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | //---------------------------------------------------------------------- |
| 67 | // Assignment operator |
| 68 | //---------------------------------------------------------------------- |
| 69 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 70 | const lldb::SBThreadPlan &SBThreadPlan::operator=(const SBThreadPlan &rhs) { |
| 71 | if (this != &rhs) |
| 72 | m_opaque_sp = rhs.m_opaque_sp; |
| 73 | return *this; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 74 | } |
| 75 | //---------------------------------------------------------------------- |
| 76 | // Destructor |
| 77 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 78 | SBThreadPlan::~SBThreadPlan() {} |
| 79 | |
| 80 | lldb_private::ThreadPlan *SBThreadPlan::get() { return m_opaque_sp.get(); } |
| 81 | |
| 82 | bool SBThreadPlan::IsValid() const { return m_opaque_sp.get() != NULL; } |
| 83 | |
| 84 | void SBThreadPlan::Clear() { m_opaque_sp.reset(); } |
| 85 | |
| 86 | lldb::StopReason SBThreadPlan::GetStopReason() { return eStopReasonNone; } |
| 87 | |
| 88 | size_t SBThreadPlan::GetStopReasonDataCount() { return 0; } |
| 89 | |
| 90 | uint64_t SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) { return 0; } |
| 91 | |
| 92 | SBThread SBThreadPlan::GetThread() const { |
| 93 | if (m_opaque_sp) { |
| 94 | return SBThread(m_opaque_sp->GetThread().shared_from_this()); |
| 95 | } else |
| 96 | return SBThread(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | bool SBThreadPlan::GetDescription(lldb::SBStream &description) const { |
| 100 | if (m_opaque_sp) { |
| 101 | m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull); |
| 102 | } else { |
| 103 | description.Printf("Empty SBThreadPlan"); |
| 104 | } |
| 105 | return true; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 108 | void SBThreadPlan::SetThreadPlan(const ThreadPlanSP &lldb_object_sp) { |
| 109 | m_opaque_sp = lldb_object_sp; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 112 | void SBThreadPlan::SetPlanComplete(bool success) { |
| 113 | if (m_opaque_sp) |
| 114 | m_opaque_sp->SetPlanComplete(success); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 117 | bool SBThreadPlan::IsPlanComplete() { |
| 118 | if (m_opaque_sp) |
| 119 | return m_opaque_sp->IsPlanComplete(); |
| 120 | else |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 121 | return true; |
| 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | bool SBThreadPlan::IsPlanStale() { |
| 125 | if (m_opaque_sp) |
| 126 | return m_opaque_sp->IsPlanStale(); |
| 127 | else |
| 128 | return true; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 131 | bool SBThreadPlan::IsValid() { |
| 132 | if (m_opaque_sp) |
| 133 | return m_opaque_sp->ValidatePlan(nullptr); |
| 134 | else |
| 135 | return false; |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 138 | // This section allows an SBThreadPlan to push another of the common types of |
| 139 | // plans... |
| 140 | // |
| 141 | // FIXME, you should only be able to queue thread plans from inside the methods |
| 142 | // of a |
| 143 | // Scripted Thread Plan. Need a way to enforce that. |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 144 | |
| 145 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | SBThreadPlan::QueueThreadPlanForStepOverRange(SBAddress &sb_start_address, |
| 147 | lldb::addr_t size) { |
| 148 | if (m_opaque_sp) { |
| 149 | Address *start_address = sb_start_address.get(); |
| 150 | if (!start_address) { |
| 151 | return SBThreadPlan(); |
| 152 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 153 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 154 | AddressRange range(*start_address, size); |
| 155 | SymbolContext sc; |
| 156 | start_address->CalculateSymbolContext(&sc); |
| 157 | return SBThreadPlan( |
| 158 | m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange( |
| 159 | false, range, sc, eAllThreads)); |
| 160 | } else { |
| 161 | return SBThreadPlan(); |
| 162 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 166 | SBThreadPlan::QueueThreadPlanForStepInRange(SBAddress &sb_start_address, |
| 167 | lldb::addr_t size) { |
| 168 | if (m_opaque_sp) { |
| 169 | Address *start_address = sb_start_address.get(); |
| 170 | if (!start_address) { |
| 171 | return SBThreadPlan(); |
| 172 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 173 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 174 | AddressRange range(*start_address, size); |
| 175 | SymbolContext sc; |
| 176 | start_address->CalculateSymbolContext(&sc); |
| 177 | return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepInRange( |
| 178 | false, range, sc, NULL, eAllThreads)); |
| 179 | } else { |
| 180 | return SBThreadPlan(); |
| 181 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 185 | SBThreadPlan::QueueThreadPlanForStepOut(uint32_t frame_idx_to_step_to, |
| 186 | bool first_insn) { |
| 187 | if (m_opaque_sp) { |
| 188 | SymbolContext sc; |
| 189 | sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext( |
| 190 | lldb::eSymbolContextEverything); |
| 191 | return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForStepOut( |
| 192 | false, &sc, first_insn, false, eVoteYes, eVoteNoOpinion, |
| 193 | frame_idx_to_step_to)); |
| 194 | } else { |
| 195 | return SBThreadPlan(); |
| 196 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | SBThreadPlan |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 200 | SBThreadPlan::QueueThreadPlanForRunToAddress(SBAddress sb_address) { |
| 201 | if (m_opaque_sp) { |
| 202 | Address *address = sb_address.get(); |
| 203 | if (!address) |
| 204 | return SBThreadPlan(); |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | return SBThreadPlan(m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress( |
| 207 | false, *address, false)); |
| 208 | } else { |
| 209 | return SBThreadPlan(); |
| 210 | } |
Jim Ingham | 2bdbfd5 | 2014-09-29 23:17:18 +0000 | [diff] [blame] | 211 | } |