blob: 400d9923d859f80593ada0f981b9b50dfb80b638 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- 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 Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/lldb-private-log.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000013#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Clayton0603aa92010-10-04 01:05:56 +000014#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Core/Log.h"
Greg Clayton160c9d82013-05-01 21:54:04 +000016#include "lldb/Core/State.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000017#include "lldb/Core/Stream.h"
18#include "lldb/Core/StreamString.h"
Jim Inghamee8aea12010-09-08 03:14:33 +000019#include "lldb/Core/RegularExpression.h"
Greg Clayton7260f622011-04-18 08:33:37 +000020#include "lldb/Host/Host.h"
Jim Ingham4da62062014-01-23 21:52:47 +000021#include "lldb/Interpreter/OptionValueFileSpecList.h"
Jim Ingham1f51e602012-09-27 01:15:29 +000022#include "lldb/Symbol/Function.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000023#include "lldb/Target/DynamicLoader.h"
24#include "lldb/Target/ExecutionContext.h"
Jim Ingham5a369122010-09-28 01:25:32 +000025#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026#include "lldb/Target/Process.h"
27#include "lldb/Target/RegisterContext.h"
Greg Claytonf4b47e12010-08-04 01:40:35 +000028#include "lldb/Target/StopInfo.h"
Jason Molendab4892cd2014-05-13 22:02:48 +000029#include "lldb/Target/SystemRuntime.h"
Greg Clayton896dff62010-07-23 16:45:51 +000030#include "lldb/Target/Target.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000031#include "lldb/Target/Thread.h"
32#include "lldb/Target/ThreadPlan.h"
33#include "lldb/Target/ThreadPlanCallFunction.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000034#include "lldb/Target/ThreadPlanBase.h"
35#include "lldb/Target/ThreadPlanStepInstruction.h"
36#include "lldb/Target/ThreadPlanStepOut.h"
37#include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
38#include "lldb/Target/ThreadPlanStepThrough.h"
39#include "lldb/Target/ThreadPlanStepInRange.h"
40#include "lldb/Target/ThreadPlanStepOverRange.h"
41#include "lldb/Target/ThreadPlanRunToAddress.h"
42#include "lldb/Target/ThreadPlanStepUntil.h"
Jim Ingham1b54c882010-06-16 02:00:15 +000043#include "lldb/Target/ThreadSpec.h"
Jim Ingham87c11912010-08-12 02:14:28 +000044#include "lldb/Target/Unwind.h"
Greg Clayton56d9a1b2011-08-22 02:49:39 +000045#include "Plugins/Process/Utility/UnwindLLDB.h"
46#include "UnwindMacOSXFrameBackchain.h"
47
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048
49using namespace lldb;
50using namespace lldb_private;
51
Greg Clayton67cc0632012-08-22 17:17:09 +000052
53const ThreadPropertiesSP &
54Thread::GetGlobalProperties()
55{
56 static ThreadPropertiesSP g_settings_sp;
57 if (!g_settings_sp)
58 g_settings_sp.reset (new ThreadProperties (true));
59 return g_settings_sp;
60}
61
62static PropertyDefinition
63g_properties[] =
64{
Jim Ingham4b4b2472014-03-13 02:47:14 +000065 { "step-in-avoid-nodebug", OptionValue::eTypeBoolean, true, true, NULL, NULL, "If true, step-in will not stop in functions with no debug information." },
66 { "step-out-avoid-nodebug", OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, when step-in/step-out/step-over leave the current frame, they will continue to step out till they come to a function with "
67 "debug information. Passing a frame argument to step-out will override this option." },
Greg Clayton67cc0632012-08-22 17:17:09 +000068 { "step-avoid-regexp", OptionValue::eTypeRegex , true , REG_EXTENDED, "^std::", NULL, "A regular expression defining functions step-in won't stop in." },
Jim Ingham4da62062014-01-23 21:52:47 +000069 { "step-avoid-libraries", OptionValue::eTypeFileSpecList , true , REG_EXTENDED, NULL, NULL, "A list of libraries that source stepping won't stop in." },
Greg Clayton67cc0632012-08-22 17:17:09 +000070 { "trace-thread", OptionValue::eTypeBoolean, false, false, NULL, NULL, "If true, this thread will single-step and log execution." },
71 { NULL , OptionValue::eTypeInvalid, false, 0 , NULL, NULL, NULL }
72};
73
74enum {
Jim Ingham4b4b2472014-03-13 02:47:14 +000075 ePropertyStepInAvoidsNoDebug,
76 ePropertyStepOutAvoidsNoDebug,
Greg Clayton67cc0632012-08-22 17:17:09 +000077 ePropertyStepAvoidRegex,
Jim Ingham4da62062014-01-23 21:52:47 +000078 ePropertyStepAvoidLibraries,
Greg Clayton67cc0632012-08-22 17:17:09 +000079 ePropertyEnableThreadTrace
80};
81
82
83class ThreadOptionValueProperties : public OptionValueProperties
84{
85public:
86 ThreadOptionValueProperties (const ConstString &name) :
87 OptionValueProperties (name)
88 {
89 }
90
91 // This constructor is used when creating ThreadOptionValueProperties when it
92 // is part of a new lldb_private::Thread instance. It will copy all current
93 // global property values as needed
94 ThreadOptionValueProperties (ThreadProperties *global_properties) :
Greg Clayton6920b522012-08-22 18:39:03 +000095 OptionValueProperties(*global_properties->GetValueProperties())
Greg Clayton67cc0632012-08-22 17:17:09 +000096 {
97 }
98
99 virtual const Property *
100 GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const
101 {
102 // When gettings the value for a key from the thread options, we will always
103 // try and grab the setting from the current thread if there is one. Else we just
104 // use the one from this instance.
105 if (exe_ctx)
106 {
107 Thread *thread = exe_ctx->GetThreadPtr();
108 if (thread)
109 {
110 ThreadOptionValueProperties *instance_properties = static_cast<ThreadOptionValueProperties *>(thread->GetValueProperties().get());
111 if (this != instance_properties)
112 return instance_properties->ProtectedGetPropertyAtIndex (idx);
113 }
114 }
115 return ProtectedGetPropertyAtIndex (idx);
116 }
117};
118
119
120
121ThreadProperties::ThreadProperties (bool is_global) :
122 Properties ()
123{
124 if (is_global)
125 {
126 m_collection_sp.reset (new ThreadOptionValueProperties(ConstString("thread")));
127 m_collection_sp->Initialize(g_properties);
128 }
129 else
130 m_collection_sp.reset (new ThreadOptionValueProperties(Thread::GetGlobalProperties().get()));
131}
132
133ThreadProperties::~ThreadProperties()
134{
135}
136
137const RegularExpression *
138ThreadProperties::GetSymbolsToAvoidRegexp()
139{
140 const uint32_t idx = ePropertyStepAvoidRegex;
141 return m_collection_sp->GetPropertyAtIndexAsOptionValueRegex (NULL, idx);
142}
143
Jim Ingham4da62062014-01-23 21:52:47 +0000144FileSpecList &
145ThreadProperties::GetLibrariesToAvoid() const
146{
147 const uint32_t idx = ePropertyStepAvoidLibraries;
148 OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx);
149 assert(option_value);
150 return option_value->GetCurrentValue();
151}
152
Greg Clayton67cc0632012-08-22 17:17:09 +0000153bool
154ThreadProperties::GetTraceEnabledState() const
155{
156 const uint32_t idx = ePropertyEnableThreadTrace;
157 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
158}
159
Jim Ingham4b4b2472014-03-13 02:47:14 +0000160bool
161ThreadProperties::GetStepInAvoidsNoDebug() const
162{
163 const uint32_t idx = ePropertyStepInAvoidsNoDebug;
164 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
165}
166
167bool
168ThreadProperties::GetStepOutAvoidsNoDebug() const
169{
170 const uint32_t idx = ePropertyStepOutAvoidsNoDebug;
171 return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
172}
173
174
Jim Ingham4f465cf2012-10-10 18:32:14 +0000175//------------------------------------------------------------------
176// Thread Event Data
177//------------------------------------------------------------------
Greg Clayton67cc0632012-08-22 17:17:09 +0000178
Jim Ingham4f465cf2012-10-10 18:32:14 +0000179
180const ConstString &
181Thread::ThreadEventData::GetFlavorString ()
182{
183 static ConstString g_flavor ("Thread::ThreadEventData");
184 return g_flavor;
185}
186
187Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp) :
188 m_thread_sp (thread_sp),
189 m_stack_id ()
190{
191}
192
193Thread::ThreadEventData::ThreadEventData (const lldb::ThreadSP thread_sp, const StackID &stack_id) :
194 m_thread_sp (thread_sp),
195 m_stack_id (stack_id)
196{
197}
198
199Thread::ThreadEventData::ThreadEventData () :
200 m_thread_sp (),
201 m_stack_id ()
202{
203}
204
205Thread::ThreadEventData::~ThreadEventData ()
206{
207}
208
209void
210Thread::ThreadEventData::Dump (Stream *s) const
211{
212
213}
214
215const Thread::ThreadEventData *
216Thread::ThreadEventData::GetEventDataFromEvent (const Event *event_ptr)
217{
218 if (event_ptr)
219 {
220 const EventData *event_data = event_ptr->GetData();
221 if (event_data && event_data->GetFlavor() == ThreadEventData::GetFlavorString())
222 return static_cast <const ThreadEventData *> (event_ptr->GetData());
223 }
224 return NULL;
225}
226
227ThreadSP
228Thread::ThreadEventData::GetThreadFromEvent (const Event *event_ptr)
229{
230 ThreadSP thread_sp;
231 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
232 if (event_data)
233 thread_sp = event_data->GetThread();
234 return thread_sp;
235}
236
237StackID
238Thread::ThreadEventData::GetStackIDFromEvent (const Event *event_ptr)
239{
240 StackID stack_id;
241 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
242 if (event_data)
243 stack_id = event_data->GetStackID();
244 return stack_id;
245}
246
Jason Molendab57e4a12013-11-04 09:33:30 +0000247StackFrameSP
Jim Ingham4f465cf2012-10-10 18:32:14 +0000248Thread::ThreadEventData::GetStackFrameFromEvent (const Event *event_ptr)
249{
250 const ThreadEventData *event_data = GetEventDataFromEvent (event_ptr);
Jason Molendab57e4a12013-11-04 09:33:30 +0000251 StackFrameSP frame_sp;
Jim Ingham4f465cf2012-10-10 18:32:14 +0000252 if (event_data)
253 {
254 ThreadSP thread_sp = event_data->GetThread();
255 if (thread_sp)
256 {
257 frame_sp = thread_sp->GetStackFrameList()->GetFrameWithStackID (event_data->GetStackID());
258 }
259 }
260 return frame_sp;
261}
262
263//------------------------------------------------------------------
264// Thread class
265//------------------------------------------------------------------
266
267ConstString &
268Thread::GetStaticBroadcasterClass ()
269{
270 static ConstString class_name ("lldb.thread");
271 return class_name;
272}
273
Jason Molendaa8ff5432014-03-06 06:31:18 +0000274Thread::Thread (Process &process, lldb::tid_t tid, bool use_invalid_index_id) :
Greg Clayton67cc0632012-08-22 17:17:09 +0000275 ThreadProperties (false),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276 UserID (tid),
Jim Ingham4f465cf2012-10-10 18:32:14 +0000277 Broadcaster(&process.GetTarget().GetDebugger(), Thread::GetStaticBroadcasterClass().AsCString()),
278 m_process_wp (process.shared_from_this()),
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000279 m_stop_info_sp (),
280 m_stop_info_stop_id (0),
Jason Molendaa8ff5432014-03-06 06:31:18 +0000281 m_index_id (use_invalid_index_id ? LLDB_INVALID_INDEX32 : process.GetNextThreadIndexID(tid)),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282 m_reg_context_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283 m_state (eStateUnloaded),
Greg Clayton12daf9462010-08-25 00:35:26 +0000284 m_state_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000285 m_plan_stack (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000286 m_completed_plan_stack(),
Greg Clayton39d0ab32012-03-29 01:41:38 +0000287 m_frame_mutex (Mutex::eMutexTypeRecursive),
Greg Clayton7e9b1fd2011-08-12 21:40:01 +0000288 m_curr_frames_sp (),
289 m_prev_frames_sp (),
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000290 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
Jim Ingham87c11912010-08-12 02:14:28 +0000291 m_resume_state (eStateRunning),
Jim Ingham92087d82012-01-31 23:09:20 +0000292 m_temporary_resume_state (eStateRunning),
Jim Ingham773d9812010-11-18 02:47:07 +0000293 m_unwinder_ap (),
Jim Ingham77787032011-01-20 02:03:18 +0000294 m_destroy_called (false),
Jason Molenda705b1802014-06-13 02:37:02 +0000295 m_override_should_notify (eLazyBoolCalculate),
296 m_extended_info_fetched (false),
297 m_extended_info ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000298{
Greg Clayton5160ce52013-03-27 23:08:40 +0000299 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000300 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000301 log->Printf ("%p Thread::Thread(tid = 0x%4.4" PRIx64 ")",
302 static_cast<void*>(this), GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000303
Jim Ingham4f465cf2012-10-10 18:32:14 +0000304 CheckInWithManager();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000305 QueueFundamentalPlan(true);
306}
307
308
309Thread::~Thread()
310{
Greg Clayton5160ce52013-03-27 23:08:40 +0000311 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000312 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000313 log->Printf ("%p Thread::~Thread(tid = 0x%4.4" PRIx64 ")",
314 static_cast<void*>(this), GetID());
Jim Ingham773d9812010-11-18 02:47:07 +0000315 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor.
316 assert (m_destroy_called);
317}
318
319void
320Thread::DestroyThread ()
321{
Jim Inghamb1499242013-10-18 17:11:02 +0000322 // Tell any plans on the plan stacks that the thread is being destroyed since
323 // any plans that have a thread go away in the middle of might need
324 // to do cleanup, or in some cases NOT do cleanup...
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000325 for (auto plan : m_plan_stack)
326 plan->ThreadDestroyed();
327
Jim Inghamb1499242013-10-18 17:11:02 +0000328 for (auto plan : m_discarded_plan_stack)
329 plan->ThreadDestroyed();
330
331 for (auto plan : m_completed_plan_stack)
332 plan->ThreadDestroyed();
333
Greg Clayton35a4cc52012-10-29 20:52:08 +0000334 m_destroy_called = true;
Jim Ingham773d9812010-11-18 02:47:07 +0000335 m_plan_stack.clear();
336 m_discarded_plan_stack.clear();
337 m_completed_plan_stack.clear();
Greg Clayton6e10f142013-07-30 00:23:06 +0000338
339 // Push a ThreadPlanNull on the plan stack. That way we can continue assuming that the
340 // plan stack is never empty, but if somebody errantly asks questions of a destroyed thread
341 // without checking first whether it is destroyed, they won't crash.
342 ThreadPlanSP null_plan_sp(new ThreadPlanNull (*this));
343 m_plan_stack.push_back (null_plan_sp);
344
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000345 m_stop_info_sp.reset();
Greg Clayton35a4cc52012-10-29 20:52:08 +0000346 m_reg_context_sp.reset();
347 m_unwinder_ap.reset();
348 Mutex::Locker locker(m_frame_mutex);
349 m_curr_frames_sp.reset();
350 m_prev_frames_sp.reset();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
Jim Ingham4f465cf2012-10-10 18:32:14 +0000353void
354Thread::BroadcastSelectedFrameChange(StackID &new_frame_id)
355{
356 if (EventTypeHasListeners(eBroadcastBitSelectedFrameChanged))
357 BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id));
358}
359
360uint32_t
Jason Molendab57e4a12013-11-04 09:33:30 +0000361Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast)
Jim Ingham4f465cf2012-10-10 18:32:14 +0000362{
363 uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
364 if (broadcast)
365 BroadcastSelectedFrameChange(frame->GetStackID());
366 return ret_value;
367}
368
369bool
370Thread::SetSelectedFrameByIndex (uint32_t frame_idx, bool broadcast)
371{
Jason Molendab57e4a12013-11-04 09:33:30 +0000372 StackFrameSP frame_sp(GetStackFrameList()->GetFrameAtIndex (frame_idx));
Jim Ingham4f465cf2012-10-10 18:32:14 +0000373 if (frame_sp)
374 {
375 GetStackFrameList()->SetSelectedFrame(frame_sp.get());
376 if (broadcast)
377 BroadcastSelectedFrameChange(frame_sp->GetStackID());
378 return true;
379 }
380 else
381 return false;
382}
383
Jim Ingham93208b82013-01-31 21:46:01 +0000384bool
385Thread::SetSelectedFrameByIndexNoisily (uint32_t frame_idx, Stream &output_stream)
386{
387 const bool broadcast = true;
388 bool success = SetSelectedFrameByIndex (frame_idx, broadcast);
389 if (success)
390 {
Jason Molendab57e4a12013-11-04 09:33:30 +0000391 StackFrameSP frame_sp = GetSelectedFrame();
Jim Ingham93208b82013-01-31 21:46:01 +0000392 if (frame_sp)
393 {
394 bool already_shown = false;
395 SymbolContext frame_sc(frame_sp->GetSymbolContext(eSymbolContextLineEntry));
396 if (GetProcess()->GetTarget().GetDebugger().GetUseExternalEditor() && frame_sc.line_entry.file && frame_sc.line_entry.line != 0)
397 {
398 already_shown = Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
399 }
400
401 bool show_frame_info = true;
402 bool show_source = !already_shown;
403 return frame_sp->GetStatus (output_stream, show_frame_info, show_source);
404 }
405 return false;
406 }
407 else
408 return false;
409}
410
Jim Ingham4f465cf2012-10-10 18:32:14 +0000411
Jim Inghamb15bfc72010-10-20 00:39:53 +0000412lldb::StopInfoSP
Greg Claytonf4b47e12010-08-04 01:40:35 +0000413Thread::GetStopInfo ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000414{
Greg Clayton6e10f142013-07-30 00:23:06 +0000415 if (m_destroy_called)
416 return m_stop_info_sp;
417
Jim Inghamb15bfc72010-10-20 00:39:53 +0000418 ThreadPlanSP plan_sp (GetCompletedPlan());
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000419 ProcessSP process_sp (GetProcess());
420 const uint32_t stop_id = process_sp ? process_sp->GetStopID() : UINT32_MAX;
Jim Inghamfbbfe6e2012-05-01 18:38:37 +0000421 if (plan_sp && plan_sp->PlanSucceeded())
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000422 {
Jim Ingham73ca05a2011-12-17 01:35:57 +0000423 return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject());
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000424 }
Jim Inghamb15bfc72010-10-20 00:39:53 +0000425 else
Jim Ingham79c35da2011-08-09 00:32:52 +0000426 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000427 if ((m_stop_info_stop_id == stop_id) || // Stop info is valid, just return what we have (even if empty)
428 (m_stop_info_sp && m_stop_info_sp->IsValid())) // Stop info is valid, just return what we have
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000429 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000430 return m_stop_info_sp;
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000431 }
Jim Ingham79c35da2011-08-09 00:32:52 +0000432 else
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000433 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000434 GetPrivateStopInfo ();
435 return m_stop_info_sp;
Andrew Kaylorba4e61d2013-05-07 18:35:34 +0000436 }
Jim Ingham79c35da2011-08-09 00:32:52 +0000437 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000438}
439
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000440lldb::StopInfoSP
441Thread::GetPrivateStopInfo ()
442{
Greg Clayton6e10f142013-07-30 00:23:06 +0000443 if (m_destroy_called)
444 return m_stop_info_sp;
445
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000446 ProcessSP process_sp (GetProcess());
447 if (process_sp)
448 {
Daniel Malea246cb612013-05-14 15:20:12 +0000449 const uint32_t process_stop_id = process_sp->GetStopID();
450 if (m_stop_info_stop_id != process_stop_id)
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000451 {
Daniel Malea246cb612013-05-14 15:20:12 +0000452 if (m_stop_info_sp)
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000453 {
Daniel Malea246cb612013-05-14 15:20:12 +0000454 if (m_stop_info_sp->IsValid()
455 || IsStillAtLastBreakpointHit()
456 || GetCurrentPlan()->IsVirtualStep())
457 SetStopInfo (m_stop_info_sp);
458 else
459 m_stop_info_sp.reset();
460 }
461
462 if (!m_stop_info_sp)
463 {
464 if (CalculateStopInfo() == false)
465 SetStopInfo (StopInfoSP());
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000466 }
467 }
468 }
469 return m_stop_info_sp;
470}
471
472
Greg Clayton97d5cf02012-09-25 02:40:06 +0000473lldb::StopReason
474Thread::GetStopReason()
475{
476 lldb::StopInfoSP stop_info_sp (GetStopInfo ());
477 if (stop_info_sp)
Filipe Cabecinhase26391a2012-09-28 15:55:43 +0000478 return stop_info_sp->GetStopReason();
Greg Clayton97d5cf02012-09-25 02:40:06 +0000479 return eStopReasonNone;
480}
481
482
483
Jim Ingham77787032011-01-20 02:03:18 +0000484void
485Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp)
486{
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000487 m_stop_info_sp = stop_info_sp;
488 if (m_stop_info_sp)
Jim Ingham221d51c2013-05-08 00:35:16 +0000489 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000490 m_stop_info_sp->MakeStopInfoValid();
Jim Ingham221d51c2013-05-08 00:35:16 +0000491 // If we are overriding the ShouldReportStop, do that here:
492 if (m_override_should_notify != eLazyBoolCalculate)
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000493 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes);
Jim Ingham221d51c2013-05-08 00:35:16 +0000494 }
495
Greg Clayton1ac04c32012-02-21 00:09:25 +0000496 ProcessSP process_sp (GetProcess());
497 if (process_sp)
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000498 m_stop_info_stop_id = process_sp->GetStopID();
Greg Clayton1ac04c32012-02-21 00:09:25 +0000499 else
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000500 m_stop_info_stop_id = UINT32_MAX;
Greg Clayton8cda7f02013-05-21 21:55:59 +0000501 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_THREAD));
502 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000503 log->Printf("%p: tid = 0x%" PRIx64 ": stop info = %s (stop_id = %u)\n",
504 static_cast<void*>(this), GetID(),
505 stop_info_sp ? stop_info_sp->GetDescription() : "<NULL>",
506 m_stop_info_stop_id);
Jim Ingham77787032011-01-20 02:03:18 +0000507}
508
509void
Jim Ingham221d51c2013-05-08 00:35:16 +0000510Thread::SetShouldReportStop (Vote vote)
511{
512 if (vote == eVoteNoOpinion)
513 return;
514 else
515 {
516 m_override_should_notify = (vote == eVoteYes ? eLazyBoolYes : eLazyBoolNo);
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000517 if (m_stop_info_sp)
518 m_stop_info_sp->OverrideShouldNotify (m_override_should_notify == eLazyBoolYes);
Jim Ingham221d51c2013-05-08 00:35:16 +0000519 }
520}
521
522void
Jim Ingham77787032011-01-20 02:03:18 +0000523Thread::SetStopInfoToNothing()
524{
525 // Note, we can't just NULL out the private reason, or the native thread implementation will try to
526 // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number.
527 SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER));
528}
529
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000530bool
531Thread::ThreadStoppedForAReason (void)
532{
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000533 return (bool) GetPrivateStopInfo ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000534}
535
Jim Ingham77787032011-01-20 02:03:18 +0000536bool
537Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state)
538{
Greg Claytonf74cf862013-11-13 23:28:31 +0000539 saved_state.register_backup_sp.reset();
540 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
541 if (frame_sp)
542 {
543 lldb::RegisterCheckpointSP reg_checkpoint_sp(new RegisterCheckpoint(RegisterCheckpoint::Reason::eExpression));
544 if (reg_checkpoint_sp)
545 {
546 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext());
547 if (reg_ctx_sp && reg_ctx_sp->ReadAllRegisterValues (*reg_checkpoint_sp))
548 saved_state.register_backup_sp = reg_checkpoint_sp;
549 }
550 }
551 if (!saved_state.register_backup_sp)
Jim Ingham77787032011-01-20 02:03:18 +0000552 return false;
553
554 saved_state.stop_info_sp = GetStopInfo();
Greg Clayton1ac04c32012-02-21 00:09:25 +0000555 ProcessSP process_sp (GetProcess());
556 if (process_sp)
557 saved_state.orig_stop_id = process_sp->GetStopID();
Jim Ingham625fca72012-09-07 23:36:43 +0000558 saved_state.current_inlined_depth = GetCurrentInlinedDepth();
559
Jim Ingham77787032011-01-20 02:03:18 +0000560 return true;
561}
562
563bool
Jim Ingham8559a352012-11-26 23:52:18 +0000564Thread::RestoreRegisterStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
Jim Ingham77787032011-01-20 02:03:18 +0000565{
Greg Claytonf74cf862013-11-13 23:28:31 +0000566 if (saved_state.register_backup_sp)
567 {
568 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
569 if (frame_sp)
570 {
571 lldb::RegisterContextSP reg_ctx_sp (frame_sp->GetRegisterContext());
572 if (reg_ctx_sp)
573 {
574 bool ret = reg_ctx_sp->WriteAllRegisterValues (*saved_state.register_backup_sp);
575
576 // Clear out all stack frames as our world just changed.
577 ClearStackFrames();
578 reg_ctx_sp->InvalidateIfNeeded(true);
579 if (m_unwinder_ap.get())
580 m_unwinder_ap->Clear();
581 return ret;
582 }
583 }
584 }
585 return false;
Jim Ingham8559a352012-11-26 23:52:18 +0000586}
587
588bool
589Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
590{
Jim Ingham0c270682011-01-25 02:47:23 +0000591 if (saved_state.stop_info_sp)
592 saved_state.stop_info_sp->MakeStopInfoValid();
Jim Ingham77787032011-01-20 02:03:18 +0000593 SetStopInfo(saved_state.stop_info_sp);
Jim Ingham625fca72012-09-07 23:36:43 +0000594 GetStackFrameList()->SetCurrentInlinedDepth (saved_state.current_inlined_depth);
Jim Ingham77787032011-01-20 02:03:18 +0000595 return true;
596}
597
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598StateType
599Thread::GetState() const
600{
601 // If any other threads access this we will need a mutex for it
602 Mutex::Locker locker(m_state_mutex);
603 return m_state;
604}
605
606void
607Thread::SetState(StateType state)
608{
609 Mutex::Locker locker(m_state_mutex);
610 m_state = state;
611}
612
613void
614Thread::WillStop()
615{
616 ThreadPlan *current_plan = GetCurrentPlan();
617
618 // FIXME: I may decide to disallow threads with no plans. In which
619 // case this should go to an assert.
620
621 if (!current_plan)
622 return;
623
624 current_plan->WillStop();
625}
626
627void
628Thread::SetupForResume ()
629{
630 if (GetResumeState() != eStateSuspended)
631 {
632
633 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
634 // telling the current plan it will resume, since we might change what the current
635 // plan is.
636
Greg Clayton1afa68e2013-04-02 20:32:37 +0000637// StopReason stop_reason = lldb::eStopReasonInvalid;
638// StopInfoSP stop_info_sp = GetStopInfo();
639// if (stop_info_sp.get())
640// stop_reason = stop_info_sp->GetStopReason();
641// if (stop_reason == lldb::eStopReasonBreakpoint)
642 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext());
643 if (reg_ctx_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000644 {
Greg Clayton1afa68e2013-04-02 20:32:37 +0000645 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(reg_ctx_sp->GetPC());
646 if (bp_site_sp)
Jim Inghamb01e7422010-06-19 04:45:32 +0000647 {
Greg Clayton1afa68e2013-04-02 20:32:37 +0000648 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
649 // special to step over a breakpoint.
650
651 ThreadPlan *cur_plan = GetCurrentPlan();
Jim Inghamb01e7422010-06-19 04:45:32 +0000652
Greg Clayton1afa68e2013-04-02 20:32:37 +0000653 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
654 {
655 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
656 if (step_bp_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000657 {
Greg Clayton1afa68e2013-04-02 20:32:37 +0000658 ThreadPlanSP step_bp_plan_sp;
659 step_bp_plan->SetPrivate (true);
660
661 if (GetCurrentPlan()->RunState() != eStateStepping)
662 {
663 step_bp_plan->SetAutoContinue(true);
664 }
665 step_bp_plan_sp.reset (step_bp_plan);
666 QueueThreadPlan (step_bp_plan_sp, false);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000667 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000668 }
669 }
670 }
671 }
672}
673
674bool
Greg Clayton160c9d82013-05-01 21:54:04 +0000675Thread::ShouldResume (StateType resume_state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000676{
677 // At this point clear the completed plan stack.
678 m_completed_plan_stack.clear();
679 m_discarded_plan_stack.clear();
Jim Ingham221d51c2013-05-08 00:35:16 +0000680 m_override_should_notify = eLazyBoolCalculate;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000681
Greg Clayton97d5cf02012-09-25 02:40:06 +0000682 m_temporary_resume_state = resume_state;
Jim Ingham92087d82012-01-31 23:09:20 +0000683
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000684 lldb::ThreadSP backing_thread_sp (GetBackingThread ());
685 if (backing_thread_sp)
686 backing_thread_sp->m_temporary_resume_state = resume_state;
687
688 // Make sure m_stop_info_sp is valid
689 GetPrivateStopInfo();
Greg Clayton160c9d82013-05-01 21:54:04 +0000690
Jim Ingham92087d82012-01-31 23:09:20 +0000691 // This is a little dubious, but we are trying to limit how often we actually fetch stop info from
692 // the target, 'cause that slows down single stepping. So assume that if we got to the point where
693 // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know
694 // about the fact that we are resuming...
Greg Clayton1ac04c32012-02-21 00:09:25 +0000695 const uint32_t process_stop_id = GetProcess()->GetStopID();
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000696 if (m_stop_info_stop_id == process_stop_id &&
697 (m_stop_info_sp && m_stop_info_sp->IsValid()))
Jim Ingham92087d82012-01-31 23:09:20 +0000698 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000699 StopInfo *stop_info = GetPrivateStopInfo().get();
Jim Ingham92087d82012-01-31 23:09:20 +0000700 if (stop_info)
701 stop_info->WillResume (resume_state);
702 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000703
704 // Tell all the plans that we are about to resume in case they need to clear any state.
705 // We distinguish between the plan on the top of the stack and the lower
706 // plans in case a plan needs to do any special business before it runs.
707
Greg Claytond1d06e42013-04-20 00:27:58 +0000708 bool need_to_resume = false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000709 ThreadPlan *plan_ptr = GetCurrentPlan();
Greg Claytond1d06e42013-04-20 00:27:58 +0000710 if (plan_ptr)
711 {
712 need_to_resume = plan_ptr->WillResume(resume_state, true);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000713
Greg Claytond1d06e42013-04-20 00:27:58 +0000714 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
715 {
716 plan_ptr->WillResume (resume_state, false);
717 }
718
719 // If the WillResume for the plan says we are faking a resume, then it will have set an appropriate stop info.
720 // In that case, don't reset it here.
721
722 if (need_to_resume && resume_state != eStateSuspended)
723 {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000724 m_stop_info_sp.reset();
Greg Claytond1d06e42013-04-20 00:27:58 +0000725 }
Jim Ingham513c6bb2012-09-01 01:02:41 +0000726 }
727
Greg Clayton160c9d82013-05-01 21:54:04 +0000728 if (need_to_resume)
729 {
730 ClearStackFrames();
731 // Let Thread subclasses do any special work they need to prior to resuming
732 WillResume (resume_state);
733 }
734
Jim Ingham513c6bb2012-09-01 01:02:41 +0000735 return need_to_resume;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000736}
737
738void
739Thread::DidResume ()
740{
741 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
742}
743
Andrew Kaylor29d65742013-05-10 17:19:04 +0000744void
745Thread::DidStop ()
746{
747 SetState (eStateStopped);
748}
749
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000750bool
751Thread::ShouldStop (Event* event_ptr)
752{
753 ThreadPlan *current_plan = GetCurrentPlan();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000754
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000755 bool should_stop = true;
756
Greg Clayton5160ce52013-03-27 23:08:40 +0000757 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000758
Jim Ingham92087d82012-01-31 23:09:20 +0000759 if (GetResumeState () == eStateSuspended)
760 {
761 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +0000762 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000763 __FUNCTION__, GetID (), GetProtocolID());
Jim Ingham92087d82012-01-31 23:09:20 +0000764 return false;
765 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000766
Jim Ingham92087d82012-01-31 23:09:20 +0000767 if (GetTemporaryResumeState () == eStateSuspended)
768 {
769 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +0000770 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", should_stop = 0 (ignore since thread was suspended)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000771 __FUNCTION__, GetID (), GetProtocolID());
Jim Ingham92087d82012-01-31 23:09:20 +0000772 return false;
773 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000774
Daniel Malea246cb612013-05-14 15:20:12 +0000775 // Based on the current thread plan and process stop info, check if this
776 // thread caused the process to stop. NOTE: this must take place before
777 // the plan is moved from the current plan stack to the completed plan
778 // stack.
Jim Ingham92087d82012-01-31 23:09:20 +0000779 if (ThreadStoppedForAReason() == false)
780 {
781 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +0000782 log->Printf ("Thread::%s for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64 ", should_stop = 0 (ignore since no stop reason)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000783 __FUNCTION__, GetID (), GetProtocolID(),
Greg Clayton1afa68e2013-04-02 20:32:37 +0000784 GetRegisterContext() ? GetRegisterContext()->GetPC() : LLDB_INVALID_ADDRESS);
Jim Ingham92087d82012-01-31 23:09:20 +0000785 return false;
786 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000787
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000788 if (log)
789 {
Jim Inghamdee1bc92013-06-22 00:27:45 +0000790 log->Printf ("Thread::%s(%p) for tid = 0x%4.4" PRIx64 " 0x%4.4" PRIx64 ", pc = 0x%16.16" PRIx64,
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000791 __FUNCTION__, static_cast<void*>(this), GetID (),
Greg Clayton160c9d82013-05-01 21:54:04 +0000792 GetProtocolID (),
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000793 GetRegisterContext()
794 ? GetRegisterContext()->GetPC()
795 : LLDB_INVALID_ADDRESS);
Jim Ingham10c4b242011-10-15 00:23:43 +0000796 log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797 StreamString s;
Jim Ingham10c4b242011-10-15 00:23:43 +0000798 s.IndentMore();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799 DumpThreadPlans(&s);
Jim Ingham10c4b242011-10-15 00:23:43 +0000800 log->Printf ("Plan stack initial state:\n%s", s.GetData());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000801 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000802
Jim Ingham06e827c2010-11-11 19:26:09 +0000803 // The top most plan always gets to do the trace log...
804 current_plan->DoTraceLog ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000805
Jim Ingham6d66ce62012-04-20 21:16:56 +0000806 // First query the stop info's ShouldStopSynchronous. This handles "synchronous" stop reasons, for example the breakpoint
807 // command on internal breakpoints. If a synchronous stop reason says we should not stop, then we don't have to
808 // do any more work on this stop.
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000809 StopInfoSP private_stop_info (GetPrivateStopInfo());
Jim Ingham6d66ce62012-04-20 21:16:56 +0000810 if (private_stop_info && private_stop_info->ShouldStopSynchronous(event_ptr) == false)
811 {
812 if (log)
813 log->Printf ("StopInfo::ShouldStop async callback says we should not stop, returning ShouldStop of false.");
814 return false;
815 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000816
Jim Inghambad39e42012-09-05 21:12:49 +0000817 // If we've already been restarted, don't query the plans since the state they would examine is not current.
818 if (Process::ProcessEventData::GetRestartedFromEvent(event_ptr))
819 return false;
820
821 // Before the plans see the state of the world, calculate the current inlined depth.
822 GetStackFrameList()->CalculateCurrentInlinedDepth();
823
Jim Ingham25f66702011-12-03 01:52:59 +0000824 // If the base plan doesn't understand why we stopped, then we have to find a plan that does.
825 // If that plan is still working, then we don't need to do any more work. If the plan that explains
826 // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide
827 // whether they still need to do more work.
828
829 bool done_processing_current_plan = false;
830
Jim Ingham0161b492013-02-09 01:29:05 +0000831 if (!current_plan->PlanExplainsStop(event_ptr))
Jim Ingham25f66702011-12-03 01:52:59 +0000832 {
833 if (current_plan->TracerExplainsStop())
834 {
835 done_processing_current_plan = true;
836 should_stop = false;
837 }
838 else
839 {
Jim Inghamcf274f92012-04-09 22:37:39 +0000840 // If the current plan doesn't explain the stop, then find one that
Jim Ingham25f66702011-12-03 01:52:59 +0000841 // does and let it handle the situation.
842 ThreadPlan *plan_ptr = current_plan;
843 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
844 {
Jim Ingham0161b492013-02-09 01:29:05 +0000845 if (plan_ptr->PlanExplainsStop(event_ptr))
Jim Ingham25f66702011-12-03 01:52:59 +0000846 {
847 should_stop = plan_ptr->ShouldStop (event_ptr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000848
Jim Ingham25f66702011-12-03 01:52:59 +0000849 // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it
850 // and all the plans below it off the stack.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000851
Jim Ingham25f66702011-12-03 01:52:59 +0000852 if (plan_ptr->MischiefManaged())
853 {
Jim Ingham031177e2012-05-11 23:49:49 +0000854 // We're going to pop the plans up to and including the plan that explains the stop.
Jim Ingham7ba6e992012-05-11 23:47:32 +0000855 ThreadPlan *prev_plan_ptr = GetPreviousPlan (plan_ptr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000856
Jim Ingham25f66702011-12-03 01:52:59 +0000857 do
858 {
859 if (should_stop)
860 current_plan->WillStop();
861 PopPlan();
862 }
Jim Ingham7ba6e992012-05-11 23:47:32 +0000863 while ((current_plan = GetCurrentPlan()) != prev_plan_ptr);
864 // Now, if the responsible plan was not "Okay to discard" then we're done,
865 // otherwise we forward this to the next plan in the stack below.
866 if (plan_ptr->IsMasterPlan() && !plan_ptr->OkayToDiscard())
867 done_processing_current_plan = true;
868 else
869 done_processing_current_plan = false;
Jim Ingham25f66702011-12-03 01:52:59 +0000870 }
871 else
872 done_processing_current_plan = true;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000873
Jim Ingham25f66702011-12-03 01:52:59 +0000874 break;
875 }
876
877 }
878 }
879 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000880
Jim Ingham25f66702011-12-03 01:52:59 +0000881 if (!done_processing_current_plan)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000882 {
Jim Inghamb01e7422010-06-19 04:45:32 +0000883 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000884
Jim Ingham10c4b242011-10-15 00:23:43 +0000885 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000886 log->Printf("Plan %s explains stop, auto-continue %i.",
887 current_plan->GetName(), over_ride_stop);
888
Jim Ingham0f16e732011-02-08 05:20:59 +0000889 // We're starting from the base plan, so just let it decide;
890 if (PlanIsBasePlan(current_plan))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000891 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000892 should_stop = current_plan->ShouldStop (event_ptr);
893 if (log)
Greg Claytonaf247d72011-05-19 03:54:16 +0000894 log->Printf("Base plan says should stop: %i.", should_stop);
Jim Ingham0f16e732011-02-08 05:20:59 +0000895 }
896 else
897 {
898 // Otherwise, don't let the base plan override what the other plans say to do, since
899 // presumably if there were other plans they would know what to do...
900 while (1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000901 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000902 if (PlanIsBasePlan(current_plan))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000903 break;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000904
Jim Ingham0f16e732011-02-08 05:20:59 +0000905 should_stop = current_plan->ShouldStop(event_ptr);
906 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000907 log->Printf("Plan %s should stop: %d.",
908 current_plan->GetName(), should_stop);
Jim Ingham0f16e732011-02-08 05:20:59 +0000909 if (current_plan->MischiefManaged())
910 {
911 if (should_stop)
912 current_plan->WillStop();
913
914 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
915 // Otherwise, see if the plan's parent wants to stop.
916
917 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
918 {
919 PopPlan();
920 break;
921 }
922 else
923 {
924
925 PopPlan();
926
927 current_plan = GetCurrentPlan();
928 if (current_plan == NULL)
929 {
930 break;
931 }
932 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000933 }
934 else
935 {
Jim Ingham0f16e732011-02-08 05:20:59 +0000936 break;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000937 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938 }
939 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000940
Jim Inghamb01e7422010-06-19 04:45:32 +0000941 if (over_ride_stop)
942 should_stop = false;
Jim Ingham64e7ead2012-05-03 21:19:36 +0000943
944 // One other potential problem is that we set up a master plan, then stop in before it is complete - for instance
945 // by hitting a breakpoint during a step-over - then do some step/finish/etc operations that wind up
946 // past the end point condition of the initial plan. We don't want to strand the original plan on the stack,
947 // This code clears stale plans off the stack.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000948
Jim Ingham64e7ead2012-05-03 21:19:36 +0000949 if (should_stop)
950 {
951 ThreadPlan *plan_ptr = GetCurrentPlan();
952 while (!PlanIsBasePlan(plan_ptr))
953 {
954 bool stale = plan_ptr->IsPlanStale ();
955 ThreadPlan *examined_plan = plan_ptr;
956 plan_ptr = GetPreviousPlan (examined_plan);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000957
Jim Ingham64e7ead2012-05-03 21:19:36 +0000958 if (stale)
959 {
960 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000961 log->Printf("Plan %s being discarded in cleanup, it says it is already done.",
962 examined_plan->GetName());
Jim Ingham64e7ead2012-05-03 21:19:36 +0000963 DiscardThreadPlansUpToPlan(examined_plan);
964 }
965 }
966 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000967
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000968 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000969
Jim Ingham10c4b242011-10-15 00:23:43 +0000970 if (log)
971 {
972 StreamString s;
973 s.IndentMore();
974 DumpThreadPlans(&s);
975 log->Printf ("Plan stack final state:\n%s", s.GetData());
976 log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop);
977 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000978 return should_stop;
979}
980
981Vote
982Thread::ShouldReportStop (Event* event_ptr)
983{
984 StateType thread_state = GetResumeState ();
Jim Ingham92087d82012-01-31 23:09:20 +0000985 StateType temp_thread_state = GetTemporaryResumeState();
986
Greg Clayton5160ce52013-03-27 23:08:40 +0000987 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton2cad65a2010-09-03 17:10:42 +0000988
989 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
990 {
991 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +0000992 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (state was suspended or invalid)", GetID(), eVoteNoOpinion);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000993 return eVoteNoOpinion;
Greg Clayton2cad65a2010-09-03 17:10:42 +0000994 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000995
Jim Ingham92087d82012-01-31 23:09:20 +0000996 if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid)
997 {
998 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +0000999 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (temporary state was suspended or invalid)", GetID(), eVoteNoOpinion);
Jim Ingham92087d82012-01-31 23:09:20 +00001000 return eVoteNoOpinion;
1001 }
1002
1003 if (!ThreadStoppedForAReason())
1004 {
1005 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +00001006 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i (thread didn't stop for a reason.)", GetID(), eVoteNoOpinion);
Jim Ingham92087d82012-01-31 23:09:20 +00001007 return eVoteNoOpinion;
1008 }
1009
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001010 if (m_completed_plan_stack.size() > 0)
1011 {
1012 // Don't use GetCompletedPlan here, since that suppresses private plans.
Greg Clayton2cad65a2010-09-03 17:10:42 +00001013 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +00001014 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote for complete stack's back plan", GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001015 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
1016 }
1017 else
Greg Clayton2cad65a2010-09-03 17:10:42 +00001018 {
Jim Ingham0161b492013-02-09 01:29:05 +00001019 Vote thread_vote = eVoteNoOpinion;
1020 ThreadPlan *plan_ptr = GetCurrentPlan();
1021 while (1)
1022 {
1023 if (plan_ptr->PlanExplainsStop(event_ptr))
1024 {
1025 thread_vote = plan_ptr->ShouldReportStop(event_ptr);
1026 break;
1027 }
1028 if (PlanIsBasePlan(plan_ptr))
1029 break;
1030 else
1031 plan_ptr = GetPreviousPlan(plan_ptr);
1032 }
Greg Clayton2cad65a2010-09-03 17:10:42 +00001033 if (log)
Greg Clayton160c9d82013-05-01 21:54:04 +00001034 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4" PRIx64 ": returning vote %i for current plan", GetID(), thread_vote);
Jim Ingham0161b492013-02-09 01:29:05 +00001035
1036 return thread_vote;
Greg Clayton2cad65a2010-09-03 17:10:42 +00001037 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001038}
1039
1040Vote
1041Thread::ShouldReportRun (Event* event_ptr)
1042{
1043 StateType thread_state = GetResumeState ();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001044
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001045 if (thread_state == eStateSuspended
1046 || thread_state == eStateInvalid)
Jim Ingham444586b2011-01-24 06:34:17 +00001047 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001048 return eVoteNoOpinion;
Jim Ingham444586b2011-01-24 06:34:17 +00001049 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001050
Greg Clayton5160ce52013-03-27 23:08:40 +00001051 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001052 if (m_completed_plan_stack.size() > 0)
1053 {
1054 // Don't use GetCompletedPlan here, since that suppresses private plans.
Jim Ingham444586b2011-01-24 06:34:17 +00001055 if (log)
Jim Inghamdee1bc92013-06-22 00:27:45 +00001056 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001057 GetIndexID(), static_cast<void*>(this), GetID(),
Greg Clayton160c9d82013-05-01 21:54:04 +00001058 StateAsCString(GetTemporaryResumeState()),
Jim Ingham444586b2011-01-24 06:34:17 +00001059 m_completed_plan_stack.back()->GetName());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001060
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001061 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
1062 }
1063 else
Jim Ingham444586b2011-01-24 06:34:17 +00001064 {
1065 if (log)
Jim Inghamdee1bc92013-06-22 00:27:45 +00001066 log->Printf ("Current Plan for thread %d(%p) (0x%4.4" PRIx64 ", %s): %s being asked whether we should report run.",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001067 GetIndexID(), static_cast<void*>(this), GetID(),
Greg Clayton160c9d82013-05-01 21:54:04 +00001068 StateAsCString(GetTemporaryResumeState()),
Jim Ingham444586b2011-01-24 06:34:17 +00001069 GetCurrentPlan()->GetName());
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001070
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001071 return GetCurrentPlan()->ShouldReportRun (event_ptr);
Jim Ingham444586b2011-01-24 06:34:17 +00001072 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001073}
1074
Jim Ingham1b54c882010-06-16 02:00:15 +00001075bool
1076Thread::MatchesSpec (const ThreadSpec *spec)
1077{
1078 if (spec == NULL)
1079 return true;
Jim Ingham1b54c882010-06-16 02:00:15 +00001080
Jim Ingham3d902922012-03-07 22:03:04 +00001081 return spec->ThreadPassesBasicTests(*this);
Jim Ingham1b54c882010-06-16 02:00:15 +00001082}
1083
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001084void
1085Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
1086{
1087 if (thread_plan_sp)
1088 {
Jim Ingham06e827c2010-11-11 19:26:09 +00001089 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
1090 if (!thread_plan_sp->GetThreadPlanTracer())
1091 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
Jim Inghamb15bfc72010-10-20 00:39:53 +00001092 m_plan_stack.push_back (thread_plan_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001093
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001094 thread_plan_sp->DidPush();
1095
Greg Clayton5160ce52013-03-27 23:08:40 +00001096 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001097 if (log)
1098 {
1099 StreamString s;
1100 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
Jim Inghamdee1bc92013-06-22 00:27:45 +00001101 log->Printf("Thread::PushPlan(0x%p): \"%s\", tid = 0x%4.4" PRIx64 ".",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001102 static_cast<void*>(this), s.GetData(),
Jim Inghamb15bfc72010-10-20 00:39:53 +00001103 thread_plan_sp->GetThread().GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001104 }
1105 }
1106}
1107
1108void
1109Thread::PopPlan ()
1110{
Greg Clayton5160ce52013-03-27 23:08:40 +00001111 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001112
Jim Ingham4fc6cb92012-08-22 21:34:33 +00001113 if (m_plan_stack.size() <= 1)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001114 return;
1115 else
1116 {
1117 ThreadPlanSP &plan = m_plan_stack.back();
1118 if (log)
1119 {
Daniel Malead01b2952012-11-29 21:49:15 +00001120 log->Printf("Popping plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001121 }
1122 m_completed_plan_stack.push_back (plan);
1123 plan->WillPop();
1124 m_plan_stack.pop_back();
1125 }
1126}
1127
1128void
1129Thread::DiscardPlan ()
1130{
Jim Inghamdee1bc92013-06-22 00:27:45 +00001131 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001132 if (m_plan_stack.size() > 1)
1133 {
1134 ThreadPlanSP &plan = m_plan_stack.back();
Jim Inghamdee1bc92013-06-22 00:27:45 +00001135 if (log)
1136 log->Printf("Discarding plan: \"%s\", tid = 0x%4.4" PRIx64 ".", plan->GetName(), plan->GetThread().GetID());
1137
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001138 m_discarded_plan_stack.push_back (plan);
1139 plan->WillPop();
1140 m_plan_stack.pop_back();
1141 }
1142}
1143
1144ThreadPlan *
1145Thread::GetCurrentPlan ()
1146{
Jim Inghame1471232012-04-19 00:17:05 +00001147 // There will always be at least the base plan. If somebody is mucking with a
1148 // thread with an empty plan stack, we should assert right away.
Greg Claytond1d06e42013-04-20 00:27:58 +00001149 if (m_plan_stack.empty())
1150 return NULL;
Jim Inghame1471232012-04-19 00:17:05 +00001151 return m_plan_stack.back().get();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001152}
1153
1154ThreadPlanSP
1155Thread::GetCompletedPlan ()
1156{
1157 ThreadPlanSP empty_plan_sp;
1158 if (!m_completed_plan_stack.empty())
1159 {
1160 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1161 {
1162 ThreadPlanSP completed_plan_sp;
1163 completed_plan_sp = m_completed_plan_stack[i];
1164 if (!completed_plan_sp->GetPrivate ())
1165 return completed_plan_sp;
1166 }
1167 }
1168 return empty_plan_sp;
1169}
1170
Jim Ingham73ca05a2011-12-17 01:35:57 +00001171ValueObjectSP
1172Thread::GetReturnValueObject ()
1173{
1174 if (!m_completed_plan_stack.empty())
1175 {
1176 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1177 {
1178 ValueObjectSP return_valobj_sp;
1179 return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject();
1180 if (return_valobj_sp)
1181 return return_valobj_sp;
1182 }
1183 }
1184 return ValueObjectSP();
1185}
1186
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001187bool
1188Thread::IsThreadPlanDone (ThreadPlan *plan)
1189{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001190 if (!m_completed_plan_stack.empty())
1191 {
1192 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
1193 {
1194 if (m_completed_plan_stack[i].get() == plan)
1195 return true;
1196 }
1197 }
1198 return false;
1199}
1200
1201bool
1202Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
1203{
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001204 if (!m_discarded_plan_stack.empty())
1205 {
1206 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
1207 {
1208 if (m_discarded_plan_stack[i].get() == plan)
1209 return true;
1210 }
1211 }
1212 return false;
1213}
1214
1215ThreadPlan *
1216Thread::GetPreviousPlan (ThreadPlan *current_plan)
1217{
1218 if (current_plan == NULL)
1219 return NULL;
1220
1221 int stack_size = m_completed_plan_stack.size();
1222 for (int i = stack_size - 1; i > 0; i--)
1223 {
1224 if (current_plan == m_completed_plan_stack[i].get())
1225 return m_completed_plan_stack[i-1].get();
1226 }
1227
1228 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
1229 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001230 if (m_plan_stack.size() > 0)
1231 return m_plan_stack.back().get();
1232 else
1233 return NULL;
1234 }
1235
1236 stack_size = m_plan_stack.size();
1237 for (int i = stack_size - 1; i > 0; i--)
1238 {
1239 if (current_plan == m_plan_stack[i].get())
1240 return m_plan_stack[i-1].get();
1241 }
1242 return NULL;
1243}
1244
1245void
1246Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
1247{
1248 if (abort_other_plans)
1249 DiscardThreadPlans(true);
1250
1251 PushPlan (thread_plan_sp);
1252}
1253
Jim Ingham06e827c2010-11-11 19:26:09 +00001254
1255void
1256Thread::EnableTracer (bool value, bool single_stepping)
1257{
1258 int stack_size = m_plan_stack.size();
1259 for (int i = 0; i < stack_size; i++)
1260 {
1261 if (m_plan_stack[i]->GetThreadPlanTracer())
1262 {
1263 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
1264 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
1265 }
1266 }
1267}
1268
1269void
1270Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
1271{
1272 int stack_size = m_plan_stack.size();
1273 for (int i = 0; i < stack_size; i++)
1274 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
1275}
1276
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001277void
Jim Ingham399f1ca2010-11-05 19:25:48 +00001278Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
1279{
Jim Ingham64e7ead2012-05-03 21:19:36 +00001280 DiscardThreadPlansUpToPlan (up_to_plan_sp.get());
1281}
1282
1283void
1284Thread::DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr)
1285{
Greg Clayton5160ce52013-03-27 23:08:40 +00001286 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham399f1ca2010-11-05 19:25:48 +00001287 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001288 log->Printf("Discarding thread plans for thread tid = 0x%4.4" PRIx64 ", up to %p",
1289 GetID(), static_cast<void*>(up_to_plan_ptr));
Jim Ingham399f1ca2010-11-05 19:25:48 +00001290
1291 int stack_size = m_plan_stack.size();
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001292
Jim Ingham399f1ca2010-11-05 19:25:48 +00001293 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
1294 // stack, and if so discard up to and including it.
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001295
Jim Ingham64e7ead2012-05-03 21:19:36 +00001296 if (up_to_plan_ptr == NULL)
Jim Ingham399f1ca2010-11-05 19:25:48 +00001297 {
1298 for (int i = stack_size - 1; i > 0; i--)
1299 DiscardPlan();
1300 }
1301 else
1302 {
1303 bool found_it = false;
1304 for (int i = stack_size - 1; i > 0; i--)
1305 {
Jim Ingham64e7ead2012-05-03 21:19:36 +00001306 if (m_plan_stack[i].get() == up_to_plan_ptr)
Jim Ingham399f1ca2010-11-05 19:25:48 +00001307 found_it = true;
1308 }
1309 if (found_it)
1310 {
1311 bool last_one = false;
1312 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
1313 {
Jim Ingham64e7ead2012-05-03 21:19:36 +00001314 if (GetCurrentPlan() == up_to_plan_ptr)
Jim Ingham399f1ca2010-11-05 19:25:48 +00001315 last_one = true;
1316 DiscardPlan();
1317 }
1318 }
1319 }
1320 return;
1321}
1322
1323void
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001324Thread::DiscardThreadPlans(bool force)
1325{
Greg Clayton5160ce52013-03-27 23:08:40 +00001326 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001327 if (log)
1328 {
Daniel Malead01b2952012-11-29 21:49:15 +00001329 log->Printf("Discarding thread plans for thread (tid = 0x%4.4" PRIx64 ", force %d)", GetID(), force);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001330 }
1331
1332 if (force)
1333 {
1334 int stack_size = m_plan_stack.size();
1335 for (int i = stack_size - 1; i > 0; i--)
1336 {
1337 DiscardPlan();
1338 }
1339 return;
1340 }
1341
1342 while (1)
1343 {
1344
1345 int master_plan_idx;
Jim Inghama39ad072012-09-11 00:09:25 +00001346 bool discard = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001347
1348 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
1349 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
1350 {
1351 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
1352 {
1353 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
1354 break;
1355 }
1356 }
1357
1358 if (discard)
1359 {
1360 // First pop all the dependent plans:
1361 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
1362 {
1363
1364 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
1365 // for the plan leaves it in a state that it is safe to pop the plan
1366 // with no more notice?
1367 DiscardPlan();
1368 }
1369
1370 // Now discard the master plan itself.
1371 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
1372 // discard it's dependent plans, but not it...
1373 if (master_plan_idx > 0)
1374 {
1375 DiscardPlan();
1376 }
1377 }
1378 else
1379 {
1380 // If the master plan doesn't want to get discarded, then we're done.
1381 break;
1382 }
1383
1384 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001385}
1386
Jim Inghamcf274f92012-04-09 22:37:39 +00001387bool
1388Thread::PlanIsBasePlan (ThreadPlan *plan_ptr)
1389{
1390 if (plan_ptr->IsBasePlan())
1391 return true;
1392 else if (m_plan_stack.size() == 0)
1393 return false;
1394 else
1395 return m_plan_stack[0].get() == plan_ptr;
1396}
1397
Jim Ingham93208b82013-01-31 21:46:01 +00001398Error
1399Thread::UnwindInnermostExpression()
1400{
1401 Error error;
1402 int stack_size = m_plan_stack.size();
1403
1404 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
1405 // stack, and if so discard up to and including it.
1406
1407 for (int i = stack_size - 1; i > 0; i--)
1408 {
1409 if (m_plan_stack[i]->GetKind() == ThreadPlan::eKindCallFunction)
1410 {
1411 DiscardThreadPlansUpToPlan(m_plan_stack[i].get());
1412 return error;
1413 }
1414 }
1415 error.SetErrorString("No expressions currently active on this thread");
1416 return error;
1417}
1418
1419
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001420ThreadPlanSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001421Thread::QueueFundamentalPlan (bool abort_other_plans)
1422{
1423 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
1424 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001425 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001426}
1427
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001428ThreadPlanSP
Greg Clayton481cef22011-01-21 06:11:58 +00001429Thread::QueueThreadPlanForStepSingleInstruction
1430(
1431 bool step_over,
1432 bool abort_other_plans,
1433 bool stop_other_threads
1434)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001435{
1436 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
1437 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001438 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001439}
1440
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001441ThreadPlanSP
Jim Inghamc6276822012-12-12 19:58:40 +00001442Thread::QueueThreadPlanForStepOverRange
Greg Clayton474966a2010-06-12 18:59:55 +00001443(
1444 bool abort_other_plans,
Greg Clayton474966a2010-06-12 18:59:55 +00001445 const AddressRange &range,
Jim Inghamc6276822012-12-12 19:58:40 +00001446 const SymbolContext &addr_context,
Jim Ingham4b4b2472014-03-13 02:47:14 +00001447 lldb::RunMode stop_other_threads,
1448 LazyBool step_out_avoids_code_withoug_debug_info
Jim Inghamc6276822012-12-12 19:58:40 +00001449)
1450{
1451 ThreadPlanSP thread_plan_sp;
Jim Ingham4b4b2472014-03-13 02:47:14 +00001452 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads, step_out_avoids_code_withoug_debug_info));
1453
Jim Inghamc6276822012-12-12 19:58:40 +00001454 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001455 return thread_plan_sp;
Jim Inghamc6276822012-12-12 19:58:40 +00001456}
1457
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001458ThreadPlanSP
Jim Inghamc6276822012-12-12 19:58:40 +00001459Thread::QueueThreadPlanForStepInRange
1460(
1461 bool abort_other_plans,
1462 const AddressRange &range,
1463 const SymbolContext &addr_context,
1464 const char *step_in_target,
Greg Clayton474966a2010-06-12 18:59:55 +00001465 lldb::RunMode stop_other_threads,
Jim Ingham4b4b2472014-03-13 02:47:14 +00001466 LazyBool step_in_avoids_code_without_debug_info,
1467 LazyBool step_out_avoids_code_without_debug_info
Greg Clayton474966a2010-06-12 18:59:55 +00001468)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001469{
1470 ThreadPlanSP thread_plan_sp;
Jim Ingham4b4b2472014-03-13 02:47:14 +00001471 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this,
1472 range,
1473 addr_context,
1474 stop_other_threads,
1475 step_in_avoids_code_without_debug_info,
1476 step_out_avoids_code_without_debug_info);
1477
Jim Inghamc6276822012-12-12 19:58:40 +00001478 if (step_in_target)
1479 plan->SetStepInTarget(step_in_target);
Jim Ingham4b4b2472014-03-13 02:47:14 +00001480
Jim Inghamc6276822012-12-12 19:58:40 +00001481 thread_plan_sp.reset (plan);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001482
1483 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001484 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001485}
1486
1487
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001488ThreadPlanSP
Greg Clayton481cef22011-01-21 06:11:58 +00001489Thread::QueueThreadPlanForStepOut
1490(
1491 bool abort_other_plans,
1492 SymbolContext *addr_context,
1493 bool first_insn,
1494 bool stop_other_threads,
1495 Vote stop_vote,
1496 Vote run_vote,
Jim Ingham4b4b2472014-03-13 02:47:14 +00001497 uint32_t frame_idx,
1498 LazyBool step_out_avoids_code_withoug_debug_info
Greg Clayton481cef22011-01-21 06:11:58 +00001499)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001500{
Greg Clayton481cef22011-01-21 06:11:58 +00001501 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this,
1502 addr_context,
1503 first_insn,
1504 stop_other_threads,
1505 stop_vote,
1506 run_vote,
Jim Ingham4b4b2472014-03-13 02:47:14 +00001507 frame_idx,
1508 step_out_avoids_code_withoug_debug_info));
1509
1510 if (thread_plan_sp->ValidatePlan(NULL))
1511 {
1512 QueueThreadPlan (thread_plan_sp, abort_other_plans);
1513 return thread_plan_sp;
1514 }
1515 else
1516 {
1517 return ThreadPlanSP();
1518 }
1519}
1520
1521ThreadPlanSP
1522Thread::QueueThreadPlanForStepOutNoShouldStop
1523(
1524 bool abort_other_plans,
1525 SymbolContext *addr_context,
1526 bool first_insn,
1527 bool stop_other_threads,
1528 Vote stop_vote,
1529 Vote run_vote,
1530 uint32_t frame_idx
1531)
1532{
1533 ThreadPlanStepOut *new_plan = new ThreadPlanStepOut (*this,
1534 addr_context,
1535 first_insn,
1536 stop_other_threads,
1537 stop_vote,
1538 run_vote,
1539 frame_idx,
1540 eLazyBoolNo);
1541 new_plan->ClearShouldStopHereCallbacks();
1542 ThreadPlanSP thread_plan_sp(new_plan);
Sean Callanan708709c2012-07-31 22:19:25 +00001543
1544 if (thread_plan_sp->ValidatePlan(NULL))
1545 {
1546 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001547 return thread_plan_sp;
Sean Callanan708709c2012-07-31 22:19:25 +00001548 }
1549 else
1550 {
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001551 return ThreadPlanSP();
Sean Callanan708709c2012-07-31 22:19:25 +00001552 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001553}
1554
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001555ThreadPlanSP
Jim Ingham18de2fd2012-05-10 01:35:39 +00001556Thread::QueueThreadPlanForStepThrough (StackID &return_stack_id, bool abort_other_plans, bool stop_other_threads)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001557{
Jim Ingham18de2fd2012-05-10 01:35:39 +00001558 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, return_stack_id, stop_other_threads));
Jim Ingham25f66702011-12-03 01:52:59 +00001559 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL))
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001560 return ThreadPlanSP();
Jim Ingham25f66702011-12-03 01:52:59 +00001561
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001562 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001563 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001564}
1565
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001566ThreadPlanSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001567Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
1568 Address &target_addr,
1569 bool stop_other_threads)
1570{
1571 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
1572 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001573 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001574}
1575
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001576ThreadPlanSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001577Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
Greg Clayton481cef22011-01-21 06:11:58 +00001578 lldb::addr_t *address_list,
1579 size_t num_addresses,
1580 bool stop_other_threads,
1581 uint32_t frame_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001582{
Greg Clayton481cef22011-01-21 06:11:58 +00001583 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx));
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001584 QueueThreadPlan (thread_plan_sp, abort_other_plans);
Jim Ingham4d56e9c2013-07-18 21:48:26 +00001585 return thread_plan_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001586
1587}
1588
1589uint32_t
1590Thread::GetIndexID () const
1591{
1592 return m_index_id;
1593}
1594
1595void
1596Thread::DumpThreadPlans (lldb_private::Stream *s) const
1597{
1598 uint32_t stack_size = m_plan_stack.size();
Greg Clayton1346f7e2010-09-03 22:45:01 +00001599 int i;
Jim Ingham10c4b242011-10-15 00:23:43 +00001600 s->Indent();
Daniel Malead01b2952012-11-29 21:49:15 +00001601 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4" PRIx64 ", stack_size = %d\n", GetIndexID(), GetID(), stack_size);
Greg Clayton1346f7e2010-09-03 22:45:01 +00001602 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001603 {
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001604 s->IndentMore();
Jim Ingham10c4b242011-10-15 00:23:43 +00001605 s->Indent();
1606 s->Printf ("Element %d: ", i);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001607 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001608 s->EOL();
Jim Ingham10c4b242011-10-15 00:23:43 +00001609 s->IndentLess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001610 }
1611
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001612 stack_size = m_completed_plan_stack.size();
Jim Ingham10c4b242011-10-15 00:23:43 +00001613 if (stack_size > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001614 {
Jim Ingham10c4b242011-10-15 00:23:43 +00001615 s->Indent();
1616 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
1617 for (i = stack_size - 1; i >= 0; i--)
1618 {
1619 s->IndentMore();
1620 s->Indent();
1621 s->Printf ("Element %d: ", i);
1622 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1623 s->EOL();
1624 s->IndentLess();
1625 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001626 }
1627
1628 stack_size = m_discarded_plan_stack.size();
Jim Ingham10c4b242011-10-15 00:23:43 +00001629 if (stack_size > 0)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001630 {
Jim Ingham10c4b242011-10-15 00:23:43 +00001631 s->Indent();
1632 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
1633 for (i = stack_size - 1; i >= 0; i--)
1634 {
1635 s->IndentMore();
1636 s->Indent();
1637 s->Printf ("Element %d: ", i);
1638 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1639 s->EOL();
1640 s->IndentLess();
1641 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001642 }
1643
1644}
1645
Greg Claytond9e416c2012-02-18 05:35:26 +00001646TargetSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001647Thread::CalculateTarget ()
1648{
Greg Clayton1ac04c32012-02-21 00:09:25 +00001649 TargetSP target_sp;
1650 ProcessSP process_sp(GetProcess());
1651 if (process_sp)
1652 target_sp = process_sp->CalculateTarget();
1653 return target_sp;
1654
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001655}
1656
Greg Claytond9e416c2012-02-18 05:35:26 +00001657ProcessSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001658Thread::CalculateProcess ()
1659{
Greg Clayton1ac04c32012-02-21 00:09:25 +00001660 return GetProcess();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001661}
1662
Greg Claytond9e416c2012-02-18 05:35:26 +00001663ThreadSP
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001664Thread::CalculateThread ()
1665{
Greg Claytond9e416c2012-02-18 05:35:26 +00001666 return shared_from_this();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001667}
1668
Jason Molendab57e4a12013-11-04 09:33:30 +00001669StackFrameSP
1670Thread::CalculateStackFrame ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001671{
Jason Molendab57e4a12013-11-04 09:33:30 +00001672 return StackFrameSP();
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001673}
1674
1675void
Greg Clayton0603aa92010-10-04 01:05:56 +00001676Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001677{
Greg Clayton1ac04c32012-02-21 00:09:25 +00001678 exe_ctx.SetContext (shared_from_this());
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001679}
1680
Greg Clayton12daf9462010-08-25 00:35:26 +00001681
Greg Clayton39d0ab32012-03-29 01:41:38 +00001682StackFrameListSP
Greg Clayton12daf9462010-08-25 00:35:26 +00001683Thread::GetStackFrameList ()
1684{
Greg Clayton39d0ab32012-03-29 01:41:38 +00001685 StackFrameListSP frame_list_sp;
1686 Mutex::Locker locker(m_frame_mutex);
1687 if (m_curr_frames_sp)
1688 {
1689 frame_list_sp = m_curr_frames_sp;
1690 }
1691 else
1692 {
1693 frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true));
1694 m_curr_frames_sp = frame_list_sp;
1695 }
1696 return frame_list_sp;
Greg Clayton12daf9462010-08-25 00:35:26 +00001697}
1698
Greg Clayton12daf9462010-08-25 00:35:26 +00001699void
1700Thread::ClearStackFrames ()
1701{
Greg Clayton39d0ab32012-03-29 01:41:38 +00001702 Mutex::Locker locker(m_frame_mutex);
1703
Greg Clayton160c9d82013-05-01 21:54:04 +00001704 Unwind *unwinder = GetUnwinder ();
1705 if (unwinder)
1706 unwinder->Clear();
1707
Jim Inghamb0c72a52012-02-29 03:40:22 +00001708 // Only store away the old "reference" StackFrameList if we got all its frames:
1709 // FIXME: At some point we can try to splice in the frames we have fetched into
1710 // the new frame as we make it, but let's not try that now.
1711 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
Greg Clayton7e9b1fd2011-08-12 21:40:01 +00001712 m_prev_frames_sp.swap (m_curr_frames_sp);
1713 m_curr_frames_sp.reset();
Jason Molenda705b1802014-06-13 02:37:02 +00001714
1715 m_extended_info.reset();
1716 m_extended_info_fetched = false;
Jim Ingham87c11912010-08-12 02:14:28 +00001717}
1718
Jason Molendab57e4a12013-11-04 09:33:30 +00001719lldb::StackFrameSP
Greg Clayton5ccbd292011-01-06 22:15:06 +00001720Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1721{
Greg Clayton39d0ab32012-03-29 01:41:38 +00001722 return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx);
Greg Clayton5ccbd292011-01-06 22:15:06 +00001723}
1724
Jim Ingham44137582012-09-12 00:40:39 +00001725
1726Error
Jim Ingham4f465cf2012-10-10 18:32:14 +00001727Thread::ReturnFromFrameWithIndex (uint32_t frame_idx, lldb::ValueObjectSP return_value_sp, bool broadcast)
Jim Ingham44137582012-09-12 00:40:39 +00001728{
Jason Molendab57e4a12013-11-04 09:33:30 +00001729 StackFrameSP frame_sp = GetStackFrameAtIndex (frame_idx);
Jim Ingham44137582012-09-12 00:40:39 +00001730 Error return_error;
1731
1732 if (!frame_sp)
1733 {
Daniel Malead01b2952012-11-29 21:49:15 +00001734 return_error.SetErrorStringWithFormat("Could not find frame with index %d in thread 0x%" PRIx64 ".", frame_idx, GetID());
Jim Ingham44137582012-09-12 00:40:39 +00001735 }
1736
Jim Ingham4f465cf2012-10-10 18:32:14 +00001737 return ReturnFromFrame(frame_sp, return_value_sp, broadcast);
Jim Ingham44137582012-09-12 00:40:39 +00001738}
1739
1740Error
Jason Molendab57e4a12013-11-04 09:33:30 +00001741Thread::ReturnFromFrame (lldb::StackFrameSP frame_sp, lldb::ValueObjectSP return_value_sp, bool broadcast)
Jim Ingham44137582012-09-12 00:40:39 +00001742{
1743 Error return_error;
1744
1745 if (!frame_sp)
1746 {
1747 return_error.SetErrorString("Can't return to a null frame.");
1748 return return_error;
1749 }
1750
1751 Thread *thread = frame_sp->GetThread().get();
Jim Inghamcb640dd2012-09-14 02:14:15 +00001752 uint32_t older_frame_idx = frame_sp->GetFrameIndex() + 1;
Jason Molendab57e4a12013-11-04 09:33:30 +00001753 StackFrameSP older_frame_sp = thread->GetStackFrameAtIndex(older_frame_idx);
Jim Ingham93208b82013-01-31 21:46:01 +00001754 if (!older_frame_sp)
1755 {
1756 return_error.SetErrorString("No older frame to return to.");
1757 return return_error;
1758 }
Jim Ingham44137582012-09-12 00:40:39 +00001759
1760 if (return_value_sp)
Jim Ingham1f51e602012-09-27 01:15:29 +00001761 {
Jim Ingham44137582012-09-12 00:40:39 +00001762 lldb::ABISP abi = thread->GetProcess()->GetABI();
1763 if (!abi)
1764 {
1765 return_error.SetErrorString("Could not find ABI to set return value.");
Jim Ingham28eb5712012-10-12 17:34:26 +00001766 return return_error;
Jim Ingham44137582012-09-12 00:40:39 +00001767 }
Jim Ingham1f51e602012-09-27 01:15:29 +00001768 SymbolContext sc = frame_sp->GetSymbolContext(eSymbolContextFunction);
1769
1770 // FIXME: ValueObject::Cast doesn't currently work correctly, at least not for scalars.
1771 // Turn that back on when that works.
1772 if (0 && sc.function != NULL)
1773 {
1774 Type *function_type = sc.function->GetType();
1775 if (function_type)
1776 {
Greg Clayton57ee3062013-07-11 22:46:58 +00001777 ClangASTType return_type = sc.function->GetClangType().GetFunctionReturnType();
Jim Ingham1f51e602012-09-27 01:15:29 +00001778 if (return_type)
1779 {
Jim Ingham1f51e602012-09-27 01:15:29 +00001780 StreamString s;
Greg Clayton57ee3062013-07-11 22:46:58 +00001781 return_type.DumpTypeDescription(&s);
1782 ValueObjectSP cast_value_sp = return_value_sp->Cast(return_type);
Jim Ingham1f51e602012-09-27 01:15:29 +00001783 if (cast_value_sp)
1784 {
1785 cast_value_sp->SetFormat(eFormatHex);
1786 return_value_sp = cast_value_sp;
1787 }
1788 }
1789 }
1790 }
1791
Jim Inghamcb640dd2012-09-14 02:14:15 +00001792 return_error = abi->SetReturnValueObject(older_frame_sp, return_value_sp);
Jim Ingham44137582012-09-12 00:40:39 +00001793 if (!return_error.Success())
1794 return return_error;
1795 }
1796
1797 // Now write the return registers for the chosen frame:
Jim Inghamcb640dd2012-09-14 02:14:15 +00001798 // Note, we can't use ReadAllRegisterValues->WriteAllRegisterValues, since the read & write
Jim Ingham93208b82013-01-31 21:46:01 +00001799 // cook their data
1800
Jason Molendab57e4a12013-11-04 09:33:30 +00001801 StackFrameSP youngest_frame_sp = thread->GetStackFrameAtIndex(0);
Jim Ingham93208b82013-01-31 21:46:01 +00001802 if (youngest_frame_sp)
Jim Ingham44137582012-09-12 00:40:39 +00001803 {
Greg Clayton1afa68e2013-04-02 20:32:37 +00001804 lldb::RegisterContextSP reg_ctx_sp (youngest_frame_sp->GetRegisterContext());
1805 if (reg_ctx_sp)
Jim Ingham93208b82013-01-31 21:46:01 +00001806 {
Greg Clayton1afa68e2013-04-02 20:32:37 +00001807 bool copy_success = reg_ctx_sp->CopyFromRegisterContext(older_frame_sp->GetRegisterContext());
1808 if (copy_success)
1809 {
1810 thread->DiscardThreadPlans(true);
1811 thread->ClearStackFrames();
1812 if (broadcast && EventTypeHasListeners(eBroadcastBitStackChanged))
1813 BroadcastEvent(eBroadcastBitStackChanged, new ThreadEventData (this->shared_from_this()));
1814 }
1815 else
1816 {
1817 return_error.SetErrorString("Could not reset register values.");
1818 }
Jim Ingham93208b82013-01-31 21:46:01 +00001819 }
1820 else
1821 {
Greg Clayton1afa68e2013-04-02 20:32:37 +00001822 return_error.SetErrorString("Frame has no register context.");
Jim Ingham93208b82013-01-31 21:46:01 +00001823 }
Jim Ingham44137582012-09-12 00:40:39 +00001824 }
1825 else
1826 {
Jim Ingham93208b82013-01-31 21:46:01 +00001827 return_error.SetErrorString("Returned past top frame.");
Jim Ingham44137582012-09-12 00:40:39 +00001828 }
Greg Claytonabb487f2013-02-01 02:52:31 +00001829 return return_error;
Jim Ingham44137582012-09-12 00:40:39 +00001830}
1831
Richard Mittonf86248d2013-09-12 02:20:34 +00001832static void DumpAddressList (Stream &s, const std::vector<Address> &list, ExecutionContextScope *exe_scope)
1833{
1834 for (size_t n=0;n<list.size();n++)
1835 {
1836 s << "\t";
1837 list[n].Dump (&s, exe_scope, Address::DumpStyleResolvedDescription, Address::DumpStyleSectionNameOffset);
1838 s << "\n";
1839 }
1840}
1841
1842Error
1843Thread::JumpToLine (const FileSpec &file, uint32_t line, bool can_leave_function, std::string *warnings)
1844{
1845 ExecutionContext exe_ctx (GetStackFrameAtIndex(0));
1846 Target *target = exe_ctx.GetTargetPtr();
1847 TargetSP target_sp = exe_ctx.GetTargetSP();
1848 RegisterContext *reg_ctx = exe_ctx.GetRegisterContext();
Jason Molendab57e4a12013-11-04 09:33:30 +00001849 StackFrame *frame = exe_ctx.GetFramePtr();
Richard Mittonf86248d2013-09-12 02:20:34 +00001850 const SymbolContext &sc = frame->GetSymbolContext(eSymbolContextFunction);
1851
1852 // Find candidate locations.
1853 std::vector<Address> candidates, within_function, outside_function;
1854 target->GetImages().FindAddressesForLine (target_sp, file, line, sc.function, within_function, outside_function);
1855
1856 // If possible, we try and stay within the current function.
1857 // Within a function, we accept multiple locations (optimized code may do this,
1858 // there's no solution here so we do the best we can).
1859 // However if we're trying to leave the function, we don't know how to pick the
1860 // right location, so if there's more than one then we bail.
1861 if (!within_function.empty())
1862 candidates = within_function;
1863 else if (outside_function.size() == 1 && can_leave_function)
1864 candidates = outside_function;
1865
1866 // Check if we got anything.
1867 if (candidates.empty())
1868 {
1869 if (outside_function.empty())
1870 {
1871 return Error("Cannot locate an address for %s:%i.",
1872 file.GetFilename().AsCString(), line);
1873 }
1874 else if (outside_function.size() == 1)
1875 {
1876 return Error("%s:%i is outside the current function.",
1877 file.GetFilename().AsCString(), line);
1878 }
1879 else
1880 {
1881 StreamString sstr;
1882 DumpAddressList(sstr, outside_function, target);
1883 return Error("%s:%i has multiple candidate locations:\n%s",
1884 file.GetFilename().AsCString(), line, sstr.GetString().c_str());
1885 }
1886 }
1887
1888 // Accept the first location, warn about any others.
1889 Address dest = candidates[0];
1890 if (warnings && candidates.size() > 1)
1891 {
1892 StreamString sstr;
1893 sstr.Printf("%s:%i appears multiple times in this function, selecting the first location:\n",
1894 file.GetFilename().AsCString(), line);
1895 DumpAddressList(sstr, candidates, target);
1896 *warnings = sstr.GetString();
1897 }
1898
1899 if (!reg_ctx->SetPC (dest))
1900 return Error("Cannot change PC to target address.");
1901
1902 return Error();
1903}
1904
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001905void
Greg Clayton0603aa92010-10-04 01:05:56 +00001906Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001907{
Greg Clayton1ac04c32012-02-21 00:09:25 +00001908 ExecutionContext exe_ctx (shared_from_this());
1909 Process *process = exe_ctx.GetProcessPtr();
1910 if (process == NULL)
1911 return;
1912
Jason Molendab57e4a12013-11-04 09:33:30 +00001913 StackFrameSP frame_sp;
Greg Clayton0603aa92010-10-04 01:05:56 +00001914 SymbolContext frame_sc;
Greg Clayton0603aa92010-10-04 01:05:56 +00001915 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001916 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001917 frame_sp = GetStackFrameAtIndex (frame_idx);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001918 if (frame_sp)
1919 {
Greg Claytonc14ee322011-09-22 04:58:26 +00001920 exe_ctx.SetFrameSP(frame_sp);
1921 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001922 }
1923 }
1924
Greg Clayton1ac04c32012-02-21 00:09:25 +00001925 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
Greg Clayton0603aa92010-10-04 01:05:56 +00001926 assert (thread_format);
Greg Clayton0603aa92010-10-04 01:05:56 +00001927 Debugger::FormatPrompt (thread_format,
Greg Claytonc14ee322011-09-22 04:58:26 +00001928 frame_sp ? &frame_sc : NULL,
Greg Clayton0603aa92010-10-04 01:05:56 +00001929 &exe_ctx,
1930 NULL,
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001931 strm);
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001932}
1933
Greg Clayton99d0faf2010-11-18 23:32:35 +00001934void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001935Thread::SettingsInitialize ()
Jim Inghamee8aea12010-09-08 03:14:33 +00001936{
Greg Clayton99d0faf2010-11-18 23:32:35 +00001937}
Jim Inghamee8aea12010-09-08 03:14:33 +00001938
Greg Clayton99d0faf2010-11-18 23:32:35 +00001939void
Caroline Tice20bd37f2011-03-10 22:14:10 +00001940Thread::SettingsTerminate ()
Greg Clayton99d0faf2010-11-18 23:32:35 +00001941{
Greg Clayton99d0faf2010-11-18 23:32:35 +00001942}
Jim Inghamee8aea12010-09-08 03:14:33 +00001943
Richard Mitton0a558352013-10-17 21:14:00 +00001944lldb::addr_t
1945Thread::GetThreadPointer ()
1946{
1947 return LLDB_INVALID_ADDRESS;
1948}
1949
1950addr_t
1951Thread::GetThreadLocalData (const ModuleSP module)
1952{
1953 // The default implementation is to ask the dynamic loader for it.
1954 // This can be overridden for specific platforms.
1955 DynamicLoader *loader = GetProcess()->GetDynamicLoader();
1956 if (loader)
1957 return loader->GetThreadLocalData (module, shared_from_this());
1958 else
1959 return LLDB_INVALID_ADDRESS;
1960}
1961
Jason Molendab4892cd2014-05-13 22:02:48 +00001962bool
1963Thread::SafeToCallFunctions ()
1964{
1965 Process *process = GetProcess().get();
1966 if (process)
1967 {
1968 SystemRuntime *runtime = process->GetSystemRuntime ();
1969 if (runtime)
1970 {
1971 return runtime->SafeToCallFunctionsOnThisThread (shared_from_this());
1972 }
1973 }
1974 return true;
1975}
1976
Jason Molendab57e4a12013-11-04 09:33:30 +00001977lldb::StackFrameSP
1978Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
Jim Inghame4284b72010-09-23 17:40:12 +00001979{
Jason Molendab57e4a12013-11-04 09:33:30 +00001980 return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr);
Jim Inghame4284b72010-09-23 17:40:12 +00001981}
Caroline Ticeceb6b132010-10-26 03:11:13 +00001982
1983const char *
1984Thread::StopReasonAsCString (lldb::StopReason reason)
1985{
1986 switch (reason)
1987 {
Andrew Kaylorf85defa2012-12-20 23:08:03 +00001988 case eStopReasonInvalid: return "invalid";
1989 case eStopReasonNone: return "none";
1990 case eStopReasonTrace: return "trace";
1991 case eStopReasonBreakpoint: return "breakpoint";
1992 case eStopReasonWatchpoint: return "watchpoint";
1993 case eStopReasonSignal: return "signal";
1994 case eStopReasonException: return "exception";
1995 case eStopReasonExec: return "exec";
1996 case eStopReasonPlanComplete: return "plan complete";
1997 case eStopReasonThreadExiting: return "thread exiting";
Caroline Ticeceb6b132010-10-26 03:11:13 +00001998 }
1999
2000
2001 static char unknown_state_string[64];
2002 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
2003 return unknown_state_string;
2004}
2005
2006const char *
2007Thread::RunModeAsCString (lldb::RunMode mode)
2008{
2009 switch (mode)
2010 {
2011 case eOnlyThisThread: return "only this thread";
2012 case eAllThreads: return "all threads";
2013 case eOnlyDuringStepping: return "only during stepping";
2014 }
2015
2016 static char unknown_state_string[64];
2017 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
2018 return unknown_state_string;
2019}
Jim Ingham06e827c2010-11-11 19:26:09 +00002020
Greg Clayton7260f622011-04-18 08:33:37 +00002021size_t
2022Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
2023{
Greg Clayton1ac04c32012-02-21 00:09:25 +00002024 ExecutionContext exe_ctx (shared_from_this());
2025 Target *target = exe_ctx.GetTargetPtr();
2026 Process *process = exe_ctx.GetProcessPtr();
Greg Clayton7260f622011-04-18 08:33:37 +00002027 size_t num_frames_shown = 0;
2028 strm.Indent();
Greg Clayton1ac04c32012-02-21 00:09:25 +00002029 bool is_selected = false;
2030 if (process)
2031 {
2032 if (process->GetThreadList().GetSelectedThread().get() == this)
2033 is_selected = true;
2034 }
2035 strm.Printf("%c ", is_selected ? '*' : ' ');
2036 if (target && target->GetDebugger().GetUseExternalEditor())
Greg Clayton7260f622011-04-18 08:33:37 +00002037 {
Jason Molendab57e4a12013-11-04 09:33:30 +00002038 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
Jim Inghame610d642011-08-16 00:07:28 +00002039 if (frame_sp)
Greg Clayton5113dc82011-08-12 06:47:54 +00002040 {
Jim Inghame610d642011-08-16 00:07:28 +00002041 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
2042 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
2043 {
2044 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
2045 }
Greg Clayton5113dc82011-08-12 06:47:54 +00002046 }
Greg Clayton7260f622011-04-18 08:33:37 +00002047 }
2048
2049 DumpUsingSettingsFormat (strm, start_frame);
2050
2051 if (num_frames > 0)
2052 {
2053 strm.IndentMore();
2054
2055 const bool show_frame_info = true;
Jim Ingham8ec10ef2013-10-18 17:38:31 +00002056
2057 const char *selected_frame_marker = NULL;
2058 if (num_frames == 1 || (GetID() != GetProcess()->GetThreadList().GetSelectedThread()->GetID()))
2059 strm.IndentMore ();
2060 else
2061 selected_frame_marker = "* ";
2062
Greg Clayton39d0ab32012-03-29 01:41:38 +00002063 num_frames_shown = GetStackFrameList ()->GetStatus (strm,
2064 start_frame,
2065 num_frames,
2066 show_frame_info,
Jim Ingham8ec10ef2013-10-18 17:38:31 +00002067 num_frames_with_source,
2068 selected_frame_marker);
2069 if (num_frames == 1)
2070 strm.IndentLess();
Jim Ingham5c4df7a2011-07-26 02:39:59 +00002071 strm.IndentLess();
Greg Clayton7260f622011-04-18 08:33:37 +00002072 }
2073 return num_frames_shown;
2074}
2075
Jason Molenda705b1802014-06-13 02:37:02 +00002076bool
2077Thread::GetDescription (Stream &strm, lldb::DescriptionLevel level, bool print_json)
2078{
2079 DumpUsingSettingsFormat (strm, 0);
2080 strm.Printf("\n");
2081
2082 StructuredData::ObjectSP thread_info = GetExtendedInfo();
2083
2084 if (thread_info && print_json)
2085 {
2086 thread_info->Dump (strm);
2087 strm.Printf("\n");
2088 return true;
2089 }
2090
2091 if (thread_info)
2092 {
2093 StructuredData::ObjectSP activity = thread_info->GetObjectForDotSeparatedPath("activity");
2094 StructuredData::ObjectSP breadcrumb = thread_info->GetObjectForDotSeparatedPath("breadcrumb");
2095 StructuredData::ObjectSP messages = thread_info->GetObjectForDotSeparatedPath("trace_messages");
2096
2097 bool printed_activity = false;
2098 if (activity && activity->GetType() == StructuredData::Type::eTypeDictionary)
2099 {
2100 StructuredData::Dictionary *activity_dict = activity->GetAsDictionary();
2101 StructuredData::ObjectSP id = activity_dict->GetValueForKey("id");
2102 StructuredData::ObjectSP name = activity_dict->GetValueForKey("name");
2103 if (name && name->GetType() == StructuredData::Type::eTypeString
2104 && id && id->GetType() == StructuredData::Type::eTypeInteger)
2105 {
2106 strm.Printf(" Activity '%s', 0x%" PRIx64 "\n", name->GetAsString()->GetValue().c_str(), id->GetAsInteger()->GetValue());
2107 }
2108 printed_activity = true;
2109 }
2110 bool printed_breadcrumb = false;
2111 if (breadcrumb && breadcrumb->GetType() == StructuredData::Type::eTypeDictionary)
2112 {
2113 if (printed_activity)
2114 strm.Printf ("\n");
2115 StructuredData::Dictionary *breadcrumb_dict = breadcrumb->GetAsDictionary();
2116 StructuredData::ObjectSP breadcrumb_text = breadcrumb_dict->GetValueForKey ("name");
2117 if (breadcrumb_text && breadcrumb_text->GetType() == StructuredData::Type::eTypeString)
2118 {
2119 strm.Printf (" Current Breadcrumb: %s\n", breadcrumb_text->GetAsString()->GetValue().c_str());
2120 }
2121 printed_breadcrumb = true;
2122 }
2123 if (messages && messages->GetType() == StructuredData::Type::eTypeArray)
2124 {
2125 if (printed_breadcrumb)
2126 strm.Printf("\n");
2127 StructuredData::Array *messages_array = messages->GetAsArray();
2128 const size_t msg_count = messages_array->GetSize();
2129 if (msg_count > 0)
2130 {
2131 strm.Printf (" %zu trace messages:\n", msg_count);
2132 for (size_t i = 0; i < msg_count; i++)
2133 {
2134 StructuredData::ObjectSP message = messages_array->GetItemAtIndex(i);
2135 if (message && message->GetType() == StructuredData::Type::eTypeDictionary)
2136 {
2137 StructuredData::Dictionary *message_dict = message->GetAsDictionary();
2138 StructuredData::ObjectSP message_text = message_dict->GetValueForKey ("message");
2139 if (message_text && message_text->GetType() == StructuredData::Type::eTypeString)
2140 {
2141 strm.Printf (" %s\n", message_text->GetAsString()->GetValue().c_str());
2142 }
2143 }
2144 }
2145 }
2146 }
2147 }
2148
2149 return true;
2150}
2151
Greg Clayton7260f622011-04-18 08:33:37 +00002152size_t
2153Thread::GetStackFrameStatus (Stream& strm,
2154 uint32_t first_frame,
2155 uint32_t num_frames,
2156 bool show_frame_info,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002157 uint32_t num_frames_with_source)
Greg Clayton7260f622011-04-18 08:33:37 +00002158{
Greg Clayton39d0ab32012-03-29 01:41:38 +00002159 return GetStackFrameList()->GetStatus (strm,
2160 first_frame,
2161 num_frames,
2162 show_frame_info,
Greg Clayton53eb7ad2012-07-11 20:33:48 +00002163 num_frames_with_source);
Greg Clayton7260f622011-04-18 08:33:37 +00002164}
2165
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002166Unwind *
2167Thread::GetUnwinder ()
2168{
2169 if (m_unwinder_ap.get() == NULL)
2170 {
Greg Clayton1ac04c32012-02-21 00:09:25 +00002171 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002172 const llvm::Triple::ArchType machine = target_arch.GetMachine();
2173 switch (machine)
2174 {
2175 case llvm::Triple::x86_64:
2176 case llvm::Triple::x86:
2177 case llvm::Triple::arm:
Jason Molendaa3329782014-03-29 18:54:20 +00002178 case llvm::Triple::arm64:
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002179 case llvm::Triple::thumb:
Ed Masteb73f8442013-10-10 00:59:47 +00002180 case llvm::Triple::mips64:
Deepak Panickal6d3df422014-02-19 11:16:46 +00002181 case llvm::Triple::hexagon:
Greg Clayton56d9a1b2011-08-22 02:49:39 +00002182 m_unwinder_ap.reset (new UnwindLLDB (*this));
2183 break;
2184
2185 default:
2186 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
2187 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
2188 break;
2189 }
2190 }
2191 return m_unwinder_ap.get();
2192}
2193
2194
Greg Claytonfa559e52012-05-18 02:38:05 +00002195void
2196Thread::Flush ()
2197{
2198 ClearStackFrames ();
2199 m_reg_context_sp.reset();
2200}
Jim Ingham5d88a062012-10-16 00:09:33 +00002201
Filipe Cabecinhasb3d5d712012-11-20 00:11:13 +00002202bool
Jim Ingham5d88a062012-10-16 00:09:33 +00002203Thread::IsStillAtLastBreakpointHit ()
2204{
2205 // If we are currently stopped at a breakpoint, always return that stopinfo and don't reset it.
2206 // This allows threads to maintain their breakpoint stopinfo, such as when thread-stepping in
2207 // multithreaded programs.
Greg Clayton6e0ff1a2013-05-09 01:55:29 +00002208 if (m_stop_info_sp) {
2209 StopReason stop_reason = m_stop_info_sp->GetStopReason();
Jim Ingham5d88a062012-10-16 00:09:33 +00002210 if (stop_reason == lldb::eStopReasonBreakpoint) {
Greg Clayton6e0ff1a2013-05-09 01:55:29 +00002211 uint64_t value = m_stop_info_sp->GetValue();
Greg Clayton1afa68e2013-04-02 20:32:37 +00002212 lldb::RegisterContextSP reg_ctx_sp (GetRegisterContext());
2213 if (reg_ctx_sp)
2214 {
2215 lldb::addr_t pc = reg_ctx_sp->GetPC();
2216 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +00002217 if (bp_site_sp &&
2218 static_cast<break_id_t>(value) == bp_site_sp->GetID())
Greg Clayton1afa68e2013-04-02 20:32:37 +00002219 return true;
2220 }
Jim Ingham5d88a062012-10-16 00:09:33 +00002221 }
2222 }
2223 return false;
2224}
Greg Clayton44d93782014-01-27 23:43:24 +00002225
2226
2227Error
2228Thread::StepIn (bool source_step,
Jim Ingham4b4b2472014-03-13 02:47:14 +00002229 LazyBool step_in_avoids_code_without_debug_info,
2230 LazyBool step_out_avoids_code_without_debug_info)
2231
Greg Clayton44d93782014-01-27 23:43:24 +00002232{
2233 Error error;
2234 Process *process = GetProcess().get();
2235 if (StateIsStoppedState (process->GetState(), true))
2236 {
2237 StackFrameSP frame_sp = GetStackFrameAtIndex (0);
2238 ThreadPlanSP new_plan_sp;
2239 const lldb::RunMode run_mode = eOnlyThisThread;
2240 const bool abort_other_plans = false;
2241
2242 if (source_step && frame_sp && frame_sp->HasDebugInformation ())
2243 {
2244 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
2245 new_plan_sp = QueueThreadPlanForStepInRange (abort_other_plans,
2246 sc.line_entry.range,
2247 sc,
2248 NULL,
2249 run_mode,
Jim Ingham4b4b2472014-03-13 02:47:14 +00002250 step_in_avoids_code_without_debug_info,
2251 step_out_avoids_code_without_debug_info);
Greg Clayton44d93782014-01-27 23:43:24 +00002252 }
2253 else
2254 {
2255 new_plan_sp = QueueThreadPlanForStepSingleInstruction (false,
2256 abort_other_plans,
2257 run_mode);
2258 }
2259
2260 new_plan_sp->SetIsMasterPlan(true);
2261 new_plan_sp->SetOkayToDiscard(false);
2262
2263 // Why do we need to set the current thread by ID here???
2264 process->GetThreadList().SetSelectedThreadByID (GetID());
2265 error = process->Resume();
2266 }
2267 else
2268 {
2269 error.SetErrorString("process not stopped");
2270 }
2271 return error;
2272}
2273
2274Error
Jim Ingham4b4b2472014-03-13 02:47:14 +00002275Thread::StepOver (bool source_step,
2276 LazyBool step_out_avoids_code_without_debug_info)
Greg Clayton44d93782014-01-27 23:43:24 +00002277{
2278 Error error;
2279 Process *process = GetProcess().get();
2280 if (StateIsStoppedState (process->GetState(), true))
2281 {
2282 StackFrameSP frame_sp = GetStackFrameAtIndex (0);
2283 ThreadPlanSP new_plan_sp;
2284
2285 const lldb::RunMode run_mode = eOnlyThisThread;
2286 const bool abort_other_plans = false;
2287
2288 if (source_step && frame_sp && frame_sp->HasDebugInformation ())
2289 {
2290 SymbolContext sc(frame_sp->GetSymbolContext(eSymbolContextEverything));
2291 new_plan_sp = QueueThreadPlanForStepOverRange (abort_other_plans,
2292 sc.line_entry.range,
2293 sc,
Jim Ingham4b4b2472014-03-13 02:47:14 +00002294 run_mode,
2295 step_out_avoids_code_without_debug_info);
Greg Clayton44d93782014-01-27 23:43:24 +00002296 }
2297 else
2298 {
2299 new_plan_sp = QueueThreadPlanForStepSingleInstruction (true,
2300 abort_other_plans,
2301 run_mode);
2302 }
2303
2304 new_plan_sp->SetIsMasterPlan(true);
2305 new_plan_sp->SetOkayToDiscard(false);
2306
2307 // Why do we need to set the current thread by ID here???
2308 process->GetThreadList().SetSelectedThreadByID (GetID());
2309 error = process->Resume();
2310 }
2311 else
2312 {
2313 error.SetErrorString("process not stopped");
2314 }
2315 return error;
2316}
2317
2318Error
2319Thread::StepOut ()
2320{
2321 Error error;
2322 Process *process = GetProcess().get();
2323 if (StateIsStoppedState (process->GetState(), true))
2324 {
2325 const bool first_instruction = false;
2326 const bool stop_other_threads = false;
2327 const bool abort_other_plans = false;
2328
2329 ThreadPlanSP new_plan_sp(QueueThreadPlanForStepOut (abort_other_plans,
2330 NULL,
2331 first_instruction,
2332 stop_other_threads,
2333 eVoteYes,
2334 eVoteNoOpinion,
2335 0));
2336
2337 new_plan_sp->SetIsMasterPlan(true);
2338 new_plan_sp->SetOkayToDiscard(false);
2339
2340 // Why do we need to set the current thread by ID here???
2341 process->GetThreadList().SetSelectedThreadByID (GetID());
2342 error = process->Resume();
2343 }
2344 else
2345 {
2346 error.SetErrorString("process not stopped");
2347 }
2348 return error;
Jim Ingham4b4b2472014-03-13 02:47:14 +00002349}