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 | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 262 | LogSP 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 | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 273 | LogSP 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 | |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +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) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | { |
| 488 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 489 | // special to step over a breakpoint. |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 490 | |
| 491 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 492 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 493 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 494 | { |
| 495 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 496 | if (step_bp_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 498 | ThreadPlanSP step_bp_plan_sp; |
| 499 | step_bp_plan->SetPrivate (true); |
| 500 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 502 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 503 | step_bp_plan->SetAutoContinue(true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 504 | } |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 505 | step_bp_plan_sp.reset (step_bp_plan); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 506 | QueueThreadPlan (step_bp_plan_sp, false); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | } |
| 511 | } |
| 512 | |
| 513 | bool |
| 514 | Thread::WillResume (StateType resume_state) |
| 515 | { |
| 516 | // At this point clear the completed plan stack. |
| 517 | m_completed_plan_stack.clear(); |
| 518 | m_discarded_plan_stack.clear(); |
| 519 | |
Greg Clayton | 97d5cf0 | 2012-09-25 02:40:06 +0000 | [diff] [blame] | 520 | m_temporary_resume_state = resume_state; |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 521 | |
| 522 | // This is a little dubious, but we are trying to limit how often we actually fetch stop info from |
| 523 | // the target, 'cause that slows down single stepping. So assume that if we got to the point where |
| 524 | // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know |
| 525 | // about the fact that we are resuming... |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 526 | const uint32_t process_stop_id = GetProcess()->GetStopID(); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 527 | if (m_thread_stop_reason_stop_id == process_stop_id && |
| 528 | (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid())) |
| 529 | { |
| 530 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 531 | if (stop_info) |
| 532 | stop_info->WillResume (resume_state); |
| 533 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | |
| 535 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 536 | // We distinguish between the plan on the top of the stack and the lower |
| 537 | // plans in case a plan needs to do any special business before it runs. |
| 538 | |
| 539 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 540 | bool need_to_resume = plan_ptr->WillResume(resume_state, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 541 | |
| 542 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 543 | { |
| 544 | plan_ptr->WillResume (resume_state, false); |
| 545 | } |
Greg Clayton | f4b47e1 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 546 | |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 547 | // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info. |
| 548 | // In that case, don't reset it here. |
| 549 | |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 550 | if (need_to_resume && resume_state != eStateSuspended) |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 551 | { |
| 552 | m_actual_stop_info_sp.reset(); |
| 553 | } |
| 554 | |
| 555 | return need_to_resume; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | void |
| 559 | Thread::DidResume () |
| 560 | { |
| 561 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 562 | } |
| 563 | |
| 564 | bool |
| 565 | Thread::ShouldStop (Event* event_ptr) |
| 566 | { |
| 567 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 568 | bool should_stop = true; |
| 569 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 570 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 571 | |
| 572 | if (GetResumeState () == eStateSuspended) |
| 573 | { |
| 574 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 575 | 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] | 576 | __FUNCTION__, |
| 577 | GetID ()); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 578 | // log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 579 | // __FUNCTION__, |
| 580 | // GetID (), |
| 581 | // GetRegisterContext()->GetPC()); |
| 582 | return false; |
| 583 | } |
| 584 | |
| 585 | if (GetTemporaryResumeState () == eStateSuspended) |
| 586 | { |
| 587 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 588 | 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] | 589 | __FUNCTION__, |
| 590 | GetID ()); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 591 | // log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since thread was suspended)", |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 592 | // __FUNCTION__, |
| 593 | // GetID (), |
| 594 | // GetRegisterContext()->GetPC()); |
| 595 | return false; |
| 596 | } |
| 597 | |
| 598 | if (ThreadStoppedForAReason() == false) |
| 599 | { |
| 600 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 601 | 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] | 602 | __FUNCTION__, |
| 603 | GetID (), |
| 604 | GetRegisterContext()->GetPC()); |
| 605 | return false; |
| 606 | } |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 607 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 608 | if (log) |
| 609 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 610 | 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] | 611 | __FUNCTION__, |
| 612 | GetID (), |
| 613 | GetRegisterContext()->GetPC()); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 614 | log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | StreamString s; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 616 | s.IndentMore(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 617 | DumpThreadPlans(&s); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 618 | log->Printf ("Plan stack initial state:\n%s", s.GetData()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 619 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 620 | |
| 621 | // The top most plan always gets to do the trace log... |
| 622 | current_plan->DoTraceLog (); |
Jim Ingham | 6d66ce6 | 2012-04-20 21:16:56 +0000 | [diff] [blame] | 623 | |
| 624 | // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint |
| 625 | // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to |
| 626 | // do any more work on this stop. |
| 627 | StopInfoSP private_stop_info (GetPrivateStopReason()); |
| 628 | if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false) |
| 629 | { |
| 630 | if (log) |
| 631 | log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false."); |
| 632 | return false; |
| 633 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 634 | |
Jim Ingham | bad39e4 | 2012-09-05 21:12:49 +0000 | [diff] [blame] | 635 | // If we've already been restarted, don't query the plans since the state they would examine is not current. |
| 636 | if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr)) |
| 637 | return false; |
| 638 | |
| 639 | // Before the plans see the state of the world, calculate the current inlined depth. |
| 640 | GetStackFrameList()->CalculateCurrentInlinedDepth(); |
| 641 | |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 642 | // If the base plan doesn't understand why we stopped, then we have to find a plan that does. |
| 643 | // If that plan is still working, then we don't need to do any more work. If the plan that explains |
| 644 | // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide |
| 645 | // whether they still need to do more work. |
| 646 | |
| 647 | bool done_processing_current_plan = false; |
| 648 | |
| 649 | if (!current_plan->PlanExplainsStop()) |
| 650 | { |
| 651 | if (current_plan->TracerExplainsStop()) |
| 652 | { |
| 653 | done_processing_current_plan = true; |
| 654 | should_stop = false; |
| 655 | } |
| 656 | else |
| 657 | { |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 658 | // 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] | 659 | // does and let it handle the situation. |
| 660 | ThreadPlan *plan_ptr = current_plan; |
| 661 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 662 | { |
| 663 | if (plan_ptr->PlanExplainsStop()) |
| 664 | { |
| 665 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 666 | |
| 667 | // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it |
| 668 | // and all the plans below it off the stack. |
| 669 | |
| 670 | if (plan_ptr->MischiefManaged()) |
| 671 | { |
Jim Ingham | 031177e | 2012-05-11 23:49:49 +0000 | [diff] [blame] | 672 | // 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] | 673 | ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr); |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 674 | |
| 675 | do |
| 676 | { |
| 677 | if (should_stop) |
| 678 | current_plan->WillStop(); |
| 679 | PopPlan(); |
| 680 | } |
Jim Ingham | 7ba6e99 | 2012-05-11 23:47:32 +0000 | [diff] [blame] | 681 | while ((current_plan = GetCurrentPlan()) != prev_plan_ptr); |
| 682 | // Now, if the responsible plan was not "Okay to discard" then we're done, |
| 683 | // otherwise we forward this to the next plan in the stack below. |
| 684 | if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard()) |
| 685 | done_processing_current_plan = true; |
| 686 | else |
| 687 | done_processing_current_plan = false; |
Jim Ingham | 25f6670 | 2011-12-03 01:52:59 +0000 | [diff] [blame] | 688 | } |
| 689 | else |
| 690 | done_processing_current_plan = true; |
| 691 | |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | if (!done_processing_current_plan) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 700 | { |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 701 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 702 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 703 | if (log) |
| 704 | log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop); |
| 705 | |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 706 | // We're starting from the base plan, so just let it decide; |
| 707 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 708 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 709 | should_stop = current_plan->ShouldStop (event_ptr); |
| 710 | if (log) |
Greg Clayton | af247d7 | 2011-05-19 03:54:16 +0000 | [diff] [blame] | 711 | log->Printf("Base plan says should stop: %i.", should_stop); |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 712 | } |
| 713 | else |
| 714 | { |
| 715 | // Otherwise, don't let the base plan override what the other plans say to do, since |
| 716 | // presumably if there were other plans they would know what to do... |
| 717 | while (1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 718 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 719 | if (PlanIsBasePlan(current_plan)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 720 | break; |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 721 | |
| 722 | should_stop = current_plan->ShouldStop(event_ptr); |
| 723 | if (log) |
| 724 | log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop); |
| 725 | if (current_plan->MischiefManaged()) |
| 726 | { |
| 727 | if (should_stop) |
| 728 | current_plan->WillStop(); |
| 729 | |
| 730 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 731 | // Otherwise, see if the plan's parent wants to stop. |
| 732 | |
| 733 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 734 | { |
| 735 | PopPlan(); |
| 736 | break; |
| 737 | } |
| 738 | else |
| 739 | { |
| 740 | |
| 741 | PopPlan(); |
| 742 | |
| 743 | current_plan = GetCurrentPlan(); |
| 744 | if (current_plan == NULL) |
| 745 | { |
| 746 | break; |
| 747 | } |
| 748 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 749 | } |
| 750 | else |
| 751 | { |
Jim Ingham | 0f16e73 | 2011-02-08 05:20:59 +0000 | [diff] [blame] | 752 | break; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 753 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 754 | } |
| 755 | } |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 756 | |
Jim Ingham | b01e742 | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 757 | if (over_ride_stop) |
| 758 | should_stop = false; |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 759 | |
| 760 | // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance |
| 761 | // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up |
| 762 | // past the end point condition of the initial plan. We don't want to strand the original plan on the stack, |
| 763 | // This code clears stale plans off the stack. |
| 764 | |
| 765 | if (should_stop) |
| 766 | { |
| 767 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 768 | while (!PlanIsBasePlan(plan_ptr)) |
| 769 | { |
| 770 | bool stale = plan_ptr->IsPlanStale (); |
| 771 | ThreadPlan *examined_plan = plan_ptr; |
| 772 | plan_ptr = GetPreviousPlan (examined_plan); |
| 773 | |
| 774 | if (stale) |
| 775 | { |
| 776 | if (log) |
| 777 | log->Printf("Plan %s being discarded in cleanup, it says it is already done.", examined_plan->GetName()); |
| 778 | DiscardThreadPlansUpToPlan(examined_plan); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 783 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 784 | |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 785 | if (log) |
| 786 | { |
| 787 | StreamString s; |
| 788 | s.IndentMore(); |
| 789 | DumpThreadPlans(&s); |
| 790 | log->Printf ("Plan stack final state:\n%s", s.GetData()); |
| 791 | log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop); |
| 792 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | return should_stop; |
| 794 | } |
| 795 | |
| 796 | Vote |
| 797 | Thread::ShouldReportStop (Event* event_ptr) |
| 798 | { |
| 799 | StateType thread_state = GetResumeState (); |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 800 | StateType temp_thread_state = GetTemporaryResumeState(); |
| 801 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 802 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 803 | |
| 804 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 805 | { |
| 806 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 807 | 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] | 808 | return eVoteNoOpinion; |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 809 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 810 | |
Jim Ingham | 92087d8 | 2012-01-31 23:09:20 +0000 | [diff] [blame] | 811 | if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid) |
| 812 | { |
| 813 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 814 | 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] | 815 | return eVoteNoOpinion; |
| 816 | } |
| 817 | |
| 818 | if (!ThreadStoppedForAReason()) |
| 819 | { |
| 820 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 821 | 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] | 822 | return eVoteNoOpinion; |
| 823 | } |
| 824 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | if (m_completed_plan_stack.size() > 0) |
| 826 | { |
| 827 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 828 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 829 | 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] | 830 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 831 | } |
| 832 | else |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 833 | { |
| 834 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 835 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for current plan\n", GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 836 | return GetCurrentPlan()->ShouldReportStop (event_ptr); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 837 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | Vote |
| 841 | Thread::ShouldReportRun (Event* event_ptr) |
| 842 | { |
| 843 | StateType thread_state = GetResumeState (); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 844 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 845 | if (thread_state == eStateSuspended |
| 846 | || thread_state == eStateInvalid) |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 847 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 848 | return eVoteNoOpinion; |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 852 | if (m_completed_plan_stack.size() > 0) |
| 853 | { |
| 854 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 855 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 856 | 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] | 857 | GetIndexID(), |
| 858 | GetID(), |
| 859 | m_completed_plan_stack.back()->GetName()); |
| 860 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 861 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 862 | } |
| 863 | else |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 864 | { |
| 865 | if (log) |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 866 | 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] | 867 | GetIndexID(), |
| 868 | GetID(), |
| 869 | GetCurrentPlan()->GetName()); |
| 870 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 871 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | 444586b | 2011-01-24 06:34:17 +0000 | [diff] [blame] | 872 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | } |
| 874 | |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 875 | bool |
| 876 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 877 | { |
| 878 | if (spec == NULL) |
| 879 | return true; |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 880 | |
Jim Ingham | 3d90292 | 2012-03-07 22:03:04 +0000 | [diff] [blame] | 881 | return spec->ThreadPassesBasicTests(*this); |
Jim Ingham | 1b54c88 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 884 | void |
| 885 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 886 | { |
| 887 | if (thread_plan_sp) |
| 888 | { |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 889 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 890 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 891 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 892 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 893 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 894 | thread_plan_sp->DidPush(); |
| 895 | |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 896 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 897 | if (log) |
| 898 | { |
| 899 | StreamString s; |
| 900 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 901 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4" PRIx64 ".", |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 902 | s.GetData(), |
Jim Ingham | b15bfc7 | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 903 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 904 | } |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | void |
| 909 | Thread::PopPlan () |
| 910 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 911 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 912 | |
Jim Ingham | 4fc6cb9 | 2012-08-22 21:34:33 +0000 | [diff] [blame] | 913 | if (m_plan_stack.size() <= 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 914 | return; |
| 915 | else |
| 916 | { |
| 917 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 918 | if (log) |
| 919 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 920 | 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] | 921 | } |
| 922 | m_completed_plan_stack.push_back (plan); |
| 923 | plan->WillPop(); |
| 924 | m_plan_stack.pop_back(); |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | void |
| 929 | Thread::DiscardPlan () |
| 930 | { |
| 931 | if (m_plan_stack.size() > 1) |
| 932 | { |
| 933 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 934 | m_discarded_plan_stack.push_back (plan); |
| 935 | plan->WillPop(); |
| 936 | m_plan_stack.pop_back(); |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | ThreadPlan * |
| 941 | Thread::GetCurrentPlan () |
| 942 | { |
Jim Ingham | e147123 | 2012-04-19 00:17:05 +0000 | [diff] [blame] | 943 | // There will always be at least the base plan. If somebody is mucking with a |
| 944 | // thread with an empty plan stack, we should assert right away. |
| 945 | assert (!m_plan_stack.empty()); |
| 946 | |
| 947 | return m_plan_stack.back().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | ThreadPlanSP |
| 951 | Thread::GetCompletedPlan () |
| 952 | { |
| 953 | ThreadPlanSP empty_plan_sp; |
| 954 | if (!m_completed_plan_stack.empty()) |
| 955 | { |
| 956 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 957 | { |
| 958 | ThreadPlanSP completed_plan_sp; |
| 959 | completed_plan_sp = m_completed_plan_stack[i]; |
| 960 | if (!completed_plan_sp->GetPrivate ()) |
| 961 | return completed_plan_sp; |
| 962 | } |
| 963 | } |
| 964 | return empty_plan_sp; |
| 965 | } |
| 966 | |
Jim Ingham | 73ca05a | 2011-12-17 01:35:57 +0000 | [diff] [blame] | 967 | ValueObjectSP |
| 968 | Thread::GetReturnValueObject () |
| 969 | { |
| 970 | if (!m_completed_plan_stack.empty()) |
| 971 | { |
| 972 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 973 | { |
| 974 | ValueObjectSP return_valobj_sp; |
| 975 | return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject(); |
| 976 | if (return_valobj_sp) |
| 977 | return return_valobj_sp; |
| 978 | } |
| 979 | } |
| 980 | return ValueObjectSP(); |
| 981 | } |
| 982 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 983 | bool |
| 984 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 985 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 986 | if (!m_completed_plan_stack.empty()) |
| 987 | { |
| 988 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 989 | { |
| 990 | if (m_completed_plan_stack[i].get() == plan) |
| 991 | return true; |
| 992 | } |
| 993 | } |
| 994 | return false; |
| 995 | } |
| 996 | |
| 997 | bool |
| 998 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 999 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1000 | if (!m_discarded_plan_stack.empty()) |
| 1001 | { |
| 1002 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 1003 | { |
| 1004 | if (m_discarded_plan_stack[i].get() == plan) |
| 1005 | return true; |
| 1006 | } |
| 1007 | } |
| 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | ThreadPlan * |
| 1012 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 1013 | { |
| 1014 | if (current_plan == NULL) |
| 1015 | return NULL; |
| 1016 | |
| 1017 | int stack_size = m_completed_plan_stack.size(); |
| 1018 | for (int i = stack_size - 1; i > 0; i--) |
| 1019 | { |
| 1020 | if (current_plan == m_completed_plan_stack[i].get()) |
| 1021 | return m_completed_plan_stack[i-1].get(); |
| 1022 | } |
| 1023 | |
| 1024 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 1025 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1026 | if (m_plan_stack.size() > 0) |
| 1027 | return m_plan_stack.back().get(); |
| 1028 | else |
| 1029 | return NULL; |
| 1030 | } |
| 1031 | |
| 1032 | stack_size = m_plan_stack.size(); |
| 1033 | for (int i = stack_size - 1; i > 0; i--) |
| 1034 | { |
| 1035 | if (current_plan == m_plan_stack[i].get()) |
| 1036 | return m_plan_stack[i-1].get(); |
| 1037 | } |
| 1038 | return NULL; |
| 1039 | } |
| 1040 | |
| 1041 | void |
| 1042 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 1043 | { |
| 1044 | if (abort_other_plans) |
| 1045 | DiscardThreadPlans(true); |
| 1046 | |
| 1047 | PushPlan (thread_plan_sp); |
| 1048 | } |
| 1049 | |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1050 | |
| 1051 | void |
| 1052 | Thread::EnableTracer (bool value, bool single_stepping) |
| 1053 | { |
| 1054 | int stack_size = m_plan_stack.size(); |
| 1055 | for (int i = 0; i < stack_size; i++) |
| 1056 | { |
| 1057 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 1058 | { |
| 1059 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 1060 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 1061 | } |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | void |
| 1066 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 1067 | { |
| 1068 | int stack_size = m_plan_stack.size(); |
| 1069 | for (int i = 0; i < stack_size; i++) |
| 1070 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 1071 | } |
| 1072 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1073 | void |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1074 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 1075 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1076 | DiscardThreadPlansUpToPlan (up_to_plan_sp.get()); |
| 1077 | } |
| 1078 | |
| 1079 | void |
| 1080 | Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr) |
| 1081 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1082 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1083 | if (log) |
| 1084 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1085 | 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] | 1086 | } |
| 1087 | |
| 1088 | int stack_size = m_plan_stack.size(); |
| 1089 | |
| 1090 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1091 | // stack, and if so discard up to and including it. |
| 1092 | |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1093 | if (up_to_plan_ptr == NULL) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1094 | { |
| 1095 | for (int i = stack_size - 1; i > 0; i--) |
| 1096 | DiscardPlan(); |
| 1097 | } |
| 1098 | else |
| 1099 | { |
| 1100 | bool found_it = false; |
| 1101 | for (int i = stack_size - 1; i > 0; i--) |
| 1102 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1103 | if (m_plan_stack[i].get() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1104 | found_it = true; |
| 1105 | } |
| 1106 | if (found_it) |
| 1107 | { |
| 1108 | bool last_one = false; |
| 1109 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 1110 | { |
Jim Ingham | 64e7ead | 2012-05-03 21:19:36 +0000 | [diff] [blame] | 1111 | if (GetCurrentPlan() == up_to_plan_ptr) |
Jim Ingham | 399f1ca | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 1112 | last_one = true; |
| 1113 | DiscardPlan(); |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | return; |
| 1118 | } |
| 1119 | |
| 1120 | void |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1121 | Thread::DiscardThreadPlans(bool force) |
| 1122 | { |
Greg Clayton | 2d4edfb | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 1123 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1124 | if (log) |
| 1125 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1126 | 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] | 1127 | } |
| 1128 | |
| 1129 | if (force) |
| 1130 | { |
| 1131 | int stack_size = m_plan_stack.size(); |
| 1132 | for (int i = stack_size - 1; i > 0; i--) |
| 1133 | { |
| 1134 | DiscardPlan(); |
| 1135 | } |
| 1136 | return; |
| 1137 | } |
| 1138 | |
| 1139 | while (1) |
| 1140 | { |
| 1141 | |
| 1142 | int master_plan_idx; |
Jim Ingham | a39ad07 | 2012-09-11 00:09:25 +0000 | [diff] [blame] | 1143 | bool discard = true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1144 | |
| 1145 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 1146 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 1147 | { |
| 1148 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 1149 | { |
| 1150 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 1151 | break; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | if (discard) |
| 1156 | { |
| 1157 | // First pop all the dependent plans: |
| 1158 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 1159 | { |
| 1160 | |
| 1161 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 1162 | // for the plan leaves it in a state that it is safe to pop the plan |
| 1163 | // with no more notice? |
| 1164 | DiscardPlan(); |
| 1165 | } |
| 1166 | |
| 1167 | // Now discard the master plan itself. |
| 1168 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 1169 | // discard it's dependent plans, but not it... |
| 1170 | if (master_plan_idx > 0) |
| 1171 | { |
| 1172 | DiscardPlan(); |
| 1173 | } |
| 1174 | } |
| 1175 | else |
| 1176 | { |
| 1177 | // If the master plan doesn't want to get discarded, then we're done. |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Jim Ingham | cf274f9 | 2012-04-09 22:37:39 +0000 | [diff] [blame] | 1184 | bool |
| 1185 | Thread::PlanIsBasePlan (ThreadPlan *plan_ptr) |
| 1186 | { |
| 1187 | if (plan_ptr->IsBasePlan()) |
| 1188 | return true; |
| 1189 | else if (m_plan_stack.size() == 0) |
| 1190 | return false; |
| 1191 | else |
| 1192 | return m_plan_stack[0].get() == plan_ptr; |
| 1193 | } |
| 1194 | |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1195 | Error |
| 1196 | Thread::UnwindInnermostExpression() |
| 1197 | { |
| 1198 | Error error; |
| 1199 | int stack_size = m_plan_stack.size(); |
| 1200 | |
| 1201 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 1202 | // stack, and if so discard up to and including it. |
| 1203 | |
| 1204 | for (int i = stack_size - 1; i > 0; i--) |
| 1205 | { |
| 1206 | if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction) |
| 1207 | { |
| 1208 | DiscardThreadPlansUpToPlan(m_plan_stack[i].get()); |
| 1209 | return error; |
| 1210 | } |
| 1211 | } |
| 1212 | error.SetErrorString("No expressions currently active on this thread"); |
| 1213 | return error; |
| 1214 | } |
| 1215 | |
| 1216 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1217 | ThreadPlan * |
| 1218 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 1219 | { |
| 1220 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 1221 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1222 | return thread_plan_sp.get(); |
| 1223 | } |
| 1224 | |
| 1225 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1226 | Thread::QueueThreadPlanForStepSingleInstruction |
| 1227 | ( |
| 1228 | bool step_over, |
| 1229 | bool abort_other_plans, |
| 1230 | bool stop_other_threads |
| 1231 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1232 | { |
| 1233 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 1234 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1235 | return thread_plan_sp.get(); |
| 1236 | } |
| 1237 | |
| 1238 | ThreadPlan * |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1239 | Thread::QueueThreadPlanForStepOverRange |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1240 | ( |
| 1241 | bool abort_other_plans, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1242 | const AddressRange &range, |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1243 | const SymbolContext &addr_context, |
| 1244 | lldb::RunMode stop_other_threads |
| 1245 | ) |
| 1246 | { |
| 1247 | ThreadPlanSP thread_plan_sp; |
| 1248 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 1249 | |
| 1250 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1251 | return thread_plan_sp.get(); |
| 1252 | } |
| 1253 | |
| 1254 | ThreadPlan * |
| 1255 | Thread::QueueThreadPlanForStepInRange |
| 1256 | ( |
| 1257 | bool abort_other_plans, |
| 1258 | const AddressRange &range, |
| 1259 | const SymbolContext &addr_context, |
| 1260 | const char *step_in_target, |
Greg Clayton | 474966a | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 1261 | lldb::RunMode stop_other_threads, |
| 1262 | bool avoid_code_without_debug_info |
| 1263 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1264 | { |
| 1265 | ThreadPlanSP thread_plan_sp; |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1266 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 1267 | if (avoid_code_without_debug_info) |
| 1268 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1269 | else |
Jim Ingham | c627682 | 2012-12-12 19:58:40 +0000 | [diff] [blame] | 1270 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 1271 | if (step_in_target) |
| 1272 | plan->SetStepInTarget(step_in_target); |
| 1273 | thread_plan_sp.reset (plan); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1274 | |
| 1275 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1276 | return thread_plan_sp.get(); |
| 1277 | } |
| 1278 | |
| 1279 | |
| 1280 | ThreadPlan * |
| 1281 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 1282 | { |
| 1283 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 1284 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1285 | return thread_plan_sp.get(); |
| 1286 | } |
| 1287 | |
| 1288 | ThreadPlan * |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1289 | Thread::QueueThreadPlanForStepOut |
| 1290 | ( |
| 1291 | bool abort_other_plans, |
| 1292 | SymbolContext *addr_context, |
| 1293 | bool first_insn, |
| 1294 | bool stop_other_threads, |
| 1295 | Vote stop_vote, |
| 1296 | Vote run_vote, |
| 1297 | uint32_t frame_idx |
| 1298 | ) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1299 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1300 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 1301 | addr_context, |
| 1302 | first_insn, |
| 1303 | stop_other_threads, |
| 1304 | stop_vote, |
| 1305 | run_vote, |
| 1306 | frame_idx)); |
Sean Callanan | 708709c | 2012-07-31 22:19:25 +0000 | [diff] [blame] | 1307 | |
| 1308 | if (thread_plan_sp->ValidatePlan(NULL)) |
| 1309 | { |
| 1310 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1311 | return thread_plan_sp.get(); |
| 1312 | } |
| 1313 | else |
| 1314 | { |
| 1315 | return NULL; |
| 1316 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | ThreadPlan * |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1320 | 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] | 1321 | { |
Jim Ingham | 18de2fd | 2012-05-10 01:35:39 +0000 | [diff] [blame] | 1322 | 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] | 1323 | if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL)) |
| 1324 | return NULL; |
| 1325 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1326 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1327 | return thread_plan_sp.get(); |
| 1328 | } |
| 1329 | |
| 1330 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1331 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 1332 | Address& function, |
| 1333 | lldb::addr_t arg, |
| 1334 | bool stop_other_threads, |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1335 | bool unwind_on_error, |
| 1336 | bool ignore_breakpoints) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1337 | { |
Jim Ingham | 184e981 | 2013-01-15 02:47:48 +0000 | [diff] [blame] | 1338 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, |
| 1339 | function, |
| 1340 | ClangASTType(), |
| 1341 | arg, |
| 1342 | stop_other_threads, |
| 1343 | unwind_on_error, |
| 1344 | ignore_breakpoints)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1345 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1346 | return thread_plan_sp.get(); |
| 1347 | } |
| 1348 | |
| 1349 | ThreadPlan * |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1350 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 1351 | Address &target_addr, |
| 1352 | bool stop_other_threads) |
| 1353 | { |
| 1354 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 1355 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1356 | return thread_plan_sp.get(); |
| 1357 | } |
| 1358 | |
| 1359 | ThreadPlan * |
| 1360 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1361 | lldb::addr_t *address_list, |
| 1362 | size_t num_addresses, |
| 1363 | bool stop_other_threads, |
| 1364 | uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1365 | { |
Greg Clayton | 481cef2 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 1366 | 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] | 1367 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 1368 | return thread_plan_sp.get(); |
| 1369 | |
| 1370 | } |
| 1371 | |
| 1372 | uint32_t |
| 1373 | Thread::GetIndexID () const |
| 1374 | { |
| 1375 | return m_index_id; |
| 1376 | } |
| 1377 | |
| 1378 | void |
| 1379 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 1380 | { |
| 1381 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | 1346f7e | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 1382 | int i; |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1383 | s->Indent(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1384 | 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] | 1385 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1386 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1387 | s->IndentMore(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1388 | s->Indent(); |
| 1389 | s->Printf ("Element %d: ", i); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1390 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1391 | s->EOL(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1392 | s->IndentLess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1393 | } |
| 1394 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1395 | stack_size = m_completed_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1396 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1397 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1398 | s->Indent(); |
| 1399 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
| 1400 | for (i = stack_size - 1; i >= 0; i--) |
| 1401 | { |
| 1402 | s->IndentMore(); |
| 1403 | s->Indent(); |
| 1404 | s->Printf ("Element %d: ", i); |
| 1405 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1406 | s->EOL(); |
| 1407 | s->IndentLess(); |
| 1408 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | stack_size = m_discarded_plan_stack.size(); |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1412 | if (stack_size > 0) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1413 | { |
Jim Ingham | 10c4b24 | 2011-10-15 00:23:43 +0000 | [diff] [blame] | 1414 | s->Indent(); |
| 1415 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
| 1416 | for (i = stack_size - 1; i >= 0; i--) |
| 1417 | { |
| 1418 | s->IndentMore(); |
| 1419 | s->Indent(); |
| 1420 | s->Printf ("Element %d: ", i); |
| 1421 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 1422 | s->EOL(); |
| 1423 | s->IndentLess(); |
| 1424 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | } |
| 1428 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1429 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1430 | Thread::CalculateTarget () |
| 1431 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1432 | TargetSP target_sp; |
| 1433 | ProcessSP process_sp(GetProcess()); |
| 1434 | if (process_sp) |
| 1435 | target_sp = process_sp->CalculateTarget(); |
| 1436 | return target_sp; |
| 1437 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1438 | } |
| 1439 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1440 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1441 | Thread::CalculateProcess () |
| 1442 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1443 | return GetProcess(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1444 | } |
| 1445 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1446 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1447 | Thread::CalculateThread () |
| 1448 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1449 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1450 | } |
| 1451 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1452 | StackFrameSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1453 | Thread::CalculateStackFrame () |
| 1454 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1455 | return StackFrameSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1459 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1460 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1461 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1464 | |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1465 | StackFrameListSP |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1466 | Thread::GetStackFrameList () |
| 1467 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1468 | StackFrameListSP frame_list_sp; |
| 1469 | Mutex::Locker locker(m_frame_mutex); |
| 1470 | if (m_curr_frames_sp) |
| 1471 | { |
| 1472 | frame_list_sp = m_curr_frames_sp; |
| 1473 | } |
| 1474 | else |
| 1475 | { |
| 1476 | frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true)); |
| 1477 | m_curr_frames_sp = frame_list_sp; |
| 1478 | } |
| 1479 | return frame_list_sp; |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1480 | } |
| 1481 | |
Greg Clayton | 12daf946 | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 1482 | void |
| 1483 | Thread::ClearStackFrames () |
| 1484 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1485 | Mutex::Locker locker(m_frame_mutex); |
| 1486 | |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 1487 | // Only store away the old "reference" StackFrameList if we got all its frames: |
| 1488 | // FIXME: At some point we can try to splice in the frames we have fetched into |
| 1489 | // the new frame as we make it, but let's not try that now. |
| 1490 | if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched()) |
Greg Clayton | 7e9b1fd | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 1491 | m_prev_frames_sp.swap (m_curr_frames_sp); |
| 1492 | m_curr_frames_sp.reset(); |
Jim Ingham | 87c1191 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 1493 | } |
| 1494 | |
| 1495 | lldb::StackFrameSP |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1496 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 1497 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1498 | return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1501 | |
| 1502 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1503 | 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] | 1504 | { |
| 1505 | StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx); |
| 1506 | Error return_error; |
| 1507 | |
| 1508 | if (!frame_sp) |
| 1509 | { |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1510 | 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] | 1511 | } |
| 1512 | |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1513 | return ReturnFromFrame(frame_sp, return_value_sp, broadcast); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | Error |
Jim Ingham | 4f465cf | 2012-10-10 18:32:14 +0000 | [diff] [blame] | 1517 | 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] | 1518 | { |
| 1519 | Error return_error; |
| 1520 | |
| 1521 | if (!frame_sp) |
| 1522 | { |
| 1523 | return_error.SetErrorString("Can't return to a null frame."); |
| 1524 | return return_error; |
| 1525 | } |
| 1526 | |
| 1527 | Thread *thread = frame_sp->GetThread().get(); |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1528 | uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1; |
| 1529 | StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1530 | if (!older_frame_sp) |
| 1531 | { |
| 1532 | return_error.SetErrorString("No older frame to return to."); |
| 1533 | return return_error; |
| 1534 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1535 | |
| 1536 | if (return_value_sp) |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1537 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1538 | lldb::ABISP abi = thread->GetProcess()->GetABI(); |
| 1539 | if (!abi) |
| 1540 | { |
| 1541 | return_error.SetErrorString("Could not find ABI to set return value."); |
Jim Ingham | 28eb571 | 2012-10-12 17:34:26 +0000 | [diff] [blame] | 1542 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1543 | } |
Jim Ingham | 1f51e60 | 2012-09-27 01:15:29 +0000 | [diff] [blame] | 1544 | SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction); |
| 1545 | |
| 1546 | // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars. |
| 1547 | // Turn that back on when that works. |
| 1548 | if (0 && sc.function != NULL) |
| 1549 | { |
| 1550 | Type *function_type = sc.function->GetType(); |
| 1551 | if (function_type) |
| 1552 | { |
| 1553 | clang_type_t return_type = sc.function->GetReturnClangType(); |
| 1554 | if (return_type) |
| 1555 | { |
| 1556 | ClangASTType ast_type (function_type->GetClangAST(), return_type); |
| 1557 | StreamString s; |
| 1558 | ast_type.DumpTypeDescription(&s); |
| 1559 | ValueObjectSP cast_value_sp = return_value_sp->Cast(ast_type); |
| 1560 | if (cast_value_sp) |
| 1561 | { |
| 1562 | cast_value_sp->SetFormat(eFormatHex); |
| 1563 | return_value_sp = cast_value_sp; |
| 1564 | } |
| 1565 | } |
| 1566 | } |
| 1567 | } |
| 1568 | |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1569 | return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1570 | if (!return_error.Success()) |
| 1571 | return return_error; |
| 1572 | } |
| 1573 | |
| 1574 | // Now write the return registers for the chosen frame: |
Jim Ingham | cb640dd | 2012-09-14 02:14:15 +0000 | [diff] [blame] | 1575 | // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1576 | // cook their data |
| 1577 | |
| 1578 | StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0); |
| 1579 | if (youngest_frame_sp) |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1580 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1581 | bool copy_success = youngest_frame_sp->GetRegisterContext()->CopyFromRegisterContext(older_frame_sp->GetRegisterContext()); |
| 1582 | if (copy_success) |
| 1583 | { |
| 1584 | thread->DiscardThreadPlans(true); |
| 1585 | thread->ClearStackFrames(); |
| 1586 | if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged)) |
| 1587 | BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this())); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1588 | } |
| 1589 | else |
| 1590 | { |
| 1591 | return_error.SetErrorString("Could not reset register values."); |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1592 | } |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1593 | } |
| 1594 | else |
| 1595 | { |
Jim Ingham | 93208b8 | 2013-01-31 21:46:01 +0000 | [diff] [blame] | 1596 | return_error.SetErrorString("Returned past top frame."); |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1597 | } |
Greg Clayton | abb487f | 2013-02-01 02:52:31 +0000 | [diff] [blame^] | 1598 | return return_error; |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1601 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1602 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1603 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1604 | ExecutionContext exe_ctx (shared_from_this()); |
| 1605 | Process *process = exe_ctx.GetProcessPtr(); |
| 1606 | if (process == NULL) |
| 1607 | return; |
| 1608 | |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1609 | StackFrameSP frame_sp; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1610 | SymbolContext frame_sc; |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1611 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1612 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1613 | frame_sp = GetStackFrameAtIndex (frame_idx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1614 | if (frame_sp) |
| 1615 | { |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1616 | exe_ctx.SetFrameSP(frame_sp); |
| 1617 | frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1621 | const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat(); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1622 | assert (thread_format); |
| 1623 | const char *end = NULL; |
| 1624 | Debugger::FormatPrompt (thread_format, |
Greg Clayton | c14ee32 | 2011-09-22 04:58:26 +0000 | [diff] [blame] | 1625 | frame_sp ? &frame_sc : NULL, |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1626 | &exe_ctx, |
| 1627 | NULL, |
| 1628 | strm, |
| 1629 | &end); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1632 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1633 | Thread::SettingsInitialize () |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1634 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1635 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1636 | |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1637 | void |
Caroline Tice | 20bd37f | 2011-03-10 22:14:10 +0000 | [diff] [blame] | 1638 | Thread::SettingsTerminate () |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1639 | { |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1640 | } |
Jim Ingham | ee8aea1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1641 | |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1642 | lldb::StackFrameSP |
| 1643 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1644 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1645 | return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
Jim Ingham | e4284b7 | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1646 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1647 | |
| 1648 | const char * |
| 1649 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1650 | { |
| 1651 | switch (reason) |
| 1652 | { |
Andrew Kaylor | f85defa | 2012-12-20 23:08:03 +0000 | [diff] [blame] | 1653 | case eStopReasonInvalid: return "invalid"; |
| 1654 | case eStopReasonNone: return "none"; |
| 1655 | case eStopReasonTrace: return "trace"; |
| 1656 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1657 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1658 | case eStopReasonSignal: return "signal"; |
| 1659 | case eStopReasonException: return "exception"; |
| 1660 | case eStopReasonExec: return "exec"; |
| 1661 | case eStopReasonPlanComplete: return "plan complete"; |
| 1662 | case eStopReasonThreadExiting: return "thread exiting"; |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | |
| 1666 | static char unknown_state_string[64]; |
| 1667 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1668 | return unknown_state_string; |
| 1669 | } |
| 1670 | |
| 1671 | const char * |
| 1672 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1673 | { |
| 1674 | switch (mode) |
| 1675 | { |
| 1676 | case eOnlyThisThread: return "only this thread"; |
| 1677 | case eAllThreads: return "all threads"; |
| 1678 | case eOnlyDuringStepping: return "only during stepping"; |
| 1679 | } |
| 1680 | |
| 1681 | static char unknown_state_string[64]; |
| 1682 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1683 | return unknown_state_string; |
| 1684 | } |
Jim Ingham | 06e827c | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1685 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1686 | size_t |
| 1687 | Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source) |
| 1688 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1689 | ExecutionContext exe_ctx (shared_from_this()); |
| 1690 | Target *target = exe_ctx.GetTargetPtr(); |
| 1691 | Process *process = exe_ctx.GetProcessPtr(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1692 | size_t num_frames_shown = 0; |
| 1693 | strm.Indent(); |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1694 | bool is_selected = false; |
| 1695 | if (process) |
| 1696 | { |
| 1697 | if (process->GetThreadList().GetSelectedThread().get() == this) |
| 1698 | is_selected = true; |
| 1699 | } |
| 1700 | strm.Printf("%c ", is_selected ? '*' : ' '); |
| 1701 | if (target && target->GetDebugger().GetUseExternalEditor()) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1702 | { |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1703 | StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame); |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1704 | if (frame_sp) |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1705 | { |
Jim Ingham | e610d64 | 2011-08-16 00:07:28 +0000 | [diff] [blame] | 1706 | SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry)); |
| 1707 | if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file) |
| 1708 | { |
| 1709 | Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line); |
| 1710 | } |
Greg Clayton | 5113dc8 | 2011-08-12 06:47:54 +0000 | [diff] [blame] | 1711 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | DumpUsingSettingsFormat (strm, start_frame); |
| 1715 | |
| 1716 | if (num_frames > 0) |
| 1717 | { |
| 1718 | strm.IndentMore(); |
| 1719 | |
| 1720 | const bool show_frame_info = true; |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1721 | strm.IndentMore (); |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1722 | num_frames_shown = GetStackFrameList ()->GetStatus (strm, |
| 1723 | start_frame, |
| 1724 | num_frames, |
| 1725 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1726 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1727 | strm.IndentLess(); |
Jim Ingham | 5c4df7a | 2011-07-26 02:39:59 +0000 | [diff] [blame] | 1728 | strm.IndentLess(); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1729 | } |
| 1730 | return num_frames_shown; |
| 1731 | } |
| 1732 | |
| 1733 | size_t |
| 1734 | Thread::GetStackFrameStatus (Stream& strm, |
| 1735 | uint32_t first_frame, |
| 1736 | uint32_t num_frames, |
| 1737 | bool show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1738 | uint32_t num_frames_with_source) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1739 | { |
Greg Clayton | 39d0ab3 | 2012-03-29 01:41:38 +0000 | [diff] [blame] | 1740 | return GetStackFrameList()->GetStatus (strm, |
| 1741 | first_frame, |
| 1742 | num_frames, |
| 1743 | show_frame_info, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1744 | num_frames_with_source); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1745 | } |
| 1746 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1747 | bool |
| 1748 | Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint) |
| 1749 | { |
| 1750 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1751 | if (frame_sp) |
| 1752 | { |
| 1753 | checkpoint.SetStackID(frame_sp->GetStackID()); |
| 1754 | return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData()); |
| 1755 | } |
| 1756 | return false; |
| 1757 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1758 | |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1759 | bool |
| 1760 | Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) |
| 1761 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1762 | return ResetFrameZeroRegisters (checkpoint.GetData()); |
| 1763 | } |
| 1764 | |
| 1765 | bool |
| 1766 | Thread::ResetFrameZeroRegisters (lldb::DataBufferSP register_data_sp) |
| 1767 | { |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1768 | lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0)); |
| 1769 | if (frame_sp) |
| 1770 | { |
Jim Ingham | 4413758 | 2012-09-12 00:40:39 +0000 | [diff] [blame] | 1771 | bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (register_data_sp); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1772 | |
| 1773 | // Clear out all stack frames as our world just changed. |
| 1774 | ClearStackFrames(); |
| 1775 | frame_sp->GetRegisterContext()->InvalidateIfNeeded(true); |
Jason Molenda | d525d07 | 2012-11-14 04:26:02 +0000 | [diff] [blame] | 1776 | if (m_unwinder_ap.get()) |
| 1777 | m_unwinder_ap->Clear(); |
Peter Collingbourne | 5a6fa54 | 2011-06-03 20:40:54 +0000 | [diff] [blame] | 1778 | |
| 1779 | return ret; |
| 1780 | } |
| 1781 | return false; |
| 1782 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1783 | |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1784 | Unwind * |
| 1785 | Thread::GetUnwinder () |
| 1786 | { |
| 1787 | if (m_unwinder_ap.get() == NULL) |
| 1788 | { |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 1789 | const ArchSpec target_arch (CalculateTarget()->GetArchitecture ()); |
Greg Clayton | 56d9a1b | 2011-08-22 02:49:39 +0000 | [diff] [blame] | 1790 | const llvm::Triple::ArchType machine = target_arch.GetMachine(); |
| 1791 | switch (machine) |
| 1792 | { |
| 1793 | case llvm::Triple::x86_64: |
| 1794 | case llvm::Triple::x86: |
| 1795 | case llvm::Triple::arm: |
| 1796 | case llvm::Triple::thumb: |
| 1797 | m_unwinder_ap.reset (new UnwindLLDB (*this)); |
| 1798 | break; |
| 1799 | |
| 1800 | default: |
| 1801 | if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple) |
| 1802 | m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this)); |
| 1803 | break; |
| 1804 | } |
| 1805 | } |
| 1806 | return m_unwinder_ap.get(); |
| 1807 | } |
| 1808 | |
| 1809 | |
Greg Clayton | fa559e5 | 2012-05-18 02:38:05 +0000 | [diff] [blame] | 1810 | void |
| 1811 | Thread::Flush () |
| 1812 | { |
| 1813 | ClearStackFrames (); |
| 1814 | m_reg_context_sp.reset(); |
| 1815 | } |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1816 | |
Filipe Cabecinhas | b3d5d71 | 2012-11-20 00:11:13 +0000 | [diff] [blame] | 1817 | bool |
Jim Ingham | 5d88a06 | 2012-10-16 00:09:33 +0000 | [diff] [blame] | 1818 | Thread::IsStillAtLastBreakpointHit () |
| 1819 | { |
| 1820 | // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it. |
| 1821 | // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in |
| 1822 | // multithreaded programs. |
| 1823 | if (m_actual_stop_info_sp) { |
| 1824 | StopReason stop_reason = m_actual_stop_info_sp->GetStopReason(); |
| 1825 | if (stop_reason == lldb::eStopReasonBreakpoint) { |
| 1826 | uint64_t value = m_actual_stop_info_sp->GetValue(); |
| 1827 | lldb::addr_t pc = GetRegisterContext()->GetPC(); |
| 1828 | BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc); |
| 1829 | if (bp_site_sp && value == bp_site_sp->GetID()) |
| 1830 | return true; |
| 1831 | } |
| 1832 | } |
| 1833 | return false; |
| 1834 | } |