Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- 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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/BreakpointLocation.h" |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Log.h" |
| 14 | #include "lldb/Core/Stream.h" |
| 15 | #include "lldb/Core/StreamString.h" |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 16 | #include "lldb/Core/RegularExpression.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Host/Host.h" |
| 18 | #include "lldb/Target/DynamicLoader.h" |
| 19 | #include "lldb/Target/ExecutionContext.h" |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 20 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Target/Process.h" |
| 22 | #include "lldb/Target/RegisterContext.h" |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 23 | #include "lldb/Target/StopInfo.h" |
Greg Clayton | 7661a98 | 2010-07-23 16:45:51 +0000 | [diff] [blame] | 24 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 25 | #include "lldb/Target/Thread.h" |
| 26 | #include "lldb/Target/ThreadPlan.h" |
| 27 | #include "lldb/Target/ThreadPlanCallFunction.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #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 Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 37 | #include "lldb/Target/ThreadSpec.h" |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 38 | #include "lldb/Target/Unwind.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 39 | |
| 40 | using namespace lldb; |
| 41 | using namespace lldb_private; |
| 42 | |
| 43 | Thread::Thread (Process &process, lldb::tid_t tid) : |
| 44 | UserID (tid), |
Greg Clayton | c0c1b0c | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 45 | ThreadInstanceSettings (*GetSettingsController()), |
Benjamin Kramer | 36a0810 | 2010-07-16 12:32:33 +0000 | [diff] [blame] | 46 | m_process (process), |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 47 | m_actual_stop_info_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 48 | m_index_id (process.GetNextThreadIndexID ()), |
| 49 | m_reg_context_sp (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 50 | m_state (eStateUnloaded), |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 51 | m_state_mutex (Mutex::eMutexTypeRecursive), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 52 | m_plan_stack (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 53 | m_completed_plan_stack(), |
Greg Clayton | f40e308 | 2010-08-26 02:28:22 +0000 | [diff] [blame] | 54 | m_curr_frames_ap (), |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 55 | m_resume_signal (LLDB_INVALID_SIGNAL_NUMBER), |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 56 | m_resume_state (eStateRunning), |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 57 | m_unwinder_ap (), |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 58 | m_destroy_called (false), |
| 59 | m_thread_stop_reason_stop_id (0) |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 61 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 62 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 63 | if (log) |
| 64 | log->Printf ("%p Thread::Thread(tid = 0x%4.4x)", this, GetID()); |
| 65 | |
| 66 | QueueFundamentalPlan(true); |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 67 | UpdateInstanceName(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | |
| 71 | Thread::~Thread() |
| 72 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 73 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 74 | if (log) |
| 75 | log->Printf ("%p Thread::~Thread(tid = 0x%4.4x)", this, GetID()); |
Jim Ingham | cdea236 | 2010-11-18 02:47:07 +0000 | [diff] [blame] | 76 | /// If you hit this assert, it means your derived class forgot to call DoDestroy in its destructor. |
| 77 | assert (m_destroy_called); |
| 78 | } |
| 79 | |
| 80 | void |
| 81 | Thread::DestroyThread () |
| 82 | { |
| 83 | m_plan_stack.clear(); |
| 84 | m_discarded_plan_stack.clear(); |
| 85 | m_completed_plan_stack.clear(); |
| 86 | m_destroy_called = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 89 | lldb::StopInfoSP |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 90 | Thread::GetStopInfo () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 91 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 92 | ThreadPlanSP plan_sp (GetCompletedPlan()); |
| 93 | if (plan_sp) |
| 94 | return StopInfo::CreateStopReasonWithPlan (plan_sp); |
| 95 | else |
| 96 | return GetPrivateStopReason (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 99 | void |
| 100 | Thread::SetStopInfo (const lldb::StopInfoSP &stop_info_sp) |
| 101 | { |
| 102 | m_actual_stop_info_sp = stop_info_sp; |
| 103 | m_thread_stop_reason_stop_id = GetProcess().GetStopID(); |
| 104 | } |
| 105 | |
| 106 | void |
| 107 | Thread::SetStopInfoToNothing() |
| 108 | { |
| 109 | // Note, we can't just NULL out the private reason, or the native thread implementation will try to |
| 110 | // go calculate it again. For now, just set it to a Unix Signal with an invalid signal number. |
| 111 | SetStopInfo (StopInfo::CreateStopReasonWithSignal (*this, LLDB_INVALID_SIGNAL_NUMBER)); |
| 112 | } |
| 113 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | bool |
| 115 | Thread::ThreadStoppedForAReason (void) |
| 116 | { |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 117 | return GetPrivateStopReason () != NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | } |
| 119 | |
Jim Ingham | 15dcb7c | 2011-01-20 02:03:18 +0000 | [diff] [blame] | 120 | bool |
| 121 | Thread::CheckpointThreadState (ThreadStateCheckpoint &saved_state) |
| 122 | { |
| 123 | if (!SaveFrameZeroState(saved_state.register_backup)) |
| 124 | return false; |
| 125 | |
| 126 | saved_state.stop_info_sp = GetStopInfo(); |
| 127 | saved_state.orig_stop_id = GetProcess().GetStopID(); |
| 128 | |
| 129 | return true; |
| 130 | } |
| 131 | |
| 132 | bool |
| 133 | Thread::RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state) |
| 134 | { |
| 135 | RestoreSaveFrameZero(saved_state.register_backup); |
| 136 | saved_state.stop_info_sp->MakeStopInfoValid(); |
| 137 | SetStopInfo(saved_state.stop_info_sp); |
| 138 | return true; |
| 139 | } |
| 140 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | StateType |
| 142 | Thread::GetState() const |
| 143 | { |
| 144 | // If any other threads access this we will need a mutex for it |
| 145 | Mutex::Locker locker(m_state_mutex); |
| 146 | return m_state; |
| 147 | } |
| 148 | |
| 149 | void |
| 150 | Thread::SetState(StateType state) |
| 151 | { |
| 152 | Mutex::Locker locker(m_state_mutex); |
| 153 | m_state = state; |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | Thread::WillStop() |
| 158 | { |
| 159 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 160 | |
| 161 | // FIXME: I may decide to disallow threads with no plans. In which |
| 162 | // case this should go to an assert. |
| 163 | |
| 164 | if (!current_plan) |
| 165 | return; |
| 166 | |
| 167 | current_plan->WillStop(); |
| 168 | } |
| 169 | |
| 170 | void |
| 171 | Thread::SetupForResume () |
| 172 | { |
| 173 | if (GetResumeState() != eStateSuspended) |
| 174 | { |
| 175 | |
| 176 | // If we're at a breakpoint push the step-over breakpoint plan. Do this before |
| 177 | // telling the current plan it will resume, since we might change what the current |
| 178 | // plan is. |
| 179 | |
| 180 | lldb::addr_t pc = GetRegisterContext()->GetPC(); |
| 181 | BreakpointSiteSP bp_site_sp = GetProcess().GetBreakpointSiteList().FindByAddress(pc); |
| 182 | if (bp_site_sp && bp_site_sp->IsEnabled()) |
| 183 | { |
| 184 | // Note, don't assume there's a ThreadPlanStepOverBreakpoint, the target may not require anything |
| 185 | // special to step over a breakpoint. |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 186 | |
| 187 | ThreadPlan *cur_plan = GetCurrentPlan(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 189 | if (cur_plan->GetKind() != ThreadPlan::eKindStepOverBreakpoint) |
| 190 | { |
| 191 | ThreadPlanStepOverBreakpoint *step_bp_plan = new ThreadPlanStepOverBreakpoint (*this); |
| 192 | if (step_bp_plan) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 193 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 194 | ThreadPlanSP step_bp_plan_sp; |
| 195 | step_bp_plan->SetPrivate (true); |
| 196 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 197 | if (GetCurrentPlan()->RunState() != eStateStepping) |
| 198 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 199 | step_bp_plan->SetAutoContinue(true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 200 | } |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 201 | step_bp_plan_sp.reset (step_bp_plan); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | QueueThreadPlan (step_bp_plan_sp, false); |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | bool |
| 210 | Thread::WillResume (StateType resume_state) |
| 211 | { |
| 212 | // At this point clear the completed plan stack. |
| 213 | m_completed_plan_stack.clear(); |
| 214 | m_discarded_plan_stack.clear(); |
| 215 | |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 216 | StopInfo *stop_info = GetPrivateStopReason().get(); |
| 217 | if (stop_info) |
| 218 | stop_info->WillResume (resume_state); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | |
| 220 | // Tell all the plans that we are about to resume in case they need to clear any state. |
| 221 | // We distinguish between the plan on the top of the stack and the lower |
| 222 | // plans in case a plan needs to do any special business before it runs. |
| 223 | |
| 224 | ThreadPlan *plan_ptr = GetCurrentPlan(); |
| 225 | plan_ptr->WillResume(resume_state, true); |
| 226 | |
| 227 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 228 | { |
| 229 | plan_ptr->WillResume (resume_state, false); |
| 230 | } |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 231 | |
Greg Clayton | 643ee73 | 2010-08-04 01:40:35 +0000 | [diff] [blame] | 232 | m_actual_stop_info_sp.reset(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
| 236 | void |
| 237 | Thread::DidResume () |
| 238 | { |
| 239 | SetResumeSignal (LLDB_INVALID_SIGNAL_NUMBER); |
| 240 | } |
| 241 | |
| 242 | bool |
| 243 | Thread::ShouldStop (Event* event_ptr) |
| 244 | { |
| 245 | ThreadPlan *current_plan = GetCurrentPlan(); |
| 246 | bool should_stop = true; |
| 247 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 248 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | if (log) |
| 250 | { |
| 251 | StreamString s; |
| 252 | DumpThreadPlans(&s); |
| 253 | log->PutCString (s.GetData()); |
| 254 | } |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 255 | |
| 256 | // The top most plan always gets to do the trace log... |
| 257 | current_plan->DoTraceLog (); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | |
| 259 | if (current_plan->PlanExplainsStop()) |
| 260 | { |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 261 | bool over_ride_stop = current_plan->ShouldAutoContinue(event_ptr); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | while (1) |
| 263 | { |
| 264 | should_stop = current_plan->ShouldStop(event_ptr); |
| 265 | if (current_plan->MischiefManaged()) |
| 266 | { |
| 267 | if (should_stop) |
| 268 | current_plan->WillStop(); |
| 269 | |
| 270 | // If a Master Plan wants to stop, and wants to stick on the stack, we let it. |
| 271 | // Otherwise, see if the plan's parent wants to stop. |
| 272 | |
| 273 | if (should_stop && current_plan->IsMasterPlan() && !current_plan->OkayToDiscard()) |
| 274 | { |
| 275 | PopPlan(); |
| 276 | break; |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | |
| 281 | PopPlan(); |
| 282 | |
| 283 | current_plan = GetCurrentPlan(); |
| 284 | if (current_plan == NULL) |
| 285 | { |
| 286 | break; |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | break; |
| 294 | } |
| 295 | } |
Jim Ingham | 5a47e8b | 2010-06-19 04:45:32 +0000 | [diff] [blame] | 296 | if (over_ride_stop) |
| 297 | should_stop = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | } |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 299 | else if (current_plan->TracerExplainsStop()) |
| 300 | { |
| 301 | return false; |
| 302 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 303 | else |
| 304 | { |
| 305 | // If the current plan doesn't explain the stop, then, find one that |
| 306 | // does and let it handle the situation. |
| 307 | ThreadPlan *plan_ptr = current_plan; |
| 308 | while ((plan_ptr = GetPreviousPlan(plan_ptr)) != NULL) |
| 309 | { |
| 310 | if (plan_ptr->PlanExplainsStop()) |
| 311 | { |
| 312 | should_stop = plan_ptr->ShouldStop (event_ptr); |
| 313 | break; |
| 314 | } |
| 315 | |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | return should_stop; |
| 320 | } |
| 321 | |
| 322 | Vote |
| 323 | Thread::ShouldReportStop (Event* event_ptr) |
| 324 | { |
| 325 | StateType thread_state = GetResumeState (); |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 326 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 327 | |
| 328 | if (thread_state == eStateSuspended || thread_state == eStateInvalid) |
| 329 | { |
| 330 | if (log) |
| 331 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote %i (state was suspended or invalid)\n", GetID(), eVoteNoOpinion); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 332 | return eVoteNoOpinion; |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 333 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 334 | |
| 335 | if (m_completed_plan_stack.size() > 0) |
| 336 | { |
| 337 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 338 | if (log) |
| 339 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote for complete stack's back plan\n", GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | return m_completed_plan_stack.back()->ShouldReportStop (event_ptr); |
| 341 | } |
| 342 | else |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 343 | { |
| 344 | if (log) |
| 345 | log->Printf ("Thread::ShouldReportStop() tid = 0x%4.4x: returning vote for current plan\n", GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 346 | return GetCurrentPlan()->ShouldReportStop (event_ptr); |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 347 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | Vote |
| 351 | Thread::ShouldReportRun (Event* event_ptr) |
| 352 | { |
| 353 | StateType thread_state = GetResumeState (); |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 354 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 355 | if (thread_state == eStateSuspended |
| 356 | || thread_state == eStateInvalid) |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 357 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | return eVoteNoOpinion; |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 359 | } |
| 360 | |
| 361 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 362 | if (m_completed_plan_stack.size() > 0) |
| 363 | { |
| 364 | // Don't use GetCompletedPlan here, since that suppresses private plans. |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 365 | if (log) |
| 366 | log->Printf ("Current Plan for thread %d (0x%4.4x): %s being asked whether we should report run.", |
| 367 | GetIndexID(), |
| 368 | GetID(), |
| 369 | m_completed_plan_stack.back()->GetName()); |
| 370 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 371 | return m_completed_plan_stack.back()->ShouldReportRun (event_ptr); |
| 372 | } |
| 373 | else |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 374 | { |
| 375 | if (log) |
| 376 | log->Printf ("Current Plan for thread %d (0x%4.4x): %s being asked whether we should report run.", |
| 377 | GetIndexID(), |
| 378 | GetID(), |
| 379 | GetCurrentPlan()->GetName()); |
| 380 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 381 | return GetCurrentPlan()->ShouldReportRun (event_ptr); |
Jim Ingham | ac95966 | 2011-01-24 06:34:17 +0000 | [diff] [blame^] | 382 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 385 | bool |
| 386 | Thread::MatchesSpec (const ThreadSpec *spec) |
| 387 | { |
| 388 | if (spec == NULL) |
| 389 | return true; |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 390 | |
Jim Ingham | 649492b | 2010-06-18 01:00:58 +0000 | [diff] [blame] | 391 | return spec->ThreadPassesBasicTests(this); |
Jim Ingham | 3c7b5b9 | 2010-06-16 02:00:15 +0000 | [diff] [blame] | 392 | } |
| 393 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 394 | void |
| 395 | Thread::PushPlan (ThreadPlanSP &thread_plan_sp) |
| 396 | { |
| 397 | if (thread_plan_sp) |
| 398 | { |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 399 | // If the thread plan doesn't already have a tracer, give it its parent's tracer: |
| 400 | if (!thread_plan_sp->GetThreadPlanTracer()) |
| 401 | thread_plan_sp->SetThreadPlanTracer(m_plan_stack.back()->GetThreadPlanTracer()); |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 402 | m_plan_stack.push_back (thread_plan_sp); |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 403 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 404 | thread_plan_sp->DidPush(); |
| 405 | |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 406 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 407 | if (log) |
| 408 | { |
| 409 | StreamString s; |
| 410 | thread_plan_sp->GetDescription (&s, lldb::eDescriptionLevelFull); |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 411 | log->Printf("Pushing plan: \"%s\", tid = 0x%4.4x.", |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | s.GetData(), |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 413 | thread_plan_sp->GetThread().GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 414 | } |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | void |
| 419 | Thread::PopPlan () |
| 420 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 421 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 423 | if (m_plan_stack.empty()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | return; |
| 425 | else |
| 426 | { |
| 427 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 428 | if (log) |
| 429 | { |
Jim Ingham | 83e8b9d | 2010-11-10 18:17:03 +0000 | [diff] [blame] | 430 | log->Printf("Popping plan: \"%s\", tid = 0x%4.4x.", plan->GetName(), plan->GetThread().GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 431 | } |
| 432 | m_completed_plan_stack.push_back (plan); |
| 433 | plan->WillPop(); |
| 434 | m_plan_stack.pop_back(); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | void |
| 439 | Thread::DiscardPlan () |
| 440 | { |
| 441 | if (m_plan_stack.size() > 1) |
| 442 | { |
| 443 | ThreadPlanSP &plan = m_plan_stack.back(); |
| 444 | m_discarded_plan_stack.push_back (plan); |
| 445 | plan->WillPop(); |
| 446 | m_plan_stack.pop_back(); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | ThreadPlan * |
| 451 | Thread::GetCurrentPlan () |
| 452 | { |
Jim Ingham | 6297a3a | 2010-10-20 00:39:53 +0000 | [diff] [blame] | 453 | if (m_plan_stack.empty()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | return NULL; |
| 455 | else |
| 456 | return m_plan_stack.back().get(); |
| 457 | } |
| 458 | |
| 459 | ThreadPlanSP |
| 460 | Thread::GetCompletedPlan () |
| 461 | { |
| 462 | ThreadPlanSP empty_plan_sp; |
| 463 | if (!m_completed_plan_stack.empty()) |
| 464 | { |
| 465 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 466 | { |
| 467 | ThreadPlanSP completed_plan_sp; |
| 468 | completed_plan_sp = m_completed_plan_stack[i]; |
| 469 | if (!completed_plan_sp->GetPrivate ()) |
| 470 | return completed_plan_sp; |
| 471 | } |
| 472 | } |
| 473 | return empty_plan_sp; |
| 474 | } |
| 475 | |
| 476 | bool |
| 477 | Thread::IsThreadPlanDone (ThreadPlan *plan) |
| 478 | { |
| 479 | ThreadPlanSP empty_plan_sp; |
| 480 | if (!m_completed_plan_stack.empty()) |
| 481 | { |
| 482 | for (int i = m_completed_plan_stack.size() - 1; i >= 0; i--) |
| 483 | { |
| 484 | if (m_completed_plan_stack[i].get() == plan) |
| 485 | return true; |
| 486 | } |
| 487 | } |
| 488 | return false; |
| 489 | } |
| 490 | |
| 491 | bool |
| 492 | Thread::WasThreadPlanDiscarded (ThreadPlan *plan) |
| 493 | { |
| 494 | ThreadPlanSP empty_plan_sp; |
| 495 | if (!m_discarded_plan_stack.empty()) |
| 496 | { |
| 497 | for (int i = m_discarded_plan_stack.size() - 1; i >= 0; i--) |
| 498 | { |
| 499 | if (m_discarded_plan_stack[i].get() == plan) |
| 500 | return true; |
| 501 | } |
| 502 | } |
| 503 | return false; |
| 504 | } |
| 505 | |
| 506 | ThreadPlan * |
| 507 | Thread::GetPreviousPlan (ThreadPlan *current_plan) |
| 508 | { |
| 509 | if (current_plan == NULL) |
| 510 | return NULL; |
| 511 | |
| 512 | int stack_size = m_completed_plan_stack.size(); |
| 513 | for (int i = stack_size - 1; i > 0; i--) |
| 514 | { |
| 515 | if (current_plan == m_completed_plan_stack[i].get()) |
| 516 | return m_completed_plan_stack[i-1].get(); |
| 517 | } |
| 518 | |
| 519 | if (stack_size > 0 && m_completed_plan_stack[0].get() == current_plan) |
| 520 | { |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 521 | if (m_plan_stack.size() > 0) |
| 522 | return m_plan_stack.back().get(); |
| 523 | else |
| 524 | return NULL; |
| 525 | } |
| 526 | |
| 527 | stack_size = m_plan_stack.size(); |
| 528 | for (int i = stack_size - 1; i > 0; i--) |
| 529 | { |
| 530 | if (current_plan == m_plan_stack[i].get()) |
| 531 | return m_plan_stack[i-1].get(); |
| 532 | } |
| 533 | return NULL; |
| 534 | } |
| 535 | |
| 536 | void |
| 537 | Thread::QueueThreadPlan (ThreadPlanSP &thread_plan_sp, bool abort_other_plans) |
| 538 | { |
| 539 | if (abort_other_plans) |
| 540 | DiscardThreadPlans(true); |
| 541 | |
| 542 | PushPlan (thread_plan_sp); |
| 543 | } |
| 544 | |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 545 | |
| 546 | void |
| 547 | Thread::EnableTracer (bool value, bool single_stepping) |
| 548 | { |
| 549 | int stack_size = m_plan_stack.size(); |
| 550 | for (int i = 0; i < stack_size; i++) |
| 551 | { |
| 552 | if (m_plan_stack[i]->GetThreadPlanTracer()) |
| 553 | { |
| 554 | m_plan_stack[i]->GetThreadPlanTracer()->EnableTracing(value); |
| 555 | m_plan_stack[i]->GetThreadPlanTracer()->EnableSingleStep(single_stepping); |
| 556 | } |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | void |
| 561 | Thread::SetTracer (lldb::ThreadPlanTracerSP &tracer_sp) |
| 562 | { |
| 563 | int stack_size = m_plan_stack.size(); |
| 564 | for (int i = 0; i < stack_size; i++) |
| 565 | m_plan_stack[i]->SetThreadPlanTracer(tracer_sp); |
| 566 | } |
| 567 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 568 | void |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 569 | Thread::DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp) |
| 570 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 571 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Jim Ingham | ea9d426 | 2010-11-05 19:25:48 +0000 | [diff] [blame] | 572 | if (log) |
| 573 | { |
| 574 | log->Printf("Discarding thread plans for thread tid = 0x%4.4x, up to %p", GetID(), up_to_plan_sp.get()); |
| 575 | } |
| 576 | |
| 577 | int stack_size = m_plan_stack.size(); |
| 578 | |
| 579 | // If the input plan is NULL, discard all plans. Otherwise make sure this plan is in the |
| 580 | // stack, and if so discard up to and including it. |
| 581 | |
| 582 | if (up_to_plan_sp.get() == NULL) |
| 583 | { |
| 584 | for (int i = stack_size - 1; i > 0; i--) |
| 585 | DiscardPlan(); |
| 586 | } |
| 587 | else |
| 588 | { |
| 589 | bool found_it = false; |
| 590 | for (int i = stack_size - 1; i > 0; i--) |
| 591 | { |
| 592 | if (m_plan_stack[i] == up_to_plan_sp) |
| 593 | found_it = true; |
| 594 | } |
| 595 | if (found_it) |
| 596 | { |
| 597 | bool last_one = false; |
| 598 | for (int i = stack_size - 1; i > 0 && !last_one ; i--) |
| 599 | { |
| 600 | if (GetCurrentPlan() == up_to_plan_sp.get()) |
| 601 | last_one = true; |
| 602 | DiscardPlan(); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | return; |
| 607 | } |
| 608 | |
| 609 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 610 | Thread::DiscardThreadPlans(bool force) |
| 611 | { |
Greg Clayton | e005f2c | 2010-11-06 01:53:30 +0000 | [diff] [blame] | 612 | LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 613 | if (log) |
| 614 | { |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 615 | log->Printf("Discarding thread plans for thread (tid = 0x%4.4x, force %d)", GetID(), force); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | if (force) |
| 619 | { |
| 620 | int stack_size = m_plan_stack.size(); |
| 621 | for (int i = stack_size - 1; i > 0; i--) |
| 622 | { |
| 623 | DiscardPlan(); |
| 624 | } |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | while (1) |
| 629 | { |
| 630 | |
| 631 | int master_plan_idx; |
| 632 | bool discard; |
| 633 | |
| 634 | // Find the first master plan, see if it wants discarding, and if yes discard up to it. |
| 635 | for (master_plan_idx = m_plan_stack.size() - 1; master_plan_idx >= 0; master_plan_idx--) |
| 636 | { |
| 637 | if (m_plan_stack[master_plan_idx]->IsMasterPlan()) |
| 638 | { |
| 639 | discard = m_plan_stack[master_plan_idx]->OkayToDiscard(); |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | if (discard) |
| 645 | { |
| 646 | // First pop all the dependent plans: |
| 647 | for (int i = m_plan_stack.size() - 1; i > master_plan_idx; i--) |
| 648 | { |
| 649 | |
| 650 | // FIXME: Do we need a finalize here, or is the rule that "PrepareForStop" |
| 651 | // for the plan leaves it in a state that it is safe to pop the plan |
| 652 | // with no more notice? |
| 653 | DiscardPlan(); |
| 654 | } |
| 655 | |
| 656 | // Now discard the master plan itself. |
| 657 | // The bottom-most plan never gets discarded. "OkayToDiscard" for it means |
| 658 | // discard it's dependent plans, but not it... |
| 659 | if (master_plan_idx > 0) |
| 660 | { |
| 661 | DiscardPlan(); |
| 662 | } |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | // If the master plan doesn't want to get discarded, then we're done. |
| 667 | break; |
| 668 | } |
| 669 | |
| 670 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | ThreadPlan * |
| 674 | Thread::QueueFundamentalPlan (bool abort_other_plans) |
| 675 | { |
| 676 | ThreadPlanSP thread_plan_sp (new ThreadPlanBase(*this)); |
| 677 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 678 | return thread_plan_sp.get(); |
| 679 | } |
| 680 | |
| 681 | ThreadPlan * |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 682 | Thread::QueueThreadPlanForStepSingleInstruction |
| 683 | ( |
| 684 | bool step_over, |
| 685 | bool abort_other_plans, |
| 686 | bool stop_other_threads |
| 687 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 688 | { |
| 689 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepInstruction (*this, step_over, stop_other_threads, eVoteNoOpinion, eVoteNoOpinion)); |
| 690 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 691 | return thread_plan_sp.get(); |
| 692 | } |
| 693 | |
| 694 | ThreadPlan * |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 695 | Thread::QueueThreadPlanForStepRange |
| 696 | ( |
| 697 | bool abort_other_plans, |
| 698 | StepType type, |
| 699 | const AddressRange &range, |
| 700 | const SymbolContext &addr_context, |
| 701 | lldb::RunMode stop_other_threads, |
| 702 | bool avoid_code_without_debug_info |
| 703 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 704 | { |
| 705 | ThreadPlanSP thread_plan_sp; |
| 706 | if (type == eStepTypeInto) |
Greg Clayton | 8f5fd6b | 2010-06-12 18:59:55 +0000 | [diff] [blame] | 707 | { |
| 708 | ThreadPlanStepInRange *plan = new ThreadPlanStepInRange (*this, range, addr_context, stop_other_threads); |
| 709 | if (avoid_code_without_debug_info) |
| 710 | plan->GetFlags().Set (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 711 | else |
| 712 | plan->GetFlags().Clear (ThreadPlanShouldStopHere::eAvoidNoDebug); |
| 713 | thread_plan_sp.reset (plan); |
| 714 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 715 | else |
| 716 | thread_plan_sp.reset (new ThreadPlanStepOverRange (*this, range, addr_context, stop_other_threads)); |
| 717 | |
| 718 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 719 | return thread_plan_sp.get(); |
| 720 | } |
| 721 | |
| 722 | |
| 723 | ThreadPlan * |
| 724 | Thread::QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans) |
| 725 | { |
| 726 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOverBreakpoint (*this)); |
| 727 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 728 | return thread_plan_sp.get(); |
| 729 | } |
| 730 | |
| 731 | ThreadPlan * |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 732 | Thread::QueueThreadPlanForStepOut |
| 733 | ( |
| 734 | bool abort_other_plans, |
| 735 | SymbolContext *addr_context, |
| 736 | bool first_insn, |
| 737 | bool stop_other_threads, |
| 738 | Vote stop_vote, |
| 739 | Vote run_vote, |
| 740 | uint32_t frame_idx |
| 741 | ) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | { |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 743 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepOut (*this, |
| 744 | addr_context, |
| 745 | first_insn, |
| 746 | stop_other_threads, |
| 747 | stop_vote, |
| 748 | run_vote, |
| 749 | frame_idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 750 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 751 | return thread_plan_sp.get(); |
| 752 | } |
| 753 | |
| 754 | ThreadPlan * |
| 755 | Thread::QueueThreadPlanForStepThrough (bool abort_other_plans, bool stop_other_threads) |
| 756 | { |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 757 | // Try the dynamic loader first: |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 758 | ThreadPlanSP thread_plan_sp(GetProcess().GetDynamicLoader()->GetStepThroughTrampolinePlan (*this, stop_other_threads)); |
Jim Ingham | b66cd07 | 2010-09-28 01:25:32 +0000 | [diff] [blame] | 759 | // If that didn't come up with anything, try the ObjC runtime plugin: |
| 760 | if (thread_plan_sp.get() == NULL) |
| 761 | { |
| 762 | ObjCLanguageRuntime *objc_runtime = GetProcess().GetObjCLanguageRuntime(); |
| 763 | if (objc_runtime) |
| 764 | thread_plan_sp = objc_runtime->GetStepThroughTrampolinePlan (*this, stop_other_threads); |
| 765 | } |
| 766 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 767 | if (thread_plan_sp.get() == NULL) |
| 768 | { |
| 769 | thread_plan_sp.reset(new ThreadPlanStepThrough (*this, stop_other_threads)); |
| 770 | if (thread_plan_sp && !thread_plan_sp->ValidatePlan (NULL)) |
Greg Clayton | f8e98a6 | 2010-07-23 15:37:46 +0000 | [diff] [blame] | 771 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 772 | } |
| 773 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 774 | return thread_plan_sp.get(); |
| 775 | } |
| 776 | |
| 777 | ThreadPlan * |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 778 | Thread::QueueThreadPlanForCallFunction (bool abort_other_plans, |
| 779 | Address& function, |
| 780 | lldb::addr_t arg, |
| 781 | bool stop_other_threads, |
| 782 | bool discard_on_error) |
| 783 | { |
| 784 | ThreadPlanSP thread_plan_sp (new ThreadPlanCallFunction (*this, function, arg, stop_other_threads, discard_on_error)); |
| 785 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 786 | return thread_plan_sp.get(); |
| 787 | } |
| 788 | |
| 789 | ThreadPlan * |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 790 | Thread::QueueThreadPlanForRunToAddress (bool abort_other_plans, |
| 791 | Address &target_addr, |
| 792 | bool stop_other_threads) |
| 793 | { |
| 794 | ThreadPlanSP thread_plan_sp (new ThreadPlanRunToAddress (*this, target_addr, stop_other_threads)); |
| 795 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 796 | return thread_plan_sp.get(); |
| 797 | } |
| 798 | |
| 799 | ThreadPlan * |
| 800 | Thread::QueueThreadPlanForStepUntil (bool abort_other_plans, |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 801 | lldb::addr_t *address_list, |
| 802 | size_t num_addresses, |
| 803 | bool stop_other_threads, |
| 804 | uint32_t frame_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 805 | { |
Greg Clayton | 1ebdcc7 | 2011-01-21 06:11:58 +0000 | [diff] [blame] | 806 | ThreadPlanSP thread_plan_sp (new ThreadPlanStepUntil (*this, address_list, num_addresses, stop_other_threads, frame_idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 807 | QueueThreadPlan (thread_plan_sp, abort_other_plans); |
| 808 | return thread_plan_sp.get(); |
| 809 | |
| 810 | } |
| 811 | |
| 812 | uint32_t |
| 813 | Thread::GetIndexID () const |
| 814 | { |
| 815 | return m_index_id; |
| 816 | } |
| 817 | |
| 818 | void |
| 819 | Thread::DumpThreadPlans (lldb_private::Stream *s) const |
| 820 | { |
| 821 | uint32_t stack_size = m_plan_stack.size(); |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 822 | int i; |
| 823 | s->Printf ("Plan Stack for thread #%u: tid = 0x%4.4x, stack_size = %d\n", GetIndexID(), GetID(), stack_size); |
| 824 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 825 | { |
| 826 | s->Printf ("Element %d: ", i); |
| 827 | s->IndentMore(); |
| 828 | m_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 829 | s->IndentLess(); |
| 830 | s->EOL(); |
| 831 | } |
| 832 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 833 | stack_size = m_completed_plan_stack.size(); |
| 834 | s->Printf ("Completed Plan Stack: %d elements.\n", stack_size); |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 835 | for (i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 836 | { |
| 837 | s->Printf ("Element %d: ", i); |
| 838 | s->IndentMore(); |
| 839 | m_completed_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 840 | s->IndentLess(); |
| 841 | s->EOL(); |
| 842 | } |
| 843 | |
| 844 | stack_size = m_discarded_plan_stack.size(); |
| 845 | s->Printf ("Discarded Plan Stack: %d elements.\n", stack_size); |
Greg Clayton | f04d661 | 2010-09-03 22:45:01 +0000 | [diff] [blame] | 846 | for (int i = stack_size - 1; i >= 0; i--) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 847 | { |
| 848 | s->Printf ("Element %d: ", i); |
| 849 | s->IndentMore(); |
| 850 | m_discarded_plan_stack[i]->GetDescription (s, eDescriptionLevelFull); |
| 851 | s->IndentLess(); |
| 852 | s->EOL(); |
| 853 | } |
| 854 | |
| 855 | } |
| 856 | |
| 857 | Target * |
| 858 | Thread::CalculateTarget () |
| 859 | { |
| 860 | return m_process.CalculateTarget(); |
| 861 | } |
| 862 | |
| 863 | Process * |
| 864 | Thread::CalculateProcess () |
| 865 | { |
| 866 | return &m_process; |
| 867 | } |
| 868 | |
| 869 | Thread * |
| 870 | Thread::CalculateThread () |
| 871 | { |
| 872 | return this; |
| 873 | } |
| 874 | |
| 875 | StackFrame * |
| 876 | Thread::CalculateStackFrame () |
| 877 | { |
| 878 | return NULL; |
| 879 | } |
| 880 | |
| 881 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 882 | Thread::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 883 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 884 | m_process.CalculateExecutionContext (exe_ctx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | exe_ctx.thread = this; |
| 886 | exe_ctx.frame = NULL; |
| 887 | } |
| 888 | |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 889 | |
| 890 | StackFrameList & |
| 891 | Thread::GetStackFrameList () |
| 892 | { |
Greg Clayton | f40e308 | 2010-08-26 02:28:22 +0000 | [diff] [blame] | 893 | if (m_curr_frames_ap.get() == NULL) |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 894 | m_curr_frames_ap.reset (new StackFrameList (*this, m_prev_frames_sp, true)); |
Greg Clayton | f40e308 | 2010-08-26 02:28:22 +0000 | [diff] [blame] | 895 | return *m_curr_frames_ap; |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | |
| 899 | |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 900 | uint32_t |
| 901 | Thread::GetStackFrameCount() |
| 902 | { |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 903 | return GetStackFrameList().GetNumFrames(); |
| 904 | } |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 905 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 906 | |
Greg Clayton | 782b9cc | 2010-08-25 00:35:26 +0000 | [diff] [blame] | 907 | void |
| 908 | Thread::ClearStackFrames () |
| 909 | { |
Greg Clayton | 5205f0b | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 910 | if (m_curr_frames_ap.get() && m_curr_frames_ap->GetNumFrames (false) > 1) |
| 911 | m_prev_frames_sp.reset (m_curr_frames_ap.release()); |
| 912 | else |
| 913 | m_curr_frames_ap.release(); |
| 914 | |
| 915 | // StackFrameList::Merge (m_curr_frames_ap, m_prev_frames_sp); |
| 916 | // assert (m_curr_frames_ap.get() == NULL); |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | lldb::StackFrameSP |
| 920 | Thread::GetStackFrameAtIndex (uint32_t idx) |
| 921 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 922 | return GetStackFrameList().GetFrameAtIndex(idx); |
Jim Ingham | 7121908 | 2010-08-12 02:14:28 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Greg Clayton | c12b6b4 | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 925 | uint32_t |
| 926 | Thread::GetSelectedFrameIndex () |
| 927 | { |
| 928 | return GetStackFrameList().GetSelectedFrameIndex(); |
| 929 | } |
| 930 | |
Greg Clayton | 08d7d3a | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 931 | lldb::StackFrameSP |
| 932 | Thread::GetFrameWithConcreteFrameIndex (uint32_t unwind_idx) |
| 933 | { |
| 934 | return GetStackFrameList().GetFrameWithConcreteFrameIndex (unwind_idx); |
| 935 | } |
| 936 | |
| 937 | |
Greg Clayton | c12b6b4 | 2010-10-10 22:28:11 +0000 | [diff] [blame] | 938 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 939 | lldb::StackFrameSP |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 940 | Thread::GetSelectedFrame () |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 941 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 942 | return GetStackFrameAtIndex (GetStackFrameList().GetSelectedFrameIndex()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | uint32_t |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 946 | Thread::SetSelectedFrame (lldb_private::StackFrame *frame) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 947 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 948 | return GetStackFrameList().SetSelectedFrame(frame); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | void |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 952 | Thread::SetSelectedFrameByIndex (uint32_t idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 953 | { |
Jim Ingham | c833295 | 2010-08-26 21:32:51 +0000 | [diff] [blame] | 954 | GetStackFrameList().SetSelectedFrameByIndex(idx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | void |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 958 | Thread::DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 959 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 960 | ExecutionContext exe_ctx; |
| 961 | SymbolContext frame_sc; |
| 962 | CalculateExecutionContext (exe_ctx); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 963 | |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 964 | if (frame_idx != LLDB_INVALID_INDEX32) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 965 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 966 | StackFrameSP frame_sp(GetStackFrameAtIndex (frame_idx)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 967 | if (frame_sp) |
| 968 | { |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 969 | exe_ctx.frame = frame_sp.get(); |
| 970 | frame_sc = exe_ctx.frame->GetSymbolContext(eSymbolContextEverything); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Greg Clayton | a830adb | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 974 | const char *thread_format = GetProcess().GetTarget().GetDebugger().GetThreadFormat(); |
| 975 | assert (thread_format); |
| 976 | const char *end = NULL; |
| 977 | Debugger::FormatPrompt (thread_format, |
| 978 | exe_ctx.frame ? &frame_sc : NULL, |
| 979 | &exe_ctx, |
| 980 | NULL, |
| 981 | strm, |
| 982 | &end); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | lldb::ThreadSP |
| 986 | Thread::GetSP () |
| 987 | { |
| 988 | return m_process.GetThreadList().GetThreadSPForThreadPtr(this); |
| 989 | } |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 990 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 991 | |
| 992 | void |
| 993 | Thread::Initialize () |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 994 | { |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 995 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 996 | usc.reset (new SettingsController); |
| 997 | UserSettingsController::InitializeSettingsController (usc, |
| 998 | SettingsController::global_settings_table, |
| 999 | SettingsController::instance_settings_table); |
| 1000 | } |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1001 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1002 | void |
| 1003 | Thread::Terminate () |
| 1004 | { |
| 1005 | UserSettingsControllerSP &usc = GetSettingsController(); |
| 1006 | UserSettingsController::FinalizeSettingsController (usc); |
| 1007 | usc.reset(); |
| 1008 | } |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1009 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1010 | UserSettingsControllerSP & |
| 1011 | Thread::GetSettingsController () |
| 1012 | { |
| 1013 | static UserSettingsControllerSP g_settings_controller; |
Jim Ingham | 20594b1 | 2010-09-08 03:14:33 +0000 | [diff] [blame] | 1014 | return g_settings_controller; |
| 1015 | } |
| 1016 | |
Caroline Tice | 1ebef44 | 2010-09-27 00:30:10 +0000 | [diff] [blame] | 1017 | void |
| 1018 | Thread::UpdateInstanceName () |
| 1019 | { |
| 1020 | StreamString sstr; |
| 1021 | const char *name = GetName(); |
| 1022 | |
| 1023 | if (name && name[0] != '\0') |
| 1024 | sstr.Printf ("%s", name); |
| 1025 | else if ((GetIndexID() != 0) || (GetID() != 0)) |
| 1026 | sstr.Printf ("0x%4.4x", GetIndexID(), GetID()); |
| 1027 | |
| 1028 | if (sstr.GetSize() > 0) |
| 1029 | Thread::GetSettingsController()->RenameInstanceSettings (GetInstanceName().AsCString(), sstr.GetData()); |
| 1030 | } |
| 1031 | |
Jim Ingham | ccd584d | 2010-09-23 17:40:12 +0000 | [diff] [blame] | 1032 | lldb::StackFrameSP |
| 1033 | Thread::GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr) |
| 1034 | { |
| 1035 | return GetStackFrameList().GetStackFrameSPForStackFramePtr (stack_frame_ptr); |
| 1036 | } |
Caroline Tice | 7826c88 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 1037 | |
| 1038 | const char * |
| 1039 | Thread::StopReasonAsCString (lldb::StopReason reason) |
| 1040 | { |
| 1041 | switch (reason) |
| 1042 | { |
| 1043 | case eStopReasonInvalid: return "invalid"; |
| 1044 | case eStopReasonNone: return "none"; |
| 1045 | case eStopReasonTrace: return "trace"; |
| 1046 | case eStopReasonBreakpoint: return "breakpoint"; |
| 1047 | case eStopReasonWatchpoint: return "watchpoint"; |
| 1048 | case eStopReasonSignal: return "signal"; |
| 1049 | case eStopReasonException: return "exception"; |
| 1050 | case eStopReasonPlanComplete: return "plan complete"; |
| 1051 | } |
| 1052 | |
| 1053 | |
| 1054 | static char unknown_state_string[64]; |
| 1055 | snprintf(unknown_state_string, sizeof (unknown_state_string), "StopReason = %i", reason); |
| 1056 | return unknown_state_string; |
| 1057 | } |
| 1058 | |
| 1059 | const char * |
| 1060 | Thread::RunModeAsCString (lldb::RunMode mode) |
| 1061 | { |
| 1062 | switch (mode) |
| 1063 | { |
| 1064 | case eOnlyThisThread: return "only this thread"; |
| 1065 | case eAllThreads: return "all threads"; |
| 1066 | case eOnlyDuringStepping: return "only during stepping"; |
| 1067 | } |
| 1068 | |
| 1069 | static char unknown_state_string[64]; |
| 1070 | snprintf(unknown_state_string, sizeof (unknown_state_string), "RunMode = %i", mode); |
| 1071 | return unknown_state_string; |
| 1072 | } |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1073 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1074 | #pragma mark "Thread::SettingsController" |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1075 | //-------------------------------------------------------------- |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1076 | // class Thread::SettingsController |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1077 | //-------------------------------------------------------------- |
| 1078 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1079 | Thread::SettingsController::SettingsController () : |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1080 | UserSettingsController ("thread", Process::GetSettingsController()) |
| 1081 | { |
| 1082 | m_default_settings.reset (new ThreadInstanceSettings (*this, false, |
| 1083 | InstanceSettings::GetDefaultName().AsCString())); |
| 1084 | } |
| 1085 | |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1086 | Thread::SettingsController::~SettingsController () |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1087 | { |
| 1088 | } |
| 1089 | |
| 1090 | lldb::InstanceSettingsSP |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1091 | Thread::SettingsController::CreateInstanceSettings (const char *instance_name) |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1092 | { |
Greg Clayton | c0c1b0c | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 1093 | ThreadInstanceSettings *new_settings = new ThreadInstanceSettings (*GetSettingsController(), |
| 1094 | false, |
| 1095 | instance_name); |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1096 | lldb::InstanceSettingsSP new_settings_sp (new_settings); |
| 1097 | return new_settings_sp; |
| 1098 | } |
| 1099 | |
| 1100 | #pragma mark "ThreadInstanceSettings" |
| 1101 | //-------------------------------------------------------------- |
| 1102 | // class ThreadInstanceSettings |
| 1103 | //-------------------------------------------------------------- |
| 1104 | |
| 1105 | ThreadInstanceSettings::ThreadInstanceSettings (UserSettingsController &owner, bool live_instance, const char *name) : |
Greg Clayton | 638351a | 2010-12-04 00:10:17 +0000 | [diff] [blame] | 1106 | InstanceSettings (owner, name ? name : InstanceSettings::InvalidName().AsCString(), live_instance), |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1107 | m_avoid_regexp_ap (), |
| 1108 | m_trace_enabled (false) |
| 1109 | { |
| 1110 | // CopyInstanceSettings is a pure virtual function in InstanceSettings; it therefore cannot be called |
| 1111 | // until the vtables for ThreadInstanceSettings are properly set up, i.e. AFTER all the initializers. |
| 1112 | // For this reason it has to be called here, rather than in the initializer or in the parent constructor. |
| 1113 | // This is true for CreateInstanceName() too. |
| 1114 | |
| 1115 | if (GetInstanceName() == InstanceSettings::InvalidName()) |
| 1116 | { |
| 1117 | ChangeInstanceName (std::string (CreateInstanceName().AsCString())); |
| 1118 | m_owner.RegisterInstanceSettings (this); |
| 1119 | } |
| 1120 | |
| 1121 | if (live_instance) |
| 1122 | { |
| 1123 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1124 | CopyInstanceSettings (pending_settings,false); |
| 1125 | //m_owner.RemovePendingSettings (m_instance_name); |
| 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | ThreadInstanceSettings::ThreadInstanceSettings (const ThreadInstanceSettings &rhs) : |
Greg Clayton | c0c1b0c | 2010-11-19 03:46:01 +0000 | [diff] [blame] | 1130 | InstanceSettings (*Thread::GetSettingsController(), CreateInstanceName().AsCString()), |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1131 | m_avoid_regexp_ap (), |
| 1132 | m_trace_enabled (rhs.m_trace_enabled) |
| 1133 | { |
| 1134 | if (m_instance_name != InstanceSettings::GetDefaultName()) |
| 1135 | { |
| 1136 | const lldb::InstanceSettingsSP &pending_settings = m_owner.FindPendingSettings (m_instance_name); |
| 1137 | CopyInstanceSettings (pending_settings,false); |
| 1138 | m_owner.RemovePendingSettings (m_instance_name); |
| 1139 | } |
| 1140 | if (rhs.m_avoid_regexp_ap.get() != NULL) |
| 1141 | m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText())); |
| 1142 | } |
| 1143 | |
| 1144 | ThreadInstanceSettings::~ThreadInstanceSettings () |
| 1145 | { |
| 1146 | } |
| 1147 | |
| 1148 | ThreadInstanceSettings& |
| 1149 | ThreadInstanceSettings::operator= (const ThreadInstanceSettings &rhs) |
| 1150 | { |
| 1151 | if (this != &rhs) |
| 1152 | { |
| 1153 | if (rhs.m_avoid_regexp_ap.get() != NULL) |
| 1154 | m_avoid_regexp_ap.reset(new RegularExpression(rhs.m_avoid_regexp_ap->GetText())); |
| 1155 | else |
| 1156 | m_avoid_regexp_ap.reset(NULL); |
| 1157 | } |
| 1158 | m_trace_enabled = rhs.m_trace_enabled; |
| 1159 | return *this; |
| 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | void |
| 1164 | ThreadInstanceSettings::UpdateInstanceSettingsVariable (const ConstString &var_name, |
| 1165 | const char *index_value, |
| 1166 | const char *value, |
| 1167 | const ConstString &instance_name, |
| 1168 | const SettingEntry &entry, |
| 1169 | lldb::VarSetOperationType op, |
| 1170 | Error &err, |
| 1171 | bool pending) |
| 1172 | { |
| 1173 | if (var_name == StepAvoidRegexpVarName()) |
| 1174 | { |
| 1175 | std::string regexp_text; |
| 1176 | if (m_avoid_regexp_ap.get() != NULL) |
| 1177 | regexp_text.append (m_avoid_regexp_ap->GetText()); |
| 1178 | UserSettingsController::UpdateStringVariable (op, regexp_text, value, err); |
| 1179 | if (regexp_text.empty()) |
| 1180 | m_avoid_regexp_ap.reset(); |
| 1181 | else |
| 1182 | { |
| 1183 | m_avoid_regexp_ap.reset(new RegularExpression(regexp_text.c_str())); |
| 1184 | |
| 1185 | } |
| 1186 | } |
| 1187 | else if (var_name == GetTraceThreadVarName()) |
| 1188 | { |
| 1189 | bool success; |
| 1190 | bool result = Args::StringToBoolean(value, false, &success); |
| 1191 | |
| 1192 | if (success) |
| 1193 | { |
| 1194 | m_trace_enabled = result; |
| 1195 | if (!pending) |
| 1196 | { |
| 1197 | Thread *myself = static_cast<Thread *> (this); |
| 1198 | myself->EnableTracer(m_trace_enabled, true); |
| 1199 | } |
| 1200 | } |
| 1201 | else |
| 1202 | { |
| 1203 | err.SetErrorStringWithFormat ("Bad value \"%s\" for trace-thread, should be Boolean.", value); |
| 1204 | } |
| 1205 | |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | void |
| 1210 | ThreadInstanceSettings::CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, |
| 1211 | bool pending) |
| 1212 | { |
| 1213 | if (new_settings.get() == NULL) |
| 1214 | return; |
| 1215 | |
| 1216 | ThreadInstanceSettings *new_process_settings = (ThreadInstanceSettings *) new_settings.get(); |
| 1217 | if (new_process_settings->GetSymbolsToAvoidRegexp() != NULL) |
| 1218 | m_avoid_regexp_ap.reset (new RegularExpression (new_process_settings->GetSymbolsToAvoidRegexp()->GetText())); |
| 1219 | else |
| 1220 | m_avoid_regexp_ap.reset (); |
| 1221 | } |
| 1222 | |
| 1223 | bool |
| 1224 | ThreadInstanceSettings::GetInstanceSettingsValue (const SettingEntry &entry, |
| 1225 | const ConstString &var_name, |
| 1226 | StringList &value, |
| 1227 | Error *err) |
| 1228 | { |
| 1229 | if (var_name == StepAvoidRegexpVarName()) |
| 1230 | { |
| 1231 | if (m_avoid_regexp_ap.get() != NULL) |
| 1232 | { |
| 1233 | std::string regexp_text("\""); |
| 1234 | regexp_text.append(m_avoid_regexp_ap->GetText()); |
| 1235 | regexp_text.append ("\""); |
| 1236 | value.AppendString (regexp_text.c_str()); |
| 1237 | } |
| 1238 | |
| 1239 | } |
| 1240 | else if (var_name == GetTraceThreadVarName()) |
| 1241 | { |
| 1242 | value.AppendString(m_trace_enabled ? "true" : "false"); |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | if (err) |
| 1247 | err->SetErrorStringWithFormat ("unrecognized variable name '%s'", var_name.AsCString()); |
| 1248 | return false; |
| 1249 | } |
| 1250 | return true; |
| 1251 | } |
| 1252 | |
| 1253 | const ConstString |
| 1254 | ThreadInstanceSettings::CreateInstanceName () |
| 1255 | { |
| 1256 | static int instance_count = 1; |
| 1257 | StreamString sstr; |
| 1258 | |
| 1259 | sstr.Printf ("thread_%d", instance_count); |
| 1260 | ++instance_count; |
| 1261 | |
| 1262 | const ConstString ret_val (sstr.GetData()); |
| 1263 | return ret_val; |
| 1264 | } |
| 1265 | |
| 1266 | const ConstString & |
| 1267 | ThreadInstanceSettings::StepAvoidRegexpVarName () |
| 1268 | { |
| 1269 | static ConstString step_avoid_var_name ("step-avoid-regexp"); |
| 1270 | |
| 1271 | return step_avoid_var_name; |
| 1272 | } |
| 1273 | |
| 1274 | const ConstString & |
| 1275 | ThreadInstanceSettings::GetTraceThreadVarName () |
| 1276 | { |
| 1277 | static ConstString trace_thread_var_name ("trace-thread"); |
| 1278 | |
| 1279 | return trace_thread_var_name; |
| 1280 | } |
| 1281 | |
| 1282 | //-------------------------------------------------- |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1283 | // SettingsController Variable Tables |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1284 | //-------------------------------------------------- |
| 1285 | |
| 1286 | SettingEntry |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1287 | Thread::SettingsController::global_settings_table[] = |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1288 | { |
| 1289 | //{ "var-name", var-type , "default", enum-table, init'd, hidden, "help-text"}, |
| 1290 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 1291 | }; |
| 1292 | |
| 1293 | |
| 1294 | SettingEntry |
Greg Clayton | 990de7b | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 1295 | Thread::SettingsController::instance_settings_table[] = |
Jim Ingham | 745ac7a | 2010-11-11 19:26:09 +0000 | [diff] [blame] | 1296 | { |
| 1297 | //{ "var-name", var-type, "default", enum-table, init'd, hidden, "help-text"}, |
| 1298 | { "step-avoid-regexp", eSetVarTypeString, "", NULL, false, false, "A regular expression defining functions step-in won't stop in." }, |
| 1299 | { "trace-thread", eSetVarTypeBoolean, "false", NULL, false, false, "If true, this thread will single-step and log execution." }, |
| 1300 | { NULL, eSetVarTypeNone, NULL, NULL, 0, 0, NULL } |
| 1301 | }; |