blob: 0db727ed6946a3f18952eb6472fbe634873f089a [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 Claytonc51ffbf2011-08-12 21:40:01 +000057 m_curr_frames_sp (),
58 m_prev_frames_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000059 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
Jim Ingham71219082010-08-12 02:14:28 +000060 m_resume_state (eStateRunning),
Jim Ingham149d1f52012-01-31 23:09:20 +000061 m_temporary_resume_state (eStateRunning),
Jim Inghamcdea2362010-11-18 02:47:07 +000062 m_unwinder_ap (),
Jim Ingham15dcb7c2011-01-20 02:03:18 +000063 m_destroy_called (false),
64 m_thread_stop_reason_stop_id (0)
Jim Ingham71219082010-08-12 02:14:28 +000065
Chris Lattner24943d22010-06-08 16:52:24 +000066{
Greg Claytone005f2c2010-11-06 01:53:30 +000067 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000068 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +000069 log->Printf ("%p Thread::Thread(tid = 0x%4.4llx)", this, GetID());
Chris Lattner24943d22010-06-08 16:52:24 +000070
71 QueueFundamentalPlan(true);
Caroline Tice1ebef442010-09-27 00:30:10 +000072 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +000073}
74
75
76Thread::~Thread()
77{
Greg Claytone005f2c2010-11-06 01:53:30 +000078 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000079 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +000080 log->Printf ("%p Thread::~Thread(tid = 0x%4.4llx)", this, GetID());
Jim Inghamcdea2362010-11-18 02:47:07 +000081 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor.
82 assert (m_destroy_called);
83}
84
85void
86Thread::DestroyThread ()
87{
88 m_plan_stack.clear();
89 m_discarded_plan_stack.clear();
90 m_completed_plan_stack.clear();
91 m_destroy_called = true;
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93
Jim Ingham6297a3a2010-10-20 00:39:53 +000094lldb::StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +000095Thread::GetStopInfo ()
Chris Lattner24943d22010-06-08 16:52:24 +000096{
Jim Ingham6297a3a2010-10-20 00:39:53 +000097 ThreadPlanSP plan_sp (GetCompletedPlan());
98 if (plan_sp)
Jim Ingham1586d972011-12-17 01:35:57 +000099 return StopInfo::CreateStopReasonWithPlan (plan_sp, GetReturnValueObject());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000100 else
Jim Ingham24e0d612011-08-09 00:32:52 +0000101 {
Greg Claytonf4124de2012-02-21 00:09:25 +0000102 ProcessSP process_sp (GetProcess());
103 if (process_sp
104 && m_actual_stop_info_sp
Jim Ingham24e0d612011-08-09 00:32:52 +0000105 && m_actual_stop_info_sp->IsValid()
Greg Claytonf4124de2012-02-21 00:09:25 +0000106 && m_thread_stop_reason_stop_id == process_sp->GetStopID())
Jim Ingham24e0d612011-08-09 00:32:52 +0000107 return m_actual_stop_info_sp;
108 else
109 return GetPrivateStopReason ();
110 }
Chris Lattner24943d22010-06-08 16:52:24 +0000111}
112
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000113void
114Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp)
115{
116 m_actual_stop_info_sp = stop_info_sp;
Jim Ingham24e0d612011-08-09 00:32:52 +0000117 if (m_actual_stop_info_sp)
118 m_actual_stop_info_sp->MakeStopInfoValid();
Greg Claytonf4124de2012-02-21 00:09:25 +0000119 ProcessSP process_sp (GetProcess());
120 if (process_sp)
121 m_thread_stop_reason_stop_id = process_sp->GetStopID();
122 else
123 m_thread_stop_reason_stop_id = UINT32_MAX;
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000124}
125
126void
127Thread::SetStopInfoToNothing()
128{
129 // Note, we can't just NULL out the private reason, or the native thread implementation will try to
130 // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number.
131 SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER));
132}
133
Chris Lattner24943d22010-06-08 16:52:24 +0000134bool
135Thread::ThreadStoppedForAReason (void)
136{
Greg Clayton643ee732010-08-04 01:40:35 +0000137 return GetPrivateStopReason () != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000138}
139
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000140bool
141Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state)
142{
143 if (!SaveFrameZeroState(saved_state.register_backup))
144 return false;
145
146 saved_state.stop_info_sp = GetStopInfo();
Greg Claytonf4124de2012-02-21 00:09:25 +0000147 ProcessSP process_sp (GetProcess());
148 if (process_sp)
149 saved_state.orig_stop_id = process_sp->GetStopID();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000150 return true;
151}
152
153bool
154Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state)
155{
156 RestoreSaveFrameZero(saved_state.register_backup);
Jim Ingham11a837d2011-01-25 02:47:23 +0000157 if (saved_state.stop_info_sp)
158 saved_state.stop_info_sp->MakeStopInfoValid();
Jim Ingham15dcb7c2011-01-20 02:03:18 +0000159 SetStopInfo(saved_state.stop_info_sp);
160 return true;
161}
162
Chris Lattner24943d22010-06-08 16:52:24 +0000163StateType
164Thread::GetState() const
165{
166 // If any other threads access this we will need a mutex for it
167 Mutex::Locker locker(m_state_mutex);
168 return m_state;
169}
170
171void
172Thread::SetState(StateType state)
173{
174 Mutex::Locker locker(m_state_mutex);
175 m_state = state;
176}
177
178void
179Thread::WillStop()
180{
181 ThreadPlan *current_plan = GetCurrentPlan();
182
183 // FIXME: I may decide to disallow threads with no plans. In which
184 // case this should go to an assert.
185
186 if (!current_plan)
187 return;
188
189 current_plan->WillStop();
190}
191
192void
193Thread::SetupForResume ()
194{
195 if (GetResumeState() != eStateSuspended)
196 {
197
198 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
199 // telling the current plan it will resume, since we might change what the current
200 // plan is.
201
202 lldb::addr_t pc = GetRegisterContext()->GetPC();
Greg Claytonf4124de2012-02-21 00:09:25 +0000203 BreakpointSiteSP bp_site_sp = GetProcess()->GetBreakpointSiteList().FindByAddress(pc);
Chris Lattner24943d22010-06-08 16:52:24 +0000204 if (bp_site_sp && bp_site_sp->IsEnabled())
205 {
206 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
207 // special to step over a breakpoint.
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000208
209 ThreadPlan *cur_plan = GetCurrentPlan();
Chris Lattner24943d22010-06-08 16:52:24 +0000210
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000211 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
212 {
213 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
214 if (step_bp_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000215 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000216 ThreadPlanSP step_bp_plan_sp;
217 step_bp_plan->SetPrivate (true);
218
Chris Lattner24943d22010-06-08 16:52:24 +0000219 if (GetCurrentPlan()->RunState() != eStateStepping)
220 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000221 step_bp_plan->SetAutoContinue(true);
Chris Lattner24943d22010-06-08 16:52:24 +0000222 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000223 step_bp_plan_sp.reset (step_bp_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000224 QueueThreadPlan (step_bp_plan_sp, false);
225 }
226 }
227 }
228 }
229}
230
231bool
232Thread::WillResume (StateType resume_state)
233{
234 // At this point clear the completed plan stack.
235 m_completed_plan_stack.clear();
236 m_discarded_plan_stack.clear();
237
Jim Ingham149d1f52012-01-31 23:09:20 +0000238 SetTemporaryResumeState(resume_state);
239
240 // This is a little dubious, but we are trying to limit how often we actually fetch stop info from
241 // the target, 'cause that slows down single stepping. So assume that if we got to the point where
242 // we're about to resume, and we haven't yet had to fetch the stop reason, then it doesn't need to know
243 // about the fact that we are resuming...
Greg Claytonf4124de2012-02-21 00:09:25 +0000244 const uint32_t process_stop_id = GetProcess()->GetStopID();
Jim Ingham149d1f52012-01-31 23:09:20 +0000245 if (m_thread_stop_reason_stop_id == process_stop_id &&
246 (m_actual_stop_info_sp && m_actual_stop_info_sp->IsValid()))
247 {
248 StopInfo *stop_info = GetPrivateStopReason().get();
249 if (stop_info)
250 stop_info->WillResume (resume_state);
251 }
Chris Lattner24943d22010-06-08 16:52:24 +0000252
253 // Tell all the plans that we are about to resume in case they need to clear any state.
254 // We distinguish between the plan on the top of the stack and the lower
255 // plans in case a plan needs to do any special business before it runs.
256
257 ThreadPlan *plan_ptr = GetCurrentPlan();
258 plan_ptr->WillResume(resume_state, true);
259
260 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
261 {
262 plan_ptr->WillResume (resume_state, false);
263 }
Greg Clayton643ee732010-08-04 01:40:35 +0000264
Greg Clayton643ee732010-08-04 01:40:35 +0000265 m_actual_stop_info_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000266 return true;
267}
268
269void
270Thread::DidResume ()
271{
272 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
273}
274
275bool
276Thread::ShouldStop (Event* event_ptr)
277{
278 ThreadPlan *current_plan = GetCurrentPlan();
279 bool should_stop = true;
280
Greg Claytone005f2c2010-11-06 01:53:30 +0000281 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Ingham149d1f52012-01-31 23:09:20 +0000282
283 if (GetResumeState () == eStateSuspended)
284 {
285 if (log)
286 log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)",
287 __FUNCTION__,
288 GetID ());
289// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)",
290// __FUNCTION__,
291// GetID (),
292// GetRegisterContext()->GetPC());
293 return false;
294 }
295
296 if (GetTemporaryResumeState () == eStateSuspended)
297 {
298 if (log)
299 log->Printf ("Thread::%s for tid = 0x%4.4llx, should_stop = 0 (ignore since thread was suspended)",
300 __FUNCTION__,
301 GetID ());
302// log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since thread was suspended)",
303// __FUNCTION__,
304// GetID (),
305// GetRegisterContext()->GetPC());
306 return false;
307 }
308
309 if (ThreadStoppedForAReason() == false)
310 {
311 if (log)
312 log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx, should_stop = 0 (ignore since no stop reason)",
313 __FUNCTION__,
314 GetID (),
315 GetRegisterContext()->GetPC());
316 return false;
317 }
318
Chris Lattner24943d22010-06-08 16:52:24 +0000319 if (log)
320 {
Jim Ingham149d1f52012-01-31 23:09:20 +0000321 log->Printf ("Thread::%s for tid = 0x%4.4llx, pc = 0x%16.16llx",
322 __FUNCTION__,
323 GetID (),
324 GetRegisterContext()->GetPC());
Jim Inghame8f4e112011-10-15 00:23:43 +0000325 log->Printf ("^^^^^^^^ Thread::ShouldStop Begin ^^^^^^^^");
Chris Lattner24943d22010-06-08 16:52:24 +0000326 StreamString s;
Jim Inghame8f4e112011-10-15 00:23:43 +0000327 s.IndentMore();
Chris Lattner24943d22010-06-08 16:52:24 +0000328 DumpThreadPlans(&s);
Jim Inghame8f4e112011-10-15 00:23:43 +0000329 log->Printf ("Plan stack initial state:\n%s", s.GetData());
Chris Lattner24943d22010-06-08 16:52:24 +0000330 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000331
332 // The top most plan always gets to do the trace log...
333 current_plan->DoTraceLog ();
Chris Lattner24943d22010-06-08 16:52:24 +0000334
Jim Inghamad382c52011-12-03 01:52:59 +0000335 // If the base plan doesn't understand why we stopped, then we have to find a plan that does.
336 // If that plan is still working, then we don't need to do any more work. If the plan that explains
337 // the stop is done, then we should pop all the plans below it, and pop it, and then let the plans above it decide
338 // whether they still need to do more work.
339
340 bool done_processing_current_plan = false;
341
342 if (!current_plan->PlanExplainsStop())
343 {
344 if (current_plan->TracerExplainsStop())
345 {
346 done_processing_current_plan = true;
347 should_stop = false;
348 }
349 else
350 {
351 // If the current plan doesn't explain the stop, then, find one that
352 // does and let it handle the situation.
353 ThreadPlan *plan_ptr = current_plan;
354 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
355 {
356 if (plan_ptr->PlanExplainsStop())
357 {
358 should_stop = plan_ptr->ShouldStop (event_ptr);
359
360 // plan_ptr explains the stop, next check whether plan_ptr is done, if so, then we should take it
361 // and all the plans below it off the stack.
362
363 if (plan_ptr->MischiefManaged())
364 {
365 // We're going to pop the plans up to AND INCLUDING the plan that explains the stop.
366 plan_ptr = GetPreviousPlan(plan_ptr);
367
368 do
369 {
370 if (should_stop)
371 current_plan->WillStop();
372 PopPlan();
373 }
374 while ((current_plan = GetCurrentPlan()) != plan_ptr);
375 done_processing_current_plan = false;
376 }
377 else
378 done_processing_current_plan = true;
379
380 break;
381 }
382
383 }
384 }
385 }
386
387 if (!done_processing_current_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000388 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000389 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
Jim Inghamf9f40c22011-02-08 05:20:59 +0000390
Jim Inghame8f4e112011-10-15 00:23:43 +0000391 if (log)
392 log->Printf("Plan %s explains stop, auto-continue %i.", current_plan->GetName(), over_ride_stop);
393
Jim Inghamf9f40c22011-02-08 05:20:59 +0000394 // We're starting from the base plan, so just let it decide;
395 if (PlanIsBasePlan(current_plan))
Chris Lattner24943d22010-06-08 16:52:24 +0000396 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000397 should_stop = current_plan->ShouldStop (event_ptr);
398 if (log)
Greg Clayton628cead2011-05-19 03:54:16 +0000399 log->Printf("Base plan says should stop: %i.", should_stop);
Jim Inghamf9f40c22011-02-08 05:20:59 +0000400 }
401 else
402 {
403 // Otherwise, don't let the base plan override what the other plans say to do, since
404 // presumably if there were other plans they would know what to do...
405 while (1)
Chris Lattner24943d22010-06-08 16:52:24 +0000406 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000407 if (PlanIsBasePlan(current_plan))
Chris Lattner24943d22010-06-08 16:52:24 +0000408 break;
Jim Inghamf9f40c22011-02-08 05:20:59 +0000409
410 should_stop = current_plan->ShouldStop(event_ptr);
411 if (log)
412 log->Printf("Plan %s should stop: %d.", current_plan->GetName(), should_stop);
413 if (current_plan->MischiefManaged())
414 {
415 if (should_stop)
416 current_plan->WillStop();
417
418 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
419 // Otherwise, see if the plan's parent wants to stop.
420
421 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
422 {
423 PopPlan();
424 break;
425 }
426 else
427 {
428
429 PopPlan();
430
431 current_plan = GetCurrentPlan();
432 if (current_plan == NULL)
433 {
434 break;
435 }
436 }
437
Chris Lattner24943d22010-06-08 16:52:24 +0000438 }
439 else
440 {
Jim Inghamf9f40c22011-02-08 05:20:59 +0000441 break;
Chris Lattner24943d22010-06-08 16:52:24 +0000442 }
Chris Lattner24943d22010-06-08 16:52:24 +0000443 }
444 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000445 if (over_ride_stop)
446 should_stop = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000447 }
Chris Lattner24943d22010-06-08 16:52:24 +0000448
Jim Inghame8f4e112011-10-15 00:23:43 +0000449 if (log)
450 {
451 StreamString s;
452 s.IndentMore();
453 DumpThreadPlans(&s);
454 log->Printf ("Plan stack final state:\n%s", s.GetData());
455 log->Printf ("vvvvvvvv Thread::ShouldStop End (returning %i) vvvvvvvv", should_stop);
456 }
Chris Lattner24943d22010-06-08 16:52:24 +0000457 return should_stop;
458}
459
460Vote
461Thread::ShouldReportStop (Event* event_ptr)
462{
463 StateType thread_state = GetResumeState ();
Jim Ingham149d1f52012-01-31 23:09:20 +0000464 StateType temp_thread_state = GetTemporaryResumeState();
465
Greg Claytone005f2c2010-11-06 01:53:30 +0000466 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton5205f0b2010-09-03 17:10:42 +0000467
468 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
469 {
470 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000471 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 +0000472 return eVoteNoOpinion;
Greg Clayton5205f0b2010-09-03 17:10:42 +0000473 }
Chris Lattner24943d22010-06-08 16:52:24 +0000474
Jim Ingham149d1f52012-01-31 23:09:20 +0000475 if (temp_thread_state == eStateSuspended || temp_thread_state == eStateInvalid)
476 {
477 if (log)
478 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (temporary state was suspended or invalid)\n", GetID(), eVoteNoOpinion);
479 return eVoteNoOpinion;
480 }
481
482 if (!ThreadStoppedForAReason())
483 {
484 if (log)
485 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote %i (thread didn't stop for a reason.)\n", GetID(), eVoteNoOpinion);
486 return eVoteNoOpinion;
487 }
488
Chris Lattner24943d22010-06-08 16:52:24 +0000489 if (m_completed_plan_stack.size() > 0)
490 {
491 // Don't use GetCompletedPlan here, since that suppresses private plans.
Greg Clayton5205f0b2010-09-03 17:10:42 +0000492 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000493 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 +0000494 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
495 }
496 else
Greg Clayton5205f0b2010-09-03 17:10:42 +0000497 {
498 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000499 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4llx: returning vote for current plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000500 return GetCurrentPlan()->ShouldReportStop (event_ptr);
Greg Clayton5205f0b2010-09-03 17:10:42 +0000501 }
Chris Lattner24943d22010-06-08 16:52:24 +0000502}
503
504Vote
505Thread::ShouldReportRun (Event* event_ptr)
506{
507 StateType thread_state = GetResumeState ();
Jim Inghamac959662011-01-24 06:34:17 +0000508
Chris Lattner24943d22010-06-08 16:52:24 +0000509 if (thread_state == eStateSuspended
510 || thread_state == eStateInvalid)
Jim Inghamac959662011-01-24 06:34:17 +0000511 {
Chris Lattner24943d22010-06-08 16:52:24 +0000512 return eVoteNoOpinion;
Jim Inghamac959662011-01-24 06:34:17 +0000513 }
514
515 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000516 if (m_completed_plan_stack.size() > 0)
517 {
518 // Don't use GetCompletedPlan here, since that suppresses private plans.
Jim Inghamac959662011-01-24 06:34:17 +0000519 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000520 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 +0000521 GetIndexID(),
522 GetID(),
523 m_completed_plan_stack.back()->GetName());
524
Chris Lattner24943d22010-06-08 16:52:24 +0000525 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
526 }
527 else
Jim Inghamac959662011-01-24 06:34:17 +0000528 {
529 if (log)
Greg Clayton444e35b2011-10-19 18:09:39 +0000530 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 +0000531 GetIndexID(),
532 GetID(),
533 GetCurrentPlan()->GetName());
534
Chris Lattner24943d22010-06-08 16:52:24 +0000535 return GetCurrentPlan()->ShouldReportRun (event_ptr);
Jim Inghamac959662011-01-24 06:34:17 +0000536 }
Chris Lattner24943d22010-06-08 16:52:24 +0000537}
538
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000539bool
540Thread::MatchesSpec (const ThreadSpec *spec)
541{
542 if (spec == NULL)
543 return true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000544
Jim Ingham649492b2010-06-18 01:00:58 +0000545 return spec->ThreadPassesBasicTests(this);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000546}
547
Chris Lattner24943d22010-06-08 16:52:24 +0000548void
549Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
550{
551 if (thread_plan_sp)
552 {
Jim Ingham745ac7a2010-11-11 19:26:09 +0000553 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
554 if (!thread_plan_sp->GetThreadPlanTracer())
555 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000556 m_plan_stack.push_back (thread_plan_sp);
Jim Ingham745ac7a2010-11-11 19:26:09 +0000557
Chris Lattner24943d22010-06-08 16:52:24 +0000558 thread_plan_sp->DidPush();
559
Greg Claytone005f2c2010-11-06 01:53:30 +0000560 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000561 if (log)
562 {
563 StreamString s;
564 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
Greg Clayton444e35b2011-10-19 18:09:39 +0000565 log->Printf("Pushing plan: \"%s\", tid = 0x%4.4llx.",
Chris Lattner24943d22010-06-08 16:52:24 +0000566 s.GetData(),
Jim Ingham6297a3a2010-10-20 00:39:53 +0000567 thread_plan_sp->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000568 }
569 }
570}
571
572void
573Thread::PopPlan ()
574{
Greg Claytone005f2c2010-11-06 01:53:30 +0000575 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000576
Jim Ingham6297a3a2010-10-20 00:39:53 +0000577 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000578 return;
579 else
580 {
581 ThreadPlanSP &plan = m_plan_stack.back();
582 if (log)
583 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000584 log->Printf("Popping plan: \"%s\", tid = 0x%4.4llx.", plan->GetName(), plan->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000585 }
586 m_completed_plan_stack.push_back (plan);
587 plan->WillPop();
588 m_plan_stack.pop_back();
589 }
590}
591
592void
593Thread::DiscardPlan ()
594{
595 if (m_plan_stack.size() > 1)
596 {
597 ThreadPlanSP &plan = m_plan_stack.back();
598 m_discarded_plan_stack.push_back (plan);
599 plan->WillPop();
600 m_plan_stack.pop_back();
601 }
602}
603
604ThreadPlan *
605Thread::GetCurrentPlan ()
606{
Jim Ingham6297a3a2010-10-20 00:39:53 +0000607 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000608 return NULL;
609 else
610 return m_plan_stack.back().get();
611}
612
613ThreadPlanSP
614Thread::GetCompletedPlan ()
615{
616 ThreadPlanSP empty_plan_sp;
617 if (!m_completed_plan_stack.empty())
618 {
619 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
620 {
621 ThreadPlanSP completed_plan_sp;
622 completed_plan_sp = m_completed_plan_stack[i];
623 if (!completed_plan_sp->GetPrivate ())
624 return completed_plan_sp;
625 }
626 }
627 return empty_plan_sp;
628}
629
Jim Ingham1586d972011-12-17 01:35:57 +0000630ValueObjectSP
631Thread::GetReturnValueObject ()
632{
633 if (!m_completed_plan_stack.empty())
634 {
635 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
636 {
637 ValueObjectSP return_valobj_sp;
638 return_valobj_sp = m_completed_plan_stack[i]->GetReturnValueObject();
639 if (return_valobj_sp)
640 return return_valobj_sp;
641 }
642 }
643 return ValueObjectSP();
644}
645
Chris Lattner24943d22010-06-08 16:52:24 +0000646bool
647Thread::IsThreadPlanDone (ThreadPlan *plan)
648{
Chris Lattner24943d22010-06-08 16:52:24 +0000649 if (!m_completed_plan_stack.empty())
650 {
651 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
652 {
653 if (m_completed_plan_stack[i].get() == plan)
654 return true;
655 }
656 }
657 return false;
658}
659
660bool
661Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
662{
Chris Lattner24943d22010-06-08 16:52:24 +0000663 if (!m_discarded_plan_stack.empty())
664 {
665 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
666 {
667 if (m_discarded_plan_stack[i].get() == plan)
668 return true;
669 }
670 }
671 return false;
672}
673
674ThreadPlan *
675Thread::GetPreviousPlan (ThreadPlan *current_plan)
676{
677 if (current_plan == NULL)
678 return NULL;
679
680 int stack_size = m_completed_plan_stack.size();
681 for (int i = stack_size - 1; i > 0; i--)
682 {
683 if (current_plan == m_completed_plan_stack[i].get())
684 return m_completed_plan_stack[i-1].get();
685 }
686
687 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
688 {
Chris Lattner24943d22010-06-08 16:52:24 +0000689 if (m_plan_stack.size() > 0)
690 return m_plan_stack.back().get();
691 else
692 return NULL;
693 }
694
695 stack_size = m_plan_stack.size();
696 for (int i = stack_size - 1; i > 0; i--)
697 {
698 if (current_plan == m_plan_stack[i].get())
699 return m_plan_stack[i-1].get();
700 }
701 return NULL;
702}
703
704void
705Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
706{
707 if (abort_other_plans)
708 DiscardThreadPlans(true);
709
710 PushPlan (thread_plan_sp);
711}
712
Jim Ingham745ac7a2010-11-11 19:26:09 +0000713
714void
715Thread::EnableTracer (bool value, bool single_stepping)
716{
717 int stack_size = m_plan_stack.size();
718 for (int i = 0; i < stack_size; i++)
719 {
720 if (m_plan_stack[i]->GetThreadPlanTracer())
721 {
722 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
723 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
724 }
725 }
726}
727
728void
729Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
730{
731 int stack_size = m_plan_stack.size();
732 for (int i = 0; i < stack_size; i++)
733 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
734}
735
Chris Lattner24943d22010-06-08 16:52:24 +0000736void
Jim Inghamea9d4262010-11-05 19:25:48 +0000737Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
738{
Greg Claytone005f2c2010-11-06 01:53:30 +0000739 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamea9d4262010-11-05 19:25:48 +0000740 if (log)
741 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000742 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 +0000743 }
744
745 int stack_size = m_plan_stack.size();
746
747 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
748 // stack, and if so discard up to and including it.
749
750 if (up_to_plan_sp.get() == NULL)
751 {
752 for (int i = stack_size - 1; i > 0; i--)
753 DiscardPlan();
754 }
755 else
756 {
757 bool found_it = false;
758 for (int i = stack_size - 1; i > 0; i--)
759 {
760 if (m_plan_stack[i] == up_to_plan_sp)
761 found_it = true;
762 }
763 if (found_it)
764 {
765 bool last_one = false;
766 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
767 {
768 if (GetCurrentPlan() == up_to_plan_sp.get())
769 last_one = true;
770 DiscardPlan();
771 }
772 }
773 }
774 return;
775}
776
777void
Chris Lattner24943d22010-06-08 16:52:24 +0000778Thread::DiscardThreadPlans(bool force)
779{
Greg Claytone005f2c2010-11-06 01:53:30 +0000780 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000781 if (log)
782 {
Greg Clayton444e35b2011-10-19 18:09:39 +0000783 log->Printf("Discarding thread plans for thread (tid = 0x%4.4llx, force %d)", GetID(), force);
Chris Lattner24943d22010-06-08 16:52:24 +0000784 }
785
786 if (force)
787 {
788 int stack_size = m_plan_stack.size();
789 for (int i = stack_size - 1; i > 0; i--)
790 {
791 DiscardPlan();
792 }
793 return;
794 }
795
796 while (1)
797 {
798
799 int master_plan_idx;
800 bool discard;
801
802 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
803 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
804 {
805 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
806 {
807 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
808 break;
809 }
810 }
811
812 if (discard)
813 {
814 // First pop all the dependent plans:
815 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
816 {
817
818 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
819 // for the plan leaves it in a state that it is safe to pop the plan
820 // with no more notice?
821 DiscardPlan();
822 }
823
824 // Now discard the master plan itself.
825 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
826 // discard it's dependent plans, but not it...
827 if (master_plan_idx > 0)
828 {
829 DiscardPlan();
830 }
831 }
832 else
833 {
834 // If the master plan doesn't want to get discarded, then we're done.
835 break;
836 }
837
838 }
Chris Lattner24943d22010-06-08 16:52:24 +0000839}
840
841ThreadPlan *
842Thread::QueueFundamentalPlan (bool abort_other_plans)
843{
844 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
845 QueueThreadPlan (thread_plan_sp, abort_other_plans);
846 return thread_plan_sp.get();
847}
848
849ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000850Thread::QueueThreadPlanForStepSingleInstruction
851(
852 bool step_over,
853 bool abort_other_plans,
854 bool stop_other_threads
855)
Chris Lattner24943d22010-06-08 16:52:24 +0000856{
857 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
858 QueueThreadPlan (thread_plan_sp, abort_other_plans);
859 return thread_plan_sp.get();
860}
861
862ThreadPlan *
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000863Thread::QueueThreadPlanForStepRange
864(
865 bool abort_other_plans,
866 StepType type,
867 const AddressRange &range,
868 const SymbolContext &addr_context,
869 lldb::RunMode stop_other_threads,
870 bool avoid_code_without_debug_info
871)
Chris Lattner24943d22010-06-08 16:52:24 +0000872{
873 ThreadPlanSP thread_plan_sp;
874 if (type == eStepTypeInto)
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000875 {
876 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
877 if (avoid_code_without_debug_info)
878 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
879 else
880 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
881 thread_plan_sp.reset (plan);
882 }
Chris Lattner24943d22010-06-08 16:52:24 +0000883 else
884 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
885
886 QueueThreadPlan (thread_plan_sp, abort_other_plans);
887 return thread_plan_sp.get();
888}
889
890
891ThreadPlan *
892Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
893{
894 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
895 QueueThreadPlan (thread_plan_sp, abort_other_plans);
896 return thread_plan_sp.get();
897}
898
899ThreadPlan *
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000900Thread::QueueThreadPlanForStepOut
901(
902 bool abort_other_plans,
903 SymbolContext *addr_context,
904 bool first_insn,
905 bool stop_other_threads,
906 Vote stop_vote,
907 Vote run_vote,
908 uint32_t frame_idx
909)
Chris Lattner24943d22010-06-08 16:52:24 +0000910{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000911 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this,
912 addr_context,
913 first_insn,
914 stop_other_threads,
915 stop_vote,
916 run_vote,
917 frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000918 QueueThreadPlan (thread_plan_sp, abort_other_plans);
919 return thread_plan_sp.get();
920}
921
922ThreadPlan *
923Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads)
924{
Jim Inghamad382c52011-12-03 01:52:59 +0000925 ThreadPlanSP thread_plan_sp(new ThreadPlanStepThrough (*this, stop_other_threads));
926 if (!thread_plan_sp || !thread_plan_sp->ValidatePlan (NULL))
927 return NULL;
928
Chris Lattner24943d22010-06-08 16:52:24 +0000929 QueueThreadPlan (thread_plan_sp, abort_other_plans);
930 return thread_plan_sp.get();
931}
932
933ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000934Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
935 Address& function,
936 lldb::addr_t arg,
937 bool stop_other_threads,
938 bool discard_on_error)
939{
Jim Ingham016ef882011-12-22 19:12:40 +0000940 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, ClangASTType(), arg, stop_other_threads, discard_on_error));
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::QueueThreadPlanForRunToAddress (bool abort_other_plans,
947 Address &target_addr,
948 bool stop_other_threads)
949{
950 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
951 QueueThreadPlan (thread_plan_sp, abort_other_plans);
952 return thread_plan_sp.get();
953}
954
955ThreadPlan *
956Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000957 lldb::addr_t *address_list,
958 size_t num_addresses,
959 bool stop_other_threads,
960 uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000961{
Greg Clayton1ebdcc72011-01-21 06:11:58 +0000962 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000963 QueueThreadPlan (thread_plan_sp, abort_other_plans);
964 return thread_plan_sp.get();
965
966}
967
968uint32_t
969Thread::GetIndexID () const
970{
971 return m_index_id;
972}
973
974void
975Thread::DumpThreadPlans (lldb_private::Stream *s) const
976{
977 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000978 int i;
Jim Inghame8f4e112011-10-15 00:23:43 +0000979 s->Indent();
Greg Clayton444e35b2011-10-19 18:09:39 +0000980 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 +0000981 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000982 {
Chris Lattner24943d22010-06-08 16:52:24 +0000983 s->IndentMore();
Jim Inghame8f4e112011-10-15 00:23:43 +0000984 s->Indent();
985 s->Printf ("Element %d: ", i);
Chris Lattner24943d22010-06-08 16:52:24 +0000986 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
Chris Lattner24943d22010-06-08 16:52:24 +0000987 s->EOL();
Jim Inghame8f4e112011-10-15 00:23:43 +0000988 s->IndentLess();
Chris Lattner24943d22010-06-08 16:52:24 +0000989 }
990
Chris Lattner24943d22010-06-08 16:52:24 +0000991 stack_size = m_completed_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +0000992 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +0000993 {
Jim Inghame8f4e112011-10-15 00:23:43 +0000994 s->Indent();
995 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
996 for (i = stack_size - 1; i >= 0; i--)
997 {
998 s->IndentMore();
999 s->Indent();
1000 s->Printf ("Element %d: ", i);
1001 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1002 s->EOL();
1003 s->IndentLess();
1004 }
Chris Lattner24943d22010-06-08 16:52:24 +00001005 }
1006
1007 stack_size = m_discarded_plan_stack.size();
Jim Inghame8f4e112011-10-15 00:23:43 +00001008 if (stack_size > 0)
Chris Lattner24943d22010-06-08 16:52:24 +00001009 {
Jim Inghame8f4e112011-10-15 00:23:43 +00001010 s->Indent();
1011 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
1012 for (i = stack_size - 1; i >= 0; i--)
1013 {
1014 s->IndentMore();
1015 s->Indent();
1016 s->Printf ("Element %d: ", i);
1017 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
1018 s->EOL();
1019 s->IndentLess();
1020 }
Chris Lattner24943d22010-06-08 16:52:24 +00001021 }
1022
1023}
1024
Greg Clayton289afcb2012-02-18 05:35:26 +00001025TargetSP
Chris Lattner24943d22010-06-08 16:52:24 +00001026Thread::CalculateTarget ()
1027{
Greg Claytonf4124de2012-02-21 00:09:25 +00001028 TargetSP target_sp;
1029 ProcessSP process_sp(GetProcess());
1030 if (process_sp)
1031 target_sp = process_sp->CalculateTarget();
1032 return target_sp;
1033
Chris Lattner24943d22010-06-08 16:52:24 +00001034}
1035
Greg Clayton289afcb2012-02-18 05:35:26 +00001036ProcessSP
Chris Lattner24943d22010-06-08 16:52:24 +00001037Thread::CalculateProcess ()
1038{
Greg Claytonf4124de2012-02-21 00:09:25 +00001039 return GetProcess();
Chris Lattner24943d22010-06-08 16:52:24 +00001040}
1041
Greg Clayton289afcb2012-02-18 05:35:26 +00001042ThreadSP
Chris Lattner24943d22010-06-08 16:52:24 +00001043Thread::CalculateThread ()
1044{
Greg Clayton289afcb2012-02-18 05:35:26 +00001045 return shared_from_this();
Chris Lattner24943d22010-06-08 16:52:24 +00001046}
1047
Greg Clayton289afcb2012-02-18 05:35:26 +00001048StackFrameSP
Chris Lattner24943d22010-06-08 16:52:24 +00001049Thread::CalculateStackFrame ()
1050{
Greg Clayton289afcb2012-02-18 05:35:26 +00001051 return StackFrameSP();
Chris Lattner24943d22010-06-08 16:52:24 +00001052}
1053
1054void
Greg Claytona830adb2010-10-04 01:05:56 +00001055Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +00001056{
Greg Claytonf4124de2012-02-21 00:09:25 +00001057 exe_ctx.SetContext (shared_from_this());
Chris Lattner24943d22010-06-08 16:52:24 +00001058}
1059
Greg Clayton782b9cc2010-08-25 00:35:26 +00001060
1061StackFrameList &
1062Thread::GetStackFrameList ()
1063{
Greg Claytonc51ffbf2011-08-12 21:40:01 +00001064 if (!m_curr_frames_sp)
1065 m_curr_frames_sp.reset (new StackFrameList (*this, m_prev_frames_sp, true));
1066 return *m_curr_frames_sp;
Greg Clayton782b9cc2010-08-25 00:35:26 +00001067}
1068
Greg Clayton782b9cc2010-08-25 00:35:26 +00001069void
1070Thread::ClearStackFrames ()
1071{
Greg Claytonc51ffbf2011-08-12 21:40:01 +00001072 if (m_curr_frames_sp && m_curr_frames_sp->GetNumFrames (false) > 1)
1073 m_prev_frames_sp.swap (m_curr_frames_sp);
1074 m_curr_frames_sp.reset();
Jim Ingham71219082010-08-12 02:14:28 +00001075}
1076
1077lldb::StackFrameSP
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001078Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1079{
1080 return GetStackFrameList().GetFrameWithConcreteFrameIndex (unwind_idx);
1081}
1082
Chris Lattner24943d22010-06-08 16:52:24 +00001083void
Greg Claytona830adb2010-10-04 01:05:56 +00001084Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +00001085{
Greg Claytonf4124de2012-02-21 00:09:25 +00001086 ExecutionContext exe_ctx (shared_from_this());
1087 Process *process = exe_ctx.GetProcessPtr();
1088 if (process == NULL)
1089 return;
1090
Greg Clayton567e7f32011-09-22 04:58:26 +00001091 StackFrameSP frame_sp;
Greg Claytona830adb2010-10-04 01:05:56 +00001092 SymbolContext frame_sc;
Greg Claytona830adb2010-10-04 01:05:56 +00001093 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +00001094 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001095 frame_sp = GetStackFrameAtIndex (frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001096 if (frame_sp)
1097 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001098 exe_ctx.SetFrameSP(frame_sp);
1099 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +00001100 }
1101 }
1102
Greg Claytonf4124de2012-02-21 00:09:25 +00001103 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001104 assert (thread_format);
1105 const char *end = NULL;
1106 Debugger::FormatPrompt (thread_format,
Greg Clayton567e7f32011-09-22 04:58:26 +00001107 frame_sp ? &frame_sc : NULL,
Greg Claytona830adb2010-10-04 01:05:56 +00001108 &exe_ctx,
1109 NULL,
1110 strm,
1111 &end);
Chris Lattner24943d22010-06-08 16:52:24 +00001112}
1113
Greg Clayton990de7b2010-11-18 23:32:35 +00001114void
Caroline Tice2a456812011-03-10 22:14:10 +00001115Thread::SettingsInitialize ()
Jim Ingham20594b12010-09-08 03:14:33 +00001116{
Greg Clayton334d33a2012-01-30 07:41:31 +00001117 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001118 SettingsController::global_settings_table,
1119 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001120
1121 // Now call SettingsInitialize() on each 'child' setting of Thread.
1122 // Currently there are none.
Greg Clayton990de7b2010-11-18 23:32:35 +00001123}
Jim Ingham20594b12010-09-08 03:14:33 +00001124
Greg Clayton990de7b2010-11-18 23:32:35 +00001125void
Caroline Tice2a456812011-03-10 22:14:10 +00001126Thread::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001127{
Caroline Tice2a456812011-03-10 22:14:10 +00001128 // Must call SettingsTerminate() on each 'child' setting of Thread before terminating Thread settings.
1129 // Currently there are none.
1130
1131 // Now terminate Thread Settings.
1132
Greg Clayton990de7b2010-11-18 23:32:35 +00001133 UserSettingsControllerSP &usc = GetSettingsController();
1134 UserSettingsController::FinalizeSettingsController (usc);
1135 usc.reset();
1136}
Jim Ingham20594b12010-09-08 03:14:33 +00001137
Greg Clayton990de7b2010-11-18 23:32:35 +00001138UserSettingsControllerSP &
1139Thread::GetSettingsController ()
1140{
Greg Clayton334d33a2012-01-30 07:41:31 +00001141 static UserSettingsControllerSP g_settings_controller_sp;
1142 if (!g_settings_controller_sp)
1143 {
1144 g_settings_controller_sp.reset (new Thread::SettingsController);
1145 // The first shared pointer to Target::SettingsController in
1146 // g_settings_controller_sp must be fully created above so that
1147 // the TargetInstanceSettings can use a weak_ptr to refer back
1148 // to the master setttings controller
1149 InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp,
1150 false,
1151 InstanceSettings::GetDefaultName().AsCString()));
1152
1153 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1154 }
1155 return g_settings_controller_sp;
Jim Ingham20594b12010-09-08 03:14:33 +00001156}
1157
Caroline Tice1ebef442010-09-27 00:30:10 +00001158void
1159Thread::UpdateInstanceName ()
1160{
1161 StreamString sstr;
1162 const char *name = GetName();
1163
1164 if (name && name[0] != '\0')
1165 sstr.Printf ("%s", name);
1166 else if ((GetIndexID() != 0) || (GetID() != 0))
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001167 sstr.Printf ("0x%4.4x", GetIndexID());
Caroline Tice1ebef442010-09-27 00:30:10 +00001168
1169 if (sstr.GetSize() > 0)
1170 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1171}
1172
Jim Inghamccd584d2010-09-23 17:40:12 +00001173lldb::StackFrameSP
1174Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
1175{
1176 return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr);
1177}
Caroline Tice7826c882010-10-26 03:11:13 +00001178
1179const char *
1180Thread::StopReasonAsCString (lldb::StopReason reason)
1181{
1182 switch (reason)
1183 {
1184 case eStopReasonInvalid: return "invalid";
1185 case eStopReasonNone: return "none";
1186 case eStopReasonTrace: return "trace";
1187 case eStopReasonBreakpoint: return "breakpoint";
1188 case eStopReasonWatchpoint: return "watchpoint";
1189 case eStopReasonSignal: return "signal";
1190 case eStopReasonException: return "exception";
1191 case eStopReasonPlanComplete: return "plan complete";
1192 }
1193
1194
1195 static char unknown_state_string[64];
1196 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
1197 return unknown_state_string;
1198}
1199
1200const char *
1201Thread::RunModeAsCString (lldb::RunMode mode)
1202{
1203 switch (mode)
1204 {
1205 case eOnlyThisThread: return "only this thread";
1206 case eAllThreads: return "all threads";
1207 case eOnlyDuringStepping: return "only during stepping";
1208 }
1209
1210 static char unknown_state_string[64];
1211 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1212 return unknown_state_string;
1213}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001214
Greg Claytonabe0fed2011-04-18 08:33:37 +00001215size_t
1216Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
1217{
Greg Claytonf4124de2012-02-21 00:09:25 +00001218 ExecutionContext exe_ctx (shared_from_this());
1219 Target *target = exe_ctx.GetTargetPtr();
1220 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001221 size_t num_frames_shown = 0;
1222 strm.Indent();
Greg Claytonf4124de2012-02-21 00:09:25 +00001223 bool is_selected = false;
1224 if (process)
1225 {
1226 if (process->GetThreadList().GetSelectedThread().get() == this)
1227 is_selected = true;
1228 }
1229 strm.Printf("%c ", is_selected ? '*' : ' ');
1230 if (target && target->GetDebugger().GetUseExternalEditor())
Greg Claytonabe0fed2011-04-18 08:33:37 +00001231 {
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001232 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001233 if (frame_sp)
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001234 {
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001235 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
1236 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
1237 {
1238 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
1239 }
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001240 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001241 }
1242
1243 DumpUsingSettingsFormat (strm, start_frame);
1244
1245 if (num_frames > 0)
1246 {
1247 strm.IndentMore();
1248
1249 const bool show_frame_info = true;
1250 const uint32_t source_lines_before = 3;
1251 const uint32_t source_lines_after = 3;
Jim Ingham7868bcc2011-07-26 02:39:59 +00001252 strm.IndentMore ();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001253 num_frames_shown = GetStackFrameList ().GetStatus (strm,
1254 start_frame,
1255 num_frames,
1256 show_frame_info,
1257 num_frames_with_source,
1258 source_lines_before,
1259 source_lines_after);
1260 strm.IndentLess();
Jim Ingham7868bcc2011-07-26 02:39:59 +00001261 strm.IndentLess();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001262 }
1263 return num_frames_shown;
1264}
1265
1266size_t
1267Thread::GetStackFrameStatus (Stream& strm,
1268 uint32_t first_frame,
1269 uint32_t num_frames,
1270 bool show_frame_info,
1271 uint32_t num_frames_with_source,
1272 uint32_t source_lines_before,
1273 uint32_t source_lines_after)
1274{
1275 return GetStackFrameList().GetStatus (strm,
1276 first_frame,
1277 num_frames,
1278 show_frame_info,
1279 num_frames_with_source,
1280 source_lines_before,
1281 source_lines_after);
1282}
1283
Peter Collingbournee426d852011-06-03 20:40:54 +00001284bool
1285Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint)
1286{
1287 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1288 if (frame_sp)
1289 {
1290 checkpoint.SetStackID(frame_sp->GetStackID());
1291 return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData());
1292 }
1293 return false;
1294}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001295
Peter Collingbournee426d852011-06-03 20:40:54 +00001296bool
1297Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint)
1298{
1299 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1300 if (frame_sp)
1301 {
1302 bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (checkpoint.GetData());
1303
1304 // Clear out all stack frames as our world just changed.
1305 ClearStackFrames();
1306 frame_sp->GetRegisterContext()->InvalidateIfNeeded(true);
1307
1308 return ret;
1309 }
1310 return false;
1311}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001312
Greg Clayton37f962e2011-08-22 02:49:39 +00001313Unwind *
1314Thread::GetUnwinder ()
1315{
1316 if (m_unwinder_ap.get() == NULL)
1317 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001318 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
Greg Clayton37f962e2011-08-22 02:49:39 +00001319 const llvm::Triple::ArchType machine = target_arch.GetMachine();
1320 switch (machine)
1321 {
1322 case llvm::Triple::x86_64:
1323 case llvm::Triple::x86:
1324 case llvm::Triple::arm:
1325 case llvm::Triple::thumb:
1326 m_unwinder_ap.reset (new UnwindLLDB (*this));
1327 break;
1328
1329 default:
1330 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
1331 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
1332 break;
1333 }
1334 }
1335 return m_unwinder_ap.get();
1336}
1337
1338
Greg Clayton990de7b2010-11-18 23:32:35 +00001339#pragma mark "Thread::SettingsController"
Jim Ingham745ac7a2010-11-11 19:26:09 +00001340//--------------------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001341// class Thread::SettingsController
Jim Ingham745ac7a2010-11-11 19:26:09 +00001342//--------------------------------------------------------------
1343
Greg Clayton990de7b2010-11-18 23:32:35 +00001344Thread::SettingsController::SettingsController () :
Jim Ingham745ac7a2010-11-11 19:26:09 +00001345 UserSettingsController ("thread", Process::GetSettingsController())
1346{
Jim Ingham745ac7a2010-11-11 19:26:09 +00001347}
1348
Greg Clayton990de7b2010-11-18 23:32:35 +00001349Thread::SettingsController::~SettingsController ()
Jim Ingham745ac7a2010-11-11 19:26:09 +00001350{
1351}
1352
1353lldb::InstanceSettingsSP
Greg Clayton990de7b2010-11-18 23:32:35 +00001354Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
Jim Ingham745ac7a2010-11-11 19:26:09 +00001355{
Greg Clayton334d33a2012-01-30 07:41:31 +00001356 lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(),
1357 false,
1358 instance_name));
Jim Ingham745ac7a2010-11-11 19:26:09 +00001359 return new_settings_sp;
1360}
1361
1362#pragma mark "ThreadInstanceSettings"
1363//--------------------------------------------------------------
1364// class ThreadInstanceSettings
1365//--------------------------------------------------------------
1366
Greg Clayton334d33a2012-01-30 07:41:31 +00001367ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) :
1368 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001369 m_avoid_regexp_ap (),
1370 m_trace_enabled (false)
1371{
1372 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1373 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1374 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1375 // This is true for CreateInstanceName() too.
1376
1377 if (GetInstanceName() == InstanceSettings::InvalidName())
1378 {
1379 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00001380 owner_sp->RegisterInstanceSettings (this);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001381 }
1382
1383 if (live_instance)
1384 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001385 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001386 }
1387}
1388
1389ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00001390 InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001391 m_avoid_regexp_ap (),
1392 m_trace_enabled (rhs.m_trace_enabled)
1393{
1394 if (m_instance_name != InstanceSettings::GetDefaultName())
1395 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001396 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
1397 if (owner_sp)
1398 {
1399 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
1400 owner_sp->RemovePendingSettings (m_instance_name);
1401 }
Jim Ingham745ac7a2010-11-11 19:26:09 +00001402 }
1403 if (rhs.m_avoid_regexp_ap.get() != NULL)
1404 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1405}
1406
1407ThreadInstanceSettings::~ThreadInstanceSettings ()
1408{
1409}
1410
1411ThreadInstanceSettings&
1412ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1413{
1414 if (this != &rhs)
1415 {
1416 if (rhs.m_avoid_regexp_ap.get() != NULL)
1417 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1418 else
1419 m_avoid_regexp_ap.reset(NULL);
1420 }
1421 m_trace_enabled = rhs.m_trace_enabled;
1422 return *this;
1423}
1424
1425
1426void
1427ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1428 const char *index_value,
1429 const char *value,
1430 const ConstString &instance_name,
1431 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001432 VarSetOperationType op,
Jim Ingham745ac7a2010-11-11 19:26:09 +00001433 Error &err,
1434 bool pending)
1435{
1436 if (var_name == StepAvoidRegexpVarName())
1437 {
1438 std::string regexp_text;
1439 if (m_avoid_regexp_ap.get() != NULL)
1440 regexp_text.append (m_avoid_regexp_ap->GetText());
1441 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1442 if (regexp_text.empty())
1443 m_avoid_regexp_ap.reset();
1444 else
1445 {
1446 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1447
1448 }
1449 }
1450 else if (var_name == GetTraceThreadVarName())
1451 {
1452 bool success;
1453 bool result = Args::StringToBoolean(value, false, &success);
1454
1455 if (success)
1456 {
1457 m_trace_enabled = result;
1458 if (!pending)
1459 {
1460 Thread *myself = static_cast<Thread *> (this);
1461 myself->EnableTracer(m_trace_enabled, true);
1462 }
1463 }
1464 else
1465 {
1466 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1467 }
1468
1469 }
1470}
1471
1472void
1473ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1474 bool pending)
1475{
1476 if (new_settings.get() == NULL)
1477 return;
1478
1479 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1480 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1481 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1482 else
1483 m_avoid_regexp_ap.reset ();
1484}
1485
1486bool
1487ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1488 const ConstString &var_name,
1489 StringList &value,
1490 Error *err)
1491{
1492 if (var_name == StepAvoidRegexpVarName())
1493 {
1494 if (m_avoid_regexp_ap.get() != NULL)
1495 {
1496 std::string regexp_text("\"");
1497 regexp_text.append(m_avoid_regexp_ap->GetText());
1498 regexp_text.append ("\"");
1499 value.AppendString (regexp_text.c_str());
1500 }
1501
1502 }
1503 else if (var_name == GetTraceThreadVarName())
1504 {
1505 value.AppendString(m_trace_enabled ? "true" : "false");
1506 }
1507 else
1508 {
1509 if (err)
1510 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1511 return false;
1512 }
1513 return true;
1514}
1515
1516const ConstString
1517ThreadInstanceSettings::CreateInstanceName ()
1518{
1519 static int instance_count = 1;
1520 StreamString sstr;
1521
1522 sstr.Printf ("thread_%d", instance_count);
1523 ++instance_count;
1524
1525 const ConstString ret_val (sstr.GetData());
1526 return ret_val;
1527}
1528
1529const ConstString &
1530ThreadInstanceSettings::StepAvoidRegexpVarName ()
1531{
1532 static ConstString step_avoid_var_name ("step-avoid-regexp");
1533
1534 return step_avoid_var_name;
1535}
1536
1537const ConstString &
1538ThreadInstanceSettings::GetTraceThreadVarName ()
1539{
1540 static ConstString trace_thread_var_name ("trace-thread");
1541
1542 return trace_thread_var_name;
1543}
1544
1545//--------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001546// SettingsController Variable Tables
Jim Ingham745ac7a2010-11-11 19:26:09 +00001547//--------------------------------------------------
1548
1549SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001550Thread::SettingsController::global_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001551{
1552 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1553 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1554};
1555
1556
1557SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001558Thread::SettingsController::instance_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001559{
1560 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1561 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1562 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1563 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1564};