blob: fe5c4295443e062a64df8110bca0deb5834c6017 [file] [log] [blame]
Chris Lattner24943d22010-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
10#include "lldb/lldb-private-log.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000011#include "lldb/Breakpoint/BreakpointLocation.h"
Greg Claytona830adb2010-10-04 01:05:56 +000012#include "lldb/Core/Debugger.h"
Chris Lattner24943d22010-06-08 16:52:24 +000013#include "lldb/Core/Log.h"
14#include "lldb/Core/Stream.h"
15#include "lldb/Core/StreamString.h"
Jim Ingham20594b12010-09-08 03:14:33 +000016#include "lldb/Core/RegularExpression.h"
Greg Claytonabe0fed2011-04-18 08:33:37 +000017#include "lldb/Host/Host.h"
Chris Lattner24943d22010-06-08 16:52:24 +000018#include "lldb/Target/DynamicLoader.h"
19#include "lldb/Target/ExecutionContext.h"
Jim Inghamb66cd072010-09-28 01:25:32 +000020#include "lldb/Target/ObjCLanguageRuntime.h"
Chris Lattner24943d22010-06-08 16:52:24 +000021#include "lldb/Target/Process.h"
22#include "lldb/Target/RegisterContext.h"
Greg Clayton643ee732010-08-04 01:40:35 +000023#include "lldb/Target/StopInfo.h"
Greg Clayton7661a982010-07-23 16:45:51 +000024#include "lldb/Target/Target.h"
Chris Lattner24943d22010-06-08 16:52:24 +000025#include "lldb/Target/Thread.h"
26#include "lldb/Target/ThreadPlan.h"
27#include "lldb/Target/ThreadPlanCallFunction.h"
Chris Lattner24943d22010-06-08 16:52:24 +000028#include "lldb/Target/ThreadPlanBase.h"
29#include "lldb/Target/ThreadPlanStepInstruction.h"
30#include "lldb/Target/ThreadPlanStepOut.h"
31#include "lldb/Target/ThreadPlanStepOverBreakpoint.h"
32#include "lldb/Target/ThreadPlanStepThrough.h"
33#include "lldb/Target/ThreadPlanStepInRange.h"
34#include "lldb/Target/ThreadPlanStepOverRange.h"
35#include "lldb/Target/ThreadPlanRunToAddress.h"
36#include "lldb/Target/ThreadPlanStepUntil.h"
Jim Ingham3c7b5b92010-06-16 02:00:15 +000037#include "lldb/Target/ThreadSpec.h"
Jim Ingham71219082010-08-12 02:14:28 +000038#include "lldb/Target/Unwind.h"
Greg Clayton37f962e2011-08-22 02:49:39 +000039#include "Plugins/Process/Utility/UnwindLLDB.h"
40#include "UnwindMacOSXFrameBackchain.h"
41
Chris Lattner24943d22010-06-08 16:52:24 +000042
43using namespace lldb;
44using namespace lldb_private;
45
Greg Claytonf4124de2012-02-21 00:09:25 +000046Thread::Thread (const ProcessSP &process_sp, lldb::tid_t tid) :
Chris Lattner24943d22010-06-08 16:52:24 +000047 UserID (tid),
Greg Clayton334d33a2012-01-30 07:41:31 +000048 ThreadInstanceSettings (GetSettingsController()),
Greg Claytonf4124de2012-02-21 00:09:25 +000049 m_process_wp (process_sp),
Greg Clayton643ee732010-08-04 01:40:35 +000050 m_actual_stop_info_sp (),
Greg Claytonf4124de2012-02-21 00:09:25 +000051 m_index_id (process_sp->GetNextThreadIndexID ()),
Chris Lattner24943d22010-06-08 16:52:24 +000052 m_reg_context_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000053 m_state (eStateUnloaded),
Greg Clayton782b9cc2010-08-25 00:35:26 +000054 m_state_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner24943d22010-06-08 16:52:24 +000055 m_plan_stack (),
Chris Lattner24943d22010-06-08 16:52:24 +000056 m_completed_plan_stack(),
Greg Clayton2450cb12012-03-29 01:41:38 +000057 m_frame_mutex (Mutex::eMutexTypeRecursive),
Greg Claytonc51ffbf2011-08-12 21:40:01 +000058 m_curr_frames_sp (),
59 m_prev_frames_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000060 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
Jim Ingham71219082010-08-12 02:14:28 +000061 m_resume_state (eStateRunning),
Jim Ingham149d1f52012-01-31 23:09:20 +000062 m_temporary_resume_state (eStateRunning),
Jim Inghamcdea2362010-11-18 02:47:07 +000063 m_unwinder_ap (),
Jim Ingham15dcb7c2011-01-20 02:03:18 +000064 m_destroy_called (false),
65 m_thread_stop_reason_stop_id (0)
Jim Ingham71219082010-08-12 02:14:28 +000066
Chris Lattner24943d22010-06-08 16:52:24 +000067{
Greg Claytone005f2c2010-11-06 01:53:30 +000068 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000069 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +000070 log->Printf ("%p Thread::Thread(tid = 0x%4.4llx)", this, GetID());
Chris Lattner24943d22010-06-08 16:52:24 +000071
72 QueueFundamentalPlan(true);
Caroline Tice1ebef442010-09-27 00:30:10 +000073 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +000074}
75
76
77Thread::~Thread()
78{
Greg Claytone005f2c2010-11-06 01:53:30 +000079 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000080 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +000081 log->Printf ("%p Thread::~Thread(tid = 0x%4.4llx)", this, GetID());
Jim Inghamcdea2362010-11-18 02:47:07 +000082 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor.
83 assert (m_destroy_called);
84}
85
86void
87Thread::DestroyThread ()
88{
89 m_plan_stack.clear();
90 m_discarded_plan_stack.clear();
91 m_completed_plan_stack.clear();
92 m_destroy_called = true;
Chris Lattner24943d22010-06-08 16:52:24 +000093}
94
Jim Ingham6297a3a2010-10-20 00:39:53 +000095lldb::StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +000096Thread::GetStopInfo ()
Chris Lattner24943d22010-06-08 16:52:24 +000097{
Jim Ingham6297a3a2010-10-20 00:39:53 +000098 ThreadPlanSP plan_sp (GetCompletedPlan());
99 if (plan_sp)
Jim Ingham1586d972011-12-17 01:35:57 +0000100 return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000101 else
Jim Ingham24e0d612011-08-09 00:32:52 +0000102 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000103 ProcessSP process_sp (GetProcess());
104 if (process_sp
105 && m_actual_stop_info_sp
Jim Ingham24e0d612011-08-09 00:32:52 +0000106 && m_actual_stop_info_sp->IsValid()
Greg Claytonf4124de2012-02-21 00:09:25 +0000107 && m_thread_stop_reason_stop_id == process_sp->GetStopID())
Jim Ingham24e0d612011-08-09 00:32:52 +0000108 return m_actual_stop_info_sp;
109 else
110 return GetPrivateStopReason ();
111 }
Chris Lattner24943d22010-06-08 16:52:24 +0000112}
113
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000114void
115Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp)
116{
117 m_actual_stop_info_sp = stop_info_sp;
Jim Ingham24e0d612011-08-09 00:32:52 +0000118 if (m_actual_stop_info_sp)
119 m_actual_stop_info_sp->MakeStopInfoValid();
Greg Claytonf4124de2012-02-21 00:09:25 +0000120 ProcessSP process_sp (GetProcess());
121 if (process_sp)
122 m_thread_stop_reason_stop_id = process_sp->GetStopID();
123 else
124 m_thread_stop_reason_stop_id = UINT32_MAX;
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000125}
126
127void
128Thread::SetStopInfoToNothing()
129{
130 // Note, we can't just NULL out the private reason, or the native thread implementation will try to
131 // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number.
132 SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER));
133}
134
Chris Lattner24943d22010-06-08 16:52:24 +0000135bool
136Thread::ThreadStoppedForAReason (void)
137{
Greg Clayton643ee732010-08-04 01:40:35 +0000138 return GetPrivateStopReason () != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000139}
140
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000141bool
142Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state)
143{
144 if (!SaveFrameZeroState(saved_state.register_backup))
145 return false;
146
147 saved_state.stop_info_sp = GetStopInfo();
Greg Claytonf4124de2012-02-21 00:09:25 +0000148 ProcessSP process_sp (GetProcess());
149 if (process_sp)
150 saved_state.orig_stop_id = process_sp->GetStopID();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000151 return true;
152}
153
154bool
155Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
156{
157 RestoreSaveFrameZero(saved_state.register_backup);
Jim Ingham11a837d2011-01-25 02:47:23 +0000158 if (saved_state.stop_info_sp)
159 saved_state.stop_info_sp->MakeStopInfoValid();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000160 SetStopInfo(saved_state.stop_info_sp);
161 return true;
162}
163
Chris Lattner24943d22010-06-08 16:52:24 +0000164StateType
165Thread::GetState() const
166{
167 // If any other threads access this we will need a mutex for it
168 Mutex::Locker locker(m_state_mutex);
169 return m_state;
170}
171
172void
173Thread::SetState(StateType state)
174{
175 Mutex::Locker locker(m_state_mutex);
176 m_state = state;
177}
178
179void
180Thread::WillStop()
181{
182 ThreadPlan *current_plan = GetCurrentPlan();
183
184 // FIXME: I may decide to disallow threads with no plans. In which
185 // case this should go to an assert.
186
187 if (!current_plan)
188 return;
189
190 current_plan->WillStop();
191}
192
193void
194Thread::SetupForResume ()
195{
196 if (GetResumeState() != eStateSuspended)
197 {
198
199 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
200 // telling the current plan it will resume, since we might change what the current
201 // plan is.
202
203 lldb::addr_t pc = GetRegisterContext()->GetPC();
Greg Claytonf4124de2012-02-21 00:09:25 +0000204 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
Chris Lattner24943d22010-06-08 16:52:24 +0000205 if (bp_site_sp && bp_site_sp->IsEnabled())
206 {
207 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
208 // special to step over a breakpoint.
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000209
210 ThreadPlan *cur_plan = GetCurrentPlan();
Chris Lattner24943d22010-06-08 16:52:24 +0000211
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000212 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
213 {
214 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
215 if (step_bp_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000216 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000217 ThreadPlanSP step_bp_plan_sp;
218 step_bp_plan->SetPrivate (true);
219
Chris Lattner24943d22010-06-08 16:52:24 +0000220 if (GetCurrentPlan()->RunState() != eStateStepping)
221 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000222 step_bp_plan->SetAutoContinue(true);
Chris Lattner24943d22010-06-08 16:52:24 +0000223 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000224 step_bp_plan_sp.reset (step_bp_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000225 QueueThreadPlan (step_bp_plan_sp, false);
226 }
227 }
228 }
229 }
230}
231
232bool
233Thread::WillResume (StateType resume_state)
234{
235 // At this point clear the completed plan stack.
236 m_completed_plan_stack.clear();
237 m_discarded_plan_stack.clear();
238
Jim Ingham149d1f52012-01-31 23:09:20 +0000239 SetTemporaryResumeState(resume_state);
240
241 // This is a little dubious, but we are trying to limit how often we actually fetch stop info from
242 // the target, 'cause that slows down single stepping. So assume that if we got to the point where
243 // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know
244 // about the fact that we are resuming...
Greg Claytonf4124de2012-02-21 00:09:25 +0000245 const uint32_t process_stop_id = GetProcess()->GetStopID();
Jim Ingham149d1f52012-01-31 23:09:20 +0000246 if (m_thread_stop_reason_stop_id == process_stop_id &&
247 (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid()))
248 {
249 StopInfo *stop_info = GetPrivateStopReason().get();
250 if (stop_info)
251 stop_info->WillResume (resume_state);
252 }
Chris Lattner24943d22010-06-08 16:52:24 +0000253
254 // Tell all the plans that we are about to resume in case they need to clear any state.
255 // We distinguish between the plan on the top of the stack and the lower
256 // plans in case a plan needs to do any special business before it runs.
257
258 ThreadPlan *plan_ptr = GetCurrentPlan();
259 plan_ptr->WillResume(resume_state, true);
260
261 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
262 {
263 plan_ptr->WillResume (resume_state, false);
264 }
Greg Clayton643ee732010-08-04 01:40:35 +0000265
Greg Clayton643ee732010-08-04 01:40:35 +0000266 m_actual_stop_info_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000267 return true;
268}
269
270void
271Thread::DidResume ()
272{
273 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
274}
275
276bool
277Thread::ShouldStop (Event* event_ptr)
278{
279 ThreadPlan *current_plan = GetCurrentPlan();
280 bool should_stop = true;
281
Greg Claytone005f2c2010-11-06 01:53:30 +0000282 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham149d1f52012-01-31 23:09:20 +0000283
284 if (GetResumeState () == eStateSuspended)
285 {
286 if (log)
287 log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)",
288 __FUNCTION__,
289 GetID ());
290// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)",
291// __FUNCTION__,
292// GetID (),
293// GetRegisterContext()->GetPC());
294 return false;
295 }
296
297 if (GetTemporaryResumeState () == eStateSuspended)
298 {
299 if (log)
300 log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)",
301 __FUNCTION__,
302 GetID ());
303// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)",
304// __FUNCTION__,
305// GetID (),
306// GetRegisterContext()->GetPC());
307 return false;
308 }
309
310 if (ThreadStoppedForAReason() == false)
311 {
312 if (log)
313 log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)",
314 __FUNCTION__,
315 GetID (),
316 GetRegisterContext()->GetPC());
317 return false;
318 }
319
Chris Lattner24943d22010-06-08 16:52:24 +0000320 if (log)
321 {
Jim Ingham149d1f52012-01-31 23:09:20 +0000322 log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx",
323 __FUNCTION__,
324 GetID (),
325 GetRegisterContext()->GetPC());
Jim Inghame8f4e112011-10-15 00:23:43 +0000326 log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
Chris Lattner24943d22010-06-08 16:52:24 +0000327 StreamString s;
Jim Inghame8f4e112011-10-15 00:23:43 +0000328 s.IndentMore();
Chris Lattner24943d22010-06-08 16:52:24 +0000329 DumpThreadPlans(&s);
Jim Inghame8f4e112011-10-15 00:23:43 +0000330 log->Printf ("Plan stack initial state:\n%s", s.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +0000331 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000332
333 // The top most plan always gets to do the trace log...
334 current_plan->DoTraceLog ();
Chris Lattner24943d22010-06-08 16:52:24 +0000335
Jim Inghamad382c52011-12-03 01:52:59 +0000336 // If the base plan doesn't understand why we stopped, then we have to find a plan that does.
337 // If that plan is still working, then we don't need to do any more work. If the plan that explains
338 // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide
339 // whether they still need to do more work.
340
341 bool done_processing_current_plan = false;
342
343 if (!current_plan->PlanExplainsStop())
344 {
345 if (current_plan->TracerExplainsStop())
346 {
347 done_processing_current_plan = true;
348 should_stop = false;
349 }
350 else
351 {
Jim Ingham2bcbaf62012-04-09 22:37:39 +0000352 // If the current plan doesn't explain the stop, then find one that
Jim Inghamad382c52011-12-03 01:52:59 +0000353 // does and let it handle the situation.
354 ThreadPlan *plan_ptr = current_plan;
355 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
356 {
357 if (plan_ptr->PlanExplainsStop())
358 {
359 should_stop = plan_ptr->ShouldStop (event_ptr);
360
361 // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it
362 // and all the plans below it off the stack.
363
364 if (plan_ptr->MischiefManaged())
365 {
366 // We're going to pop the plans up to AND INCLUDING the plan that explains the stop.
367 plan_ptr = GetPreviousPlan(plan_ptr);
368
369 do
370 {
371 if (should_stop)
372 current_plan->WillStop();
373 PopPlan();
374 }
375 while ((current_plan = GetCurrentPlan()) != plan_ptr);
376 done_processing_current_plan = false;
377 }
378 else
379 done_processing_current_plan = true;
380
381 break;
382 }
383
384 }
385 }
386 }
387
388 if (!done_processing_current_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000389 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000390 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
Jim Inghamf9f40c22011-02-08 05:20:59 +0000391
Jim Inghame8f4e112011-10-15 00:23:43 +0000392 if (log)
393 log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop);
394
Jim Inghamf9f40c22011-02-08 05:20:59 +0000395 // We're starting from the base plan, so just let it decide;
396 if (PlanIsBasePlan(current_plan))
Chris Lattner24943d22010-06-08 16:52:24 +0000397 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000398 should_stop = current_plan->ShouldStop (event_ptr);
399 if (log)
Greg Clayton628cead2011-05-19 03:54:16 +0000400 log->Printf("Base plan says should stop: %i.", should_stop);
Jim Inghamf9f40c22011-02-08 05:20:59 +0000401 }
402 else
403 {
404 // Otherwise, don't let the base plan override what the other plans say to do, since
405 // presumably if there were other plans they would know what to do...
406 while (1)
Chris Lattner24943d22010-06-08 16:52:24 +0000407 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000408 if (PlanIsBasePlan(current_plan))
Chris Lattner24943d22010-06-08 16:52:24 +0000409 break;
Jim Inghamf9f40c22011-02-08 05:20:59 +0000410
411 should_stop = current_plan->ShouldStop(event_ptr);
412 if (log)
413 log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop);
414 if (current_plan->MischiefManaged())
415 {
416 if (should_stop)
417 current_plan->WillStop();
418
419 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
420 // Otherwise, see if the plan's parent wants to stop.
421
422 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
423 {
424 PopPlan();
425 break;
426 }
427 else
428 {
429
430 PopPlan();
431
432 current_plan = GetCurrentPlan();
433 if (current_plan == NULL)
434 {
435 break;
436 }
437 }
438
Chris Lattner24943d22010-06-08 16:52:24 +0000439 }
440 else
441 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000442 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000443 }
Chris Lattner24943d22010-06-08 16:52:24 +0000444 }
445 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000446 if (over_ride_stop)
447 should_stop = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000448 }
Chris Lattner24943d22010-06-08 16:52:24 +0000449
Jim Inghame8f4e112011-10-15 00:23:43 +0000450 if (log)
451 {
452 StreamString s;
453 s.IndentMore();
454 DumpThreadPlans(&s);
455 log->Printf ("Plan stack final state:\n%s", s.GetData());
456 log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop);
457 }
Chris Lattner24943d22010-06-08 16:52:24 +0000458 return should_stop;
459}
460
461Vote
462Thread::ShouldReportStop (Event* event_ptr)
463{
464 StateType thread_state = GetResumeState ();
Jim Ingham149d1f52012-01-31 23:09:20 +0000465 StateType temp_thread_state = GetTemporaryResumeState();
466
Greg Claytone005f2c2010-11-06 01:53:30 +0000467 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton5205f0b2010-09-03 17:10:42 +0000468
469 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
470 {
471 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000472 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000473 return eVoteNoOpinion;
Greg Clayton5205f0b2010-09-03 17:10:42 +0000474 }
Chris Lattner24943d22010-06-08 16:52:24 +0000475
Jim Ingham149d1f52012-01-31 23:09:20 +0000476 if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid)
477 {
478 if (log)
479 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion);
480 return eVoteNoOpinion;
481 }
482
483 if (!ThreadStoppedForAReason())
484 {
485 if (log)
486 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion);
487 return eVoteNoOpinion;
488 }
489
Chris Lattner24943d22010-06-08 16:52:24 +0000490 if (m_completed_plan_stack.size() > 0)
491 {
492 // Don't use GetCompletedPlan here, since that suppresses private plans.
Greg Clayton5205f0b2010-09-03 17:10:42 +0000493 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000494 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for complete stack's back plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000495 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
496 }
497 else
Greg Clayton5205f0b2010-09-03 17:10:42 +0000498 {
499 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000500 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for current plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000501 return GetCurrentPlan()->ShouldReportStop (event_ptr);
Greg Clayton5205f0b2010-09-03 17:10:42 +0000502 }
Chris Lattner24943d22010-06-08 16:52:24 +0000503}
504
505Vote
506Thread::ShouldReportRun (Event* event_ptr)
507{
508 StateType thread_state = GetResumeState ();
Jim Inghamac959662011-01-24 06:34:17 +0000509
Chris Lattner24943d22010-06-08 16:52:24 +0000510 if (thread_state == eStateSuspended
511 || thread_state == eStateInvalid)
Jim Inghamac959662011-01-24 06:34:17 +0000512 {
Chris Lattner24943d22010-06-08 16:52:24 +0000513 return eVoteNoOpinion;
Jim Inghamac959662011-01-24 06:34:17 +0000514 }
515
516 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000517 if (m_completed_plan_stack.size() > 0)
518 {
519 // Don't use GetCompletedPlan here, since that suppresses private plans.
Jim Inghamac959662011-01-24 06:34:17 +0000520 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000521 log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.",
Jim Inghamac959662011-01-24 06:34:17 +0000522 GetIndexID(),
523 GetID(),
524 m_completed_plan_stack.back()->GetName());
525
Chris Lattner24943d22010-06-08 16:52:24 +0000526 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
527 }
528 else
Jim Inghamac959662011-01-24 06:34:17 +0000529 {
530 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000531 log->Printf ("Current Plan for thread %d (0x%4.4llx): %s being asked whether we should report run.",
Jim Inghamac959662011-01-24 06:34:17 +0000532 GetIndexID(),
533 GetID(),
534 GetCurrentPlan()->GetName());
535
Chris Lattner24943d22010-06-08 16:52:24 +0000536 return GetCurrentPlan()->ShouldReportRun (event_ptr);
Jim Inghamac959662011-01-24 06:34:17 +0000537 }
Chris Lattner24943d22010-06-08 16:52:24 +0000538}
539
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000540bool
541Thread::MatchesSpec (const ThreadSpec *spec)
542{
543 if (spec == NULL)
544 return true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000545
Jim Inghama2664912012-03-07 22:03:04 +0000546 return spec->ThreadPassesBasicTests(*this);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000547}
548
Chris Lattner24943d22010-06-08 16:52:24 +0000549void
550Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
551{
552 if (thread_plan_sp)
553 {
Jim Ingham745ac7a2010-11-11 19:26:09 +0000554 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
555 if (!thread_plan_sp->GetThreadPlanTracer())
556 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000557 m_plan_stack.push_back (thread_plan_sp);
Jim Ingham745ac7a2010-11-11 19:26:09 +0000558
Chris Lattner24943d22010-06-08 16:52:24 +0000559 thread_plan_sp->DidPush();
560
Greg Claytone005f2c2010-11-06 01:53:30 +0000561 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000562 if (log)
563 {
564 StreamString s;
565 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
Greg Clayton444e35b2011-10-19 18:09:39 +0000566 log->Printf("Pushing plan: \"%s\", tid = 0x%4.4llx.",
Chris Lattner24943d22010-06-08 16:52:24 +0000567 s.GetData(),
Jim Ingham6297a3a2010-10-20 00:39:53 +0000568 thread_plan_sp->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000569 }
570 }
571}
572
573void
574Thread::PopPlan ()
575{
Greg Claytone005f2c2010-11-06 01:53:30 +0000576 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000577
Jim Ingham6297a3a2010-10-20 00:39:53 +0000578 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000579 return;
580 else
581 {
582 ThreadPlanSP &plan = m_plan_stack.back();
583 if (log)
584 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000585 log->Printf("Popping plan: \"%s\", tid = 0x%4.4llx.", plan->GetName(), plan->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000586 }
587 m_completed_plan_stack.push_back (plan);
588 plan->WillPop();
589 m_plan_stack.pop_back();
590 }
591}
592
593void
594Thread::DiscardPlan ()
595{
596 if (m_plan_stack.size() > 1)
597 {
598 ThreadPlanSP &plan = m_plan_stack.back();
599 m_discarded_plan_stack.push_back (plan);
600 plan->WillPop();
601 m_plan_stack.pop_back();
602 }
603}
604
605ThreadPlan *
606Thread::GetCurrentPlan ()
607{
Jim Ingham6297a3a2010-10-20 00:39:53 +0000608 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000609 return NULL;
610 else
611 return m_plan_stack.back().get();
612}
613
614ThreadPlanSP
615Thread::GetCompletedPlan ()
616{
617 ThreadPlanSP empty_plan_sp;
618 if (!m_completed_plan_stack.empty())
619 {
620 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
621 {
622 ThreadPlanSP completed_plan_sp;
623 completed_plan_sp = m_completed_plan_stack[i];
624 if (!completed_plan_sp->GetPrivate ())
625 return completed_plan_sp;
626 }
627 }
628 return empty_plan_sp;
629}
630
Jim Ingham1586d972011-12-17 01:35:57 +0000631ValueObjectSP
632Thread::GetReturnValueObject ()
633{
634 if (!m_completed_plan_stack.empty())
635 {
636 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
637 {
638 ValueObjectSP return_valobj_sp;
639 return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject();
640 if (return_valobj_sp)
641 return return_valobj_sp;
642 }
643 }
644 return ValueObjectSP();
645}
646
Chris Lattner24943d22010-06-08 16:52:24 +0000647bool
648Thread::IsThreadPlanDone (ThreadPlan *plan)
649{
Chris Lattner24943d22010-06-08 16:52:24 +0000650 if (!m_completed_plan_stack.empty())
651 {
652 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
653 {
654 if (m_completed_plan_stack[i].get() == plan)
655 return true;
656 }
657 }
658 return false;
659}
660
661bool
662Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
663{
Chris Lattner24943d22010-06-08 16:52:24 +0000664 if (!m_discarded_plan_stack.empty())
665 {
666 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
667 {
668 if (m_discarded_plan_stack[i].get() == plan)
669 return true;
670 }
671 }
672 return false;
673}
674
675ThreadPlan *
676Thread::GetPreviousPlan (ThreadPlan *current_plan)
677{
678 if (current_plan == NULL)
679 return NULL;
680
681 int stack_size = m_completed_plan_stack.size();
682 for (int i = stack_size - 1; i > 0; i--)
683 {
684 if (current_plan == m_completed_plan_stack[i].get())
685 return m_completed_plan_stack[i-1].get();
686 }
687
688 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
689 {
Chris Lattner24943d22010-06-08 16:52:24 +0000690 if (m_plan_stack.size() > 0)
691 return m_plan_stack.back().get();
692 else
693 return NULL;
694 }
695
696 stack_size = m_plan_stack.size();
697 for (int i = stack_size - 1; i > 0; i--)
698 {
699 if (current_plan == m_plan_stack[i].get())
700 return m_plan_stack[i-1].get();
701 }
702 return NULL;
703}
704
705void
706Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
707{
708 if (abort_other_plans)
709 DiscardThreadPlans(true);
710
711 PushPlan (thread_plan_sp);
712}
713
Jim Ingham745ac7a2010-11-11 19:26:09 +0000714
715void
716Thread::EnableTracer (bool value, bool single_stepping)
717{
718 int stack_size = m_plan_stack.size();
719 for (int i = 0; i < stack_size; i++)
720 {
721 if (m_plan_stack[i]->GetThreadPlanTracer())
722 {
723 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
724 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
725 }
726 }
727}
728
729void
730Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
731{
732 int stack_size = m_plan_stack.size();
733 for (int i = 0; i < stack_size; i++)
734 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
735}
736
Chris Lattner24943d22010-06-08 16:52:24 +0000737void
Jim Inghamea9d4262010-11-05 19:25:48 +0000738Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
739{
Greg Claytone005f2c2010-11-06 01:53:30 +0000740 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamea9d4262010-11-05 19:25:48 +0000741 if (log)
742 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000743 log->Printf("Discarding thread plans for thread tid = 0x%4.4llx, up to %p", GetID(), up_to_plan_sp.get());
Jim Inghamea9d4262010-11-05 19:25:48 +0000744 }
745
746 int stack_size = m_plan_stack.size();
747
748 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
749 // stack, and if so discard up to and including it.
750
751 if (up_to_plan_sp.get() == NULL)
752 {
753 for (int i = stack_size - 1; i > 0; i--)
754 DiscardPlan();
755 }
756 else
757 {
758 bool found_it = false;
759 for (int i = stack_size - 1; i > 0; i--)
760 {
761 if (m_plan_stack[i] == up_to_plan_sp)
762 found_it = true;
763 }
764 if (found_it)
765 {
766 bool last_one = false;
767 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
768 {
769 if (GetCurrentPlan() == up_to_plan_sp.get())
770 last_one = true;
771 DiscardPlan();
772 }
773 }
774 }
775 return;
776}
777
778void
Chris Lattner24943d22010-06-08 16:52:24 +0000779Thread::DiscardThreadPlans(bool force)
780{
Greg Claytone005f2c2010-11-06 01:53:30 +0000781 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000782 if (log)
783 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000784 log->Printf("Discarding thread plans for thread (tid = 0x%4.4llx, force %d)", GetID(), force);
Chris Lattner24943d22010-06-08 16:52:24 +0000785 }
786
787 if (force)
788 {
789 int stack_size = m_plan_stack.size();
790 for (int i = stack_size - 1; i > 0; i--)
791 {
792 DiscardPlan();
793 }
794 return;
795 }
796
797 while (1)
798 {
799
800 int master_plan_idx;
801 bool discard;
802
803 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
804 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
805 {
806 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
807 {
808 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
809 break;
810 }
811 }
812
813 if (discard)
814 {
815 // First pop all the dependent plans:
816 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
817 {
818
819 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
820 // for the plan leaves it in a state that it is safe to pop the plan
821 // with no more notice?
822 DiscardPlan();
823 }
824
825 // Now discard the master plan itself.
826 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
827 // discard it's dependent plans, but not it...
828 if (master_plan_idx > 0)
829 {
830 DiscardPlan();
831 }
832 }
833 else
834 {
835 // If the master plan doesn't want to get discarded, then we're done.
836 break;
837 }
838
839 }
Chris Lattner24943d22010-06-08 16:52:24 +0000840}
841
Jim Ingham2bcbaf62012-04-09 22:37:39 +0000842bool
843Thread::PlanIsBasePlan (ThreadPlan *plan_ptr)
844{
845 if (plan_ptr->IsBasePlan())
846 return true;
847 else if (m_plan_stack.size() == 0)
848 return false;
849 else
850 return m_plan_stack[0].get() == plan_ptr;
851}
852
Chris Lattner24943d22010-06-08 16:52:24 +0000853ThreadPlan *
854Thread::QueueFundamentalPlan (bool abort_other_plans)
855{
856 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
857 QueueThreadPlan (thread_plan_sp, abort_other_plans);
858 return thread_plan_sp.get();
859}
860
861ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000862Thread::QueueThreadPlanForStepSingleInstruction
863(
864 bool step_over,
865 bool abort_other_plans,
866 bool stop_other_threads
867)
Chris Lattner24943d22010-06-08 16:52:24 +0000868{
869 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
870 QueueThreadPlan (thread_plan_sp, abort_other_plans);
871 return thread_plan_sp.get();
872}
873
874ThreadPlan *
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000875Thread::QueueThreadPlanForStepRange
876(
877 bool abort_other_plans,
878 StepType type,
879 const AddressRange &range,
880 const SymbolContext &addr_context,
881 lldb::RunMode stop_other_threads,
882 bool avoid_code_without_debug_info
883)
Chris Lattner24943d22010-06-08 16:52:24 +0000884{
885 ThreadPlanSP thread_plan_sp;
886 if (type == eStepTypeInto)
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000887 {
888 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
889 if (avoid_code_without_debug_info)
890 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
891 else
892 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
893 thread_plan_sp.reset (plan);
894 }
Chris Lattner24943d22010-06-08 16:52:24 +0000895 else
896 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
897
898 QueueThreadPlan (thread_plan_sp, abort_other_plans);
899 return thread_plan_sp.get();
900}
901
902
903ThreadPlan *
904Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
905{
906 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
907 QueueThreadPlan (thread_plan_sp, abort_other_plans);
908 return thread_plan_sp.get();
909}
910
911ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000912Thread::QueueThreadPlanForStepOut
913(
914 bool abort_other_plans,
915 SymbolContext *addr_context,
916 bool first_insn,
917 bool stop_other_threads,
918 Vote stop_vote,
919 Vote run_vote,
920 uint32_t frame_idx
921)
Chris Lattner24943d22010-06-08 16:52:24 +0000922{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000923 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this,
924 addr_context,
925 first_insn,
926 stop_other_threads,
927 stop_vote,
928 run_vote,
929 frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000930 QueueThreadPlan (thread_plan_sp, abort_other_plans);
931 return thread_plan_sp.get();
932}
933
934ThreadPlan *
935Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads)
936{
Jim Inghamad382c52011-12-03 01:52:59 +0000937 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, stop_other_threads));
938 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL))
939 return NULL;
940
Chris Lattner24943d22010-06-08 16:52:24 +0000941 QueueThreadPlan (thread_plan_sp, abort_other_plans);
942 return thread_plan_sp.get();
943}
944
945ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000946Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
947 Address& function,
948 lldb::addr_t arg,
949 bool stop_other_threads,
950 bool discard_on_error)
951{
Jim Ingham016ef882011-12-22 19:12:40 +0000952 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, ClangASTType(), arg, stop_other_threads, discard_on_error));
Chris Lattner24943d22010-06-08 16:52:24 +0000953 QueueThreadPlan (thread_plan_sp, abort_other_plans);
954 return thread_plan_sp.get();
955}
956
957ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000958Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
959 Address &target_addr,
960 bool stop_other_threads)
961{
962 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
963 QueueThreadPlan (thread_plan_sp, abort_other_plans);
964 return thread_plan_sp.get();
965}
966
967ThreadPlan *
968Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000969 lldb::addr_t *address_list,
970 size_t num_addresses,
971 bool stop_other_threads,
972 uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000973{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000974 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000975 QueueThreadPlan (thread_plan_sp, abort_other_plans);
976 return thread_plan_sp.get();
977
978}
979
980uint32_t
981Thread::GetIndexID () const
982{
983 return m_index_id;
984}
985
986void
987Thread::DumpThreadPlans (lldb_private::Stream *s) const
988{
989 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000990 int i;
Jim Inghame8f4e112011-10-15 00:23:43 +0000991 s->Indent();
Greg Clayton444e35b2011-10-19 18:09:39 +0000992 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4llx, stack_size = %d\n", GetIndexID(), GetID(), stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000993 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000994 {
Chris Lattner24943d22010-06-08 16:52:24 +0000995 s->IndentMore();
Jim Inghame8f4e112011-10-15 00:23:43 +0000996 s->Indent();
997 s->Printf ("Element %d: ", i);
Chris Lattner24943d22010-06-08 16:52:24 +0000998 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
Chris Lattner24943d22010-06-08 16:52:24 +0000999 s->EOL();
Jim Inghame8f4e112011-10-15 00:23:43 +00001000 s->IndentLess();
Chris Lattner24943d22010-06-08 16:52:24 +00001001 }
1002
Chris Lattner24943d22010-06-08 16:52:24 +00001003 stack_size = m_completed_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +00001004 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001005 {
Jim Inghame8f4e112011-10-15 00:23:43 +00001006 s->Indent();
1007 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
1008 for (i = stack_size - 1; i >= 0; i--)
1009 {
1010 s->IndentMore();
1011 s->Indent();
1012 s->Printf ("Element %d: ", i);
1013 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1014 s->EOL();
1015 s->IndentLess();
1016 }
Chris Lattner24943d22010-06-08 16:52:24 +00001017 }
1018
1019 stack_size = m_discarded_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +00001020 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001021 {
Jim Inghame8f4e112011-10-15 00:23:43 +00001022 s->Indent();
1023 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
1024 for (i = stack_size - 1; i >= 0; i--)
1025 {
1026 s->IndentMore();
1027 s->Indent();
1028 s->Printf ("Element %d: ", i);
1029 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1030 s->EOL();
1031 s->IndentLess();
1032 }
Chris Lattner24943d22010-06-08 16:52:24 +00001033 }
1034
1035}
1036
Greg Clayton289afcb2012-02-18 05:35:26 +00001037TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001038Thread::CalculateTarget ()
1039{
Greg Claytonf4124de2012-02-21 00:09:25 +00001040 TargetSP target_sp;
1041 ProcessSP process_sp(GetProcess());
1042 if (process_sp)
1043 target_sp = process_sp->CalculateTarget();
1044 return target_sp;
1045
Chris Lattner24943d22010-06-08 16:52:24 +00001046}
1047
Greg Clayton289afcb2012-02-18 05:35:26 +00001048ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001049Thread::CalculateProcess ()
1050{
Greg Claytonf4124de2012-02-21 00:09:25 +00001051 return GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +00001052}
1053
Greg Clayton289afcb2012-02-18 05:35:26 +00001054ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001055Thread::CalculateThread ()
1056{
Greg Clayton289afcb2012-02-18 05:35:26 +00001057 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001058}
1059
Greg Clayton289afcb2012-02-18 05:35:26 +00001060StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001061Thread::CalculateStackFrame ()
1062{
Greg Clayton289afcb2012-02-18 05:35:26 +00001063 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001064}
1065
1066void
Greg Claytona830adb2010-10-04 01:05:56 +00001067Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001068{
Greg Claytonf4124de2012-02-21 00:09:25 +00001069 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001070}
1071
Greg Clayton782b9cc2010-08-25 00:35:26 +00001072
Greg Clayton2450cb12012-03-29 01:41:38 +00001073StackFrameListSP
Greg Clayton782b9cc2010-08-25 00:35:26 +00001074Thread::GetStackFrameList ()
1075{
Greg Clayton2450cb12012-03-29 01:41:38 +00001076 StackFrameListSP frame_list_sp;
1077 Mutex::Locker locker(m_frame_mutex);
1078 if (m_curr_frames_sp)
1079 {
1080 frame_list_sp = m_curr_frames_sp;
1081 }
1082 else
1083 {
1084 frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true));
1085 m_curr_frames_sp = frame_list_sp;
1086 }
1087 return frame_list_sp;
Greg Clayton782b9cc2010-08-25 00:35:26 +00001088}
1089
Greg Clayton782b9cc2010-08-25 00:35:26 +00001090void
1091Thread::ClearStackFrames ()
1092{
Greg Clayton2450cb12012-03-29 01:41:38 +00001093 Mutex::Locker locker(m_frame_mutex);
1094
Jim Inghambf97d742012-02-29 03:40:22 +00001095 // Only store away the old "reference" StackFrameList if we got all its frames:
1096 // FIXME: At some point we can try to splice in the frames we have fetched into
1097 // the new frame as we make it, but let's not try that now.
1098 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
Greg Claytonc51ffbf2011-08-12 21:40:01 +00001099 m_prev_frames_sp.swap (m_curr_frames_sp);
1100 m_curr_frames_sp.reset();
Jim Ingham71219082010-08-12 02:14:28 +00001101}
1102
1103lldb::StackFrameSP
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001104Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1105{
Greg Clayton2450cb12012-03-29 01:41:38 +00001106 return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx);
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001107}
1108
Chris Lattner24943d22010-06-08 16:52:24 +00001109void
Greg Claytona830adb2010-10-04 01:05:56 +00001110Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +00001111{
Greg Claytonf4124de2012-02-21 00:09:25 +00001112 ExecutionContext exe_ctx (shared_from_this());
1113 Process *process = exe_ctx.GetProcessPtr();
1114 if (process == NULL)
1115 return;
1116
Greg Clayton567e7f32011-09-22 04:58:26 +00001117 StackFrameSP frame_sp;
Greg Claytona830adb2010-10-04 01:05:56 +00001118 SymbolContext frame_sc;
Greg Claytona830adb2010-10-04 01:05:56 +00001119 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +00001120 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001121 frame_sp = GetStackFrameAtIndex (frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001122 if (frame_sp)
1123 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001124 exe_ctx.SetFrameSP(frame_sp);
1125 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +00001126 }
1127 }
1128
Greg Claytonf4124de2012-02-21 00:09:25 +00001129 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001130 assert (thread_format);
1131 const char *end = NULL;
1132 Debugger::FormatPrompt (thread_format,
Greg Clayton567e7f32011-09-22 04:58:26 +00001133 frame_sp ? &frame_sc : NULL,
Greg Claytona830adb2010-10-04 01:05:56 +00001134 &exe_ctx,
1135 NULL,
1136 strm,
1137 &end);
Chris Lattner24943d22010-06-08 16:52:24 +00001138}
1139
Greg Clayton990de7b2010-11-18 23:32:35 +00001140void
Caroline Tice2a456812011-03-10 22:14:10 +00001141Thread::SettingsInitialize ()
Jim Ingham20594b12010-09-08 03:14:33 +00001142{
Greg Clayton334d33a2012-01-30 07:41:31 +00001143 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001144 SettingsController::global_settings_table,
1145 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001146
1147 // Now call SettingsInitialize() on each 'child' setting of Thread.
1148 // Currently there are none.
Greg Clayton990de7b2010-11-18 23:32:35 +00001149}
Jim Ingham20594b12010-09-08 03:14:33 +00001150
Greg Clayton990de7b2010-11-18 23:32:35 +00001151void
Caroline Tice2a456812011-03-10 22:14:10 +00001152Thread::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001153{
Caroline Tice2a456812011-03-10 22:14:10 +00001154 // Must call SettingsTerminate() on each 'child' setting of Thread before terminating Thread settings.
1155 // Currently there are none.
1156
1157 // Now terminate Thread Settings.
1158
Greg Clayton990de7b2010-11-18 23:32:35 +00001159 UserSettingsControllerSP &usc = GetSettingsController();
1160 UserSettingsController::FinalizeSettingsController (usc);
1161 usc.reset();
1162}
Jim Ingham20594b12010-09-08 03:14:33 +00001163
Greg Clayton990de7b2010-11-18 23:32:35 +00001164UserSettingsControllerSP &
1165Thread::GetSettingsController ()
1166{
Greg Clayton334d33a2012-01-30 07:41:31 +00001167 static UserSettingsControllerSP g_settings_controller_sp;
1168 if (!g_settings_controller_sp)
1169 {
1170 g_settings_controller_sp.reset (new Thread::SettingsController);
1171 // The first shared pointer to Target::SettingsController in
1172 // g_settings_controller_sp must be fully created above so that
1173 // the TargetInstanceSettings can use a weak_ptr to refer back
1174 // to the master setttings controller
1175 InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp,
1176 false,
1177 InstanceSettings::GetDefaultName().AsCString()));
1178
1179 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1180 }
1181 return g_settings_controller_sp;
Jim Ingham20594b12010-09-08 03:14:33 +00001182}
1183
Caroline Tice1ebef442010-09-27 00:30:10 +00001184void
1185Thread::UpdateInstanceName ()
1186{
1187 StreamString sstr;
1188 const char *name = GetName();
1189
1190 if (name && name[0] != '\0')
1191 sstr.Printf ("%s", name);
1192 else if ((GetIndexID() != 0) || (GetID() != 0))
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001193 sstr.Printf ("0x%4.4x", GetIndexID());
Caroline Tice1ebef442010-09-27 00:30:10 +00001194
1195 if (sstr.GetSize() > 0)
1196 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1197}
1198
Jim Inghamccd584d2010-09-23 17:40:12 +00001199lldb::StackFrameSP
1200Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
1201{
Greg Clayton2450cb12012-03-29 01:41:38 +00001202 return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr);
Jim Inghamccd584d2010-09-23 17:40:12 +00001203}
Caroline Tice7826c882010-10-26 03:11:13 +00001204
1205const char *
1206Thread::StopReasonAsCString (lldb::StopReason reason)
1207{
1208 switch (reason)
1209 {
1210 case eStopReasonInvalid: return "invalid";
1211 case eStopReasonNone: return "none";
1212 case eStopReasonTrace: return "trace";
1213 case eStopReasonBreakpoint: return "breakpoint";
1214 case eStopReasonWatchpoint: return "watchpoint";
1215 case eStopReasonSignal: return "signal";
1216 case eStopReasonException: return "exception";
1217 case eStopReasonPlanComplete: return "plan complete";
1218 }
1219
1220
1221 static char unknown_state_string[64];
1222 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
1223 return unknown_state_string;
1224}
1225
1226const char *
1227Thread::RunModeAsCString (lldb::RunMode mode)
1228{
1229 switch (mode)
1230 {
1231 case eOnlyThisThread: return "only this thread";
1232 case eAllThreads: return "all threads";
1233 case eOnlyDuringStepping: return "only during stepping";
1234 }
1235
1236 static char unknown_state_string[64];
1237 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1238 return unknown_state_string;
1239}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001240
Greg Claytonabe0fed2011-04-18 08:33:37 +00001241size_t
1242Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
1243{
Greg Claytonf4124de2012-02-21 00:09:25 +00001244 ExecutionContext exe_ctx (shared_from_this());
1245 Target *target = exe_ctx.GetTargetPtr();
1246 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001247 size_t num_frames_shown = 0;
1248 strm.Indent();
Greg Claytonf4124de2012-02-21 00:09:25 +00001249 bool is_selected = false;
1250 if (process)
1251 {
1252 if (process->GetThreadList().GetSelectedThread().get() == this)
1253 is_selected = true;
1254 }
1255 strm.Printf("%c ", is_selected ? '*' : ' ');
1256 if (target && target->GetDebugger().GetUseExternalEditor())
Greg Claytonabe0fed2011-04-18 08:33:37 +00001257 {
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001258 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001259 if (frame_sp)
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001260 {
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001261 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
1262 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
1263 {
1264 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
1265 }
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001266 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001267 }
1268
1269 DumpUsingSettingsFormat (strm, start_frame);
1270
1271 if (num_frames > 0)
1272 {
1273 strm.IndentMore();
1274
1275 const bool show_frame_info = true;
1276 const uint32_t source_lines_before = 3;
1277 const uint32_t source_lines_after = 3;
Jim Ingham7868bcc2011-07-26 02:39:59 +00001278 strm.IndentMore ();
Greg Clayton2450cb12012-03-29 01:41:38 +00001279 num_frames_shown = GetStackFrameList ()->GetStatus (strm,
1280 start_frame,
1281 num_frames,
1282 show_frame_info,
1283 num_frames_with_source,
1284 source_lines_before,
1285 source_lines_after);
Greg Claytonabe0fed2011-04-18 08:33:37 +00001286 strm.IndentLess();
Jim Ingham7868bcc2011-07-26 02:39:59 +00001287 strm.IndentLess();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001288 }
1289 return num_frames_shown;
1290}
1291
1292size_t
1293Thread::GetStackFrameStatus (Stream& strm,
1294 uint32_t first_frame,
1295 uint32_t num_frames,
1296 bool show_frame_info,
1297 uint32_t num_frames_with_source,
1298 uint32_t source_lines_before,
1299 uint32_t source_lines_after)
1300{
Greg Clayton2450cb12012-03-29 01:41:38 +00001301 return GetStackFrameList()->GetStatus (strm,
1302 first_frame,
1303 num_frames,
1304 show_frame_info,
1305 num_frames_with_source,
1306 source_lines_before,
1307 source_lines_after);
Greg Claytonabe0fed2011-04-18 08:33:37 +00001308}
1309
Peter Collingbournee426d852011-06-03 20:40:54 +00001310bool
1311Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint)
1312{
1313 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1314 if (frame_sp)
1315 {
1316 checkpoint.SetStackID(frame_sp->GetStackID());
1317 return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData());
1318 }
1319 return false;
1320}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001321
Peter Collingbournee426d852011-06-03 20:40:54 +00001322bool
1323Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint)
1324{
1325 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1326 if (frame_sp)
1327 {
1328 bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (checkpoint.GetData());
1329
1330 // Clear out all stack frames as our world just changed.
1331 ClearStackFrames();
1332 frame_sp->GetRegisterContext()->InvalidateIfNeeded(true);
1333
1334 return ret;
1335 }
1336 return false;
1337}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001338
Greg Clayton37f962e2011-08-22 02:49:39 +00001339Unwind *
1340Thread::GetUnwinder ()
1341{
1342 if (m_unwinder_ap.get() == NULL)
1343 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001344 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
Greg Clayton37f962e2011-08-22 02:49:39 +00001345 const llvm::Triple::ArchType machine = target_arch.GetMachine();
1346 switch (machine)
1347 {
1348 case llvm::Triple::x86_64:
1349 case llvm::Triple::x86:
1350 case llvm::Triple::arm:
1351 case llvm::Triple::thumb:
1352 m_unwinder_ap.reset (new UnwindLLDB (*this));
1353 break;
1354
1355 default:
1356 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
1357 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
1358 break;
1359 }
1360 }
1361 return m_unwinder_ap.get();
1362}
1363
1364
Greg Clayton990de7b2010-11-18 23:32:35 +00001365#pragma mark "Thread::SettingsController"
Jim Ingham745ac7a2010-11-11 19:26:09 +00001366//--------------------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001367// class Thread::SettingsController
Jim Ingham745ac7a2010-11-11 19:26:09 +00001368//--------------------------------------------------------------
1369
Greg Clayton990de7b2010-11-18 23:32:35 +00001370Thread::SettingsController::SettingsController () :
Jim Ingham745ac7a2010-11-11 19:26:09 +00001371 UserSettingsController ("thread", Process::GetSettingsController())
1372{
Jim Ingham745ac7a2010-11-11 19:26:09 +00001373}
1374
Greg Clayton990de7b2010-11-18 23:32:35 +00001375Thread::SettingsController::~SettingsController ()
Jim Ingham745ac7a2010-11-11 19:26:09 +00001376{
1377}
1378
1379lldb::InstanceSettingsSP
Greg Clayton990de7b2010-11-18 23:32:35 +00001380Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
Jim Ingham745ac7a2010-11-11 19:26:09 +00001381{
Greg Clayton334d33a2012-01-30 07:41:31 +00001382 lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(),
1383 false,
1384 instance_name));
Jim Ingham745ac7a2010-11-11 19:26:09 +00001385 return new_settings_sp;
1386}
1387
1388#pragma mark "ThreadInstanceSettings"
1389//--------------------------------------------------------------
1390// class ThreadInstanceSettings
1391//--------------------------------------------------------------
1392
Greg Clayton334d33a2012-01-30 07:41:31 +00001393ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) :
1394 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001395 m_avoid_regexp_ap (),
1396 m_trace_enabled (false)
1397{
1398 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1399 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1400 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1401 // This is true for CreateInstanceName() too.
1402
1403 if (GetInstanceName() == InstanceSettings::InvalidName())
1404 {
1405 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00001406 owner_sp->RegisterInstanceSettings (this);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001407 }
1408
1409 if (live_instance)
1410 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001411 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001412 }
1413}
1414
1415ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00001416 InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001417 m_avoid_regexp_ap (),
1418 m_trace_enabled (rhs.m_trace_enabled)
1419{
1420 if (m_instance_name != InstanceSettings::GetDefaultName())
1421 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001422 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
1423 if (owner_sp)
1424 {
1425 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
1426 owner_sp->RemovePendingSettings (m_instance_name);
1427 }
Jim Ingham745ac7a2010-11-11 19:26:09 +00001428 }
1429 if (rhs.m_avoid_regexp_ap.get() != NULL)
1430 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1431}
1432
1433ThreadInstanceSettings::~ThreadInstanceSettings ()
1434{
1435}
1436
1437ThreadInstanceSettings&
1438ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1439{
1440 if (this != &rhs)
1441 {
1442 if (rhs.m_avoid_regexp_ap.get() != NULL)
1443 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1444 else
1445 m_avoid_regexp_ap.reset(NULL);
1446 }
1447 m_trace_enabled = rhs.m_trace_enabled;
1448 return *this;
1449}
1450
1451
1452void
1453ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1454 const char *index_value,
1455 const char *value,
1456 const ConstString &instance_name,
1457 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001458 VarSetOperationType op,
Jim Ingham745ac7a2010-11-11 19:26:09 +00001459 Error &err,
1460 bool pending)
1461{
1462 if (var_name == StepAvoidRegexpVarName())
1463 {
1464 std::string regexp_text;
1465 if (m_avoid_regexp_ap.get() != NULL)
1466 regexp_text.append (m_avoid_regexp_ap->GetText());
1467 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1468 if (regexp_text.empty())
1469 m_avoid_regexp_ap.reset();
1470 else
1471 {
1472 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1473
1474 }
1475 }
1476 else if (var_name == GetTraceThreadVarName())
1477 {
1478 bool success;
1479 bool result = Args::StringToBoolean(value, false, &success);
1480
1481 if (success)
1482 {
1483 m_trace_enabled = result;
1484 if (!pending)
1485 {
1486 Thread *myself = static_cast<Thread *> (this);
1487 myself->EnableTracer(m_trace_enabled, true);
1488 }
1489 }
1490 else
1491 {
1492 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1493 }
1494
1495 }
1496}
1497
1498void
1499ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1500 bool pending)
1501{
1502 if (new_settings.get() == NULL)
1503 return;
1504
1505 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1506 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1507 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1508 else
1509 m_avoid_regexp_ap.reset ();
1510}
1511
1512bool
1513ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1514 const ConstString &var_name,
1515 StringList &value,
1516 Error *err)
1517{
1518 if (var_name == StepAvoidRegexpVarName())
1519 {
1520 if (m_avoid_regexp_ap.get() != NULL)
1521 {
1522 std::string regexp_text("\"");
1523 regexp_text.append(m_avoid_regexp_ap->GetText());
1524 regexp_text.append ("\"");
1525 value.AppendString (regexp_text.c_str());
1526 }
1527
1528 }
1529 else if (var_name == GetTraceThreadVarName())
1530 {
1531 value.AppendString(m_trace_enabled ? "true" : "false");
1532 }
1533 else
1534 {
1535 if (err)
1536 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1537 return false;
1538 }
1539 return true;
1540}
1541
1542const ConstString
1543ThreadInstanceSettings::CreateInstanceName ()
1544{
1545 static int instance_count = 1;
1546 StreamString sstr;
1547
1548 sstr.Printf ("thread_%d", instance_count);
1549 ++instance_count;
1550
1551 const ConstString ret_val (sstr.GetData());
1552 return ret_val;
1553}
1554
1555const ConstString &
1556ThreadInstanceSettings::StepAvoidRegexpVarName ()
1557{
1558 static ConstString step_avoid_var_name ("step-avoid-regexp");
1559
1560 return step_avoid_var_name;
1561}
1562
1563const ConstString &
1564ThreadInstanceSettings::GetTraceThreadVarName ()
1565{
1566 static ConstString trace_thread_var_name ("trace-thread");
1567
1568 return trace_thread_var_name;
1569}
1570
1571//--------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001572// SettingsController Variable Tables
Jim Ingham745ac7a2010-11-11 19:26:09 +00001573//--------------------------------------------------
1574
1575SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001576Thread::SettingsController::global_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001577{
1578 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1579 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1580};
1581
1582
1583SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001584Thread::SettingsController::instance_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001585{
1586 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1587 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1588 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1589 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1590};