Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Thread.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 | |
Daniel Malea | 93a6430 | 2012-12-05 00:20:57 +0000 | [diff] [blame] | 10 | #include "lldb/lldb-python.h" |
| 11 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-private-log.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 14 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Core/Log.h" |
| 16 | #include "lldb/Core/Stream.h" |
| 17 | #include "lldb/Core/StreamString.h" |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 18 | #include "lldb/Core/RegularExpression.h" |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 19 | #include "lldb/Host/Host.h" |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 20 | #include "lldb/Symbol/Function.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Target/DynamicLoader.h" |
| 22 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | 5a36912 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 23 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Process.h" |
| 25 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 26 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | 896dff6 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 27 | #include "lldb/Target/Target.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Target/Thread.h" |
| 29 | #include "lldb/Target/ThreadPlan.h" |
| 30 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ThreadPlanBase.h" |
| 32 | #include "lldb/Target/ThreadPlanStepInstruction.h" |
| 33 | #include "lldb/Target/ThreadPlanStepOut.h" |
| 34 | #include "lldb/Target/ThreadPlanStepOverBreakpoint.h" |
| 35 | #include "lldb/Target/ThreadPlanStepThrough.h" |
| 36 | #include "lldb/Target/ThreadPlanStepInRange.h" |
| 37 | #include "lldb/Target/ThreadPlanStepOverRange.h" |
| 38 | #include "lldb/Target/ThreadPlanRunToAddress.h" |
| 39 | #include "lldb/Target/ThreadPlanStepUntil.h" |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 40 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 41 | #include "lldb/Target/Unwind.h" |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 42 | #include "Plugins/Process/Utility/UnwindLLDB.h" |
| 43 | #include "UnwindMacOSXFrameBackchain.h" |
| 44 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 45 | |
| 46 | using namespace lldb; |
| 47 | using namespace lldb_private; |
| 48 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 49 | |
| 50 | const ThreadPropertiesSP & |
| 51 | Thread::GetGlobalProperties() |
| 52 | { |
| 53 | static ThreadPropertiesSP g_settings_sp; |
| 54 | if (!g_settings_sp) |
| 55 | g_settings_sp.reset (new ThreadProperties (true)); |
| 56 | return g_settings_sp; |
| 57 | } |
| 58 | |
| 59 | static PropertyDefinition |
| 60 | g_properties[] = |
| 61 | { |
| 62 | { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." }, |
| 63 | { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." }, |
| 64 | { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL } |
| 65 | }; |
| 66 | |
| 67 | enum { |
| 68 | ePropertyStepAvoidRegex, |
| 69 | ePropertyEnableThreadTrace |
| 70 | }; |
| 71 | |
| 72 | |
| 73 | class ThreadOptionValueProperties : public OptionValueProperties |
| 74 | { |
| 75 | public: |
| 76 | ThreadOptionValueProperties (const ConstString &name) : |
| 77 | OptionValueProperties (name) |
| 78 | { |
| 79 | } |
| 80 | |
| 81 | // This constructor is used when creating ThreadOptionValueProperties when it |
| 82 | // is part of a new lldb_private::Thread instance. It will copy all current |
| 83 | // global property values as needed |
| 84 | ThreadOptionValueProperties (ThreadProperties *global_properties) : |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 85 | OptionValueProperties(*global_properties->GetValueProperties()) |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 86 | { |
| 87 | } |
| 88 | |
| 89 | virtual const Property * |
| 90 | GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const |
| 91 | { |
| 92 | // When gettings the value for a key from the thread options, we will always |
| 93 | // try and grab the setting from the current thread if there is one. Else we just |
| 94 | // use the one from this instance. |
| 95 | if (exe_ctx) |
| 96 | { |
| 97 | Thread *thread = exe_ctx->GetThreadPtr(); |
| 98 | if (thread) |
| 99 | { |
| 100 | ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get()); |
| 101 | if (this != instance_properties) |
| 102 | return instance_properties->ProtectedGetPropertyAtIndex (idx); |
| 103 | } |
| 104 | } |
| 105 | return ProtectedGetPropertyAtIndex (idx); |
| 106 | } |
| 107 | }; |
| 108 | |
| 109 | |
| 110 | |
| 111 | ThreadProperties::ThreadProperties (bool is_global) : |
| 112 | Properties () |
| 113 | { |
| 114 | if (is_global) |
| 115 | { |
| 116 | m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread"))); |
| 117 | m_collection_sp->Initialize(g_properties); |
| 118 | } |
| 119 | else |
| 120 | m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get())); |
| 121 | } |
| 122 | |
| 123 | ThreadProperties::~ThreadProperties() |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | const RegularExpression * |
| 128 | ThreadProperties::GetSymbolsToAvoidRegexp() |
| 129 | { |
| 130 | const uint32_t idx = ePropertyStepAvoidRegex; |
| 131 | return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx); |
| 132 | } |
| 133 | |
| 134 | bool |
| 135 | ThreadProperties::GetTraceEnabledState() const |
| 136 | { |
| 137 | const uint32_t idx = ePropertyEnableThreadTrace; |
| 138 | return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); |
| 139 | } |
| 140 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 141 | //------------------------------------------------------------------ |
| 142 | // Thread Event Data |
| 143 | //------------------------------------------------------------------ |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 144 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 145 | |
| 146 | const ConstString & |
| 147 | Thread::ThreadEventData::GetFlavorString () |
| 148 | { |
| 149 | static ConstString g_flavor ("Thread::ThreadEventData"); |
| 150 | return g_flavor; |
| 151 | } |
| 152 | |
| 153 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) : |
| 154 | m_thread_sp (thread_sp), |
| 155 | m_stack_id () |
| 156 | { |
| 157 | } |
| 158 | |
| 159 | Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) : |
| 160 | m_thread_sp (thread_sp), |
| 161 | m_stack_id (stack_id) |
| 162 | { |
| 163 | } |
| 164 | |
| 165 | Thread::ThreadEventData::ThreadEventData () : |
| 166 | m_thread_sp (), |
| 167 | m_stack_id () |
| 168 | { |
| 169 | } |
| 170 | |
| 171 | Thread::ThreadEventData::~ThreadEventData () |
| 172 | { |
| 173 | } |
| 174 | |
| 175 | void |
| 176 | Thread::ThreadEventData::Dump (Stream *s) const |
| 177 | { |
| 178 | |
| 179 | } |
| 180 | |
| 181 | const Thread::ThreadEventData * |
| 182 | Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr) |
| 183 | { |
| 184 | if (event_ptr) |
| 185 | { |
| 186 | const EventData *event_data = event_ptr->GetData(); |
| 187 | if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString()) |
| 188 | return static_cast <const ThreadEventData *> (event_ptr->GetData()); |
| 189 | } |
| 190 | return NULL; |
| 191 | } |
| 192 | |
| 193 | ThreadSP |
| 194 | Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr) |
| 195 | { |
| 196 | ThreadSP thread_sp; |
| 197 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 198 | if (event_data) |
| 199 | thread_sp = event_data->GetThread(); |
| 200 | return thread_sp; |
| 201 | } |
| 202 | |
| 203 | StackID |
| 204 | Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr) |
| 205 | { |
| 206 | StackID stack_id; |
| 207 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 208 | if (event_data) |
| 209 | stack_id = event_data->GetStackID(); |
| 210 | return stack_id; |
| 211 | } |
| 212 | |
| 213 | StackFrameSP |
| 214 | Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr) |
| 215 | { |
| 216 | const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr); |
| 217 | StackFrameSP frame_sp; |
| 218 | if (event_data) |
| 219 | { |
| 220 | ThreadSP thread_sp = event_data->GetThread(); |
| 221 | if (thread_sp) |
| 222 | { |
| 223 | frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID()); |
| 224 | } |
| 225 | } |
| 226 | return frame_sp; |
| 227 | } |
| 228 | |
| 229 | //------------------------------------------------------------------ |
| 230 | // Thread class |
| 231 | //------------------------------------------------------------------ |
| 232 | |
| 233 | ConstString & |
| 234 | Thread::GetStaticBroadcasterClass () |
| 235 | { |
| 236 | static ConstString class_name ("lldb.thread"); |
| 237 | return class_name; |
| 238 | } |
| 239 | |
| 240 | Thread::Thread (Process &process, lldb::tid_t tid) : |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 241 | ThreadProperties (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | UserID (tid), |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 243 | Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()), |
| 244 | m_process_wp (process.shared_from_this()), |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 245 | m_actual_stop_info_sp (), |
Han Ming Ong | c2c423e | 2013-01-08 22:10:01 +0000 | [diff] [blame] | 246 | m_index_id (process.GetNextThreadIndexID(tid)), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 247 | m_reg_context_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 248 | m_state (eStateUnloaded), |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 249 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 250 | m_plan_stack (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 251 | m_completed_plan_stack(), |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 252 | m_frame_mutex (Mutex::eMutexTypeRecursive), |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 253 | m_curr_frames_sp (), |
| 254 | m_prev_frames_sp (), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 255 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 256 | m_resume_state (eStateRunning), |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 257 | m_temporary_resume_state (eStateRunning), |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 258 | m_unwinder_ap (), |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 259 | m_destroy_called (false), |
| 260 | m_thread_stop_reason_stop_id (0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 261 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 262 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 264 | log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 266 | CheckInWithManager(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | QueueFundamentalPlan(true); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | Thread::~Thread() |
| 272 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 273 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 275 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")", this, GetID()); |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 276 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 277 | assert (m_destroy_called); |
| 278 | } |
| 279 | |
| 280 | void |
| 281 | Thread::DestroyThread () |
| 282 | { |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 283 | m_destroy_called = true; |
Jim Ingham | 773d981 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 284 | m_plan_stack.clear(); |
| 285 | m_discarded_plan_stack.clear(); |
| 286 | m_completed_plan_stack.clear(); |
Jim Ingham | d8ba464 | 2012-04-10 00:44:25 +0000 | [diff] [blame] | 287 | m_actual_stop_info_sp.reset(); |
Greg Clayton | 35a4cc5 | 2012-10-29 20:52:08 +0000 | [diff] [blame] | 288 | m_reg_context_sp.reset(); |
| 289 | m_unwinder_ap.reset(); |
| 290 | Mutex::Locker locker(m_frame_mutex); |
| 291 | m_curr_frames_sp.reset(); |
| 292 | m_prev_frames_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 295 | void |
| 296 | Thread::BroadcastSelectedFrameChange(StackID &new_frame_id) |
| 297 | { |
| 298 | if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged)) |
| 299 | BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id)); |
| 300 | } |
| 301 | |
| 302 | uint32_t |
| 303 | Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast) |
| 304 | { |
| 305 | uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame); |
| 306 | if (broadcast) |
| 307 | BroadcastSelectedFrameChange(frame->GetStackID()); |
| 308 | return ret_value; |
| 309 | } |
| 310 | |
| 311 | bool |
| 312 | Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast) |
| 313 | { |
| 314 | StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx)); |
| 315 | if (frame_sp) |
| 316 | { |
| 317 | GetStackFrameList()->SetSelectedFrame(frame_sp.get()); |
| 318 | if (broadcast) |
| 319 | BroadcastSelectedFrameChange(frame_sp->GetStackID()); |
| 320 | return true; |
| 321 | } |
| 322 | else |
| 323 | return false; |
| 324 | } |
| 325 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 326 | bool |
| 327 | Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream) |
| 328 | { |
| 329 | const bool broadcast = true; |
| 330 | bool success = SetSelectedFrameByIndex (frame_idx, broadcast); |
| 331 | if (success) |
| 332 | { |
| 333 | StackFrameSP frame_sp = GetSelectedFrame(); |
| 334 | if (frame_sp) |
| 335 | { |
| 336 | bool already_shown = false; |
| 337 | SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry)); |
| 338 | if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0) |
| 339 | { |
| 340 | already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 341 | } |
| 342 | |
| 343 | bool show_frame_info = true; |
| 344 | bool show_source = !already_shown; |
| 345 | return frame_sp->GetStatus (output_stream, show_frame_info, show_source); |
| 346 | } |
| 347 | return false; |
| 348 | } |
| 349 | else |
| 350 | return false; |
| 351 | } |
| 352 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 353 | |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 354 | lldb::StopInfoSP |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 355 | Thread::GetStopInfo () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | { |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 357 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
Jim Ingham | fbbfe6e | 2012-05-01 18:38:37 +0000 | [diff] [blame] | 358 | if (plan_sp && plan_sp->PlanSucceeded()) |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 359 | return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 360 | else |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 361 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 362 | ProcessSP process_sp (GetProcess()); |
| 363 | if (process_sp |
| 364 | && m_actual_stop_info_sp |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 365 | && m_actual_stop_info_sp->IsValid() |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 366 | && m_thread_stop_reason_stop_id == process_sp->GetStopID()) |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 367 | return m_actual_stop_info_sp; |
| 368 | else |
| 369 | return GetPrivateStopReason (); |
| 370 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | } |
| 372 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 373 | lldb::StopReason |
| 374 | Thread::GetStopReason() |
| 375 | { |
| 376 | lldb::StopInfoSP stop_info_sp (GetStopInfo ()); |
| 377 | if (stop_info_sp) |
Filipe Cabecinhas | e26391a | 2012-09-28 15:55:43 +0000 | [diff] [blame] | 378 | return stop_info_sp->GetStopReason(); |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 379 | return eStopReasonNone; |
| 380 | } |
| 381 | |
| 382 | |
| 383 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 384 | void |
| 385 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 386 | { |
| 387 | m_actual_stop_info_sp = stop_info_sp; |
Jim Ingham | 79c35da | 2011-08-09 00:32:52 +0000 | [diff] [blame] | 388 | if (m_actual_stop_info_sp) |
| 389 | m_actual_stop_info_sp->MakeStopInfoValid(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 390 | ProcessSP process_sp (GetProcess()); |
| 391 | if (process_sp) |
| 392 | m_thread_stop_reason_stop_id = process_sp->GetStopID(); |
| 393 | else |
| 394 | m_thread_stop_reason_stop_id = UINT32_MAX; |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void |
| 398 | Thread::SetStopInfoToNothing() |
| 399 | { |
| 400 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 401 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 402 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 403 | } |
| 404 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 405 | bool |
| 406 | Thread::ThreadStoppedForAReason (void) |
| 407 | { |
Jim Ingham | f94e179 | 2012-08-11 00:35:26 +0000 | [diff] [blame] | 408 | return (bool) GetPrivateStopReason (); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 409 | } |
| 410 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 411 | bool |
| 412 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 413 | { |
| 414 | if (!SaveFrameZeroState(saved_state.register_backup)) |
| 415 | return false; |
| 416 | |
| 417 | saved_state.stop_info_sp = GetStopInfo(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 418 | ProcessSP process_sp (GetProcess()); |
| 419 | if (process_sp) |
| 420 | saved_state.orig_stop_id = process_sp->GetStopID(); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 421 | saved_state.current_inlined_depth = GetCurrentInlinedDepth(); |
| 422 | |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 423 | return true; |
| 424 | } |
| 425 | |
| 426 | bool |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 427 | Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 428 | { |
| 429 | RestoreSaveFrameZero(saved_state.register_backup); |
Jim Ingham | 8559a35 | 2012-11-26 23:52:18 +0000 | [diff] [blame] | 430 | return true; |
| 431 | } |
| 432 | |
| 433 | bool |
| 434 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 435 | { |
Jim Ingham | 0c27068 | 2011-01-25 02:47:23 +0000 | [diff] [blame] | 436 | if (saved_state.stop_info_sp) |
| 437 | saved_state.stop_info_sp->MakeStopInfoValid(); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 438 | SetStopInfo(saved_state.stop_info_sp); |
Jim Ingham | 625fca7 | 2012-09-07 23:36:43 +0000 | [diff] [blame] | 439 | GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth); |
Jim Ingham | 7778703 | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 440 | return true; |
| 441 | } |
| 442 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 443 | StateType |
| 444 | Thread::GetState() const |
| 445 | { |
| 446 | // If any other threads access this we will need a mutex for it |
| 447 | Mutex::Locker locker(m_state_mutex); |
| 448 | return m_state; |
| 449 | } |
| 450 | |
| 451 | void |
| 452 | Thread::SetState(StateType state) |
| 453 | { |
| 454 | Mutex::Locker locker(m_state_mutex); |
| 455 | m_state = state; |
| 456 | } |
| 457 | |
| 458 | void |
| 459 | Thread::WillStop() |
| 460 | { |
| 461 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 462 | |
| 463 | // FIXME: I may decide to disallow threads with no plans. In which |
| 464 | // case this should go to an assert. |
| 465 | |
| 466 | if (!current_plan) |
| 467 | return; |
| 468 | |
| 469 | current_plan->WillStop(); |
| 470 | } |
| 471 | |
| 472 | void |
| 473 | Thread::SetupForResume () |
| 474 | { |
| 475 | if (GetResumeState() != eStateSuspended) |
| 476 | { |
| 477 | |
| 478 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 479 | // telling the current plan it will resume, since we might change what the current |
| 480 | // plan is. |
| 481 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 482 | // StopReason stop_reason = lldb::eStopReasonInvalid; |
| 483 | // StopInfoSP stop_info_sp = GetStopInfo(); |
| 484 | // if (stop_info_sp.get()) |
| 485 | // stop_reason = stop_info_sp->GetStopReason(); |
| 486 | // if (stop_reason == lldb::eStopReasonBreakpoint) |
| 487 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 488 | if (reg_ctx_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 489 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 490 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC()); |
| 491 | if (bp_site_sp) |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 492 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 493 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 494 | // special to step over a breakpoint. |
| 495 | |
| 496 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 497 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 498 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 499 | { |
| 500 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 501 | if (step_bp_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 502 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 503 | ThreadPlanSP step_bp_plan_sp; |
| 504 | step_bp_plan->SetPrivate (true); |
| 505 | |
| 506 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 507 | { |
| 508 | step_bp_plan->SetAutoContinue(true); |
| 509 | } |
| 510 | step_bp_plan_sp.reset (step_bp_plan); |
| 511 | QueueThreadPlan (step_bp_plan_sp, false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 512 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 513 | } |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | bool |
| 520 | Thread::WillResume (StateType resume_state) |
| 521 | { |
| 522 | // At this point clear the completed plan stack. |
| 523 | m_completed_plan_stack.clear(); |
| 524 | m_discarded_plan_stack.clear(); |
| 525 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 526 | m_temporary_resume_state = resume_state; |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 527 | |
| 528 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 529 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 530 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 531 | // about the fact that we are resuming... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 532 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 533 | if (m_thread_stop_reason_stop_id == process_stop_id && |
| 534 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) |
| 535 | { |
| 536 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 537 | if (stop_info) |
| 538 | stop_info->WillResume (resume_state); |
| 539 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 540 | |
| 541 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 542 | // We distinguish between the plan on the top of the stack and the lower |
| 543 | // plans in case a plan needs to do any special business before it runs. |
| 544 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 545 | bool need_to_resume = false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 546 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 547 | if (plan_ptr) |
| 548 | { |
| 549 | need_to_resume = plan_ptr->WillResume(resume_state, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 550 | |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 551 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 552 | { |
| 553 | plan_ptr->WillResume (resume_state, false); |
| 554 | } |
| 555 | |
| 556 | // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. |
| 557 | // In that case, don't reset it here. |
| 558 | |
| 559 | if (need_to_resume && resume_state != eStateSuspended) |
| 560 | { |
| 561 | m_actual_stop_info_sp.reset(); |
| 562 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | return need_to_resume; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void |
| 569 | Thread::DidResume () |
| 570 | { |
| 571 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 572 | } |
| 573 | |
| 574 | bool |
| 575 | Thread::ShouldStop (Event* event_ptr) |
| 576 | { |
| 577 | ThreadPlan *current_plan = GetCurrentPlan(); |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 578 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | bool should_stop = true; |
| 580 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 581 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 582 | |
| 583 | if (GetResumeState () == eStateSuspended) |
| 584 | { |
| 585 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 586 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 587 | __FUNCTION__, |
| 588 | GetID ()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 589 | return false; |
| 590 | } |
| 591 | |
| 592 | if (GetTemporaryResumeState () == eStateSuspended) |
| 593 | { |
| 594 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 595 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 596 | __FUNCTION__, |
| 597 | GetID ()); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 598 | return false; |
| 599 | } |
| 600 | |
| 601 | if (ThreadStoppedForAReason() == false) |
| 602 | { |
| 603 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 604 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since no stop reason)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 605 | __FUNCTION__, |
| 606 | GetID (), |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 607 | GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 608 | return false; |
| 609 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 610 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 611 | if (log) |
| 612 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 613 | log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64, |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 614 | __FUNCTION__, |
| 615 | GetID (), |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 616 | GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 617 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 618 | StreamString s; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 619 | s.IndentMore(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 620 | DumpThreadPlans(&s); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 621 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 622 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 623 | |
| 624 | // The top most plan always gets to do the trace log... |
| 625 | current_plan->DoTraceLog (); |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 626 | |
| 627 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 628 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 629 | // do any more work on this stop. |
| 630 | StopInfoSP private_stop_info (GetPrivateStopReason()); |
| 631 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 632 | { |
| 633 | if (log) |
| 634 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 635 | return false; |
| 636 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 637 | |
Jim Ingham | bad39e4 | 2012-09-05 21:12:49 +0000 | [diff] [blame] | 638 | // If we've already been restarted, don't query the plans since the state they would examine is not current. |
| 639 | if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) |
| 640 | return false; |
| 641 | |
| 642 | // Before the plans see the state of the world, calculate the current inlined depth. |
| 643 | GetStackFrameList()->CalculateCurrentInlinedDepth(); |
| 644 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 645 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 646 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 647 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 648 | // whether they still need to do more work. |
| 649 | |
| 650 | bool done_processing_current_plan = false; |
| 651 | |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 652 | if (!current_plan->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 653 | { |
| 654 | if (current_plan->TracerExplainsStop()) |
| 655 | { |
| 656 | done_processing_current_plan = true; |
| 657 | should_stop = false; |
| 658 | } |
| 659 | else |
| 660 | { |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 661 | // If the current plan doesn't explain the stop, then find one that |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 662 | // does and let it handle the situation. |
| 663 | ThreadPlan *plan_ptr = current_plan; |
| 664 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 665 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 666 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 667 | { |
| 668 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 669 | |
| 670 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 671 | // and all the plans below it off the stack. |
| 672 | |
| 673 | if (plan_ptr->MischiefManaged()) |
| 674 | { |
Jim Ingham | 031177e | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 675 | // We're going to pop the plans up to and including the plan that explains the stop. |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 676 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 677 | |
| 678 | do |
| 679 | { |
| 680 | if (should_stop) |
| 681 | current_plan->WillStop(); |
| 682 | PopPlan(); |
| 683 | } |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 684 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 685 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 686 | // otherwise we forward this to the next plan in the stack below. |
| 687 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 688 | done_processing_current_plan = true; |
| 689 | else |
| 690 | done_processing_current_plan = false; |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 691 | } |
| 692 | else |
| 693 | done_processing_current_plan = true; |
| 694 | |
| 695 | break; |
| 696 | } |
| 697 | |
| 698 | } |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | if (!done_processing_current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 703 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 704 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 705 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 706 | if (log) |
| 707 | log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); |
| 708 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 709 | // We're starting from the base plan, so just let it decide; |
| 710 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 711 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 712 | should_stop = current_plan->ShouldStop (event_ptr); |
| 713 | if (log) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 714 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 715 | } |
| 716 | else |
| 717 | { |
| 718 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 719 | // presumably if there were other plans they would know what to do... |
| 720 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 721 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 722 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 723 | break; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 724 | |
| 725 | should_stop = current_plan->ShouldStop(event_ptr); |
| 726 | if (log) |
| 727 | log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); |
| 728 | if (current_plan->MischiefManaged()) |
| 729 | { |
| 730 | if (should_stop) |
| 731 | current_plan->WillStop(); |
| 732 | |
| 733 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 734 | // Otherwise, see if the plan's parent wants to stop. |
| 735 | |
| 736 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 737 | { |
| 738 | PopPlan(); |
| 739 | break; |
| 740 | } |
| 741 | else |
| 742 | { |
| 743 | |
| 744 | PopPlan(); |
| 745 | |
| 746 | current_plan = GetCurrentPlan(); |
| 747 | if (current_plan == NULL) |
| 748 | { |
| 749 | break; |
| 750 | } |
| 751 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 752 | } |
| 753 | else |
| 754 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 755 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 756 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 757 | } |
| 758 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 759 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 760 | if (over_ride_stop) |
| 761 | should_stop = false; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 762 | |
| 763 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 764 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 765 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 766 | // This code clears stale plans off the stack. |
| 767 | |
| 768 | if (should_stop) |
| 769 | { |
| 770 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 771 | while (!PlanIsBasePlan(plan_ptr)) |
| 772 | { |
| 773 | bool stale = plan_ptr->IsPlanStale (); |
| 774 | ThreadPlan *examined_plan = plan_ptr; |
| 775 | plan_ptr = GetPreviousPlan (examined_plan); |
| 776 | |
| 777 | if (stale) |
| 778 | { |
| 779 | if (log) |
| 780 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); |
| 781 | DiscardThreadPlansUpToPlan(examined_plan); |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 786 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 787 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 788 | if (log) |
| 789 | { |
| 790 | StreamString s; |
| 791 | s.IndentMore(); |
| 792 | DumpThreadPlans(&s); |
| 793 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 794 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 795 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 796 | return should_stop; |
| 797 | } |
| 798 | |
| 799 | Vote |
| 800 | Thread::ShouldReportStop (Event* event_ptr) |
| 801 | { |
| 802 | StateType thread_state = GetResumeState (); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 803 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 804 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 805 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 806 | |
| 807 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 808 | { |
| 809 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 810 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 811 | return eVoteNoOpinion; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 812 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 813 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 814 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 815 | { |
| 816 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 817 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 818 | return eVoteNoOpinion; |
| 819 | } |
| 820 | |
| 821 | if (!ThreadStoppedForAReason()) |
| 822 | { |
| 823 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 824 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 825 | return eVoteNoOpinion; |
| 826 | } |
| 827 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 828 | if (m_completed_plan_stack.size() > 0) |
| 829 | { |
| 830 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 831 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 832 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for complete stack's back plan\n", GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 834 | } |
| 835 | else |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 836 | { |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 837 | Vote thread_vote = eVoteNoOpinion; |
| 838 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 839 | while (1) |
| 840 | { |
| 841 | if (plan_ptr->PlanExplainsStop(event_ptr)) |
| 842 | { |
| 843 | thread_vote = plan_ptr->ShouldReportStop(event_ptr); |
| 844 | break; |
| 845 | } |
| 846 | if (PlanIsBasePlan(plan_ptr)) |
| 847 | break; |
| 848 | else |
| 849 | plan_ptr = GetPreviousPlan(plan_ptr); |
| 850 | } |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 851 | if (log) |
Jim Ingham | 0161b49 | 2013-02-09 01:29:05 +0000 | [diff] [blame] | 852 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i for current plan\n", GetID(), thread_vote); |
| 853 | |
| 854 | return thread_vote; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 855 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | Vote |
| 859 | Thread::ShouldReportRun (Event* event_ptr) |
| 860 | { |
| 861 | StateType thread_state = GetResumeState (); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 862 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 863 | if (thread_state == eStateSuspended |
| 864 | || thread_state == eStateInvalid) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 865 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 866 | return eVoteNoOpinion; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 869 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 870 | if (m_completed_plan_stack.size() > 0) |
| 871 | { |
| 872 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 873 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 874 | log->Printf ("Current Plan for thread %d (0x%4.4" PRIx64 "): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 875 | GetIndexID(), |
| 876 | GetID(), |
| 877 | m_completed_plan_stack.back()->GetName()); |
| 878 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 879 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 880 | } |
| 881 | else |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 882 | { |
| 883 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 884 | log->Printf ("Current Plan for thread %d (0x%4.4" PRIx64 "): %s being asked whether we should report run.", |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 885 | GetIndexID(), |
| 886 | GetID(), |
| 887 | GetCurrentPlan()->GetName()); |
| 888 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 889 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 890 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 891 | } |
| 892 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 893 | bool |
| 894 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 895 | { |
| 896 | if (spec == NULL) |
| 897 | return true; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 898 | |
Jim Ingham | 3d90292 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 899 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 900 | } |
| 901 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | void |
| 903 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 904 | { |
| 905 | if (thread_plan_sp) |
| 906 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 907 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 908 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 909 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 910 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 911 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | thread_plan_sp->DidPush(); |
| 913 | |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 914 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 915 | if (log) |
| 916 | { |
| 917 | StreamString s; |
| 918 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 919 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4" PRIx64 ".", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 920 | s.GetData(), |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 921 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | void |
| 927 | Thread::PopPlan () |
| 928 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 929 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 930 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 931 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 932 | return; |
| 933 | else |
| 934 | { |
| 935 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 936 | if (log) |
| 937 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 938 | log->Printf("Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 939 | } |
| 940 | m_completed_plan_stack.push_back (plan); |
| 941 | plan->WillPop(); |
| 942 | m_plan_stack.pop_back(); |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | void |
| 947 | Thread::DiscardPlan () |
| 948 | { |
| 949 | if (m_plan_stack.size() > 1) |
| 950 | { |
| 951 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 952 | m_discarded_plan_stack.push_back (plan); |
| 953 | plan->WillPop(); |
| 954 | m_plan_stack.pop_back(); |
| 955 | } |
| 956 | } |
| 957 | |
| 958 | ThreadPlan * |
| 959 | Thread::GetCurrentPlan () |
| 960 | { |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 961 | // There will always be at least the base plan. If somebody is mucking with a |
| 962 | // thread with an empty plan stack, we should assert right away. |
Greg Clayton | d1d06e4 | 2013-04-20 00:27:58 +0000 | [diff] [blame] | 963 | if (m_plan_stack.empty()) |
| 964 | return NULL; |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 965 | return m_plan_stack.back().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | ThreadPlanSP |
| 969 | Thread::GetCompletedPlan () |
| 970 | { |
| 971 | ThreadPlanSP empty_plan_sp; |
| 972 | if (!m_completed_plan_stack.empty()) |
| 973 | { |
| 974 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 975 | { |
| 976 | ThreadPlanSP completed_plan_sp; |
| 977 | completed_plan_sp = m_completed_plan_stack[i]; |
| 978 | if (!completed_plan_sp->GetPrivate ()) |
| 979 | return completed_plan_sp; |
| 980 | } |
| 981 | } |
| 982 | return empty_plan_sp; |
| 983 | } |
| 984 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 985 | ValueObjectSP |
| 986 | Thread::GetReturnValueObject () |
| 987 | { |
| 988 | if (!m_completed_plan_stack.empty()) |
| 989 | { |
| 990 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 991 | { |
| 992 | ValueObjectSP return_valobj_sp; |
| 993 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 994 | if (return_valobj_sp) |
| 995 | return return_valobj_sp; |
| 996 | } |
| 997 | } |
| 998 | return ValueObjectSP(); |
| 999 | } |
| 1000 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1001 | bool |
| 1002 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 1003 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1004 | if (!m_completed_plan_stack.empty()) |
| 1005 | { |
| 1006 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 1007 | { |
| 1008 | if (m_completed_plan_stack[i].get() == plan) |
| 1009 | return true; |
| 1010 | } |
| 1011 | } |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | bool |
| 1016 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 1017 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1018 | if (!m_discarded_plan_stack.empty()) |
| 1019 | { |
| 1020 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 1021 | { |
| 1022 | if (m_discarded_plan_stack[i].get() == plan) |
| 1023 | return true; |
| 1024 | } |
| 1025 | } |
| 1026 | return false; |
| 1027 | } |
| 1028 | |
| 1029 | ThreadPlan * |
| 1030 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 1031 | { |
| 1032 | if (current_plan == NULL) |
| 1033 | return NULL; |
| 1034 | |
| 1035 | int stack_size = m_completed_plan_stack.size(); |
| 1036 | for (int i = stack_size - 1; i > 0; i--) |
| 1037 | { |
| 1038 | if (current_plan == m_completed_plan_stack[i].get()) |
| 1039 | return m_completed_plan_stack[i-1].get(); |
| 1040 | } |
| 1041 | |
| 1042 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 1043 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1044 | if (m_plan_stack.size() > 0) |
| 1045 | return m_plan_stack.back().get(); |
| 1046 | else |
| 1047 | return NULL; |
| 1048 | } |
| 1049 | |
| 1050 | stack_size = m_plan_stack.size(); |
| 1051 | for (int i = stack_size - 1; i > 0; i--) |
| 1052 | { |
| 1053 | if (current_plan == m_plan_stack[i].get()) |
| 1054 | return m_plan_stack[i-1].get(); |
| 1055 | } |
| 1056 | return NULL; |
| 1057 | } |
| 1058 | |
| 1059 | void |
| 1060 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 1061 | { |
| 1062 | if (abort_other_plans) |
| 1063 | DiscardThreadPlans(true); |
| 1064 | |
| 1065 | PushPlan (thread_plan_sp); |
| 1066 | } |
| 1067 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1068 | |
| 1069 | void |
| 1070 | Thread::EnableTracer (bool value, bool single_stepping) |
| 1071 | { |
| 1072 | int stack_size = m_plan_stack.size(); |
| 1073 | for (int i = 0; i < stack_size; i++) |
| 1074 | { |
| 1075 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 1076 | { |
| 1077 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 1078 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | void |
| 1084 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 1085 | { |
| 1086 | int stack_size = m_plan_stack.size(); |
| 1087 | for (int i = 0; i < stack_size; i++) |
| 1088 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 1089 | } |
| 1090 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1091 | void |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1092 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 1093 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1094 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 1095 | } |
| 1096 | |
| 1097 | void |
| 1098 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 1099 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1100 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1101 | if (log) |
| 1102 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1103 | log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p", GetID(), up_to_plan_ptr); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | int stack_size = m_plan_stack.size(); |
| 1107 | |
| 1108 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1109 | // stack, and if so discard up to and including it. |
| 1110 | |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1111 | if (up_to_plan_ptr == NULL) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1112 | { |
| 1113 | for (int i = stack_size - 1; i > 0; i--) |
| 1114 | DiscardPlan(); |
| 1115 | } |
| 1116 | else |
| 1117 | { |
| 1118 | bool found_it = false; |
| 1119 | for (int i = stack_size - 1; i > 0; i--) |
| 1120 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1121 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1122 | found_it = true; |
| 1123 | } |
| 1124 | if (found_it) |
| 1125 | { |
| 1126 | bool last_one = false; |
| 1127 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 1128 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1129 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1130 | last_one = true; |
| 1131 | DiscardPlan(); |
| 1132 | } |
| 1133 | } |
| 1134 | } |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1139 | Thread::DiscardThreadPlans(bool force) |
| 1140 | { |
Greg Clayton | 5160ce5 | 2013-03-27 23:08:40 +0000 | [diff] [blame] | 1141 | Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1142 | if (log) |
| 1143 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1144 | log->Printf("Discarding thread plans for thread (tid = 0x%4.4" PRIx64 ", force %d)", GetID(), force); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | if (force) |
| 1148 | { |
| 1149 | int stack_size = m_plan_stack.size(); |
| 1150 | for (int i = stack_size - 1; i > 0; i--) |
| 1151 | { |
| 1152 | DiscardPlan(); |
| 1153 | } |
| 1154 | return; |
| 1155 | } |
| 1156 | |
| 1157 | while (1) |
| 1158 | { |
| 1159 | |
| 1160 | int master_plan_idx; |
Jim Ingham | a39ad07 | 2012-09-11 00:09:25 +0000 | [diff] [blame] | 1161 | bool discard = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1162 | |
| 1163 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 1164 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 1165 | { |
| 1166 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 1167 | { |
| 1168 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 1169 | break; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | if (discard) |
| 1174 | { |
| 1175 | // First pop all the dependent plans: |
| 1176 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 1177 | { |
| 1178 | |
| 1179 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 1180 | // for the plan leaves it in a state that it is safe to pop the plan |
| 1181 | // with no more notice? |
| 1182 | DiscardPlan(); |
| 1183 | } |
| 1184 | |
| 1185 | // Now discard the master plan itself. |
| 1186 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 1187 | // discard it's dependent plans, but not it... |
| 1188 | if (master_plan_idx > 0) |
| 1189 | { |
| 1190 | DiscardPlan(); |
| 1191 | } |
| 1192 | } |
| 1193 | else |
| 1194 | { |
| 1195 | // If the master plan doesn't want to get discarded, then we're done. |
| 1196 | break; |
| 1197 | } |
| 1198 | |
| 1199 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1200 | } |
| 1201 | |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 1202 | bool |
| 1203 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 1204 | { |
| 1205 | if (plan_ptr->IsBasePlan()) |
| 1206 | return true; |
| 1207 | else if (m_plan_stack.size() == 0) |
| 1208 | return false; |
| 1209 | else |
| 1210 | return m_plan_stack[0].get() == plan_ptr; |
| 1211 | } |
| 1212 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1213 | Error |
| 1214 | Thread::UnwindInnermostExpression() |
| 1215 | { |
| 1216 | Error error; |
| 1217 | int stack_size = m_plan_stack.size(); |
| 1218 | |
| 1219 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1220 | // stack, and if so discard up to and including it. |
| 1221 | |
| 1222 | for (int i = stack_size - 1; i > 0; i--) |
| 1223 | { |
| 1224 | if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) |
| 1225 | { |
| 1226 | DiscardThreadPlansUpToPlan(m_plan_stack[i].get()); |
| 1227 | return error; |
| 1228 | } |
| 1229 | } |
| 1230 | error.SetErrorString("No expressions currently active on this thread"); |
| 1231 | return error; |
| 1232 | } |
| 1233 | |
| 1234 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1235 | ThreadPlan * |
| 1236 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 1237 | { |
| 1238 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 1239 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1240 | return thread_plan_sp.get(); |
| 1241 | } |
| 1242 | |
| 1243 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1244 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1245 | ( |
| 1246 | bool step_over, |
| 1247 | bool abort_other_plans, |
| 1248 | bool stop_other_threads |
| 1249 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1250 | { |
| 1251 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1252 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1253 | return thread_plan_sp.get(); |
| 1254 | } |
| 1255 | |
| 1256 | ThreadPlan * |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1257 | Thread::QueueThreadPlanForStepOverRange |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1258 | ( |
| 1259 | bool abort_other_plans, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1260 | const AddressRange &range, |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1261 | const SymbolContext &addr_context, |
| 1262 | lldb::RunMode stop_other_threads |
| 1263 | ) |
| 1264 | { |
| 1265 | ThreadPlanSP thread_plan_sp; |
| 1266 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 1267 | |
| 1268 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1269 | return thread_plan_sp.get(); |
| 1270 | } |
| 1271 | |
| 1272 | ThreadPlan * |
| 1273 | Thread::QueueThreadPlanForStepInRange |
| 1274 | ( |
| 1275 | bool abort_other_plans, |
| 1276 | const AddressRange &range, |
| 1277 | const SymbolContext &addr_context, |
| 1278 | const char *step_in_target, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1279 | lldb::RunMode stop_other_threads, |
| 1280 | bool avoid_code_without_debug_info |
| 1281 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1282 | { |
| 1283 | ThreadPlanSP thread_plan_sp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1284 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 1285 | if (avoid_code_without_debug_info) |
| 1286 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1287 | else |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1288 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1289 | if (step_in_target) |
| 1290 | plan->SetStepInTarget(step_in_target); |
| 1291 | thread_plan_sp.reset (plan); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1292 | |
| 1293 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1294 | return thread_plan_sp.get(); |
| 1295 | } |
| 1296 | |
| 1297 | |
| 1298 | ThreadPlan * |
| 1299 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 1300 | { |
| 1301 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 1302 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1303 | return thread_plan_sp.get(); |
| 1304 | } |
| 1305 | |
| 1306 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1307 | Thread::QueueThreadPlanForStepOut |
| 1308 | ( |
| 1309 | bool abort_other_plans, |
| 1310 | SymbolContext *addr_context, |
| 1311 | bool first_insn, |
| 1312 | bool stop_other_threads, |
| 1313 | Vote stop_vote, |
| 1314 | Vote run_vote, |
| 1315 | uint32_t frame_idx |
| 1316 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1317 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1318 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1319 | addr_context, |
| 1320 | first_insn, |
| 1321 | stop_other_threads, |
| 1322 | stop_vote, |
| 1323 | run_vote, |
| 1324 | frame_idx)); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1325 | |
| 1326 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1327 | { |
| 1328 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1329 | return thread_plan_sp.get(); |
| 1330 | } |
| 1331 | else |
| 1332 | { |
| 1333 | return NULL; |
| 1334 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | ThreadPlan * |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1338 | Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1339 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1340 | ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads)); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 1341 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
| 1342 | return NULL; |
| 1343 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1344 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1345 | return thread_plan_sp.get(); |
| 1346 | } |
| 1347 | |
| 1348 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1349 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 1350 | Address& function, |
| 1351 | lldb::addr_t arg, |
| 1352 | bool stop_other_threads, |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1353 | bool unwind_on_error, |
| 1354 | bool ignore_breakpoints) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1355 | { |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1356 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, |
| 1357 | function, |
| 1358 | ClangASTType(), |
| 1359 | arg, |
| 1360 | stop_other_threads, |
| 1361 | unwind_on_error, |
| 1362 | ignore_breakpoints)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1363 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1364 | return thread_plan_sp.get(); |
| 1365 | } |
| 1366 | |
| 1367 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1368 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1369 | Address &target_addr, |
| 1370 | bool stop_other_threads) |
| 1371 | { |
| 1372 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1373 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1374 | return thread_plan_sp.get(); |
| 1375 | } |
| 1376 | |
| 1377 | ThreadPlan * |
| 1378 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1379 | lldb::addr_t *address_list, |
| 1380 | size_t num_addresses, |
| 1381 | bool stop_other_threads, |
| 1382 | uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1383 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1384 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1385 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1386 | return thread_plan_sp.get(); |
| 1387 | |
| 1388 | } |
| 1389 | |
| 1390 | uint32_t |
| 1391 | Thread::GetIndexID () const |
| 1392 | { |
| 1393 | return m_index_id; |
| 1394 | } |
| 1395 | |
| 1396 | void |
| 1397 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 1398 | { |
| 1399 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1400 | int i; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1401 | s->Indent(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1402 | s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4" PRIx64 ", stack_size = %d\n", GetIndexID(), GetID(), stack_size); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1403 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1404 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1405 | s->IndentMore(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1406 | s->Indent(); |
| 1407 | s->Printf ("Element %d: ", i); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1408 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1409 | s->EOL(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1410 | s->IndentLess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1413 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1414 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1415 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1416 | s->Indent(); |
| 1417 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
| 1418 | for (i = stack_size - 1; i >= 0; i--) |
| 1419 | { |
| 1420 | s->IndentMore(); |
| 1421 | s->Indent(); |
| 1422 | s->Printf ("Element %d: ", i); |
| 1423 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1424 | s->EOL(); |
| 1425 | s->IndentLess(); |
| 1426 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1430 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1431 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1432 | s->Indent(); |
| 1433 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
| 1434 | for (i = stack_size - 1; i >= 0; i--) |
| 1435 | { |
| 1436 | s->IndentMore(); |
| 1437 | s->Indent(); |
| 1438 | s->Printf ("Element %d: ", i); |
| 1439 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1440 | s->EOL(); |
| 1441 | s->IndentLess(); |
| 1442 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | } |
| 1446 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1447 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1448 | Thread::CalculateTarget () |
| 1449 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1450 | TargetSP target_sp; |
| 1451 | ProcessSP process_sp(GetProcess()); |
| 1452 | if (process_sp) |
| 1453 | target_sp = process_sp->CalculateTarget(); |
| 1454 | return target_sp; |
| 1455 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1458 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1459 | Thread::CalculateProcess () |
| 1460 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1461 | return GetProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1464 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1465 | Thread::CalculateThread () |
| 1466 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1467 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1470 | StackFrameSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1471 | Thread::CalculateStackFrame () |
| 1472 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1473 | return StackFrameSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1477 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1478 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1479 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1482 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1483 | StackFrameListSP |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1484 | Thread::GetStackFrameList () |
| 1485 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1486 | StackFrameListSP frame_list_sp; |
| 1487 | Mutex::Locker locker(m_frame_mutex); |
| 1488 | if (m_curr_frames_sp) |
| 1489 | { |
| 1490 | frame_list_sp = m_curr_frames_sp; |
| 1491 | } |
| 1492 | else |
| 1493 | { |
| 1494 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1495 | m_curr_frames_sp = frame_list_sp; |
| 1496 | } |
| 1497 | return frame_list_sp; |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1500 | void |
| 1501 | Thread::ClearStackFrames () |
| 1502 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1503 | Mutex::Locker locker(m_frame_mutex); |
| 1504 | |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1505 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1506 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1507 | // the new frame as we make it, but let's not try that now. |
| 1508 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1509 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1510 | m_curr_frames_sp.reset(); |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | lldb::StackFrameSP |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1514 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1515 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1516 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1519 | |
| 1520 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1521 | Thread::ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1522 | { |
| 1523 | StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); |
| 1524 | Error return_error; |
| 1525 | |
| 1526 | if (!frame_sp) |
| 1527 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1528 | return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%" PRIx64 ".", frame_idx, GetID()); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1529 | } |
| 1530 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1531 | return ReturnFromFrame(frame_sp, return_value_sp, broadcast); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1535 | Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1536 | { |
| 1537 | Error return_error; |
| 1538 | |
| 1539 | if (!frame_sp) |
| 1540 | { |
| 1541 | return_error.SetErrorString("Can't return to a null frame."); |
| 1542 | return return_error; |
| 1543 | } |
| 1544 | |
| 1545 | Thread *thread = frame_sp->GetThread().get(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1546 | uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; |
| 1547 | StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1548 | if (!older_frame_sp) |
| 1549 | { |
| 1550 | return_error.SetErrorString("No older frame to return to."); |
| 1551 | return return_error; |
| 1552 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1553 | |
| 1554 | if (return_value_sp) |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1555 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1556 | lldb::ABISP abi = thread->GetProcess()->GetABI(); |
| 1557 | if (!abi) |
| 1558 | { |
| 1559 | return_error.SetErrorString("Could not find ABI to set return value."); |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1560 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1561 | } |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1562 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); |
| 1563 | |
| 1564 | // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. |
| 1565 | // Turn that back on when that works. |
| 1566 | if (0 && sc.function != NULL) |
| 1567 | { |
| 1568 | Type *function_type = sc.function->GetType(); |
| 1569 | if (function_type) |
| 1570 | { |
| 1571 | clang_type_t return_type = sc.function->GetReturnClangType(); |
| 1572 | if (return_type) |
| 1573 | { |
| 1574 | ClangASTType ast_type (function_type->GetClangAST(), return_type); |
| 1575 | StreamString s; |
| 1576 | ast_type.DumpTypeDescription(&s); |
| 1577 | ValueObjectSP cast_value_sp = return_value_sp->Cast(ast_type); |
| 1578 | if (cast_value_sp) |
| 1579 | { |
| 1580 | cast_value_sp->SetFormat(eFormatHex); |
| 1581 | return_value_sp = cast_value_sp; |
| 1582 | } |
| 1583 | } |
| 1584 | } |
| 1585 | } |
| 1586 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1587 | return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1588 | if (!return_error.Success()) |
| 1589 | return return_error; |
| 1590 | } |
| 1591 | |
| 1592 | // Now write the return registers for the chosen frame: |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1593 | // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1594 | // cook their data |
| 1595 | |
| 1596 | StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0); |
| 1597 | if (youngest_frame_sp) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1598 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1599 | lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext()); |
| 1600 | if (reg_ctx_sp) |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1601 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1602 | bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); |
| 1603 | if (copy_success) |
| 1604 | { |
| 1605 | thread->DiscardThreadPlans(true); |
| 1606 | thread->ClearStackFrames(); |
| 1607 | if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) |
| 1608 | BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | return_error.SetErrorString("Could not reset register values."); |
| 1613 | } |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1614 | } |
| 1615 | else |
| 1616 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1617 | return_error.SetErrorString("Frame has no register context."); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1618 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1619 | } |
| 1620 | else |
| 1621 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1622 | return_error.SetErrorString("Returned past top frame."); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1623 | } |
Greg Clayton | abb487f | 2013-02-01 02:52:31 +0000 | [diff] [blame] | 1624 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1627 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1628 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1629 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1630 | ExecutionContext exe_ctx (shared_from_this()); |
| 1631 | Process *process = exe_ctx.GetProcessPtr(); |
| 1632 | if (process == NULL) |
| 1633 | return; |
| 1634 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1635 | StackFrameSP frame_sp; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1636 | SymbolContext frame_sc; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1637 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1638 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1639 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1640 | if (frame_sp) |
| 1641 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1642 | exe_ctx.SetFrameSP(frame_sp); |
| 1643 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1644 | } |
| 1645 | } |
| 1646 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1647 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1648 | assert (thread_format); |
| 1649 | const char *end = NULL; |
| 1650 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1651 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1652 | &exe_ctx, |
| 1653 | NULL, |
| 1654 | strm, |
| 1655 | &end); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1658 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1659 | Thread::SettingsInitialize () |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1660 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1661 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1662 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1663 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1664 | Thread::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1665 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1666 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1667 | |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1668 | lldb::StackFrameSP |
| 1669 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1670 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1671 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1672 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1673 | |
| 1674 | const char * |
| 1675 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1676 | { |
| 1677 | switch (reason) |
| 1678 | { |
Andrew Kaylor | f85defa | 2012-12-20 23:08:03 +0000 | [diff] [blame] | 1679 | case eStopReasonInvalid: return "invalid"; |
| 1680 | case eStopReasonNone: return "none"; |
| 1681 | case eStopReasonTrace: return "trace"; |
| 1682 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1683 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1684 | case eStopReasonSignal: return "signal"; |
| 1685 | case eStopReasonException: return "exception"; |
| 1686 | case eStopReasonExec: return "exec"; |
| 1687 | case eStopReasonPlanComplete: return "plan complete"; |
| 1688 | case eStopReasonThreadExiting: return "thread exiting"; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | |
| 1692 | static char unknown_state_string[64]; |
| 1693 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1694 | return unknown_state_string; |
| 1695 | } |
| 1696 | |
| 1697 | const char * |
| 1698 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1699 | { |
| 1700 | switch (mode) |
| 1701 | { |
| 1702 | case eOnlyThisThread: return "only this thread"; |
| 1703 | case eAllThreads: return "all threads"; |
| 1704 | case eOnlyDuringStepping: return "only during stepping"; |
| 1705 | } |
| 1706 | |
| 1707 | static char unknown_state_string[64]; |
| 1708 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1709 | return unknown_state_string; |
| 1710 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1711 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1712 | size_t |
| 1713 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 1714 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1715 | ExecutionContext exe_ctx (shared_from_this()); |
| 1716 | Target *target = exe_ctx.GetTargetPtr(); |
| 1717 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1718 | size_t num_frames_shown = 0; |
| 1719 | strm.Indent(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1720 | bool is_selected = false; |
| 1721 | if (process) |
| 1722 | { |
| 1723 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 1724 | is_selected = true; |
| 1725 | } |
| 1726 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 1727 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1728 | { |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1729 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1730 | if (frame_sp) |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1731 | { |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1732 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 1733 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 1734 | { |
| 1735 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 1736 | } |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1737 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1738 | } |
| 1739 | |
| 1740 | DumpUsingSettingsFormat (strm, start_frame); |
| 1741 | |
| 1742 | if (num_frames > 0) |
| 1743 | { |
| 1744 | strm.IndentMore(); |
| 1745 | |
| 1746 | const bool show_frame_info = true; |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1747 | strm.IndentMore (); |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1748 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 1749 | start_frame, |
| 1750 | num_frames, |
| 1751 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1752 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1753 | strm.IndentLess(); |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1754 | strm.IndentLess(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1755 | } |
| 1756 | return num_frames_shown; |
| 1757 | } |
| 1758 | |
| 1759 | size_t |
| 1760 | Thread::GetStackFrameStatus (Stream& strm, |
| 1761 | uint32_t first_frame, |
| 1762 | uint32_t num_frames, |
| 1763 | bool show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1764 | uint32_t num_frames_with_source) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1765 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1766 | return GetStackFrameList()->GetStatus (strm, |
| 1767 | first_frame, |
| 1768 | num_frames, |
| 1769 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1770 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1771 | } |
| 1772 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1773 | bool |
| 1774 | Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) |
| 1775 | { |
| 1776 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1777 | if (frame_sp) |
| 1778 | { |
| 1779 | checkpoint.SetStackID(frame_sp->GetStackID()); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1780 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 1781 | if (reg_ctx_sp) |
| 1782 | return reg_ctx_sp->ReadAllRegisterValues (checkpoint.GetData()); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1783 | } |
| 1784 | return false; |
| 1785 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1786 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1787 | bool |
| 1788 | Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) |
| 1789 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1790 | return ResetFrameZeroRegisters (checkpoint.GetData()); |
| 1791 | } |
| 1792 | |
| 1793 | bool |
| 1794 | Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp) |
| 1795 | { |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1796 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1797 | if (frame_sp) |
| 1798 | { |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1799 | lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext()); |
| 1800 | if (reg_ctx_sp) |
| 1801 | { |
| 1802 | bool ret = reg_ctx_sp->WriteAllRegisterValues (register_data_sp); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1803 | |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1804 | // Clear out all stack frames as our world just changed. |
| 1805 | ClearStackFrames(); |
| 1806 | reg_ctx_sp->InvalidateIfNeeded(true); |
| 1807 | if (m_unwinder_ap.get()) |
| 1808 | m_unwinder_ap->Clear(); |
| 1809 | return ret; |
| 1810 | } |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1811 | } |
| 1812 | return false; |
| 1813 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1814 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1815 | Unwind * |
| 1816 | Thread::GetUnwinder () |
| 1817 | { |
| 1818 | if (m_unwinder_ap.get() == NULL) |
| 1819 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1820 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1821 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 1822 | switch (machine) |
| 1823 | { |
| 1824 | case llvm::Triple::x86_64: |
| 1825 | case llvm::Triple::x86: |
| 1826 | case llvm::Triple::arm: |
| 1827 | case llvm::Triple::thumb: |
| 1828 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 1829 | break; |
| 1830 | |
| 1831 | default: |
| 1832 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 1833 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 1834 | break; |
| 1835 | } |
| 1836 | } |
| 1837 | return m_unwinder_ap.get(); |
| 1838 | } |
| 1839 | |
| 1840 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 1841 | void |
| 1842 | Thread::Flush () |
| 1843 | { |
| 1844 | ClearStackFrames (); |
| 1845 | m_reg_context_sp.reset(); |
| 1846 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1847 | |
Filipe Cabecinhas | b3d5d71 | 2012-11-20 00:11:13 +0000 | [diff] [blame] | 1848 | bool |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1849 | Thread::IsStillAtLastBreakpointHit () |
| 1850 | { |
| 1851 | // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. |
| 1852 | // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in |
| 1853 | // multithreaded programs. |
| 1854 | if (m_actual_stop_info_sp) { |
| 1855 | StopReason stop_reason = m_actual_stop_info_sp->GetStopReason(); |
| 1856 | if (stop_reason == lldb::eStopReasonBreakpoint) { |
| 1857 | uint64_t value = m_actual_stop_info_sp->GetValue(); |
Greg Clayton | 1afa68e | 2013-04-02 20:32:37 +0000 | [diff] [blame] | 1858 | lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext()); |
| 1859 | if (reg_ctx_sp) |
| 1860 | { |
| 1861 | lldb::addr_t pc = reg_ctx_sp->GetPC(); |
| 1862 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 1863 | if (bp_site_sp && value == bp_site_sp->GetID()) |
| 1864 | return true; |
| 1865 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1866 | } |
| 1867 | } |
| 1868 | return false; |
| 1869 | } |