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