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