blob: d4dcd72fce80d9e956194705d6011921aaff8203 [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),
Greg Claytonc0c1b0c2010-11-19 03:46:01 +000045 ThreadInstanceSettings (*GetSettingsController()),
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),
Jim Inghamcdea2362010-11-18 02:47:07 +000057 m_unwinder_ap (),
58 m_destroy_called (false)
Jim Ingham71219082010-08-12 02:14:28 +000059
Chris Lattner24943d22010-06-08 16:52:24 +000060{
Greg Claytone005f2c2010-11-06 01:53:30 +000061 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000062 if (log)
63 log->Printf ("%p Thread::Thread(tid = 0x%4.4x)", this, GetID());
64
65 QueueFundamentalPlan(true);
Caroline Tice1ebef442010-09-27 00:30:10 +000066 UpdateInstanceName();
Chris Lattner24943d22010-06-08 16:52:24 +000067}
68
69
70Thread::~Thread()
71{
Greg Claytone005f2c2010-11-06 01:53:30 +000072 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT));
Chris Lattner24943d22010-06-08 16:52:24 +000073 if (log)
74 log->Printf ("%p Thread::~Thread(tid = 0x%4.4x)", this, GetID());
Jim Inghamcdea2362010-11-18 02:47:07 +000075 /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor.
76 assert (m_destroy_called);
77}
78
79void
80Thread::DestroyThread ()
81{
82 m_plan_stack.clear();
83 m_discarded_plan_stack.clear();
84 m_completed_plan_stack.clear();
85 m_destroy_called = true;
Chris Lattner24943d22010-06-08 16:52:24 +000086}
87
Jim Ingham6297a3a2010-10-20 00:39:53 +000088lldb::StopInfoSP
Greg Clayton643ee732010-08-04 01:40:35 +000089Thread::GetStopInfo ()
Chris Lattner24943d22010-06-08 16:52:24 +000090{
Jim Ingham6297a3a2010-10-20 00:39:53 +000091 ThreadPlanSP plan_sp (GetCompletedPlan());
92 if (plan_sp)
93 return StopInfo::CreateStopReasonWithPlan (plan_sp);
94 else
95 return GetPrivateStopReason ();
Chris Lattner24943d22010-06-08 16:52:24 +000096}
97
98bool
99Thread::ThreadStoppedForAReason (void)
100{
Greg Clayton643ee732010-08-04 01:40:35 +0000101 return GetPrivateStopReason () != NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000102}
103
104StateType
105Thread::GetState() const
106{
107 // If any other threads access this we will need a mutex for it
108 Mutex::Locker locker(m_state_mutex);
109 return m_state;
110}
111
112void
113Thread::SetState(StateType state)
114{
115 Mutex::Locker locker(m_state_mutex);
116 m_state = state;
117}
118
119void
120Thread::WillStop()
121{
122 ThreadPlan *current_plan = GetCurrentPlan();
123
124 // FIXME: I may decide to disallow threads with no plans. In which
125 // case this should go to an assert.
126
127 if (!current_plan)
128 return;
129
130 current_plan->WillStop();
131}
132
133void
134Thread::SetupForResume ()
135{
136 if (GetResumeState() != eStateSuspended)
137 {
138
139 // If we're at a breakpoint push the step-over breakpoint plan. Do this before
140 // telling the current plan it will resume, since we might change what the current
141 // plan is.
142
143 lldb::addr_t pc = GetRegisterContext()->GetPC();
144 BreakpointSiteSP bp_site_sp = GetProcess().GetBreakpointSiteList().FindByAddress(pc);
145 if (bp_site_sp && bp_site_sp->IsEnabled())
146 {
147 // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything
148 // special to step over a breakpoint.
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000149
150 ThreadPlan *cur_plan = GetCurrentPlan();
Chris Lattner24943d22010-06-08 16:52:24 +0000151
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000152 if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint)
153 {
154 ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this);
155 if (step_bp_plan)
Chris Lattner24943d22010-06-08 16:52:24 +0000156 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000157 ThreadPlanSP step_bp_plan_sp;
158 step_bp_plan->SetPrivate (true);
159
Chris Lattner24943d22010-06-08 16:52:24 +0000160 if (GetCurrentPlan()->RunState() != eStateStepping)
161 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000162 step_bp_plan->SetAutoContinue(true);
Chris Lattner24943d22010-06-08 16:52:24 +0000163 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000164 step_bp_plan_sp.reset (step_bp_plan);
Chris Lattner24943d22010-06-08 16:52:24 +0000165 QueueThreadPlan (step_bp_plan_sp, false);
166 }
167 }
168 }
169 }
170}
171
172bool
173Thread::WillResume (StateType resume_state)
174{
175 // At this point clear the completed plan stack.
176 m_completed_plan_stack.clear();
177 m_discarded_plan_stack.clear();
178
Greg Clayton643ee732010-08-04 01:40:35 +0000179 StopInfo *stop_info = GetPrivateStopReason().get();
180 if (stop_info)
181 stop_info->WillResume (resume_state);
Chris Lattner24943d22010-06-08 16:52:24 +0000182
183 // Tell all the plans that we are about to resume in case they need to clear any state.
184 // We distinguish between the plan on the top of the stack and the lower
185 // plans in case a plan needs to do any special business before it runs.
186
187 ThreadPlan *plan_ptr = GetCurrentPlan();
188 plan_ptr->WillResume(resume_state, true);
189
190 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
191 {
192 plan_ptr->WillResume (resume_state, false);
193 }
Greg Clayton643ee732010-08-04 01:40:35 +0000194
Greg Clayton643ee732010-08-04 01:40:35 +0000195 m_actual_stop_info_sp.reset();
Chris Lattner24943d22010-06-08 16:52:24 +0000196 return true;
197}
198
199void
200Thread::DidResume ()
201{
202 SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER);
203}
204
205bool
206Thread::ShouldStop (Event* event_ptr)
207{
208 ThreadPlan *current_plan = GetCurrentPlan();
209 bool should_stop = true;
210
Greg Claytone005f2c2010-11-06 01:53:30 +0000211 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000212 if (log)
213 {
214 StreamString s;
215 DumpThreadPlans(&s);
216 log->PutCString (s.GetData());
217 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000218
219 // The top most plan always gets to do the trace log...
220 current_plan->DoTraceLog ();
Chris Lattner24943d22010-06-08 16:52:24 +0000221
222 if (current_plan->PlanExplainsStop())
223 {
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000224 bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr);
Chris Lattner24943d22010-06-08 16:52:24 +0000225 while (1)
226 {
227 should_stop = current_plan->ShouldStop(event_ptr);
228 if (current_plan->MischiefManaged())
229 {
230 if (should_stop)
231 current_plan->WillStop();
232
233 // If a Master Plan wants to stop, and wants to stick on the stack, we let it.
234 // Otherwise, see if the plan's parent wants to stop.
235
236 if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard())
237 {
238 PopPlan();
239 break;
240 }
241 else
242 {
243
244 PopPlan();
245
246 current_plan = GetCurrentPlan();
247 if (current_plan == NULL)
248 {
249 break;
250 }
251 }
252
253 }
254 else
255 {
256 break;
257 }
258 }
Jim Ingham5a47e8b2010-06-19 04:45:32 +0000259 if (over_ride_stop)
260 should_stop = false;
Chris Lattner24943d22010-06-08 16:52:24 +0000261 }
Jim Ingham745ac7a2010-11-11 19:26:09 +0000262 else if (current_plan->TracerExplainsStop())
263 {
264 return false;
265 }
Chris Lattner24943d22010-06-08 16:52:24 +0000266 else
267 {
268 // If the current plan doesn't explain the stop, then, find one that
269 // does and let it handle the situation.
270 ThreadPlan *plan_ptr = current_plan;
271 while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL)
272 {
273 if (plan_ptr->PlanExplainsStop())
274 {
275 should_stop = plan_ptr->ShouldStop (event_ptr);
276 break;
277 }
278
279 }
280 }
281
282 return should_stop;
283}
284
285Vote
286Thread::ShouldReportStop (Event* event_ptr)
287{
288 StateType thread_state = GetResumeState ();
Greg Claytone005f2c2010-11-06 01:53:30 +0000289 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Greg Clayton5205f0b2010-09-03 17:10:42 +0000290
291 if (thread_state == eStateSuspended || thread_state == eStateInvalid)
292 {
293 if (log)
294 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 +0000295 return eVoteNoOpinion;
Greg Clayton5205f0b2010-09-03 17:10:42 +0000296 }
Chris Lattner24943d22010-06-08 16:52:24 +0000297
298 if (m_completed_plan_stack.size() > 0)
299 {
300 // Don't use GetCompletedPlan here, since that suppresses private plans.
Greg Clayton5205f0b2010-09-03 17:10:42 +0000301 if (log)
302 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 +0000303 return m_completed_plan_stack.back()->ShouldReportStop (event_ptr);
304 }
305 else
Greg Clayton5205f0b2010-09-03 17:10:42 +0000306 {
307 if (log)
308 log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote for current plan\n", GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000309 return GetCurrentPlan()->ShouldReportStop (event_ptr);
Greg Clayton5205f0b2010-09-03 17:10:42 +0000310 }
Chris Lattner24943d22010-06-08 16:52:24 +0000311}
312
313Vote
314Thread::ShouldReportRun (Event* event_ptr)
315{
316 StateType thread_state = GetResumeState ();
317 if (thread_state == eStateSuspended
318 || thread_state == eStateInvalid)
319 return eVoteNoOpinion;
320
321 if (m_completed_plan_stack.size() > 0)
322 {
323 // Don't use GetCompletedPlan here, since that suppresses private plans.
324 return m_completed_plan_stack.back()->ShouldReportRun (event_ptr);
325 }
326 else
327 return GetCurrentPlan()->ShouldReportRun (event_ptr);
328}
329
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000330bool
331Thread::MatchesSpec (const ThreadSpec *spec)
332{
333 if (spec == NULL)
334 return true;
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000335
Jim Ingham649492b2010-06-18 01:00:58 +0000336 return spec->ThreadPassesBasicTests(this);
Jim Ingham3c7b5b92010-06-16 02:00:15 +0000337}
338
Chris Lattner24943d22010-06-08 16:52:24 +0000339void
340Thread::PushPlan (ThreadPlanSP &thread_plan_sp)
341{
342 if (thread_plan_sp)
343 {
Jim Ingham745ac7a2010-11-11 19:26:09 +0000344 // If the thread plan doesn't already have a tracer, give it its parent's tracer:
345 if (!thread_plan_sp->GetThreadPlanTracer())
346 thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer());
Jim Ingham6297a3a2010-10-20 00:39:53 +0000347 m_plan_stack.push_back (thread_plan_sp);
Jim Ingham745ac7a2010-11-11 19:26:09 +0000348
Chris Lattner24943d22010-06-08 16:52:24 +0000349 thread_plan_sp->DidPush();
350
Greg Claytone005f2c2010-11-06 01:53:30 +0000351 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000352 if (log)
353 {
354 StreamString s;
355 thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull);
Jim Ingham6297a3a2010-10-20 00:39:53 +0000356 log->Printf("Pushing plan: \"%s\", tid = 0x%4.4x.",
Chris Lattner24943d22010-06-08 16:52:24 +0000357 s.GetData(),
Jim Ingham6297a3a2010-10-20 00:39:53 +0000358 thread_plan_sp->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000359 }
360 }
361}
362
363void
364Thread::PopPlan ()
365{
Greg Claytone005f2c2010-11-06 01:53:30 +0000366 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000367
Jim Ingham6297a3a2010-10-20 00:39:53 +0000368 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000369 return;
370 else
371 {
372 ThreadPlanSP &plan = m_plan_stack.back();
373 if (log)
374 {
Jim Ingham83e8b9d2010-11-10 18:17:03 +0000375 log->Printf("Popping plan: \"%s\", tid = 0x%4.4x.", plan->GetName(), plan->GetThread().GetID());
Chris Lattner24943d22010-06-08 16:52:24 +0000376 }
377 m_completed_plan_stack.push_back (plan);
378 plan->WillPop();
379 m_plan_stack.pop_back();
380 }
381}
382
383void
384Thread::DiscardPlan ()
385{
386 if (m_plan_stack.size() > 1)
387 {
388 ThreadPlanSP &plan = m_plan_stack.back();
389 m_discarded_plan_stack.push_back (plan);
390 plan->WillPop();
391 m_plan_stack.pop_back();
392 }
393}
394
395ThreadPlan *
396Thread::GetCurrentPlan ()
397{
Jim Ingham6297a3a2010-10-20 00:39:53 +0000398 if (m_plan_stack.empty())
Chris Lattner24943d22010-06-08 16:52:24 +0000399 return NULL;
400 else
401 return m_plan_stack.back().get();
402}
403
404ThreadPlanSP
405Thread::GetCompletedPlan ()
406{
407 ThreadPlanSP empty_plan_sp;
408 if (!m_completed_plan_stack.empty())
409 {
410 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
411 {
412 ThreadPlanSP completed_plan_sp;
413 completed_plan_sp = m_completed_plan_stack[i];
414 if (!completed_plan_sp->GetPrivate ())
415 return completed_plan_sp;
416 }
417 }
418 return empty_plan_sp;
419}
420
421bool
422Thread::IsThreadPlanDone (ThreadPlan *plan)
423{
424 ThreadPlanSP empty_plan_sp;
425 if (!m_completed_plan_stack.empty())
426 {
427 for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--)
428 {
429 if (m_completed_plan_stack[i].get() == plan)
430 return true;
431 }
432 }
433 return false;
434}
435
436bool
437Thread::WasThreadPlanDiscarded (ThreadPlan *plan)
438{
439 ThreadPlanSP empty_plan_sp;
440 if (!m_discarded_plan_stack.empty())
441 {
442 for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--)
443 {
444 if (m_discarded_plan_stack[i].get() == plan)
445 return true;
446 }
447 }
448 return false;
449}
450
451ThreadPlan *
452Thread::GetPreviousPlan (ThreadPlan *current_plan)
453{
454 if (current_plan == NULL)
455 return NULL;
456
457 int stack_size = m_completed_plan_stack.size();
458 for (int i = stack_size - 1; i > 0; i--)
459 {
460 if (current_plan == m_completed_plan_stack[i].get())
461 return m_completed_plan_stack[i-1].get();
462 }
463
464 if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan)
465 {
Chris Lattner24943d22010-06-08 16:52:24 +0000466 if (m_plan_stack.size() > 0)
467 return m_plan_stack.back().get();
468 else
469 return NULL;
470 }
471
472 stack_size = m_plan_stack.size();
473 for (int i = stack_size - 1; i > 0; i--)
474 {
475 if (current_plan == m_plan_stack[i].get())
476 return m_plan_stack[i-1].get();
477 }
478 return NULL;
479}
480
481void
482Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans)
483{
484 if (abort_other_plans)
485 DiscardThreadPlans(true);
486
487 PushPlan (thread_plan_sp);
488}
489
Jim Ingham745ac7a2010-11-11 19:26:09 +0000490
491void
492Thread::EnableTracer (bool value, bool single_stepping)
493{
494 int stack_size = m_plan_stack.size();
495 for (int i = 0; i < stack_size; i++)
496 {
497 if (m_plan_stack[i]->GetThreadPlanTracer())
498 {
499 m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value);
500 m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping);
501 }
502 }
503}
504
505void
506Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp)
507{
508 int stack_size = m_plan_stack.size();
509 for (int i = 0; i < stack_size; i++)
510 m_plan_stack[i]->SetThreadPlanTracer(tracer_sp);
511}
512
Chris Lattner24943d22010-06-08 16:52:24 +0000513void
Jim Inghamea9d4262010-11-05 19:25:48 +0000514Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp)
515{
Greg Claytone005f2c2010-11-06 01:53:30 +0000516 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Jim Inghamea9d4262010-11-05 19:25:48 +0000517 if (log)
518 {
519 log->Printf("Discarding thread plans for thread tid = 0x%4.4x, up to %p", GetID(), up_to_plan_sp.get());
520 }
521
522 int stack_size = m_plan_stack.size();
523
524 // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the
525 // stack, and if so discard up to and including it.
526
527 if (up_to_plan_sp.get() == NULL)
528 {
529 for (int i = stack_size - 1; i > 0; i--)
530 DiscardPlan();
531 }
532 else
533 {
534 bool found_it = false;
535 for (int i = stack_size - 1; i > 0; i--)
536 {
537 if (m_plan_stack[i] == up_to_plan_sp)
538 found_it = true;
539 }
540 if (found_it)
541 {
542 bool last_one = false;
543 for (int i = stack_size - 1; i > 0 && !last_one ; i--)
544 {
545 if (GetCurrentPlan() == up_to_plan_sp.get())
546 last_one = true;
547 DiscardPlan();
548 }
549 }
550 }
551 return;
552}
553
554void
Chris Lattner24943d22010-06-08 16:52:24 +0000555Thread::DiscardThreadPlans(bool force)
556{
Greg Claytone005f2c2010-11-06 01:53:30 +0000557 LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
Chris Lattner24943d22010-06-08 16:52:24 +0000558 if (log)
559 {
Greg Claytonf04d6612010-09-03 22:45:01 +0000560 log->Printf("Discarding thread plans for thread (tid = 0x%4.4x, force %d)", GetID(), force);
Chris Lattner24943d22010-06-08 16:52:24 +0000561 }
562
563 if (force)
564 {
565 int stack_size = m_plan_stack.size();
566 for (int i = stack_size - 1; i > 0; i--)
567 {
568 DiscardPlan();
569 }
570 return;
571 }
572
573 while (1)
574 {
575
576 int master_plan_idx;
577 bool discard;
578
579 // Find the first master plan, see if it wants discarding, and if yes discard up to it.
580 for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--)
581 {
582 if (m_plan_stack[master_plan_idx]->IsMasterPlan())
583 {
584 discard = m_plan_stack[master_plan_idx]->OkayToDiscard();
585 break;
586 }
587 }
588
589 if (discard)
590 {
591 // First pop all the dependent plans:
592 for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--)
593 {
594
595 // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop"
596 // for the plan leaves it in a state that it is safe to pop the plan
597 // with no more notice?
598 DiscardPlan();
599 }
600
601 // Now discard the master plan itself.
602 // The bottom-most plan never gets discarded. "OkayToDiscard" for it means
603 // discard it's dependent plans, but not it...
604 if (master_plan_idx > 0)
605 {
606 DiscardPlan();
607 }
608 }
609 else
610 {
611 // If the master plan doesn't want to get discarded, then we're done.
612 break;
613 }
614
615 }
Chris Lattner24943d22010-06-08 16:52:24 +0000616}
617
618ThreadPlan *
619Thread::QueueFundamentalPlan (bool abort_other_plans)
620{
621 ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this));
622 QueueThreadPlan (thread_plan_sp, abort_other_plans);
623 return thread_plan_sp.get();
624}
625
626ThreadPlan *
627Thread::QueueThreadPlanForStepSingleInstruction (bool step_over, bool abort_other_plans, bool stop_other_threads)
628{
629 ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion));
630 QueueThreadPlan (thread_plan_sp, abort_other_plans);
631 return thread_plan_sp.get();
632}
633
634ThreadPlan *
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000635Thread::QueueThreadPlanForStepRange
636(
637 bool abort_other_plans,
638 StepType type,
639 const AddressRange &range,
640 const SymbolContext &addr_context,
641 lldb::RunMode stop_other_threads,
642 bool avoid_code_without_debug_info
643)
Chris Lattner24943d22010-06-08 16:52:24 +0000644{
645 ThreadPlanSP thread_plan_sp;
646 if (type == eStepTypeInto)
Greg Clayton8f5fd6b2010-06-12 18:59:55 +0000647 {
648 ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads);
649 if (avoid_code_without_debug_info)
650 plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug);
651 else
652 plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug);
653 thread_plan_sp.reset (plan);
654 }
Chris Lattner24943d22010-06-08 16:52:24 +0000655 else
656 thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads));
657
658 QueueThreadPlan (thread_plan_sp, abort_other_plans);
659 return thread_plan_sp.get();
660}
661
662
663ThreadPlan *
664Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans)
665{
666 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this));
667 QueueThreadPlan (thread_plan_sp, abort_other_plans);
668 return thread_plan_sp.get();
669}
670
671ThreadPlan *
672Thread::QueueThreadPlanForStepOut (bool abort_other_plans, SymbolContext *addr_context, bool first_insn,
673 bool stop_other_threads, Vote stop_vote, Vote run_vote)
674{
675 ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, addr_context, first_insn, stop_other_threads, stop_vote, run_vote));
676 QueueThreadPlan (thread_plan_sp, abort_other_plans);
677 return thread_plan_sp.get();
678}
679
680ThreadPlan *
681Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads)
682{
Jim Inghamb66cd072010-09-28 01:25:32 +0000683 // Try the dynamic loader first:
Chris Lattner24943d22010-06-08 16:52:24 +0000684 ThreadPlanSP thread_plan_sp(GetProcess().GetDynamicLoader()->GetStepThroughTrampolinePlan (*this, stop_other_threads));
Jim Inghamb66cd072010-09-28 01:25:32 +0000685 // If that didn't come up with anything, try the ObjC runtime plugin:
686 if (thread_plan_sp.get() == NULL)
687 {
688 ObjCLanguageRuntime *objc_runtime = GetProcess().GetObjCLanguageRuntime();
689 if (objc_runtime)
690 thread_plan_sp = objc_runtime->GetStepThroughTrampolinePlan (*this, stop_other_threads);
691 }
692
Chris Lattner24943d22010-06-08 16:52:24 +0000693 if (thread_plan_sp.get() == NULL)
694 {
695 thread_plan_sp.reset(new ThreadPlanStepThrough (*this, stop_other_threads));
696 if (thread_plan_sp && !thread_plan_sp->ValidatePlan (NULL))
Greg Claytonf8e98a62010-07-23 15:37:46 +0000697 return NULL;
Chris Lattner24943d22010-06-08 16:52:24 +0000698 }
699 QueueThreadPlan (thread_plan_sp, abort_other_plans);
700 return thread_plan_sp.get();
701}
702
703ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000704Thread::QueueThreadPlanForCallFunction (bool abort_other_plans,
705 Address& function,
706 lldb::addr_t arg,
707 bool stop_other_threads,
708 bool discard_on_error)
709{
710 ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, arg, stop_other_threads, discard_on_error));
711 QueueThreadPlan (thread_plan_sp, abort_other_plans);
712 return thread_plan_sp.get();
713}
714
715ThreadPlan *
Chris Lattner24943d22010-06-08 16:52:24 +0000716Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans,
717 Address &target_addr,
718 bool stop_other_threads)
719{
720 ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads));
721 QueueThreadPlan (thread_plan_sp, abort_other_plans);
722 return thread_plan_sp.get();
723}
724
725ThreadPlan *
726Thread::QueueThreadPlanForStepUntil (bool abort_other_plans,
727 lldb::addr_t *address_list,
728 size_t num_addresses,
729 bool stop_other_threads)
730{
731 ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads));
732 QueueThreadPlan (thread_plan_sp, abort_other_plans);
733 return thread_plan_sp.get();
734
735}
736
737uint32_t
738Thread::GetIndexID () const
739{
740 return m_index_id;
741}
742
743void
744Thread::DumpThreadPlans (lldb_private::Stream *s) const
745{
746 uint32_t stack_size = m_plan_stack.size();
Greg Claytonf04d6612010-09-03 22:45:01 +0000747 int i;
748 s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4x, stack_size = %d\n", GetIndexID(), GetID(), stack_size);
749 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000750 {
751 s->Printf ("Element %d: ", i);
752 s->IndentMore();
753 m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
754 s->IndentLess();
755 s->EOL();
756 }
757
Chris Lattner24943d22010-06-08 16:52:24 +0000758 stack_size = m_completed_plan_stack.size();
759 s->Printf ("Completed Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000760 for (i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000761 {
762 s->Printf ("Element %d: ", i);
763 s->IndentMore();
764 m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
765 s->IndentLess();
766 s->EOL();
767 }
768
769 stack_size = m_discarded_plan_stack.size();
770 s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size);
Greg Claytonf04d6612010-09-03 22:45:01 +0000771 for (int i = stack_size - 1; i >= 0; i--)
Chris Lattner24943d22010-06-08 16:52:24 +0000772 {
773 s->Printf ("Element %d: ", i);
774 s->IndentMore();
775 m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull);
776 s->IndentLess();
777 s->EOL();
778 }
779
780}
781
782Target *
783Thread::CalculateTarget ()
784{
785 return m_process.CalculateTarget();
786}
787
788Process *
789Thread::CalculateProcess ()
790{
791 return &m_process;
792}
793
794Thread *
795Thread::CalculateThread ()
796{
797 return this;
798}
799
800StackFrame *
801Thread::CalculateStackFrame ()
802{
803 return NULL;
804}
805
806void
Greg Claytona830adb2010-10-04 01:05:56 +0000807Thread::CalculateExecutionContext (ExecutionContext &exe_ctx)
Chris Lattner24943d22010-06-08 16:52:24 +0000808{
Greg Claytona830adb2010-10-04 01:05:56 +0000809 m_process.CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000810 exe_ctx.thread = this;
811 exe_ctx.frame = NULL;
812}
813
Greg Clayton782b9cc2010-08-25 00:35:26 +0000814
815StackFrameList &
816Thread::GetStackFrameList ()
817{
Greg Claytonf40e3082010-08-26 02:28:22 +0000818 if (m_curr_frames_ap.get() == NULL)
Greg Clayton5205f0b2010-09-03 17:10:42 +0000819 m_curr_frames_ap.reset (new StackFrameList (*this, m_prev_frames_sp, true));
Greg Claytonf40e3082010-08-26 02:28:22 +0000820 return *m_curr_frames_ap;
Greg Clayton782b9cc2010-08-25 00:35:26 +0000821}
822
823
824
Jim Ingham71219082010-08-12 02:14:28 +0000825uint32_t
826Thread::GetStackFrameCount()
827{
Greg Clayton782b9cc2010-08-25 00:35:26 +0000828 return GetStackFrameList().GetNumFrames();
829}
Greg Clayton33ed1702010-08-24 00:45:41 +0000830
Greg Clayton33ed1702010-08-24 00:45:41 +0000831
Greg Clayton782b9cc2010-08-25 00:35:26 +0000832void
833Thread::ClearStackFrames ()
834{
Greg Clayton5205f0b2010-09-03 17:10:42 +0000835 if (m_curr_frames_ap.get() && m_curr_frames_ap->GetNumFrames (false) > 1)
836 m_prev_frames_sp.reset (m_curr_frames_ap.release());
837 else
838 m_curr_frames_ap.release();
839
840// StackFrameList::Merge (m_curr_frames_ap, m_prev_frames_sp);
841// assert (m_curr_frames_ap.get() == NULL);
Jim Ingham71219082010-08-12 02:14:28 +0000842}
843
844lldb::StackFrameSP
845Thread::GetStackFrameAtIndex (uint32_t idx)
846{
Greg Clayton72b71582010-09-02 21:44:10 +0000847 return GetStackFrameList().GetFrameAtIndex(idx);
Jim Ingham71219082010-08-12 02:14:28 +0000848}
849
Greg Claytonc12b6b42010-10-10 22:28:11 +0000850uint32_t
851Thread::GetSelectedFrameIndex ()
852{
853 return GetStackFrameList().GetSelectedFrameIndex();
854}
855
Greg Clayton08d7d3a2011-01-06 22:15:06 +0000856lldb::StackFrameSP
857Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx)
858{
859 return GetStackFrameList().GetFrameWithConcreteFrameIndex (unwind_idx);
860}
861
862
Greg Claytonc12b6b42010-10-10 22:28:11 +0000863
Chris Lattner24943d22010-06-08 16:52:24 +0000864lldb::StackFrameSP
Jim Inghamc8332952010-08-26 21:32:51 +0000865Thread::GetSelectedFrame ()
Chris Lattner24943d22010-06-08 16:52:24 +0000866{
Jim Inghamc8332952010-08-26 21:32:51 +0000867 return GetStackFrameAtIndex (GetStackFrameList().GetSelectedFrameIndex());
Chris Lattner24943d22010-06-08 16:52:24 +0000868}
869
870uint32_t
Jim Inghamc8332952010-08-26 21:32:51 +0000871Thread::SetSelectedFrame (lldb_private::StackFrame *frame)
Chris Lattner24943d22010-06-08 16:52:24 +0000872{
Jim Inghamc8332952010-08-26 21:32:51 +0000873 return GetStackFrameList().SetSelectedFrame(frame);
Chris Lattner24943d22010-06-08 16:52:24 +0000874}
875
876void
Jim Inghamc8332952010-08-26 21:32:51 +0000877Thread::SetSelectedFrameByIndex (uint32_t idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000878{
Jim Inghamc8332952010-08-26 21:32:51 +0000879 GetStackFrameList().SetSelectedFrameByIndex(idx);
Chris Lattner24943d22010-06-08 16:52:24 +0000880}
881
882void
Greg Claytona830adb2010-10-04 01:05:56 +0000883Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx)
Chris Lattner24943d22010-06-08 16:52:24 +0000884{
Greg Claytona830adb2010-10-04 01:05:56 +0000885 ExecutionContext exe_ctx;
886 SymbolContext frame_sc;
887 CalculateExecutionContext (exe_ctx);
Chris Lattner24943d22010-06-08 16:52:24 +0000888
Greg Claytona830adb2010-10-04 01:05:56 +0000889 if (frame_idx != LLDB_INVALID_INDEX32)
Chris Lattner24943d22010-06-08 16:52:24 +0000890 {
Greg Claytona830adb2010-10-04 01:05:56 +0000891 StackFrameSP frame_sp(GetStackFrameAtIndex (frame_idx));
Chris Lattner24943d22010-06-08 16:52:24 +0000892 if (frame_sp)
893 {
Greg Claytona830adb2010-10-04 01:05:56 +0000894 exe_ctx.frame = frame_sp.get();
895 frame_sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything);
Chris Lattner24943d22010-06-08 16:52:24 +0000896 }
897 }
898
Greg Claytona830adb2010-10-04 01:05:56 +0000899 const char *thread_format = GetProcess().GetTarget().GetDebugger().GetThreadFormat();
900 assert (thread_format);
901 const char *end = NULL;
902 Debugger::FormatPrompt (thread_format,
903 exe_ctx.frame ? &frame_sc : NULL,
904 &exe_ctx,
905 NULL,
906 strm,
907 &end);
Chris Lattner24943d22010-06-08 16:52:24 +0000908}
909
910lldb::ThreadSP
911Thread::GetSP ()
912{
913 return m_process.GetThreadList().GetThreadSPForThreadPtr(this);
914}
Jim Ingham20594b12010-09-08 03:14:33 +0000915
Greg Clayton990de7b2010-11-18 23:32:35 +0000916
917void
918Thread::Initialize ()
Jim Ingham20594b12010-09-08 03:14:33 +0000919{
Greg Clayton990de7b2010-11-18 23:32:35 +0000920 UserSettingsControllerSP &usc = GetSettingsController();
921 usc.reset (new SettingsController);
922 UserSettingsController::InitializeSettingsController (usc,
923 SettingsController::global_settings_table,
924 SettingsController::instance_settings_table);
925}
Jim Ingham20594b12010-09-08 03:14:33 +0000926
Greg Clayton990de7b2010-11-18 23:32:35 +0000927void
928Thread::Terminate ()
929{
930 UserSettingsControllerSP &usc = GetSettingsController();
931 UserSettingsController::FinalizeSettingsController (usc);
932 usc.reset();
933}
Jim Ingham20594b12010-09-08 03:14:33 +0000934
Greg Clayton990de7b2010-11-18 23:32:35 +0000935UserSettingsControllerSP &
936Thread::GetSettingsController ()
937{
938 static UserSettingsControllerSP g_settings_controller;
Jim Ingham20594b12010-09-08 03:14:33 +0000939 return g_settings_controller;
940}
941
Caroline Tice1ebef442010-09-27 00:30:10 +0000942void
943Thread::UpdateInstanceName ()
944{
945 StreamString sstr;
946 const char *name = GetName();
947
948 if (name && name[0] != '\0')
949 sstr.Printf ("%s", name);
950 else if ((GetIndexID() != 0) || (GetID() != 0))
951 sstr.Printf ("0x%4.4x", GetIndexID(), GetID());
952
953 if (sstr.GetSize() > 0)
954 Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData());
955}
956
Jim Inghamccd584d2010-09-23 17:40:12 +0000957lldb::StackFrameSP
958Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr)
959{
960 return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr);
961}
Caroline Tice7826c882010-10-26 03:11:13 +0000962
963const char *
964Thread::StopReasonAsCString (lldb::StopReason reason)
965{
966 switch (reason)
967 {
968 case eStopReasonInvalid: return "invalid";
969 case eStopReasonNone: return "none";
970 case eStopReasonTrace: return "trace";
971 case eStopReasonBreakpoint: return "breakpoint";
972 case eStopReasonWatchpoint: return "watchpoint";
973 case eStopReasonSignal: return "signal";
974 case eStopReasonException: return "exception";
975 case eStopReasonPlanComplete: return "plan complete";
976 }
977
978
979 static char unknown_state_string[64];
980 snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason);
981 return unknown_state_string;
982}
983
984const char *
985Thread::RunModeAsCString (lldb::RunMode mode)
986{
987 switch (mode)
988 {
989 case eOnlyThisThread: return "only this thread";
990 case eAllThreads: return "all threads";
991 case eOnlyDuringStepping: return "only during stepping";
992 }
993
994 static char unknown_state_string[64];
995 snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode);
996 return unknown_state_string;
997}
Jim Ingham745ac7a2010-11-11 19:26:09 +0000998
Greg Clayton990de7b2010-11-18 23:32:35 +0000999#pragma mark "Thread::SettingsController"
Jim Ingham745ac7a2010-11-11 19:26:09 +00001000//--------------------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001001// class Thread::SettingsController
Jim Ingham745ac7a2010-11-11 19:26:09 +00001002//--------------------------------------------------------------
1003
Greg Clayton990de7b2010-11-18 23:32:35 +00001004Thread::SettingsController::SettingsController () :
Jim Ingham745ac7a2010-11-11 19:26:09 +00001005 UserSettingsController ("thread", Process::GetSettingsController())
1006{
1007 m_default_settings.reset (new ThreadInstanceSettings (*this, false,
1008 InstanceSettings::GetDefaultName().AsCString()));
1009}
1010
Greg Clayton990de7b2010-11-18 23:32:35 +00001011Thread::SettingsController::~SettingsController ()
Jim Ingham745ac7a2010-11-11 19:26:09 +00001012{
1013}
1014
1015lldb::InstanceSettingsSP
Greg Clayton990de7b2010-11-18 23:32:35 +00001016Thread::SettingsController::CreateInstanceSettings (const char *instance_name)
Jim Ingham745ac7a2010-11-11 19:26:09 +00001017{
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001018 ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*GetSettingsController(),
1019 false,
1020 instance_name);
Jim Ingham745ac7a2010-11-11 19:26:09 +00001021 lldb::InstanceSettingsSP new_settings_sp (new_settings);
1022 return new_settings_sp;
1023}
1024
1025#pragma mark "ThreadInstanceSettings"
1026//--------------------------------------------------------------
1027// class ThreadInstanceSettings
1028//--------------------------------------------------------------
1029
1030ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) :
Greg Clayton638351a2010-12-04 00:10:17 +00001031 InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001032 m_avoid_regexp_ap (),
1033 m_trace_enabled (false)
1034{
1035 // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called
1036 // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers.
1037 // For this reason it has to be called here, rather than in the initializer or in the parent constructor.
1038 // This is true for CreateInstanceName() too.
1039
1040 if (GetInstanceName() == InstanceSettings::InvalidName())
1041 {
1042 ChangeInstanceName (std::string (CreateInstanceName().AsCString()));
1043 m_owner.RegisterInstanceSettings (this);
1044 }
1045
1046 if (live_instance)
1047 {
1048 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1049 CopyInstanceSettings (pending_settings,false);
1050 //m_owner.RemovePendingSettings (m_instance_name);
1051 }
1052}
1053
1054ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) :
Greg Claytonc0c1b0c2010-11-19 03:46:01 +00001055 InstanceSettings (*Thread::GetSettingsController(), CreateInstanceName().AsCString()),
Jim Ingham745ac7a2010-11-11 19:26:09 +00001056 m_avoid_regexp_ap (),
1057 m_trace_enabled (rhs.m_trace_enabled)
1058{
1059 if (m_instance_name != InstanceSettings::GetDefaultName())
1060 {
1061 const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name);
1062 CopyInstanceSettings (pending_settings,false);
1063 m_owner.RemovePendingSettings (m_instance_name);
1064 }
1065 if (rhs.m_avoid_regexp_ap.get() != NULL)
1066 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1067}
1068
1069ThreadInstanceSettings::~ThreadInstanceSettings ()
1070{
1071}
1072
1073ThreadInstanceSettings&
1074ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs)
1075{
1076 if (this != &rhs)
1077 {
1078 if (rhs.m_avoid_regexp_ap.get() != NULL)
1079 m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText()));
1080 else
1081 m_avoid_regexp_ap.reset(NULL);
1082 }
1083 m_trace_enabled = rhs.m_trace_enabled;
1084 return *this;
1085}
1086
1087
1088void
1089ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name,
1090 const char *index_value,
1091 const char *value,
1092 const ConstString &instance_name,
1093 const SettingEntry &entry,
1094 lldb::VarSetOperationType op,
1095 Error &err,
1096 bool pending)
1097{
1098 if (var_name == StepAvoidRegexpVarName())
1099 {
1100 std::string regexp_text;
1101 if (m_avoid_regexp_ap.get() != NULL)
1102 regexp_text.append (m_avoid_regexp_ap->GetText());
1103 UserSettingsController::UpdateStringVariable (op, regexp_text, value, err);
1104 if (regexp_text.empty())
1105 m_avoid_regexp_ap.reset();
1106 else
1107 {
1108 m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str()));
1109
1110 }
1111 }
1112 else if (var_name == GetTraceThreadVarName())
1113 {
1114 bool success;
1115 bool result = Args::StringToBoolean(value, false, &success);
1116
1117 if (success)
1118 {
1119 m_trace_enabled = result;
1120 if (!pending)
1121 {
1122 Thread *myself = static_cast<Thread *> (this);
1123 myself->EnableTracer(m_trace_enabled, true);
1124 }
1125 }
1126 else
1127 {
1128 err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value);
1129 }
1130
1131 }
1132}
1133
1134void
1135ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings,
1136 bool pending)
1137{
1138 if (new_settings.get() == NULL)
1139 return;
1140
1141 ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get();
1142 if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL)
1143 m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText()));
1144 else
1145 m_avoid_regexp_ap.reset ();
1146}
1147
1148bool
1149ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry,
1150 const ConstString &var_name,
1151 StringList &value,
1152 Error *err)
1153{
1154 if (var_name == StepAvoidRegexpVarName())
1155 {
1156 if (m_avoid_regexp_ap.get() != NULL)
1157 {
1158 std::string regexp_text("\"");
1159 regexp_text.append(m_avoid_regexp_ap->GetText());
1160 regexp_text.append ("\"");
1161 value.AppendString (regexp_text.c_str());
1162 }
1163
1164 }
1165 else if (var_name == GetTraceThreadVarName())
1166 {
1167 value.AppendString(m_trace_enabled ? "true" : "false");
1168 }
1169 else
1170 {
1171 if (err)
1172 err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString());
1173 return false;
1174 }
1175 return true;
1176}
1177
1178const ConstString
1179ThreadInstanceSettings::CreateInstanceName ()
1180{
1181 static int instance_count = 1;
1182 StreamString sstr;
1183
1184 sstr.Printf ("thread_%d", instance_count);
1185 ++instance_count;
1186
1187 const ConstString ret_val (sstr.GetData());
1188 return ret_val;
1189}
1190
1191const ConstString &
1192ThreadInstanceSettings::StepAvoidRegexpVarName ()
1193{
1194 static ConstString step_avoid_var_name ("step-avoid-regexp");
1195
1196 return step_avoid_var_name;
1197}
1198
1199const ConstString &
1200ThreadInstanceSettings::GetTraceThreadVarName ()
1201{
1202 static ConstString trace_thread_var_name ("trace-thread");
1203
1204 return trace_thread_var_name;
1205}
1206
1207//--------------------------------------------------
Greg Clayton990de7b2010-11-18 23:32:35 +00001208// SettingsController Variable Tables
Jim Ingham745ac7a2010-11-11 19:26:09 +00001209//--------------------------------------------------
1210
1211SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001212Thread::SettingsController::global_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001213{
1214 //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"},
1215 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1216};
1217
1218
1219SettingEntry
Greg Clayton990de7b2010-11-18 23:32:35 +00001220Thread::SettingsController::instance_settings_table[] =
Jim Ingham745ac7a2010-11-11 19:26:09 +00001221{
1222 //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"},
1223 { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." },
1224 { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." },
1225 { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL }
1226};