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