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