blob: 80434cf33f2972a7890c54d2fc7e009826424251 [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"
Chris Lattner24943d22010-06-08 16:52:24 +000017#include "lldb/Host/Host.h"
18#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"
Chris Lattner24943d22010-06-08 16:52:24 +000039
40using namespace lldb;
41using namespace lldb_private;
42
43Thread::Thread (Process &process, lldb::tid_t tid) :
44 UserID (tid),
Jim Ingham20594b12010-09-08 03:14:33 +000045 ThreadInstanceSettings (*(Thread::GetSettingsController().get())),
Benjamin Kramer36a08102010-07-16 12:32:33 +000046 m_process (process),
Greg Clayton643ee732010-08-04 01:40:35 +000047 m_actual_stop_info_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000048 m_index_id (process.GetNextThreadIndexID ()),
49 m_reg_context_sp (),
Chris Lattner24943d22010-06-08 16:52:24 +000050 m_state (eStateUnloaded),
Greg Clayton782b9cc2010-08-25 00:35:26 +000051 m_state_mutex (Mutex::eMutexTypeRecursive),
Chris Lattner24943d22010-06-08 16:52:24 +000052 m_plan_stack (),
Chris Lattner24943d22010-06-08 16:52:24 +000053 m_completed_plan_stack(),
Greg Claytonf40e3082010-08-26 02:28:22 +000054 m_curr_frames_ap (),
Chris Lattner24943d22010-06-08 16:52:24 +000055 m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER),
Jim Ingham71219082010-08-12 02:14:28 +000056 m_resume_state (eStateRunning),
57 m_unwinder_ap ()
58
Chris Lattner24943d22010-06-08 16:52:24 +000059{
Greg Claytone005f2c2010-11-06 01:53:30 +000060 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000061 if (log)
62 log->Printf ("%p Thread::Thread(tid = 0x%4.4x)", this, GetID());
63
64 QueueFundamentalPlan(true);
Caroline Tice1ebef442010-09-27 00:30:10 +000065 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +000066}
67
68
69Thread::~Thread()
70{
Greg Claytone005f2c2010-11-06 01:53:30 +000071 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000072 if (log)
73 log->Printf ("%p Thread::~Thread(tid = 0x%4.4x)", this, GetID());
74}
75
76int
77Thread::GetResumeSignal () const
78{
79 return m_resume_signal;
80}
81
82void
83Thread::SetResumeSignal (int signal)
84{
85 m_resume_signal = signal;
86}
87
88StateType
89Thread::GetResumeState () const
90{
91 return m_resume_state;
92}
93
94void
95Thread::SetResumeState (StateType state)
96{
97 m_resume_state = state;
98}
99
Jim Ingham6297a3a2010-10-20 00:39:53 +0000100lldb::StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +0000101Thread::GetStopInfo ()
Chris Lattner24943d22010-06-08 16:52:24 +0000102{
Jim Ingham6297a3a2010-10-20 00:39:53 +0000103 ThreadPlanSP plan_sp (GetCompletedPlan());
104 if (plan_sp)
105 return StopInfo::CreateStopReasonWithPlan (plan_sp);
106 else
107 return GetPrivateStopReason ();
Chris Lattner24943d22010-06-08 16:52:24 +0000108}
109
110bool
111Thread::ThreadStoppedForAReason (void)
112{
Greg Clayton643ee732010-08-04 01:40:35 +0000113 return GetPrivateStopReason () != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000114}
115
116StateType
117Thread::GetState() const
118{
119 // If any other threads access this we will need a mutex for it
120 Mutex::Locker locker(m_state_mutex);
121 return m_state;
122}
123
124void
125Thread::SetState(StateType state)
126{
127 Mutex::Locker locker(m_state_mutex);
128 m_state = state;
129}
130
131void
132Thread::WillStop()
133{
134 ThreadPlan *current_plan = GetCurrentPlan();
135
136 // FIXME: I may decide to disallow threads with no plans. In which
137 // case this should go to an assert.
138
139 if (!current_plan)
140 return;
141
142 current_plan->WillStop();
143}
144
145void
146Thread::SetupForResume ()
147{
148 if (GetResumeState() != eStateSuspended)
149 {
150
151 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
152 // telling the current plan it will resume, since we might change what the current
153 // plan is.
154
155 lldb::addr_t pc = GetRegisterContext()->GetPC();
156 BreakpointSiteSP bp_site_sp = GetProcess().GetBreakpointSiteList().FindByAddress(pc);
157 if (bp_site_sp && bp_site_sp->IsEnabled())
158 {
159 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
160 // special to step over a breakpoint.
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000161
162 ThreadPlan *cur_plan = GetCurrentPlan();
Chris Lattner24943d22010-06-08 16:52:24 +0000163
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000164 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
165 {
166 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
167 if (step_bp_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000168 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000169 ThreadPlanSP step_bp_plan_sp;
170 step_bp_plan->SetPrivate (true);
171
Chris Lattner24943d22010-06-08 16:52:24 +0000172 if (GetCurrentPlan()->RunState() != eStateStepping)
173 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000174 step_bp_plan->SetAutoContinue(true);
Chris Lattner24943d22010-06-08 16:52:24 +0000175 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000176 step_bp_plan_sp.reset (step_bp_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000177 QueueThreadPlan (step_bp_plan_sp, false);
178 }
179 }
180 }
181 }
182}
183
184bool
185Thread::WillResume (StateType resume_state)
186{
187 // At this point clear the completed plan stack.
188 m_completed_plan_stack.clear();
189 m_discarded_plan_stack.clear();
190
Greg Clayton643ee732010-08-04 01:40:35 +0000191 StopInfo *stop_info = GetPrivateStopReason().get();
192 if (stop_info)
193 stop_info->WillResume (resume_state);
Chris Lattner24943d22010-06-08 16:52:24 +0000194
195 // Tell all the plans that we are about to resume in case they need to clear any state.
196 // We distinguish between the plan on the top of the stack and the lower
197 // plans in case a plan needs to do any special business before it runs.
198
199 ThreadPlan *plan_ptr = GetCurrentPlan();
200 plan_ptr->WillResume(resume_state, true);
201
202 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
203 {
204 plan_ptr->WillResume (resume_state, false);
205 }
Greg Clayton643ee732010-08-04 01:40:35 +0000206
Greg Clayton643ee732010-08-04 01:40:35 +0000207 m_actual_stop_info_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000208 return true;
209}
210
211void
212Thread::DidResume ()
213{
214 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
215}
216
217bool
218Thread::ShouldStop (Event* event_ptr)
219{
220 ThreadPlan *current_plan = GetCurrentPlan();
221 bool should_stop = true;
222
Greg Claytone005f2c2010-11-06 01:53:30 +0000223 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000224 if (log)
225 {
226 StreamString s;
227 DumpThreadPlans(&s);
228 log->PutCString (s.GetData());
229 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000230
231 // The top most plan always gets to do the trace log...
232 current_plan->DoTraceLog ();
Chris Lattner24943d22010-06-08 16:52:24 +0000233
234 if (current_plan->PlanExplainsStop())
235 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000236 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +0000237 while (1)
238 {
239 should_stop = current_plan->ShouldStop(event_ptr);
240 if (current_plan->MischiefManaged())
241 {
242 if (should_stop)
243 current_plan->WillStop();
244
245 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
246 // Otherwise, see if the plan's parent wants to stop.
247
248 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
249 {
250 PopPlan();
251 break;
252 }
253 else
254 {
255
256 PopPlan();
257
258 current_plan = GetCurrentPlan();
259 if (current_plan == NULL)
260 {
261 break;
262 }
263 }
264
265 }
266 else
267 {
268 break;
269 }
270 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000271 if (over_ride_stop)
272 should_stop = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000273 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000274 else if (current_plan->TracerExplainsStop())
275 {
276 return false;
277 }
Chris Lattner24943d22010-06-08 16:52:24 +0000278 else
279 {
280 // If the current plan doesn't explain the stop, then, find one that
281 // does and let it handle the situation.
282 ThreadPlan *plan_ptr = current_plan;
283 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
284 {
285 if (plan_ptr->PlanExplainsStop())
286 {
287 should_stop = plan_ptr->ShouldStop (event_ptr);
288 break;
289 }
290
291 }
292 }
293
294 return should_stop;
295}
296
297Vote
298Thread::ShouldReportStop (Event* event_ptr)
299{
300 StateType thread_state = GetResumeState ();
Greg Claytone005f2c2010-11-06 01:53:30 +0000301 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton5205f0b2010-09-03 17:10:42 +0000302
303 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
304 {
305 if (log)
306 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion);
Chris Lattner24943d22010-06-08 16:52:24 +0000307 return eVoteNoOpinion;
Greg Clayton5205f0b2010-09-03 17:10:42 +0000308 }
Chris Lattner24943d22010-06-08 16:52:24 +0000309
310 if (m_completed_plan_stack.size() > 0)
311 {
312 // Don't use GetCompletedPlan here, since that suppresses private plans.
Greg Clayton5205f0b2010-09-03 17:10:42 +0000313 if (log)
314 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote for complete stack's back plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000315 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
316 }
317 else
Greg Clayton5205f0b2010-09-03 17:10:42 +0000318 {
319 if (log)
320 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote for current plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000321 return GetCurrentPlan()->ShouldReportStop (event_ptr);
Greg Clayton5205f0b2010-09-03 17:10:42 +0000322 }
Chris Lattner24943d22010-06-08 16:52:24 +0000323}
324
325Vote
326Thread::ShouldReportRun (Event* event_ptr)
327{
328 StateType thread_state = GetResumeState ();
329 if (thread_state == eStateSuspended
330 || thread_state == eStateInvalid)
331 return eVoteNoOpinion;
332
333 if (m_completed_plan_stack.size() > 0)
334 {
335 // Don't use GetCompletedPlan here, since that suppresses private plans.
336 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
337 }
338 else
339 return GetCurrentPlan()->ShouldReportRun (event_ptr);
340}
341
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000342bool
343Thread::MatchesSpec (const ThreadSpec *spec)
344{
345 if (spec == NULL)
346 return true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000347
Jim Ingham649492b2010-06-18 01:00:58 +0000348 return spec->ThreadPassesBasicTests(this);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000349}
350
Chris Lattner24943d22010-06-08 16:52:24 +0000351void
352Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
353{
354 if (thread_plan_sp)
355 {
Jim Ingham745ac7a2010-11-11 19:26:09 +0000356 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
357 if (!thread_plan_sp->GetThreadPlanTracer())
358 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000359 m_plan_stack.push_back (thread_plan_sp);
Jim Ingham745ac7a2010-11-11 19:26:09 +0000360
Chris Lattner24943d22010-06-08 16:52:24 +0000361 thread_plan_sp->DidPush();
362
Greg Claytone005f2c2010-11-06 01:53:30 +0000363 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000364 if (log)
365 {
366 StreamString s;
367 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
Jim Ingham6297a3a2010-10-20 00:39:53 +0000368 log->Printf("Pushing plan: \"%s\", tid = 0x%4.4x.",
Chris Lattner24943d22010-06-08 16:52:24 +0000369 s.GetData(),
Jim Ingham6297a3a2010-10-20 00:39:53 +0000370 thread_plan_sp->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000371 }
372 }
373}
374
375void
376Thread::PopPlan ()
377{
Greg Claytone005f2c2010-11-06 01:53:30 +0000378 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000379
Jim Ingham6297a3a2010-10-20 00:39:53 +0000380 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000381 return;
382 else
383 {
384 ThreadPlanSP &plan = m_plan_stack.back();
385 if (log)
386 {
Jim Ingham83e8b9d2010-11-10 18:17:03 +0000387 log->Printf("Popping plan: \"%s\", tid = 0x%4.4x.", plan->GetName(), plan->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000388 }
389 m_completed_plan_stack.push_back (plan);
390 plan->WillPop();
391 m_plan_stack.pop_back();
392 }
393}
394
395void
396Thread::DiscardPlan ()
397{
398 if (m_plan_stack.size() > 1)
399 {
400 ThreadPlanSP &plan = m_plan_stack.back();
401 m_discarded_plan_stack.push_back (plan);
402 plan->WillPop();
403 m_plan_stack.pop_back();
404 }
405}
406
407ThreadPlan *
408Thread::GetCurrentPlan ()
409{
Jim Ingham6297a3a2010-10-20 00:39:53 +0000410 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000411 return NULL;
412 else
413 return m_plan_stack.back().get();
414}
415
416ThreadPlanSP
417Thread::GetCompletedPlan ()
418{
419 ThreadPlanSP empty_plan_sp;
420 if (!m_completed_plan_stack.empty())
421 {
422 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
423 {
424 ThreadPlanSP completed_plan_sp;
425 completed_plan_sp = m_completed_plan_stack[i];
426 if (!completed_plan_sp->GetPrivate ())
427 return completed_plan_sp;
428 }
429 }
430 return empty_plan_sp;
431}
432
433bool
434Thread::IsThreadPlanDone (ThreadPlan *plan)
435{
436 ThreadPlanSP empty_plan_sp;
437 if (!m_completed_plan_stack.empty())
438 {
439 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
440 {
441 if (m_completed_plan_stack[i].get() == plan)
442 return true;
443 }
444 }
445 return false;
446}
447
448bool
449Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
450{
451 ThreadPlanSP empty_plan_sp;
452 if (!m_discarded_plan_stack.empty())
453 {
454 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
455 {
456 if (m_discarded_plan_stack[i].get() == plan)
457 return true;
458 }
459 }
460 return false;
461}
462
463ThreadPlan *
464Thread::GetPreviousPlan (ThreadPlan *current_plan)
465{
466 if (current_plan == NULL)
467 return NULL;
468
469 int stack_size = m_completed_plan_stack.size();
470 for (int i = stack_size - 1; i > 0; i--)
471 {
472 if (current_plan == m_completed_plan_stack[i].get())
473 return m_completed_plan_stack[i-1].get();
474 }
475
476 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
477 {
Chris Lattner24943d22010-06-08 16:52:24 +0000478 if (m_plan_stack.size() > 0)
479 return m_plan_stack.back().get();
480 else
481 return NULL;
482 }
483
484 stack_size = m_plan_stack.size();
485 for (int i = stack_size - 1; i > 0; i--)
486 {
487 if (current_plan == m_plan_stack[i].get())
488 return m_plan_stack[i-1].get();
489 }
490 return NULL;
491}
492
493void
494Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
495{
496 if (abort_other_plans)
497 DiscardThreadPlans(true);
498
499 PushPlan (thread_plan_sp);
500}
501
Jim Ingham745ac7a2010-11-11 19:26:09 +0000502
503void
504Thread::EnableTracer (bool value, bool single_stepping)
505{
506 int stack_size = m_plan_stack.size();
507 for (int i = 0; i < stack_size; i++)
508 {
509 if (m_plan_stack[i]->GetThreadPlanTracer())
510 {
511 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
512 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
513 }
514 }
515}
516
517void
518Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
519{
520 int stack_size = m_plan_stack.size();
521 for (int i = 0; i < stack_size; i++)
522 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
523}
524
Chris Lattner24943d22010-06-08 16:52:24 +0000525void
Jim Inghamea9d4262010-11-05 19:25:48 +0000526Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
527{
Greg Claytone005f2c2010-11-06 01:53:30 +0000528 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamea9d4262010-11-05 19:25:48 +0000529 if (log)
530 {
531 log->Printf("Discarding thread plans for thread tid = 0x%4.4x, up to %p", GetID(), up_to_plan_sp.get());
532 }
533
534 int stack_size = m_plan_stack.size();
535
536 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
537 // stack, and if so discard up to and including it.
538
539 if (up_to_plan_sp.get() == NULL)
540 {
541 for (int i = stack_size - 1; i > 0; i--)
542 DiscardPlan();
543 }
544 else
545 {
546 bool found_it = false;
547 for (int i = stack_size - 1; i > 0; i--)
548 {
549 if (m_plan_stack[i] == up_to_plan_sp)
550 found_it = true;
551 }
552 if (found_it)
553 {
554 bool last_one = false;
555 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
556 {
557 if (GetCurrentPlan() == up_to_plan_sp.get())
558 last_one = true;
559 DiscardPlan();
560 }
561 }
562 }
563 return;
564}
565
566void
Chris Lattner24943d22010-06-08 16:52:24 +0000567Thread::DiscardThreadPlans(bool force)
568{
Greg Claytone005f2c2010-11-06 01:53:30 +0000569 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000570 if (log)
571 {
Greg Claytonf04d6612010-09-03 22:45:01 +0000572 log->Printf("Discarding thread plans for thread (tid = 0x%4.4x, force %d)", GetID(), force);
Chris Lattner24943d22010-06-08 16:52:24 +0000573 }
574
575 if (force)
576 {
577 int stack_size = m_plan_stack.size();
578 for (int i = stack_size - 1; i > 0; i--)
579 {
580 DiscardPlan();
581 }
582 return;
583 }
584
585 while (1)
586 {
587
588 int master_plan_idx;
589 bool discard;
590
591 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
592 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
593 {
594 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
595 {
596 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
597 break;
598 }
599 }
600
601 if (discard)
602 {
603 // First pop all the dependent plans:
604 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
605 {
606
607 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
608 // for the plan leaves it in a state that it is safe to pop the plan
609 // with no more notice?
610 DiscardPlan();
611 }
612
613 // Now discard the master plan itself.
614 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
615 // discard it's dependent plans, but not it...
616 if (master_plan_idx > 0)
617 {
618 DiscardPlan();
619 }
620 }
621 else
622 {
623 // If the master plan doesn't want to get discarded, then we're done.
624 break;
625 }
626
627 }
628 // FIXME: What should we do about the immediate plans?
629}
630
631ThreadPlan *
632Thread::QueueFundamentalPlan (bool abort_other_plans)
633{
634 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
635 QueueThreadPlan (thread_plan_sp, abort_other_plans);
636 return thread_plan_sp.get();
637}
638
639ThreadPlan *
640Thread::QueueThreadPlanForStepSingleInstruction (bool step_over, bool abort_other_plans, bool stop_other_threads)
641{
642 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
643 QueueThreadPlan (thread_plan_sp, abort_other_plans);
644 return thread_plan_sp.get();
645}
646
647ThreadPlan *
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000648Thread::QueueThreadPlanForStepRange
649(
650 bool abort_other_plans,
651 StepType type,
652 const AddressRange &range,
653 const SymbolContext &addr_context,
654 lldb::RunMode stop_other_threads,
655 bool avoid_code_without_debug_info
656)
Chris Lattner24943d22010-06-08 16:52:24 +0000657{
658 ThreadPlanSP thread_plan_sp;
659 if (type == eStepTypeInto)
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000660 {
661 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
662 if (avoid_code_without_debug_info)
663 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
664 else
665 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
666 thread_plan_sp.reset (plan);
667 }
Chris Lattner24943d22010-06-08 16:52:24 +0000668 else
669 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
670
671 QueueThreadPlan (thread_plan_sp, abort_other_plans);
672 return thread_plan_sp.get();
673}
674
675
676ThreadPlan *
677Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
678{
679 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
680 QueueThreadPlan (thread_plan_sp, abort_other_plans);
681 return thread_plan_sp.get();
682}
683
684ThreadPlan *
685Thread::QueueThreadPlanForStepOut (bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
686 bool stop_other_threads, Vote stop_vote, Vote run_vote)
687{
688 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote));
689 QueueThreadPlan (thread_plan_sp, abort_other_plans);
690 return thread_plan_sp.get();
691}
692
693ThreadPlan *
694Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads)
695{
Jim Inghamb66cd072010-09-28 01:25:32 +0000696 // Try the dynamic loader first:
Chris Lattner24943d22010-06-08 16:52:24 +0000697 ThreadPlanSP thread_plan_sp(GetProcess().GetDynamicLoader()->GetStepThroughTrampolinePlan (*this, stop_other_threads));
Jim Inghamb66cd072010-09-28 01:25:32 +0000698 // If that didn't come up with anything, try the ObjC runtime plugin:
699 if (thread_plan_sp.get() == NULL)
700 {
701 ObjCLanguageRuntime *objc_runtime = GetProcess().GetObjCLanguageRuntime();
702 if (objc_runtime)
703 thread_plan_sp = objc_runtime->GetStepThroughTrampolinePlan (*this, stop_other_threads);
704 }
705
Chris Lattner24943d22010-06-08 16:52:24 +0000706 if (thread_plan_sp.get() == NULL)
707 {
708 thread_plan_sp.reset(new ThreadPlanStepThrough (*this, stop_other_threads));
709 if (thread_plan_sp && !thread_plan_sp->ValidatePlan (NULL))
Greg Claytonf8e98a62010-07-23 15:37:46 +0000710 return NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000711 }
712 QueueThreadPlan (thread_plan_sp, abort_other_plans);
713 return thread_plan_sp.get();
714}
715
716ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000717Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
718 Address& function,
719 lldb::addr_t arg,
720 bool stop_other_threads,
721 bool discard_on_error)
722{
723 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, arg, stop_other_threads, discard_on_error));
724 QueueThreadPlan (thread_plan_sp, abort_other_plans);
725 return thread_plan_sp.get();
726}
727
728ThreadPlan *
729Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
730 Address& function,
731 ValueList &args,
732 bool stop_other_threads,
733 bool discard_on_error)
734{
735 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, args, stop_other_threads, discard_on_error));
736 QueueThreadPlan (thread_plan_sp, abort_other_plans);
737 return thread_plan_sp.get();
738}
739
740ThreadPlan *
741Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
742 Address &target_addr,
743 bool stop_other_threads)
744{
745 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
746 QueueThreadPlan (thread_plan_sp, abort_other_plans);
747 return thread_plan_sp.get();
748}
749
750ThreadPlan *
751Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
752 lldb::addr_t *address_list,
753 size_t num_addresses,
754 bool stop_other_threads)
755{
756 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads));
757 QueueThreadPlan (thread_plan_sp, abort_other_plans);
758 return thread_plan_sp.get();
759
760}
761
762uint32_t
763Thread::GetIndexID () const
764{
765 return m_index_id;
766}
767
768void
769Thread::DumpThreadPlans (lldb_private::Stream *s) const
770{
771 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000772 int i;
773 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4x, stack_size = %d\n", GetIndexID(), GetID(), stack_size);
774 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000775 {
776 s->Printf ("Element %d: ", i);
777 s->IndentMore();
778 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
779 s->IndentLess();
780 s->EOL();
781 }
782
Chris Lattner24943d22010-06-08 16:52:24 +0000783 stack_size = m_completed_plan_stack.size();
784 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000785 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000786 {
787 s->Printf ("Element %d: ", i);
788 s->IndentMore();
789 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
790 s->IndentLess();
791 s->EOL();
792 }
793
794 stack_size = m_discarded_plan_stack.size();
795 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000796 for (int i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000797 {
798 s->Printf ("Element %d: ", i);
799 s->IndentMore();
800 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
801 s->IndentLess();
802 s->EOL();
803 }
804
805}
806
807Target *
808Thread::CalculateTarget ()
809{
810 return m_process.CalculateTarget();
811}
812
813Process *
814Thread::CalculateProcess ()
815{
816 return &m_process;
817}
818
819Thread *
820Thread::CalculateThread ()
821{
822 return this;
823}
824
825StackFrame *
826Thread::CalculateStackFrame ()
827{
828 return NULL;
829}
830
831void
Greg Claytona830adb2010-10-04 01:05:56 +0000832Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000833{
Greg Claytona830adb2010-10-04 01:05:56 +0000834 m_process.CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000835 exe_ctx.thread = this;
836 exe_ctx.frame = NULL;
837}
838
Greg Clayton782b9cc2010-08-25 00:35:26 +0000839
840StackFrameList &
841Thread::GetStackFrameList ()
842{
Greg Claytonf40e3082010-08-26 02:28:22 +0000843 if (m_curr_frames_ap.get() == NULL)
Greg Clayton5205f0b2010-09-03 17:10:42 +0000844 m_curr_frames_ap.reset (new StackFrameList (*this, m_prev_frames_sp, true));
Greg Claytonf40e3082010-08-26 02:28:22 +0000845 return *m_curr_frames_ap;
Greg Clayton782b9cc2010-08-25 00:35:26 +0000846}
847
848
849
Jim Ingham71219082010-08-12 02:14:28 +0000850uint32_t
851Thread::GetStackFrameCount()
852{
Greg Clayton782b9cc2010-08-25 00:35:26 +0000853 return GetStackFrameList().GetNumFrames();
854}
Greg Clayton33ed1702010-08-24 00:45:41 +0000855
Greg Clayton33ed1702010-08-24 00:45:41 +0000856
Greg Clayton782b9cc2010-08-25 00:35:26 +0000857void
858Thread::ClearStackFrames ()
859{
Greg Clayton5205f0b2010-09-03 17:10:42 +0000860 if (m_curr_frames_ap.get() && m_curr_frames_ap->GetNumFrames (false) > 1)
861 m_prev_frames_sp.reset (m_curr_frames_ap.release());
862 else
863 m_curr_frames_ap.release();
864
865// StackFrameList::Merge (m_curr_frames_ap, m_prev_frames_sp);
866// assert (m_curr_frames_ap.get() == NULL);
Jim Ingham71219082010-08-12 02:14:28 +0000867}
868
869lldb::StackFrameSP
870Thread::GetStackFrameAtIndex (uint32_t idx)
871{
Greg Clayton72b71582010-09-02 21:44:10 +0000872 return GetStackFrameList().GetFrameAtIndex(idx);
Jim Ingham71219082010-08-12 02:14:28 +0000873}
874
Greg Claytonc12b6b42010-10-10 22:28:11 +0000875uint32_t
876Thread::GetSelectedFrameIndex ()
877{
878 return GetStackFrameList().GetSelectedFrameIndex();
879}
880
881
Chris Lattner24943d22010-06-08 16:52:24 +0000882lldb::StackFrameSP
Jim Inghamc8332952010-08-26 21:32:51 +0000883Thread::GetSelectedFrame ()
Chris Lattner24943d22010-06-08 16:52:24 +0000884{
Jim Inghamc8332952010-08-26 21:32:51 +0000885 return GetStackFrameAtIndex (GetStackFrameList().GetSelectedFrameIndex());
Chris Lattner24943d22010-06-08 16:52:24 +0000886}
887
888uint32_t
Jim Inghamc8332952010-08-26 21:32:51 +0000889Thread::SetSelectedFrame (lldb_private::StackFrame *frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000890{
Jim Inghamc8332952010-08-26 21:32:51 +0000891 return GetStackFrameList().SetSelectedFrame(frame);
Chris Lattner24943d22010-06-08 16:52:24 +0000892}
893
894void
Jim Inghamc8332952010-08-26 21:32:51 +0000895Thread::SetSelectedFrameByIndex (uint32_t idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000896{
Jim Inghamc8332952010-08-26 21:32:51 +0000897 GetStackFrameList().SetSelectedFrameByIndex(idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000898}
899
900void
Greg Claytona830adb2010-10-04 01:05:56 +0000901Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000902{
Greg Claytona830adb2010-10-04 01:05:56 +0000903 ExecutionContext exe_ctx;
904 SymbolContext frame_sc;
905 CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000906
Greg Claytona830adb2010-10-04 01:05:56 +0000907 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +0000908 {
Greg Claytona830adb2010-10-04 01:05:56 +0000909 StackFrameSP frame_sp(GetStackFrameAtIndex (frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000910 if (frame_sp)
911 {
Greg Claytona830adb2010-10-04 01:05:56 +0000912 exe_ctx.frame = frame_sp.get();
913 frame_sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +0000914 }
915 }
916
Greg Claytona830adb2010-10-04 01:05:56 +0000917 const char *thread_format = GetProcess().GetTarget().GetDebugger().GetThreadFormat();
918 assert (thread_format);
919 const char *end = NULL;
920 Debugger::FormatPrompt (thread_format,
921 exe_ctx.frame ? &frame_sc : NULL,
922 &exe_ctx,
923 NULL,
924 strm,
925 &end);
Chris Lattner24943d22010-06-08 16:52:24 +0000926}
927
928lldb::ThreadSP
929Thread::GetSP ()
930{
931 return m_process.GetThreadList().GetThreadSPForThreadPtr(this);
932}
Jim Ingham20594b12010-09-08 03:14:33 +0000933
934lldb::UserSettingsControllerSP
935Thread::GetSettingsController (bool finish)
936{
937 static UserSettingsControllerSP g_settings_controller (new ThreadSettingsController);
938 static bool initialized = false;
939
940 if (!initialized)
941 {
942 initialized = UserSettingsController::InitializeSettingsController (g_settings_controller,
943 Thread::ThreadSettingsController::global_settings_table,
944 Thread::ThreadSettingsController::instance_settings_table);
945 }
946
947 if (finish)
948 {
949 UserSettingsController::FinalizeSettingsController (g_settings_controller);
950 g_settings_controller.reset();
951 initialized = false;
952 }
953
954 return g_settings_controller;
955}
956
Caroline Tice1ebef442010-09-27 00:30:10 +0000957void
958Thread::UpdateInstanceName ()
959{
960 StreamString sstr;
961 const char *name = GetName();
962
963 if (name && name[0] != '\0')
964 sstr.Printf ("%s", name);
965 else if ((GetIndexID() != 0) || (GetID() != 0))
966 sstr.Printf ("0x%4.4x", GetIndexID(), GetID());
967
968 if (sstr.GetSize() > 0)
969 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
970}
971
Jim Inghamccd584d2010-09-23 17:40:12 +0000972lldb::StackFrameSP
973Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
974{
975 return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr);
976}
Caroline Tice7826c882010-10-26 03:11:13 +0000977
978const char *
979Thread::StopReasonAsCString (lldb::StopReason reason)
980{
981 switch (reason)
982 {
983 case eStopReasonInvalid: return "invalid";
984 case eStopReasonNone: return "none";
985 case eStopReasonTrace: return "trace";
986 case eStopReasonBreakpoint: return "breakpoint";
987 case eStopReasonWatchpoint: return "watchpoint";
988 case eStopReasonSignal: return "signal";
989 case eStopReasonException: return "exception";
990 case eStopReasonPlanComplete: return "plan complete";
991 }
992
993
994 static char unknown_state_string[64];
995 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
996 return unknown_state_string;
997}
998
999const char *
1000Thread::RunModeAsCString (lldb::RunMode mode)
1001{
1002 switch (mode)
1003 {
1004 case eOnlyThisThread: return "only this thread";
1005 case eAllThreads: return "all threads";
1006 case eOnlyDuringStepping: return "only during stepping";
1007 }
1008
1009 static char unknown_state_string[64];
1010 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
1011 return unknown_state_string;
1012}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001013
1014#pragma mark "Thread::ThreadSettingsController"
1015//--------------------------------------------------------------
1016// class Thread::ThreadSettingsController
1017//--------------------------------------------------------------
1018
1019Thread::ThreadSettingsController::ThreadSettingsController () :
1020 UserSettingsController ("thread", Process::GetSettingsController())
1021{
1022 m_default_settings.reset (new ThreadInstanceSettings (*this, false,
1023 InstanceSettings::GetDefaultName().AsCString()));
1024}
1025
1026Thread::ThreadSettingsController::~ThreadSettingsController ()
1027{
1028}
1029
1030lldb::InstanceSettingsSP
1031Thread::ThreadSettingsController::CreateInstanceSettings (const char *instance_name)
1032{
1033 ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*(Thread::GetSettingsController().get()),
1034 false, instance_name);
1035 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1036 return new_settings_sp;
1037}
1038
1039#pragma mark "ThreadInstanceSettings"
1040//--------------------------------------------------------------
1041// class ThreadInstanceSettings
1042//--------------------------------------------------------------
1043
1044ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) :
1045 InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance),
1046 m_avoid_regexp_ap (),
1047 m_trace_enabled (false)
1048{
1049 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1050 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1051 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1052 // This is true for CreateInstanceName() too.
1053
1054 if (GetInstanceName() == InstanceSettings::InvalidName())
1055 {
1056 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1057 m_owner.RegisterInstanceSettings (this);
1058 }
1059
1060 if (live_instance)
1061 {
1062 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1063 CopyInstanceSettings (pending_settings,false);
1064 //m_owner.RemovePendingSettings (m_instance_name);
1065 }
1066}
1067
1068ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
1069 InstanceSettings (*(Thread::GetSettingsController().get()), CreateInstanceName().AsCString()),
1070 m_avoid_regexp_ap (),
1071 m_trace_enabled (rhs.m_trace_enabled)
1072{
1073 if (m_instance_name != InstanceSettings::GetDefaultName())
1074 {
1075 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1076 CopyInstanceSettings (pending_settings,false);
1077 m_owner.RemovePendingSettings (m_instance_name);
1078 }
1079 if (rhs.m_avoid_regexp_ap.get() != NULL)
1080 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1081}
1082
1083ThreadInstanceSettings::~ThreadInstanceSettings ()
1084{
1085}
1086
1087ThreadInstanceSettings&
1088ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1089{
1090 if (this != &rhs)
1091 {
1092 if (rhs.m_avoid_regexp_ap.get() != NULL)
1093 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1094 else
1095 m_avoid_regexp_ap.reset(NULL);
1096 }
1097 m_trace_enabled = rhs.m_trace_enabled;
1098 return *this;
1099}
1100
1101
1102void
1103ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1104 const char *index_value,
1105 const char *value,
1106 const ConstString &instance_name,
1107 const SettingEntry &entry,
1108 lldb::VarSetOperationType op,
1109 Error &err,
1110 bool pending)
1111{
1112 if (var_name == StepAvoidRegexpVarName())
1113 {
1114 std::string regexp_text;
1115 if (m_avoid_regexp_ap.get() != NULL)
1116 regexp_text.append (m_avoid_regexp_ap->GetText());
1117 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1118 if (regexp_text.empty())
1119 m_avoid_regexp_ap.reset();
1120 else
1121 {
1122 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1123
1124 }
1125 }
1126 else if (var_name == GetTraceThreadVarName())
1127 {
1128 bool success;
1129 bool result = Args::StringToBoolean(value, false, &success);
1130
1131 if (success)
1132 {
1133 m_trace_enabled = result;
1134 if (!pending)
1135 {
1136 Thread *myself = static_cast<Thread *> (this);
1137 myself->EnableTracer(m_trace_enabled, true);
1138 }
1139 }
1140 else
1141 {
1142 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1143 }
1144
1145 }
1146}
1147
1148void
1149ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1150 bool pending)
1151{
1152 if (new_settings.get() == NULL)
1153 return;
1154
1155 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1156 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1157 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1158 else
1159 m_avoid_regexp_ap.reset ();
1160}
1161
1162bool
1163ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1164 const ConstString &var_name,
1165 StringList &value,
1166 Error *err)
1167{
1168 if (var_name == StepAvoidRegexpVarName())
1169 {
1170 if (m_avoid_regexp_ap.get() != NULL)
1171 {
1172 std::string regexp_text("\"");
1173 regexp_text.append(m_avoid_regexp_ap->GetText());
1174 regexp_text.append ("\"");
1175 value.AppendString (regexp_text.c_str());
1176 }
1177
1178 }
1179 else if (var_name == GetTraceThreadVarName())
1180 {
1181 value.AppendString(m_trace_enabled ? "true" : "false");
1182 }
1183 else
1184 {
1185 if (err)
1186 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1187 return false;
1188 }
1189 return true;
1190}
1191
1192const ConstString
1193ThreadInstanceSettings::CreateInstanceName ()
1194{
1195 static int instance_count = 1;
1196 StreamString sstr;
1197
1198 sstr.Printf ("thread_%d", instance_count);
1199 ++instance_count;
1200
1201 const ConstString ret_val (sstr.GetData());
1202 return ret_val;
1203}
1204
1205const ConstString &
1206ThreadInstanceSettings::StepAvoidRegexpVarName ()
1207{
1208 static ConstString step_avoid_var_name ("step-avoid-regexp");
1209
1210 return step_avoid_var_name;
1211}
1212
1213const ConstString &
1214ThreadInstanceSettings::GetTraceThreadVarName ()
1215{
1216 static ConstString trace_thread_var_name ("trace-thread");
1217
1218 return trace_thread_var_name;
1219}
1220
1221//--------------------------------------------------
1222// ThreadSettingsController Variable Tables
1223//--------------------------------------------------
1224
1225SettingEntry
1226Thread::ThreadSettingsController::global_settings_table[] =
1227{
1228 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1229 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1230};
1231
1232
1233SettingEntry
1234Thread::ThreadSettingsController::instance_settings_table[] =
1235{
1236 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1237 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1238 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1239 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1240};