blob: 7a5e7f0e918e0cbec0f7928ee767b341e1d53f6c [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{
Jim Inghambf97d742012-02-29 03:40:22 +00001072 // Only store away the old "reference" StackFrameList if we got all its frames:
1073 // FIXME: At some point we can try to splice in the frames we have fetched into
1074 // the new frame as we make it, but let's not try that now.
1075 if (m_curr_frames_sp && m_curr_frames_sp->GetAllFramesFetched())
Greg Claytonc51ffbf2011-08-12 21:40:01 +00001076 m_prev_frames_sp.swap (m_curr_frames_sp);
1077 m_curr_frames_sp.reset();
Jim Ingham71219082010-08-12 02:14:28 +00001078}
1079
1080lldb::StackFrameSP
Greg Clayton08d7d3a2011-01-06 22:15:06 +00001081Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
1082{
1083 return GetStackFrameList().GetFrameWithConcreteFrameIndex (unwind_idx);
1084}
1085
Chris Lattner24943d22010-06-08 16:52:24 +00001086void
Greg Claytona830adb2010-10-04 01:05:56 +00001087Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +00001088{
Greg Claytonf4124de2012-02-21 00:09:25 +00001089 ExecutionContext exe_ctx (shared_from_this());
1090 Process *process = exe_ctx.GetProcessPtr();
1091 if (process == NULL)
1092 return;
1093
Greg Clayton567e7f32011-09-22 04:58:26 +00001094 StackFrameSP frame_sp;
Greg Claytona830adb2010-10-04 01:05:56 +00001095 SymbolContext frame_sc;
Greg Claytona830adb2010-10-04 01:05:56 +00001096 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +00001097 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001098 frame_sp = GetStackFrameAtIndex (frame_idx);
Chris Lattner24943d22010-06-08 16:52:24 +00001099 if (frame_sp)
1100 {
Greg Clayton567e7f32011-09-22 04:58:26 +00001101 exe_ctx.SetFrameSP(frame_sp);
1102 frame_sc = frame_sp->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +00001103 }
1104 }
1105
Greg Claytonf4124de2012-02-21 00:09:25 +00001106 const char *thread_format = exe_ctx.GetTargetRef().GetDebugger().GetThreadFormat();
Greg Claytona830adb2010-10-04 01:05:56 +00001107 assert (thread_format);
1108 const char *end = NULL;
1109 Debugger::FormatPrompt (thread_format,
Greg Clayton567e7f32011-09-22 04:58:26 +00001110 frame_sp ? &frame_sc : NULL,
Greg Claytona830adb2010-10-04 01:05:56 +00001111 &exe_ctx,
1112 NULL,
1113 strm,
1114 &end);
Chris Lattner24943d22010-06-08 16:52:24 +00001115}
1116
Greg Clayton990de7b2010-11-18 23:32:35 +00001117void
Caroline Tice2a456812011-03-10 22:14:10 +00001118Thread::SettingsInitialize ()
Jim Ingham20594b12010-09-08 03:14:33 +00001119{
Greg Clayton334d33a2012-01-30 07:41:31 +00001120 UserSettingsController::InitializeSettingsController (GetSettingsController(),
Greg Clayton990de7b2010-11-18 23:32:35 +00001121 SettingsController::global_settings_table,
1122 SettingsController::instance_settings_table);
Caroline Tice2a456812011-03-10 22:14:10 +00001123
1124 // Now call SettingsInitialize() on each 'child' setting of Thread.
1125 // Currently there are none.
Greg Clayton990de7b2010-11-18 23:32:35 +00001126}
Jim Ingham20594b12010-09-08 03:14:33 +00001127
Greg Clayton990de7b2010-11-18 23:32:35 +00001128void
Caroline Tice2a456812011-03-10 22:14:10 +00001129Thread::SettingsTerminate ()
Greg Clayton990de7b2010-11-18 23:32:35 +00001130{
Caroline Tice2a456812011-03-10 22:14:10 +00001131 // Must call SettingsTerminate() on each 'child' setting of Thread before terminating Thread settings.
1132 // Currently there are none.
1133
1134 // Now terminate Thread Settings.
1135
Greg Clayton990de7b2010-11-18 23:32:35 +00001136 UserSettingsControllerSP &usc = GetSettingsController();
1137 UserSettingsController::FinalizeSettingsController (usc);
1138 usc.reset();
1139}
Jim Ingham20594b12010-09-08 03:14:33 +00001140
Greg Clayton990de7b2010-11-18 23:32:35 +00001141UserSettingsControllerSP &
1142Thread::GetSettingsController ()
1143{
Greg Clayton334d33a2012-01-30 07:41:31 +00001144 static UserSettingsControllerSP g_settings_controller_sp;
1145 if (!g_settings_controller_sp)
1146 {
1147 g_settings_controller_sp.reset (new Thread::SettingsController);
1148 // The first shared pointer to Target::SettingsController in
1149 // g_settings_controller_sp must be fully created above so that
1150 // the TargetInstanceSettings can use a weak_ptr to refer back
1151 // to the master setttings controller
1152 InstanceSettingsSP default_instance_settings_sp (new ThreadInstanceSettings (g_settings_controller_sp,
1153 false,
1154 InstanceSettings::GetDefaultName().AsCString()));
1155
1156 g_settings_controller_sp->SetDefaultInstanceSettings (default_instance_settings_sp);
1157 }
1158 return g_settings_controller_sp;
Jim Ingham20594b12010-09-08 03:14:33 +00001159}
1160
Caroline Tice1ebef442010-09-27 00:30:10 +00001161void
1162Thread::UpdateInstanceName ()
1163{
1164 StreamString sstr;
1165 const char *name = GetName();
1166
1167 if (name && name[0] != '\0')
1168 sstr.Printf ("%s", name);
1169 else if ((GetIndexID() != 0) || (GetID() != 0))
Jason Molenda7e5fa7f2011-09-20 21:44:10 +00001170 sstr.Printf ("0x%4.4x", GetIndexID());
Caroline Tice1ebef442010-09-27 00:30:10 +00001171
1172 if (sstr.GetSize() > 0)
1173 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
1174}
1175
Jim Inghamccd584d2010-09-23 17:40:12 +00001176lldb::StackFrameSP
1177Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
1178{
1179 return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr);
1180}
Caroline Tice7826c882010-10-26 03:11:13 +00001181
1182const char *
1183Thread::StopReasonAsCString (lldb::StopReason reason)
1184{
1185 switch (reason)
1186 {
1187 case eStopReasonInvalid: return "invalid";
1188 case eStopReasonNone: return "none";
1189 case eStopReasonTrace: return "trace";
1190 case eStopReasonBreakpoint: return "breakpoint";
1191 case eStopReasonWatchpoint: return "watchpoint";
1192 case eStopReasonSignal: return "signal";
1193 case eStopReasonException: return "exception";
1194 case eStopReasonPlanComplete: return "plan complete";
1195 }
1196
1197
1198 static char unknown_state_string[64];
1199 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
1200 return unknown_state_string;
1201}
1202
1203const char *
1204Thread::RunModeAsCString (lldb::RunMode mode)
1205{
1206 switch (mode)
1207 {
1208 case eOnlyThisThread: return "only this thread";
1209 case eAllThreads: return "all threads";
1210 case eOnlyDuringStepping: return "only during stepping";
1211 }
1212
1213 static char unknown_state_string[64];
1214 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1215 return unknown_state_string;
1216}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001217
Greg Claytonabe0fed2011-04-18 08:33:37 +00001218size_t
1219Thread::GetStatus (Stream &strm, uint32_t start_frame, uint32_t num_frames, uint32_t num_frames_with_source)
1220{
Greg Claytonf4124de2012-02-21 00:09:25 +00001221 ExecutionContext exe_ctx (shared_from_this());
1222 Target *target = exe_ctx.GetTargetPtr();
1223 Process *process = exe_ctx.GetProcessPtr();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001224 size_t num_frames_shown = 0;
1225 strm.Indent();
Greg Claytonf4124de2012-02-21 00:09:25 +00001226 bool is_selected = false;
1227 if (process)
1228 {
1229 if (process->GetThreadList().GetSelectedThread().get() == this)
1230 is_selected = true;
1231 }
1232 strm.Printf("%c ", is_selected ? '*' : ' ');
1233 if (target && target->GetDebugger().GetUseExternalEditor())
Greg Claytonabe0fed2011-04-18 08:33:37 +00001234 {
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001235 StackFrameSP frame_sp = GetStackFrameAtIndex(start_frame);
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001236 if (frame_sp)
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001237 {
Jim Inghamc2da8eb2011-08-16 00:07:28 +00001238 SymbolContext frame_sc(frame_sp->GetSymbolContext (eSymbolContextLineEntry));
1239 if (frame_sc.line_entry.line != 0 && frame_sc.line_entry.file)
1240 {
1241 Host::OpenFileInExternalEditor (frame_sc.line_entry.file, frame_sc.line_entry.line);
1242 }
Greg Claytonc5dca6c2011-08-12 06:47:54 +00001243 }
Greg Claytonabe0fed2011-04-18 08:33:37 +00001244 }
1245
1246 DumpUsingSettingsFormat (strm, start_frame);
1247
1248 if (num_frames > 0)
1249 {
1250 strm.IndentMore();
1251
1252 const bool show_frame_info = true;
1253 const uint32_t source_lines_before = 3;
1254 const uint32_t source_lines_after = 3;
Jim Ingham7868bcc2011-07-26 02:39:59 +00001255 strm.IndentMore ();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001256 num_frames_shown = GetStackFrameList ().GetStatus (strm,
1257 start_frame,
1258 num_frames,
1259 show_frame_info,
1260 num_frames_with_source,
1261 source_lines_before,
1262 source_lines_after);
1263 strm.IndentLess();
Jim Ingham7868bcc2011-07-26 02:39:59 +00001264 strm.IndentLess();
Greg Claytonabe0fed2011-04-18 08:33:37 +00001265 }
1266 return num_frames_shown;
1267}
1268
1269size_t
1270Thread::GetStackFrameStatus (Stream& strm,
1271 uint32_t first_frame,
1272 uint32_t num_frames,
1273 bool show_frame_info,
1274 uint32_t num_frames_with_source,
1275 uint32_t source_lines_before,
1276 uint32_t source_lines_after)
1277{
1278 return GetStackFrameList().GetStatus (strm,
1279 first_frame,
1280 num_frames,
1281 show_frame_info,
1282 num_frames_with_source,
1283 source_lines_before,
1284 source_lines_after);
1285}
1286
Peter Collingbournee426d852011-06-03 20:40:54 +00001287bool
1288Thread::SaveFrameZeroState (RegisterCheckpoint &checkpoint)
1289{
1290 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1291 if (frame_sp)
1292 {
1293 checkpoint.SetStackID(frame_sp->GetStackID());
1294 return frame_sp->GetRegisterContext()->ReadAllRegisterValues (checkpoint.GetData());
1295 }
1296 return false;
1297}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001298
Peter Collingbournee426d852011-06-03 20:40:54 +00001299bool
1300Thread::RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint)
1301{
1302 lldb::StackFrameSP frame_sp(GetStackFrameAtIndex (0));
1303 if (frame_sp)
1304 {
1305 bool ret = frame_sp->GetRegisterContext()->WriteAllRegisterValues (checkpoint.GetData());
1306
1307 // Clear out all stack frames as our world just changed.
1308 ClearStackFrames();
1309 frame_sp->GetRegisterContext()->InvalidateIfNeeded(true);
1310
1311 return ret;
1312 }
1313 return false;
1314}
Greg Claytonabe0fed2011-04-18 08:33:37 +00001315
Greg Clayton37f962e2011-08-22 02:49:39 +00001316Unwind *
1317Thread::GetUnwinder ()
1318{
1319 if (m_unwinder_ap.get() == NULL)
1320 {
Greg Claytonf4124de2012-02-21 00:09:25 +00001321 const ArchSpec target_arch (CalculateTarget()->GetArchitecture ());
Greg Clayton37f962e2011-08-22 02:49:39 +00001322 const llvm::Triple::ArchType machine = target_arch.GetMachine();
1323 switch (machine)
1324 {
1325 case llvm::Triple::x86_64:
1326 case llvm::Triple::x86:
1327 case llvm::Triple::arm:
1328 case llvm::Triple::thumb:
1329 m_unwinder_ap.reset (new UnwindLLDB (*this));
1330 break;
1331
1332 default:
1333 if (target_arch.GetTriple().getVendor() == llvm::Triple::Apple)
1334 m_unwinder_ap.reset (new UnwindMacOSXFrameBackchain (*this));
1335 break;
1336 }
1337 }
1338 return m_unwinder_ap.get();
1339}
1340
1341
Greg Clayton990de7b2010-11-18 23:32:35 +00001342#pragma mark "Thread::SettingsController"
Jim Ingham745ac7a2010-11-11 19:26:09 +00001343//--------------------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001344// class Thread::SettingsController
Jim Ingham745ac7a2010-11-11 19:26:09 +00001345//--------------------------------------------------------------
1346
Greg Clayton990de7b2010-11-18 23:32:35 +00001347Thread::SettingsController::SettingsController () :
Jim Ingham745ac7a2010-11-11 19:26:09 +00001348 UserSettingsController ("thread", Process::GetSettingsController())
1349{
Jim Ingham745ac7a2010-11-11 19:26:09 +00001350}
1351
Greg Clayton990de7b2010-11-18 23:32:35 +00001352Thread::SettingsController::~SettingsController ()
Jim Ingham745ac7a2010-11-11 19:26:09 +00001353{
1354}
1355
1356lldb::InstanceSettingsSP
Greg Clayton990de7b2010-11-18 23:32:35 +00001357Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
Jim Ingham745ac7a2010-11-11 19:26:09 +00001358{
Greg Clayton334d33a2012-01-30 07:41:31 +00001359 lldb::InstanceSettingsSP new_settings_sp (new ThreadInstanceSettings (GetSettingsController(),
1360 false,
1361 instance_name));
Jim Ingham745ac7a2010-11-11 19:26:09 +00001362 return new_settings_sp;
1363}
1364
1365#pragma mark "ThreadInstanceSettings"
1366//--------------------------------------------------------------
1367// class ThreadInstanceSettings
1368//--------------------------------------------------------------
1369
Greg Clayton334d33a2012-01-30 07:41:31 +00001370ThreadInstanceSettings::ThreadInstanceSettings (const UserSettingsControllerSP &owner_sp, bool live_instance, const char *name) :
1371 InstanceSettings (owner_sp, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001372 m_avoid_regexp_ap (),
1373 m_trace_enabled (false)
1374{
1375 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1376 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1377 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1378 // This is true for CreateInstanceName() too.
1379
1380 if (GetInstanceName() == InstanceSettings::InvalidName())
1381 {
1382 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
Greg Clayton334d33a2012-01-30 07:41:31 +00001383 owner_sp->RegisterInstanceSettings (this);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001384 }
1385
1386 if (live_instance)
1387 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001388 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name),false);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001389 }
1390}
1391
1392ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
Greg Clayton334d33a2012-01-30 07:41:31 +00001393 InstanceSettings (Thread::GetSettingsController(), CreateInstanceName().AsCString()),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001394 m_avoid_regexp_ap (),
1395 m_trace_enabled (rhs.m_trace_enabled)
1396{
1397 if (m_instance_name != InstanceSettings::GetDefaultName())
1398 {
Greg Clayton334d33a2012-01-30 07:41:31 +00001399 UserSettingsControllerSP owner_sp (m_owner_wp.lock());
1400 if (owner_sp)
1401 {
1402 CopyInstanceSettings (owner_sp->FindPendingSettings (m_instance_name), false);
1403 owner_sp->RemovePendingSettings (m_instance_name);
1404 }
Jim Ingham745ac7a2010-11-11 19:26:09 +00001405 }
1406 if (rhs.m_avoid_regexp_ap.get() != NULL)
1407 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1408}
1409
1410ThreadInstanceSettings::~ThreadInstanceSettings ()
1411{
1412}
1413
1414ThreadInstanceSettings&
1415ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1416{
1417 if (this != &rhs)
1418 {
1419 if (rhs.m_avoid_regexp_ap.get() != NULL)
1420 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1421 else
1422 m_avoid_regexp_ap.reset(NULL);
1423 }
1424 m_trace_enabled = rhs.m_trace_enabled;
1425 return *this;
1426}
1427
1428
1429void
1430ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1431 const char *index_value,
1432 const char *value,
1433 const ConstString &instance_name,
1434 const SettingEntry &entry,
Greg Claytonb3448432011-03-24 21:19:54 +00001435 VarSetOperationType op,
Jim Ingham745ac7a2010-11-11 19:26:09 +00001436 Error &err,
1437 bool pending)
1438{
1439 if (var_name == StepAvoidRegexpVarName())
1440 {
1441 std::string regexp_text;
1442 if (m_avoid_regexp_ap.get() != NULL)
1443 regexp_text.append (m_avoid_regexp_ap->GetText());
1444 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1445 if (regexp_text.empty())
1446 m_avoid_regexp_ap.reset();
1447 else
1448 {
1449 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1450
1451 }
1452 }
1453 else if (var_name == GetTraceThreadVarName())
1454 {
1455 bool success;
1456 bool result = Args::StringToBoolean(value, false, &success);
1457
1458 if (success)
1459 {
1460 m_trace_enabled = result;
1461 if (!pending)
1462 {
1463 Thread *myself = static_cast<Thread *> (this);
1464 myself->EnableTracer(m_trace_enabled, true);
1465 }
1466 }
1467 else
1468 {
1469 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1470 }
1471
1472 }
1473}
1474
1475void
1476ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1477 bool pending)
1478{
1479 if (new_settings.get() == NULL)
1480 return;
1481
1482 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1483 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1484 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1485 else
1486 m_avoid_regexp_ap.reset ();
1487}
1488
1489bool
1490ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1491 const ConstString &var_name,
1492 StringList &value,
1493 Error *err)
1494{
1495 if (var_name == StepAvoidRegexpVarName())
1496 {
1497 if (m_avoid_regexp_ap.get() != NULL)
1498 {
1499 std::string regexp_text("\"");
1500 regexp_text.append(m_avoid_regexp_ap->GetText());
1501 regexp_text.append ("\"");
1502 value.AppendString (regexp_text.c_str());
1503 }
1504
1505 }
1506 else if (var_name == GetTraceThreadVarName())
1507 {
1508 value.AppendString(m_trace_enabled ? "true" : "false");
1509 }
1510 else
1511 {
1512 if (err)
1513 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1514 return false;
1515 }
1516 return true;
1517}
1518
1519const ConstString
1520ThreadInstanceSettings::CreateInstanceName ()
1521{
1522 static int instance_count = 1;
1523 StreamString sstr;
1524
1525 sstr.Printf ("thread_%d", instance_count);
1526 ++instance_count;
1527
1528 const ConstString ret_val (sstr.GetData());
1529 return ret_val;
1530}
1531
1532const ConstString &
1533ThreadInstanceSettings::StepAvoidRegexpVarName ()
1534{
1535 static ConstString step_avoid_var_name ("step-avoid-regexp");
1536
1537 return step_avoid_var_name;
1538}
1539
1540const ConstString &
1541ThreadInstanceSettings::GetTraceThreadVarName ()
1542{
1543 static ConstString trace_thread_var_name ("trace-thread");
1544
1545 return trace_thread_var_name;
1546}
1547
1548//--------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001549// SettingsController Variable Tables
Jim Ingham745ac7a2010-11-11 19:26:09 +00001550//--------------------------------------------------
1551
1552SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001553Thread::SettingsController::global_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001554{
1555 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1556 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1557};
1558
1559
1560SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001561Thread::SettingsController::instance_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001562{
1563 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1564 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1565 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1566 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1567};