blob: 6a86a3b435bfc8d7d79d73af2dde81a15ffabe16 [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 {
352 // If the current plan doesn't explain the stop, then, find one that
353 // 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
842ThreadPlan *
843Thread::QueueFundamentalPlan (bool abort_other_plans)
844{
845 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
846 QueueThreadPlan (thread_plan_sp, abort_other_plans);
847 return thread_plan_sp.get();
848}
849
850ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000851Thread::QueueThreadPlanForStepSingleInstruction
852(
853 bool step_over,
854 bool abort_other_plans,
855 bool stop_other_threads
856)
Chris Lattner24943d22010-06-08 16:52:24 +0000857{
858 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
859 QueueThreadPlan (thread_plan_sp, abort_other_plans);
860 return thread_plan_sp.get();
861}
862
863ThreadPlan *
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000864Thread::QueueThreadPlanForStepRange
865(
866 bool abort_other_plans,
867 StepType type,
868 const AddressRange &range,
869 const SymbolContext &addr_context,
870 lldb::RunMode stop_other_threads,
871 bool avoid_code_without_debug_info
872)
Chris Lattner24943d22010-06-08 16:52:24 +0000873{
874 ThreadPlanSP thread_plan_sp;
875 if (type == eStepTypeInto)
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000876 {
877 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
878 if (avoid_code_without_debug_info)
879 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
880 else
881 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
882 thread_plan_sp.reset (plan);
883 }
Chris Lattner24943d22010-06-08 16:52:24 +0000884 else
885 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
886
887 QueueThreadPlan (thread_plan_sp, abort_other_plans);
888 return thread_plan_sp.get();
889}
890
891
892ThreadPlan *
893Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
894{
895 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
896 QueueThreadPlan (thread_plan_sp, abort_other_plans);
897 return thread_plan_sp.get();
898}
899
900ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000901Thread::QueueThreadPlanForStepOut
902(
903 bool abort_other_plans,
904 SymbolContext *addr_context,
905 bool first_insn,
906 bool stop_other_threads,
907 Vote stop_vote,
908 Vote run_vote,
909 uint32_t frame_idx
910)
Chris Lattner24943d22010-06-08 16:52:24 +0000911{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000912 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this,
913 addr_context,
914 first_insn,
915 stop_other_threads,
916 stop_vote,
917 run_vote,
918 frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000919 QueueThreadPlan (thread_plan_sp, abort_other_plans);
920 return thread_plan_sp.get();
921}
922
923ThreadPlan *
924Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads)
925{
Jim Inghamad382c52011-12-03 01:52:59 +0000926 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, stop_other_threads));
927 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL))
928 return NULL;
929
Chris Lattner24943d22010-06-08 16:52:24 +0000930 QueueThreadPlan (thread_plan_sp, abort_other_plans);
931 return thread_plan_sp.get();
932}
933
934ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000935Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
936 Address& function,
937 lldb::addr_t arg,
938 bool stop_other_threads,
939 bool discard_on_error)
940{
Jim Ingham016ef882011-12-22 19:12:40 +0000941 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, ClangASTType(), arg, stop_other_threads, discard_on_error));
Chris Lattner24943d22010-06-08 16:52:24 +0000942 QueueThreadPlan (thread_plan_sp, abort_other_plans);
943 return thread_plan_sp.get();
944}
945
946ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000947Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
948 Address &target_addr,
949 bool stop_other_threads)
950{
951 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
952 QueueThreadPlan (thread_plan_sp, abort_other_plans);
953 return thread_plan_sp.get();
954}
955
956ThreadPlan *
957Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000958 lldb::addr_t *address_list,
959 size_t num_addresses,
960 bool stop_other_threads,
961 uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000962{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000963 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000964 QueueThreadPlan (thread_plan_sp, abort_other_plans);
965 return thread_plan_sp.get();
966
967}
968
969uint32_t
970Thread::GetIndexID () const
971{
972 return m_index_id;
973}
974
975void
976Thread::DumpThreadPlans (lldb_private::Stream *s) const
977{
978 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000979 int i;
Jim Inghame8f4e112011-10-15 00:23:43 +0000980 s->Indent();
Greg Clayton444e35b2011-10-19 18:09:39 +0000981 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 +0000982 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000983 {
Chris Lattner24943d22010-06-08 16:52:24 +0000984 s->IndentMore();
Jim Inghame8f4e112011-10-15 00:23:43 +0000985 s->Indent();
986 s->Printf ("Element %d: ", i);
Chris Lattner24943d22010-06-08 16:52:24 +0000987 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
Chris Lattner24943d22010-06-08 16:52:24 +0000988 s->EOL();
Jim Inghame8f4e112011-10-15 00:23:43 +0000989 s->IndentLess();
Chris Lattner24943d22010-06-08 16:52:24 +0000990 }
991
Chris Lattner24943d22010-06-08 16:52:24 +0000992 stack_size = m_completed_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +0000993 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000994 {
Jim Inghame8f4e112011-10-15 00:23:43 +0000995 s->Indent();
996 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
997 for (i = stack_size - 1; i >= 0; i--)
998 {
999 s->IndentMore();
1000 s->Indent();
1001 s->Printf ("Element %d: ", i);
1002 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1003 s->EOL();
1004 s->IndentLess();
1005 }
Chris Lattner24943d22010-06-08 16:52:24 +00001006 }
1007
1008 stack_size = m_discarded_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +00001009 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001010 {
Jim Inghame8f4e112011-10-15 00:23:43 +00001011 s->Indent();
1012 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
1013 for (i = stack_size - 1; i >= 0; i--)
1014 {
1015 s->IndentMore();
1016 s->Indent();
1017 s->Printf ("Element %d: ", i);
1018 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1019 s->EOL();
1020 s->IndentLess();
1021 }
Chris Lattner24943d22010-06-08 16:52:24 +00001022 }
1023
1024}
1025
Greg Clayton289afcb2012-02-18 05:35:26 +00001026TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001027Thread::CalculateTarget ()
1028{
Greg Claytonf4124de2012-02-21 00:09:25 +00001029 TargetSP target_sp;
1030 ProcessSP process_sp(GetProcess());
1031 if (process_sp)
1032 target_sp = process_sp->CalculateTarget();
1033 return target_sp;
1034
Chris Lattner24943d22010-06-08 16:52:24 +00001035}
1036
Greg Clayton289afcb2012-02-18 05:35:26 +00001037ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001038Thread::CalculateProcess ()
1039{
Greg Claytonf4124de2012-02-21 00:09:25 +00001040 return GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +00001041}
1042
Greg Clayton289afcb2012-02-18 05:35:26 +00001043ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001044Thread::CalculateThread ()
1045{
Greg Clayton289afcb2012-02-18 05:35:26 +00001046 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001047}
1048
Greg Clayton289afcb2012-02-18 05:35:26 +00001049StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001050Thread::CalculateStackFrame ()
1051{
Greg Clayton289afcb2012-02-18 05:35:26 +00001052 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001053}
1054
1055void
Greg Claytona830adb2010-10-04 01:05:56 +00001056Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001057{
Greg Claytonf4124de2012-02-21 00:09:25 +00001058 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001059}
1060
Greg Clayton782b9cc2010-08-25 00:35:26 +00001061
Greg Clayton2450cb12012-03-29 01:41:38 +00001062StackFrameListSP
Greg Clayton782b9cc2010-08-25 00:35:26 +00001063Thread::GetStackFrameList ()
1064{
Greg Clayton2450cb12012-03-29 01:41:38 +00001065 StackFrameListSP frame_list_sp;
1066 Mutex::Locker locker(m_frame_mutex);
1067 if (m_curr_frames_sp)
1068 {
1069 frame_list_sp = m_curr_frames_sp;
1070 }
1071 else
1072 {
1073 frame_list_sp.reset(new StackFrameList (*this, m_prev_frames_sp, true));
1074 m_curr_frames_sp = frame_list_sp;
1075 }
1076 return frame_list_sp;
Greg Clayton782b9cc2010-08-25 00:35:26 +00001077}
1078
Greg Clayton782b9cc2010-08-25 00:35:26 +00001079void
1080Thread::ClearStackFrames ()
1081{
Greg Clayton2450cb12012-03-29 01:41:38 +00001082 Mutex::Locker locker(m_frame_mutex);
1083
Jim Inghambf97d742012-02-29 03:40:22 +00001084 // Only store away the old "reference" StackFrameList if we got all its frames:
1085 // FIXME: At some point we can try to splice in the frames we have fetched into
1086 // the new frame as we make it, but let's not try that now.
1087 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
Greg Claytonc51ffbf2011-08-12 21:40:01 +00001088 m_prev_frames_sp.swap (m_curr_frames_sp);
1089 m_curr_frames_sp.reset();
Jim Ingham71219082010-08-12 02:14:28 +00001090}
1091
1092lldb::StackFrameSP
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001093Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1094{
Greg Clayton2450cb12012-03-29 01:41:38 +00001095 return GetStackFrameList()->GetFrameWithConcreteFrameIndex (unwind_idx);
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001096}
1097
Chris Lattner24943d22010-06-08 16:52:24 +00001098void
Greg Claytona830adb2010-10-04 01:05:56 +00001099Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +00001100{
Greg Claytonf4124de2012-02-21 00:09:25 +00001101 ExecutionContext exe_ctx (shared_from_this());
1102 Process *process = exe_ctx.GetProcessPtr();
1103 if (process == NULL)
1104 return;
1105
Greg Clayton567e7f32011-09-22 04:58:26 +00001106 StackFrameSP frame_sp;
Greg Claytona830adb2010-10-04 01:05:56 +00001107 SymbolContext frame_sc;
Greg Claytona830adb2010-10-04 01:05:56 +00001108 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +00001109 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001110 frame_sp = GetStackFrameAtIndex (frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001111 if (frame_sp)
1112 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001113 exe_ctx.SetFrameSP(frame_sp);
1114 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +00001115 }
1116 }
1117
Greg Claytonf4124de2012-02-21 00:09:25 +00001118 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001119 assert (thread_format);
1120 const char *end = NULL;
1121 Debugger::FormatPrompt (thread_format,
Greg Clayton567e7f32011-09-22 04:58:26 +00001122 frame_sp ? &frame_sc : NULL,
Greg Claytona830adb2010-10-04 01:05:56 +00001123 &exe_ctx,
1124 NULL,
1125 strm,
1126 &end);
Chris Lattner24943d22010-06-08 16:52:24 +00001127}
1128
Greg Clayton990de7b2010-11-18 23:32:35 +00001129void
Caroline Tice2a456812011-03-10 22:14:10 +00001130Thread::SettingsInitialize ()
Jim Ingham20594b12010-09-08 03:14:33 +00001131{
Greg Clayton334d33a2012-01-30 07:41:31 +00001132 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001133 SettingsController::global_settings_table,
1134 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001135
1136 // Now call SettingsInitialize() on each 'child' setting of Thread.
1137 // Currently there are none.
Greg Clayton990de7b2010-11-18 23:32:35 +00001138}
Jim Ingham20594b12010-09-08 03:14:33 +00001139
Greg Clayton990de7b2010-11-18 23:32:35 +00001140void
Caroline Tice2a456812011-03-10 22:14:10 +00001141Thread::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001142{
Caroline Tice2a456812011-03-10 22:14:10 +00001143 // Must call SettingsTerminate() on each 'child' setting of Thread before terminating Thread settings.
1144 // Currently there are none.
1145
1146 // Now terminate Thread Settings.
1147
Greg Clayton990de7b2010-11-18 23:32:35 +00001148 UserSettingsControllerSP &usc = GetSettingsController();
1149 UserSettingsController::FinalizeSettingsController (usc);
1150 usc.reset();
1151}
Jim Ingham20594b12010-09-08 03:14:33 +00001152
Greg Clayton990de7b2010-11-18 23:32:35 +00001153UserSettingsControllerSP &
1154Thread::GetSettingsController ()
1155{
Greg Clayton334d33a2012-01-30 07:41:31 +00001156 static UserSettingsControllerSP g_settings_controller_sp;
1157 if (!g_settings_controller_sp)
1158 {
1159 g_settings_controller_sp.reset (new Thread::SettingsController);
1160 // The first shared pointer to Target::SettingsController in
1161 // g_settings_controller_sp must be fully created above so that
1162 // the TargetInstanceSettings can use a weak_ptr to refer back
1163 // to the master setttings controller
1164 InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp,
1165 false,
1166 InstanceSettings::GetDefaultName().AsCString()));
1167
1168 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1169 }
1170 return g_settings_controller_sp;
Jim Ingham20594b12010-09-08 03:14:33 +00001171}
1172
Caroline Tice1ebef442010-09-27 00:30:10 +00001173void
1174Thread::UpdateInstanceName ()
1175{
1176 StreamString sstr;
1177 const char *name = GetName();
1178
1179 if (name && name[0] != '\0')
1180 sstr.Printf ("%s", name);
1181 else if ((GetIndexID() != 0) || (GetID() != 0))
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001182 sstr.Printf ("0x%4.4x", GetIndexID());
Caroline Tice1ebef442010-09-27 00:30:10 +00001183
1184 if (sstr.GetSize() > 0)
1185 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1186}
1187
Jim Inghamccd584d2010-09-23 17:40:12 +00001188lldb::StackFrameSP
1189Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
1190{
Greg Clayton2450cb12012-03-29 01:41:38 +00001191 return GetStackFrameList()->GetStackFrameSPForStackFramePtr (stack_frame_ptr);
Jim Inghamccd584d2010-09-23 17:40:12 +00001192}
Caroline Tice7826c882010-10-26 03:11:13 +00001193
1194const char *
1195Thread::StopReasonAsCString (lldb::StopReason reason)
1196{
1197 switch (reason)
1198 {
1199 case eStopReasonInvalid: return "invalid";
1200 case eStopReasonNone: return "none";
1201 case eStopReasonTrace: return "trace";
1202 case eStopReasonBreakpoint: return "breakpoint";
1203 case eStopReasonWatchpoint: return "watchpoint";
1204 case eStopReasonSignal: return "signal";
1205 case eStopReasonException: return "exception";
1206 case eStopReasonPlanComplete: return "plan complete";
1207 }
1208
1209
1210 static char unknown_state_string[64];
1211 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
1212 return unknown_state_string;
1213}
1214
1215const char *
1216Thread::RunModeAsCString (lldb::RunMode mode)
1217{
1218 switch (mode)
1219 {
1220 case eOnlyThisThread: return "only this thread";
1221 case eAllThreads: return "all threads";
1222 case eOnlyDuringStepping: return "only during stepping";
1223 }
1224
1225 static char unknown_state_string[64];
1226 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1227 return unknown_state_string;
1228}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001229
Greg Claytonabe0fed2011-04-18 08:33:37 +00001230size_t
1231Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
1232{
Greg Claytonf4124de2012-02-21 00:09:25 +00001233 ExecutionContext exe_ctx (shared_from_this());
1234 Target *target = exe_ctx.GetTargetPtr();
1235 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001236 size_t num_frames_shown = 0;
1237 strm.Indent();
Greg Claytonf4124de2012-02-21 00:09:25 +00001238 bool is_selected = false;
1239 if (process)
1240 {
1241 if (process->GetThreadList().GetSelectedThread().get() == this)
1242 is_selected = true;
1243 }
1244 strm.Printf("%c ", is_selected ? '*' : ' ');
1245 if (target && target->GetDebugger().GetUseExternalEditor())
Greg Claytonabe0fed2011-04-18 08:33:37 +00001246 {
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001247 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001248 if (frame_sp)
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001249 {
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001250 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
1251 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
1252 {
1253 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
1254 }
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001255 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001256 }
1257
1258 DumpUsingSettingsFormat (strm, start_frame);
1259
1260 if (num_frames > 0)
1261 {
1262 strm.IndentMore();
1263
1264 const bool show_frame_info = true;
1265 const uint32_t source_lines_before = 3;
1266 const uint32_t source_lines_after = 3;
Jim Ingham7868bcc2011-07-26 02:39:59 +00001267 strm.IndentMore ();
Greg Clayton2450cb12012-03-29 01:41:38 +00001268 num_frames_shown = GetStackFrameList ()->GetStatus (strm,
1269 start_frame,
1270 num_frames,
1271 show_frame_info,
1272 num_frames_with_source,
1273 source_lines_before,
1274 source_lines_after);
Greg Claytonabe0fed2011-04-18 08:33:37 +00001275 strm.IndentLess();
Jim Ingham7868bcc2011-07-26 02:39:59 +00001276 strm.IndentLess();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001277 }
1278 return num_frames_shown;
1279}
1280
1281size_t
1282Thread::GetStackFrameStatus (Stream& strm,
1283 uint32_t first_frame,
1284 uint32_t num_frames,
1285 bool show_frame_info,
1286 uint32_t num_frames_with_source,
1287 uint32_t source_lines_before,
1288 uint32_t source_lines_after)
1289{
Greg Clayton2450cb12012-03-29 01:41:38 +00001290 return GetStackFrameList()->GetStatus (strm,
1291 first_frame,
1292 num_frames,
1293 show_frame_info,
1294 num_frames_with_source,
1295 source_lines_before,
1296 source_lines_after);
Greg Claytonabe0fed2011-04-18 08:33:37 +00001297}
1298
Peter Collingbournee426d852011-06-03 20:40:54 +00001299bool
1300Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint)
1301{
1302 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1303 if (frame_sp)
1304 {
1305 checkpoint.SetStackID(frame_sp->GetStackID());
1306 return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData());
1307 }
1308 return false;
1309}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001310
Peter Collingbournee426d852011-06-03 20:40:54 +00001311bool
1312Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint)
1313{
1314 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1315 if (frame_sp)
1316 {
1317 bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (checkpoint.GetData());
1318
1319 // Clear out all stack frames as our world just changed.
1320 ClearStackFrames();
1321 frame_sp->GetRegisterContext()->InvalidateIfNeeded(true);
1322
1323 return ret;
1324 }
1325 return false;
1326}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001327
Greg Clayton37f962e2011-08-22 02:49:39 +00001328Unwind *
1329Thread::GetUnwinder ()
1330{
1331 if (m_unwinder_ap.get() == NULL)
1332 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001333 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
Greg Clayton37f962e2011-08-22 02:49:39 +00001334 const llvm::Triple::ArchType machine = target_arch.GetMachine();
1335 switch (machine)
1336 {
1337 case llvm::Triple::x86_64:
1338 case llvm::Triple::x86:
1339 case llvm::Triple::arm:
1340 case llvm::Triple::thumb:
1341 m_unwinder_ap.reset (new UnwindLLDB (*this));
1342 break;
1343
1344 default:
1345 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
1346 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
1347 break;
1348 }
1349 }
1350 return m_unwinder_ap.get();
1351}
1352
1353
Greg Clayton990de7b2010-11-18 23:32:35 +00001354#pragma mark "Thread::SettingsController"
Jim Ingham745ac7a2010-11-11 19:26:09 +00001355//--------------------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001356// class Thread::SettingsController
Jim Ingham745ac7a2010-11-11 19:26:09 +00001357//--------------------------------------------------------------
1358
Greg Clayton990de7b2010-11-18 23:32:35 +00001359Thread::SettingsController::SettingsController () :
Jim Ingham745ac7a2010-11-11 19:26:09 +00001360 UserSettingsController ("thread", Process::GetSettingsController())
1361{
Jim Ingham745ac7a2010-11-11 19:26:09 +00001362}
1363
Greg Clayton990de7b2010-11-18 23:32:35 +00001364Thread::SettingsController::~SettingsController ()
Jim Ingham745ac7a2010-11-11 19:26:09 +00001365{
1366}
1367
1368lldb::InstanceSettingsSP
Greg Clayton990de7b2010-11-18 23:32:35 +00001369Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
Jim Ingham745ac7a2010-11-11 19:26:09 +00001370{
Greg Clayton334d33a2012-01-30 07:41:31 +00001371 lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(),
1372 false,
1373 instance_name));
Jim Ingham745ac7a2010-11-11 19:26:09 +00001374 return new_settings_sp;
1375}
1376
1377#pragma mark "ThreadInstanceSettings"
1378//--------------------------------------------------------------
1379// class ThreadInstanceSettings
1380//--------------------------------------------------------------
1381
Greg Clayton334d33a2012-01-30 07:41:31 +00001382ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) :
1383 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001384 m_avoid_regexp_ap (),
1385 m_trace_enabled (false)
1386{
1387 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1388 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1389 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1390 // This is true for CreateInstanceName() too.
1391
1392 if (GetInstanceName() == InstanceSettings::InvalidName())
1393 {
1394 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00001395 owner_sp->RegisterInstanceSettings (this);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001396 }
1397
1398 if (live_instance)
1399 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001400 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001401 }
1402}
1403
1404ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00001405 InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001406 m_avoid_regexp_ap (),
1407 m_trace_enabled (rhs.m_trace_enabled)
1408{
1409 if (m_instance_name != InstanceSettings::GetDefaultName())
1410 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001411 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
1412 if (owner_sp)
1413 {
1414 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
1415 owner_sp->RemovePendingSettings (m_instance_name);
1416 }
Jim Ingham745ac7a2010-11-11 19:26:09 +00001417 }
1418 if (rhs.m_avoid_regexp_ap.get() != NULL)
1419 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1420}
1421
1422ThreadInstanceSettings::~ThreadInstanceSettings ()
1423{
1424}
1425
1426ThreadInstanceSettings&
1427ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1428{
1429 if (this != &rhs)
1430 {
1431 if (rhs.m_avoid_regexp_ap.get() != NULL)
1432 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1433 else
1434 m_avoid_regexp_ap.reset(NULL);
1435 }
1436 m_trace_enabled = rhs.m_trace_enabled;
1437 return *this;
1438}
1439
1440
1441void
1442ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1443 const char *index_value,
1444 const char *value,
1445 const ConstString &instance_name,
1446 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001447 VarSetOperationType op,
Jim Ingham745ac7a2010-11-11 19:26:09 +00001448 Error &err,
1449 bool pending)
1450{
1451 if (var_name == StepAvoidRegexpVarName())
1452 {
1453 std::string regexp_text;
1454 if (m_avoid_regexp_ap.get() != NULL)
1455 regexp_text.append (m_avoid_regexp_ap->GetText());
1456 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1457 if (regexp_text.empty())
1458 m_avoid_regexp_ap.reset();
1459 else
1460 {
1461 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1462
1463 }
1464 }
1465 else if (var_name == GetTraceThreadVarName())
1466 {
1467 bool success;
1468 bool result = Args::StringToBoolean(value, false, &success);
1469
1470 if (success)
1471 {
1472 m_trace_enabled = result;
1473 if (!pending)
1474 {
1475 Thread *myself = static_cast<Thread *> (this);
1476 myself->EnableTracer(m_trace_enabled, true);
1477 }
1478 }
1479 else
1480 {
1481 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1482 }
1483
1484 }
1485}
1486
1487void
1488ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1489 bool pending)
1490{
1491 if (new_settings.get() == NULL)
1492 return;
1493
1494 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1495 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1496 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1497 else
1498 m_avoid_regexp_ap.reset ();
1499}
1500
1501bool
1502ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1503 const ConstString &var_name,
1504 StringList &value,
1505 Error *err)
1506{
1507 if (var_name == StepAvoidRegexpVarName())
1508 {
1509 if (m_avoid_regexp_ap.get() != NULL)
1510 {
1511 std::string regexp_text("\"");
1512 regexp_text.append(m_avoid_regexp_ap->GetText());
1513 regexp_text.append ("\"");
1514 value.AppendString (regexp_text.c_str());
1515 }
1516
1517 }
1518 else if (var_name == GetTraceThreadVarName())
1519 {
1520 value.AppendString(m_trace_enabled ? "true" : "false");
1521 }
1522 else
1523 {
1524 if (err)
1525 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1526 return false;
1527 }
1528 return true;
1529}
1530
1531const ConstString
1532ThreadInstanceSettings::CreateInstanceName ()
1533{
1534 static int instance_count = 1;
1535 StreamString sstr;
1536
1537 sstr.Printf ("thread_%d", instance_count);
1538 ++instance_count;
1539
1540 const ConstString ret_val (sstr.GetData());
1541 return ret_val;
1542}
1543
1544const ConstString &
1545ThreadInstanceSettings::StepAvoidRegexpVarName ()
1546{
1547 static ConstString step_avoid_var_name ("step-avoid-regexp");
1548
1549 return step_avoid_var_name;
1550}
1551
1552const ConstString &
1553ThreadInstanceSettings::GetTraceThreadVarName ()
1554{
1555 static ConstString trace_thread_var_name ("trace-thread");
1556
1557 return trace_thread_var_name;
1558}
1559
1560//--------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001561// SettingsController Variable Tables
Jim Ingham745ac7a2010-11-11 19:26:09 +00001562//--------------------------------------------------
1563
1564SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001565Thread::SettingsController::global_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001566{
1567 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1568 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1569};
1570
1571
1572SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001573Thread::SettingsController::instance_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001574{
1575 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1576 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1577 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1578 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1579};