blob: eccb700fd2641bc4660f19c06c2fb79431d29811 [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 *
Chris Lattner24943d22010-06-08 16:52:24 +0000729Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
730 Address &target_addr,
731 bool stop_other_threads)
732{
733 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
734 QueueThreadPlan (thread_plan_sp, abort_other_plans);
735 return thread_plan_sp.get();
736}
737
738ThreadPlan *
739Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
740 lldb::addr_t *address_list,
741 size_t num_addresses,
742 bool stop_other_threads)
743{
744 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads));
745 QueueThreadPlan (thread_plan_sp, abort_other_plans);
746 return thread_plan_sp.get();
747
748}
749
750uint32_t
751Thread::GetIndexID () const
752{
753 return m_index_id;
754}
755
756void
757Thread::DumpThreadPlans (lldb_private::Stream *s) const
758{
759 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000760 int i;
761 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4x, stack_size = %d\n", GetIndexID(), GetID(), stack_size);
762 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000763 {
764 s->Printf ("Element %d: ", i);
765 s->IndentMore();
766 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
767 s->IndentLess();
768 s->EOL();
769 }
770
Chris Lattner24943d22010-06-08 16:52:24 +0000771 stack_size = m_completed_plan_stack.size();
772 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000773 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000774 {
775 s->Printf ("Element %d: ", i);
776 s->IndentMore();
777 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
778 s->IndentLess();
779 s->EOL();
780 }
781
782 stack_size = m_discarded_plan_stack.size();
783 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000784 for (int i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000785 {
786 s->Printf ("Element %d: ", i);
787 s->IndentMore();
788 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
789 s->IndentLess();
790 s->EOL();
791 }
792
793}
794
795Target *
796Thread::CalculateTarget ()
797{
798 return m_process.CalculateTarget();
799}
800
801Process *
802Thread::CalculateProcess ()
803{
804 return &m_process;
805}
806
807Thread *
808Thread::CalculateThread ()
809{
810 return this;
811}
812
813StackFrame *
814Thread::CalculateStackFrame ()
815{
816 return NULL;
817}
818
819void
Greg Claytona830adb2010-10-04 01:05:56 +0000820Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000821{
Greg Claytona830adb2010-10-04 01:05:56 +0000822 m_process.CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000823 exe_ctx.thread = this;
824 exe_ctx.frame = NULL;
825}
826
Greg Clayton782b9cc2010-08-25 00:35:26 +0000827
828StackFrameList &
829Thread::GetStackFrameList ()
830{
Greg Claytonf40e3082010-08-26 02:28:22 +0000831 if (m_curr_frames_ap.get() == NULL)
Greg Clayton5205f0b2010-09-03 17:10:42 +0000832 m_curr_frames_ap.reset (new StackFrameList (*this, m_prev_frames_sp, true));
Greg Claytonf40e3082010-08-26 02:28:22 +0000833 return *m_curr_frames_ap;
Greg Clayton782b9cc2010-08-25 00:35:26 +0000834}
835
836
837
Jim Ingham71219082010-08-12 02:14:28 +0000838uint32_t
839Thread::GetStackFrameCount()
840{
Greg Clayton782b9cc2010-08-25 00:35:26 +0000841 return GetStackFrameList().GetNumFrames();
842}
Greg Clayton33ed1702010-08-24 00:45:41 +0000843
Greg Clayton33ed1702010-08-24 00:45:41 +0000844
Greg Clayton782b9cc2010-08-25 00:35:26 +0000845void
846Thread::ClearStackFrames ()
847{
Greg Clayton5205f0b2010-09-03 17:10:42 +0000848 if (m_curr_frames_ap.get() && m_curr_frames_ap->GetNumFrames (false) > 1)
849 m_prev_frames_sp.reset (m_curr_frames_ap.release());
850 else
851 m_curr_frames_ap.release();
852
853// StackFrameList::Merge (m_curr_frames_ap, m_prev_frames_sp);
854// assert (m_curr_frames_ap.get() == NULL);
Jim Ingham71219082010-08-12 02:14:28 +0000855}
856
857lldb::StackFrameSP
858Thread::GetStackFrameAtIndex (uint32_t idx)
859{
Greg Clayton72b71582010-09-02 21:44:10 +0000860 return GetStackFrameList().GetFrameAtIndex(idx);
Jim Ingham71219082010-08-12 02:14:28 +0000861}
862
Greg Claytonc12b6b42010-10-10 22:28:11 +0000863uint32_t
864Thread::GetSelectedFrameIndex ()
865{
866 return GetStackFrameList().GetSelectedFrameIndex();
867}
868
869
Chris Lattner24943d22010-06-08 16:52:24 +0000870lldb::StackFrameSP
Jim Inghamc8332952010-08-26 21:32:51 +0000871Thread::GetSelectedFrame ()
Chris Lattner24943d22010-06-08 16:52:24 +0000872{
Jim Inghamc8332952010-08-26 21:32:51 +0000873 return GetStackFrameAtIndex (GetStackFrameList().GetSelectedFrameIndex());
Chris Lattner24943d22010-06-08 16:52:24 +0000874}
875
876uint32_t
Jim Inghamc8332952010-08-26 21:32:51 +0000877Thread::SetSelectedFrame (lldb_private::StackFrame *frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000878{
Jim Inghamc8332952010-08-26 21:32:51 +0000879 return GetStackFrameList().SetSelectedFrame(frame);
Chris Lattner24943d22010-06-08 16:52:24 +0000880}
881
882void
Jim Inghamc8332952010-08-26 21:32:51 +0000883Thread::SetSelectedFrameByIndex (uint32_t idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000884{
Jim Inghamc8332952010-08-26 21:32:51 +0000885 GetStackFrameList().SetSelectedFrameByIndex(idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000886}
887
888void
Greg Claytona830adb2010-10-04 01:05:56 +0000889Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000890{
Greg Claytona830adb2010-10-04 01:05:56 +0000891 ExecutionContext exe_ctx;
892 SymbolContext frame_sc;
893 CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000894
Greg Claytona830adb2010-10-04 01:05:56 +0000895 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +0000896 {
Greg Claytona830adb2010-10-04 01:05:56 +0000897 StackFrameSP frame_sp(GetStackFrameAtIndex (frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000898 if (frame_sp)
899 {
Greg Claytona830adb2010-10-04 01:05:56 +0000900 exe_ctx.frame = frame_sp.get();
901 frame_sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +0000902 }
903 }
904
Greg Claytona830adb2010-10-04 01:05:56 +0000905 const char *thread_format = GetProcess().GetTarget().GetDebugger().GetThreadFormat();
906 assert (thread_format);
907 const char *end = NULL;
908 Debugger::FormatPrompt (thread_format,
909 exe_ctx.frame ? &frame_sc : NULL,
910 &exe_ctx,
911 NULL,
912 strm,
913 &end);
Chris Lattner24943d22010-06-08 16:52:24 +0000914}
915
916lldb::ThreadSP
917Thread::GetSP ()
918{
919 return m_process.GetThreadList().GetThreadSPForThreadPtr(this);
920}
Jim Ingham20594b12010-09-08 03:14:33 +0000921
922lldb::UserSettingsControllerSP
923Thread::GetSettingsController (bool finish)
924{
925 static UserSettingsControllerSP g_settings_controller (new ThreadSettingsController);
926 static bool initialized = false;
927
928 if (!initialized)
929 {
930 initialized = UserSettingsController::InitializeSettingsController (g_settings_controller,
931 Thread::ThreadSettingsController::global_settings_table,
932 Thread::ThreadSettingsController::instance_settings_table);
933 }
934
935 if (finish)
936 {
937 UserSettingsController::FinalizeSettingsController (g_settings_controller);
938 g_settings_controller.reset();
939 initialized = false;
940 }
941
942 return g_settings_controller;
943}
944
Caroline Tice1ebef442010-09-27 00:30:10 +0000945void
946Thread::UpdateInstanceName ()
947{
948 StreamString sstr;
949 const char *name = GetName();
950
951 if (name && name[0] != '\0')
952 sstr.Printf ("%s", name);
953 else if ((GetIndexID() != 0) || (GetID() != 0))
954 sstr.Printf ("0x%4.4x", GetIndexID(), GetID());
955
956 if (sstr.GetSize() > 0)
957 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
958}
959
Jim Inghamccd584d2010-09-23 17:40:12 +0000960lldb::StackFrameSP
961Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
962{
963 return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr);
964}
Caroline Tice7826c882010-10-26 03:11:13 +0000965
966const char *
967Thread::StopReasonAsCString (lldb::StopReason reason)
968{
969 switch (reason)
970 {
971 case eStopReasonInvalid: return "invalid";
972 case eStopReasonNone: return "none";
973 case eStopReasonTrace: return "trace";
974 case eStopReasonBreakpoint: return "breakpoint";
975 case eStopReasonWatchpoint: return "watchpoint";
976 case eStopReasonSignal: return "signal";
977 case eStopReasonException: return "exception";
978 case eStopReasonPlanComplete: return "plan complete";
979 }
980
981
982 static char unknown_state_string[64];
983 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
984 return unknown_state_string;
985}
986
987const char *
988Thread::RunModeAsCString (lldb::RunMode mode)
989{
990 switch (mode)
991 {
992 case eOnlyThisThread: return "only this thread";
993 case eAllThreads: return "all threads";
994 case eOnlyDuringStepping: return "only during stepping";
995 }
996
997 static char unknown_state_string[64];
998 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
999 return unknown_state_string;
1000}
Jim Ingham745ac7a2010-11-11 19:26:09 +00001001
1002#pragma mark "Thread::ThreadSettingsController"
1003//--------------------------------------------------------------
1004// class Thread::ThreadSettingsController
1005//--------------------------------------------------------------
1006
1007Thread::ThreadSettingsController::ThreadSettingsController () :
1008 UserSettingsController ("thread", Process::GetSettingsController())
1009{
1010 m_default_settings.reset (new ThreadInstanceSettings (*this, false,
1011 InstanceSettings::GetDefaultName().AsCString()));
1012}
1013
1014Thread::ThreadSettingsController::~ThreadSettingsController ()
1015{
1016}
1017
1018lldb::InstanceSettingsSP
1019Thread::ThreadSettingsController::CreateInstanceSettings (const char *instance_name)
1020{
1021 ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*(Thread::GetSettingsController().get()),
1022 false, instance_name);
1023 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1024 return new_settings_sp;
1025}
1026
1027#pragma mark "ThreadInstanceSettings"
1028//--------------------------------------------------------------
1029// class ThreadInstanceSettings
1030//--------------------------------------------------------------
1031
1032ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) :
1033 InstanceSettings (owner, (name == NULL ? InstanceSettings::InvalidName().AsCString() : name), live_instance),
1034 m_avoid_regexp_ap (),
1035 m_trace_enabled (false)
1036{
1037 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1038 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1039 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1040 // This is true for CreateInstanceName() too.
1041
1042 if (GetInstanceName() == InstanceSettings::InvalidName())
1043 {
1044 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1045 m_owner.RegisterInstanceSettings (this);
1046 }
1047
1048 if (live_instance)
1049 {
1050 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1051 CopyInstanceSettings (pending_settings,false);
1052 //m_owner.RemovePendingSettings (m_instance_name);
1053 }
1054}
1055
1056ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
1057 InstanceSettings (*(Thread::GetSettingsController().get()), CreateInstanceName().AsCString()),
1058 m_avoid_regexp_ap (),
1059 m_trace_enabled (rhs.m_trace_enabled)
1060{
1061 if (m_instance_name != InstanceSettings::GetDefaultName())
1062 {
1063 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1064 CopyInstanceSettings (pending_settings,false);
1065 m_owner.RemovePendingSettings (m_instance_name);
1066 }
1067 if (rhs.m_avoid_regexp_ap.get() != NULL)
1068 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1069}
1070
1071ThreadInstanceSettings::~ThreadInstanceSettings ()
1072{
1073}
1074
1075ThreadInstanceSettings&
1076ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1077{
1078 if (this != &rhs)
1079 {
1080 if (rhs.m_avoid_regexp_ap.get() != NULL)
1081 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1082 else
1083 m_avoid_regexp_ap.reset(NULL);
1084 }
1085 m_trace_enabled = rhs.m_trace_enabled;
1086 return *this;
1087}
1088
1089
1090void
1091ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1092 const char *index_value,
1093 const char *value,
1094 const ConstString &instance_name,
1095 const SettingEntry &entry,
1096 lldb::VarSetOperationType op,
1097 Error &err,
1098 bool pending)
1099{
1100 if (var_name == StepAvoidRegexpVarName())
1101 {
1102 std::string regexp_text;
1103 if (m_avoid_regexp_ap.get() != NULL)
1104 regexp_text.append (m_avoid_regexp_ap->GetText());
1105 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1106 if (regexp_text.empty())
1107 m_avoid_regexp_ap.reset();
1108 else
1109 {
1110 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1111
1112 }
1113 }
1114 else if (var_name == GetTraceThreadVarName())
1115 {
1116 bool success;
1117 bool result = Args::StringToBoolean(value, false, &success);
1118
1119 if (success)
1120 {
1121 m_trace_enabled = result;
1122 if (!pending)
1123 {
1124 Thread *myself = static_cast<Thread *> (this);
1125 myself->EnableTracer(m_trace_enabled, true);
1126 }
1127 }
1128 else
1129 {
1130 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1131 }
1132
1133 }
1134}
1135
1136void
1137ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1138 bool pending)
1139{
1140 if (new_settings.get() == NULL)
1141 return;
1142
1143 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1144 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1145 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1146 else
1147 m_avoid_regexp_ap.reset ();
1148}
1149
1150bool
1151ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1152 const ConstString &var_name,
1153 StringList &value,
1154 Error *err)
1155{
1156 if (var_name == StepAvoidRegexpVarName())
1157 {
1158 if (m_avoid_regexp_ap.get() != NULL)
1159 {
1160 std::string regexp_text("\"");
1161 regexp_text.append(m_avoid_regexp_ap->GetText());
1162 regexp_text.append ("\"");
1163 value.AppendString (regexp_text.c_str());
1164 }
1165
1166 }
1167 else if (var_name == GetTraceThreadVarName())
1168 {
1169 value.AppendString(m_trace_enabled ? "true" : "false");
1170 }
1171 else
1172 {
1173 if (err)
1174 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1175 return false;
1176 }
1177 return true;
1178}
1179
1180const ConstString
1181ThreadInstanceSettings::CreateInstanceName ()
1182{
1183 static int instance_count = 1;
1184 StreamString sstr;
1185
1186 sstr.Printf ("thread_%d", instance_count);
1187 ++instance_count;
1188
1189 const ConstString ret_val (sstr.GetData());
1190 return ret_val;
1191}
1192
1193const ConstString &
1194ThreadInstanceSettings::StepAvoidRegexpVarName ()
1195{
1196 static ConstString step_avoid_var_name ("step-avoid-regexp");
1197
1198 return step_avoid_var_name;
1199}
1200
1201const ConstString &
1202ThreadInstanceSettings::GetTraceThreadVarName ()
1203{
1204 static ConstString trace_thread_var_name ("trace-thread");
1205
1206 return trace_thread_var_name;
1207}
1208
1209//--------------------------------------------------
1210// ThreadSettingsController Variable Tables
1211//--------------------------------------------------
1212
1213SettingEntry
1214Thread::ThreadSettingsController::global_settings_table[] =
1215{
1216 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1217 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1218};
1219
1220
1221SettingEntry
1222Thread::ThreadSettingsController::instance_settings_table[] =
1223{
1224 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1225 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1226 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1227 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1228};