Thread.h revision 1ebef44c126bd3a615b3ad844c46a82a82efa0e7
1f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===-- Thread.h ------------------------------------------------*- C++ -*-===// 2f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 3f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// The LLVM Compiler Infrastructure 4f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 5f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// This file is distributed under the University of Illinois Open Source 6f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// License. See LICENSE.TXT for details. 7f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// 8f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)//===----------------------------------------------------------------------===// 9f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 10f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#ifndef liblldb_Thread_h_ 11f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define liblldb_Thread_h_ 12f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "lldb/lldb-private.h" 14f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "lldb/Host/Mutex.h" 15f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "lldb/Core/UserID.h" 16f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "lldb/Core/UserSettingsController.h" 17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "lldb/Target/ExecutionContextScope.h" 18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "lldb/Target/StackFrameList.h" 19f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "libunwind/include/libunwind.h" 20f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 21f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#define LLDB_THREAD_MAX_STOP_EXC_DATA 8 22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 23f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// I forward declare these here so I don't have to #include ThreadPlan, so in turn I 24f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)// can use Thread.h in ThreadPlan.h. 25f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 26f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace lldb_private { 27f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 28f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class ThreadInstanceSettings : public InstanceSettings 29f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles){ 30f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)public: 31f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ThreadInstanceSettings (UserSettingsController &owner, bool live_instance = true, const char *name = NULL); 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 34f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ThreadInstanceSettings (const ThreadInstanceSettings &rhs); 35f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 36f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual 37f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ~ThreadInstanceSettings (); 38f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 39f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ThreadInstanceSettings& 40f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) operator= (const ThreadInstanceSettings &rhs); 41f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 42f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 43f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void 44f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) UpdateInstanceSettingsVariable (const ConstString &var_name, 45f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const char *index_value, 46f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const char *value, 47f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ConstString &instance_name, 48f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const SettingEntry &entry, 49f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) lldb::VarSetOperationType op, 50f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Error &err, 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool pending); 52f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 53f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool 54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) GetInstanceSettingsValue (const SettingEntry &entry, 55f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ConstString &var_name, 56f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) StringList &value, 57f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) Error *err); 58f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 59f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) RegularExpression * 60f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) GetSymbolsToAvoidRegexp() 61f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 62f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return m_avoid_regexp_ap.get(); 63f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 64f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 65f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static const ConstString & 66f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) StepAvoidRegexpVarName (); 67f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 68f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)protected: 69f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 70f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void 71f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 72f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool pending); 73f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 74f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const ConstString 75f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CreateInstanceName (); 76f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 77f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)private: 78f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 79f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) std::auto_ptr<RegularExpression> m_avoid_regexp_ap; 80f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)}; 81f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 82f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class Thread : 83f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public UserID, 84f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public ExecutionContextScope, 85f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public ThreadInstanceSettings 86f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles){ 87f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)public: 88f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 89f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class ThreadSettingsController : public UserSettingsController 90f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 91f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 92f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 93f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ThreadSettingsController (); 94f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 95f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) virtual 96f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ~ThreadSettingsController (); 97f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 98f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static SettingEntry global_settings_table[]; 99f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) static SettingEntry instance_settings_table[]; 100f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 101f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) protected: 102f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 103f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) lldb::InstanceSettingsSP 104f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) CreateInstanceSettings (const char *instance_name); 105f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 106f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) private: 107f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Class-wide settings. 109f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 110f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN (ThreadSettingsController); 111f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) }; 112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 113f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) class RegisterCheckpoint 114f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 115f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) public: 116f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 117f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) RegisterCheckpoint() : 118f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) m_stack_id (), 119f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) m_data_sp () 120f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 121f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 122f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 123f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) RegisterCheckpoint (const StackID &stack_id) : 124f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) m_stack_id (stack_id), 125f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) m_data_sp () 126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 127f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 128f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 129f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) ~RegisterCheckpoint() 130f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 131f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 132f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 133f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const StackID & 134f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) GetStackID() 135f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 136f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) return m_stack_id; 137f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) } 138f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 139f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void 140f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) SetStackID (const StackID &stack_id) 141f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) { 142f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) m_stack_id = stack_id; 143 } 144 145 lldb::DataBufferSP & 146 GetData() 147 { 148 return m_data_sp; 149 } 150 151 const lldb::DataBufferSP & 152 GetData() const 153 { 154 return m_data_sp; 155 } 156 157 protected: 158 StackID m_stack_id; 159 lldb::DataBufferSP m_data_sp; 160 }; 161 162 void 163 UpdateInstanceName (); 164 165 static lldb::UserSettingsControllerSP 166 GetSettingsController (bool finish = false); 167 168 Thread (Process &process, lldb::tid_t tid); 169 virtual ~Thread(); 170 171 Process & 172 GetProcess() { return m_process; } 173 174 const Process & 175 GetProcess() const { return m_process; } 176 177 int 178 GetResumeSignal () const; 179 180 void 181 SetResumeSignal (int signal); 182 183 lldb::StateType 184 GetState() const; 185 186 lldb::ThreadSP 187 GetSP (); 188 189 void 190 SetState (lldb::StateType state); 191 192 lldb::StateType 193 GetResumeState () const; 194 195 void 196 SetResumeState (lldb::StateType state); 197 198 // This function is called on all the threads before "WillResume" in case 199 // a thread needs to change its state before the ThreadList polls all the 200 // threads to figure out which ones actually will get to run and how. 201 void 202 SetupForResume (); 203 204 // Override this to do platform specific tasks before resume, but always 205 // call the Thread::WillResume at the end of your work. 206 207 virtual bool 208 WillResume (lldb::StateType resume_state); 209 210 // This clears generic thread state after a resume. If you subclass this, 211 // be sure to call it. 212 virtual void 213 DidResume (); 214 215 virtual void 216 RefreshStateAfterStop() = 0; 217 218 void 219 WillStop (); 220 221 bool 222 ShouldStop (Event *event_ptr); 223 224 lldb::Vote 225 ShouldReportStop (Event *event_ptr); 226 227 lldb::Vote 228 ShouldReportRun (Event *event_ptr); 229 230 // Return whether this thread matches the specification in ThreadSpec. This is a virtual 231 // method because at some point we may extend the thread spec with a platform specific 232 // dictionary of attributes, which then only the platform specific Thread implementation 233 // would know how to match. For now, this just calls through to the ThreadSpec's 234 // ThreadPassesBasicTests method. 235 virtual bool 236 MatchesSpec (const ThreadSpec *spec); 237 238 StopInfo * 239 GetStopInfo (); 240 241 bool 242 ThreadStoppedForAReason (); 243 244 virtual const char * 245 GetInfo () = 0; 246 247 virtual const char * 248 GetName () 249 { 250 return NULL; 251 } 252 253 virtual const char * 254 GetQueueName () 255 { 256 return NULL; 257 } 258 259 virtual uint32_t 260 GetStackFrameCount(); 261 262 virtual lldb::StackFrameSP 263 GetStackFrameAtIndex (uint32_t idx); 264 265 lldb::StackFrameSP 266 GetSelectedFrame (); 267 268 uint32_t 269 SetSelectedFrame (lldb_private::StackFrame *frame); 270 271 void 272 SetSelectedFrameByIndex (uint32_t frame_idx); 273 274 virtual RegisterContext * 275 GetRegisterContext () = 0; 276 277 virtual bool 278 SaveFrameZeroState (RegisterCheckpoint &checkpoint) = 0; 279 280 virtual bool 281 RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint) = 0; 282 283 virtual RegisterContext * 284 CreateRegisterContextForFrame (StackFrame *frame) = 0; 285 286 virtual void 287 ClearStackFrames (); 288 289 void 290 DumpInfo (Stream &strm, 291 bool show_stop_reason, 292 bool show_name, 293 bool show_queue, 294 uint32_t frame_idx);// = UINT32_MAX); 295 296 //------------------------------------------------------------------ 297 // Thread Plan Providers: 298 // This section provides the basic thread plans that the Process control 299 // machinery uses to run the target. ThreadPlan.h provides more details on 300 // how this mechanism works. 301 // The thread provides accessors to a set of plans that perform basic operations. 302 // The idea is that particular Platform plugins can override these methods to 303 // provide the implementation of these basic operations appropriate to their 304 // environment. 305 //------------------------------------------------------------------ 306 307 //------------------------------------------------------------------ 308 /// Queues the base plan for a thread. 309 /// The version returned by Process does some things that are useful, 310 /// like handle breakpoints and signals, so if you return a plugin specific 311 /// one you probably want to call through to the Process one for anything 312 /// your plugin doesn't explicitly handle. 313 /// 314 /// @param[in] abort_other_plans 315 /// \b true if we discard the currently queued plans and replace them with this one. 316 /// Otherwise this plan will go on the end of the plan stack. 317 /// 318 /// @return 319 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 320 //------------------------------------------------------------------ 321 virtual ThreadPlan * 322 QueueFundamentalPlan (bool abort_other_plans); 323 324 //------------------------------------------------------------------ 325 /// Queues the plan used to step over a breakpoint at the current PC of \a thread. 326 /// The default version returned by Process handles trap based breakpoints, and 327 /// will disable the breakpoint, single step over it, then re-enable it. 328 /// 329 /// @param[in] abort_other_plans 330 /// \b true if we discard the currently queued plans and replace them with this one. 331 /// Otherwise this plan will go on the end of the plan stack. 332 /// 333 /// @return 334 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 335 //------------------------------------------------------------------ 336 virtual ThreadPlan * 337 QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans); 338 339 //------------------------------------------------------------------ 340 /// Queues the plan used to step one instruction from the current PC of \a thread. 341 /// 342 /// @param[in] step_over 343 /// \b true if we step over calls to functions, false if we step in. 344 /// 345 /// @param[in] abort_other_plans 346 /// \b true if we discard the currently queued plans and replace them with this one. 347 /// Otherwise this plan will go on the end of the plan stack. 348 /// 349 /// @param[in] stop_other_threads 350 /// \b true if we will stop other threads while we single step this one. 351 /// 352 /// @return 353 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 354 //------------------------------------------------------------------ 355 virtual ThreadPlan * 356 QueueThreadPlanForStepSingleInstruction (bool step_over, 357 bool abort_other_plans, 358 bool stop_other_threads); 359 360 //------------------------------------------------------------------ 361 /// Queues the plan used to step through an address range, stepping into or over 362 /// function calls depending on the value of StepType. 363 /// 364 /// @param[in] abort_other_plans 365 /// \b true if we discard the currently queued plans and replace them with this one. 366 /// Otherwise this plan will go on the end of the plan stack. 367 /// 368 /// @param[in] type 369 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 370 /// 371 /// @param[in] range 372 /// The address range to step through. 373 /// 374 /// @param[in] addr_context 375 /// When dealing with stepping through inlined functions the current PC is not enough information to know 376 /// what "step" means. For instance a series of nested inline functions might start at the same address. 377 // The \a addr_context provides the current symbol context the step 378 /// is supposed to be out of. 379 // FIXME: Currently unused. 380 /// 381 /// @param[in] stop_other_threads 382 /// \b true if we will stop other threads while we single step this one. 383 /// 384 /// @return 385 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 386 //------------------------------------------------------------------ 387 virtual ThreadPlan * 388 QueueThreadPlanForStepRange (bool abort_other_plans, 389 lldb::StepType type, 390 const AddressRange &range, 391 const SymbolContext &addr_context, 392 lldb::RunMode stop_other_threads, 393 bool avoid_code_without_debug_info); 394 395 //------------------------------------------------------------------ 396 /// Queue the plan used to step out of the function at the current PC of 397 /// \a thread. 398 /// 399 /// @param[in] abort_other_plans 400 /// \b true if we discard the currently queued plans and replace them with this one. 401 /// Otherwise this plan will go on the end of the plan stack. 402 /// 403 /// @param[in] addr_context 404 /// When dealing with stepping through inlined functions the current PC is not enough information to know 405 /// what "step" means. For instance a series of nested inline functions might start at the same address. 406 // The \a addr_context provides the current symbol context the step 407 /// is supposed to be out of. 408 // FIXME: Currently unused. 409 /// 410 /// @param[in] first_insn 411 /// \b true if this is the first instruction of a function. 412 /// 413 /// @param[in] stop_other_threads 414 /// \b true if we will stop other threads while we single step this one. 415 /// 416 /// @param[in] stop_vote 417 /// @param[in] run_vote 418 /// See standard meanings for the stop & run votes in ThreadPlan.h. 419 /// 420 /// @return 421 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 422 //------------------------------------------------------------------ 423 virtual ThreadPlan * 424 QueueThreadPlanForStepOut (bool abort_other_plans, 425 SymbolContext *addr_context, 426 bool first_insn, 427 bool stop_other_threads, 428 lldb::Vote stop_vote = lldb::eVoteYes, 429 lldb::Vote run_vote = lldb::eVoteNoOpinion); 430 431 //------------------------------------------------------------------ 432 /// Gets the plan used to step through the code that steps from a function 433 /// call site at the current PC into the actual function call. 434 /// 435 /// @param[in] abort_other_plans 436 /// \b true if we discard the currently queued plans and replace them with this one. 437 /// Otherwise this plan will go on the end of the plan stack. 438 /// 439 /// @param[in] stop_other_threads 440 /// \b true if we will stop other threads while we single step this one. 441 /// 442 /// @return 443 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 444 //------------------------------------------------------------------ 445 virtual ThreadPlan * 446 QueueThreadPlanForStepThrough (bool abort_other_plans, 447 bool stop_other_threads); 448 449 //------------------------------------------------------------------ 450 /// Gets the plan used to continue from the current PC. 451 /// This is a simple plan, mostly useful as a backstop when you are continuing 452 /// for some particular purpose. 453 /// 454 /// @param[in] abort_other_plans 455 /// \b true if we discard the currently queued plans and replace them with this one. 456 /// Otherwise this plan will go on the end of the plan stack. 457 /// 458 /// @param[in] target_addr 459 /// The address to which we're running. 460 /// 461 /// @param[in] stop_other_threads 462 /// \b true if we will stop other threads while we single step this one. 463 /// 464 /// @return 465 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 466 //------------------------------------------------------------------ 467 virtual ThreadPlan * 468 QueueThreadPlanForRunToAddress (bool abort_other_plans, 469 Address &target_addr, 470 bool stop_other_threads); 471 472 virtual ThreadPlan * 473 QueueThreadPlanForStepUntil (bool abort_other_plans, 474 lldb::addr_t *address_list, 475 size_t num_addresses, 476 bool stop_others); 477 478 virtual ThreadPlan * 479 QueueThreadPlanForCallFunction (bool abort_other_plans, 480 Address& function, 481 lldb::addr_t arg, 482 bool stop_other_threads, 483 bool discard_on_error = false); 484 485 virtual ThreadPlan * 486 QueueThreadPlanForCallFunction (bool abort_other_plans, 487 Address& function, 488 ValueList &args, 489 bool stop_other_threads, 490 bool discard_on_error = false); 491 492 //------------------------------------------------------------------ 493 // Thread Plan accessors: 494 //------------------------------------------------------------------ 495 496 //------------------------------------------------------------------ 497 /// Gets the plan which will execute next on the plan stack. 498 /// 499 /// @return 500 /// A pointer to the next executed plan. 501 //------------------------------------------------------------------ 502 ThreadPlan * 503 GetCurrentPlan (); 504 505 //------------------------------------------------------------------ 506 /// Gets the inner-most plan that was popped off the plan stack in the 507 /// most recent stop. Useful for printing the stop reason accurately. 508 /// 509 /// @return 510 /// A pointer to the last completed plan. 511 //------------------------------------------------------------------ 512 lldb::ThreadPlanSP 513 GetCompletedPlan (); 514 515 //------------------------------------------------------------------ 516 /// Checks whether the given plan is in the completed plans for this 517 /// stop. 518 /// 519 /// @param[in] plan 520 /// Pointer to the plan you're checking. 521 /// 522 /// @return 523 /// Returns true if the input plan is in the completed plan stack, 524 /// false otherwise. 525 //------------------------------------------------------------------ 526 bool 527 IsThreadPlanDone (ThreadPlan *plan); 528 529 //------------------------------------------------------------------ 530 /// Checks whether the given plan is in the discarded plans for this 531 /// stop. 532 /// 533 /// @param[in] plan 534 /// Pointer to the plan you're checking. 535 /// 536 /// @return 537 /// Returns true if the input plan is in the discarded plan stack, 538 /// false otherwise. 539 //------------------------------------------------------------------ 540 bool 541 WasThreadPlanDiscarded (ThreadPlan *plan); 542 543 //------------------------------------------------------------------ 544 /// Queues a generic thread plan. 545 /// 546 /// @param[in] plan_sp 547 /// The plan to queue. 548 /// 549 /// @param[in] abort_other_plans 550 /// \b true if we discard the currently queued plans and replace them with this one. 551 /// Otherwise this plan will go on the end of the plan stack. 552 /// 553 /// @return 554 /// A pointer to the last completed plan. 555 //------------------------------------------------------------------ 556 void 557 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 558 559 560 //------------------------------------------------------------------ 561 /// Discards the plans queued on the plan stack of the current thread. This is 562 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call. 563 // But if \a force is true, all thread plans are discarded. 564 //------------------------------------------------------------------ 565 void 566 DiscardThreadPlans (bool force); 567 568 //------------------------------------------------------------------ 569 /// Prints the current plan stack. 570 /// 571 /// @param[in] s 572 /// The stream to which to dump the plan stack info. 573 /// 574 //------------------------------------------------------------------ 575 void 576 DumpThreadPlans (Stream *s) const; 577 578 //------------------------------------------------------------------ 579 /// The regular expression returned determines symbols that this 580 /// thread won't stop in during "step-in" operations. 581 /// 582 /// @return 583 /// A pointer to a regular expression to compare against symbols, 584 /// or NULL if all symbols are allowed. 585 /// 586 //------------------------------------------------------------------ 587 RegularExpression * 588 GetSymbolsToAvoidRegexp() 589 { 590 return ThreadInstanceSettings::GetSymbolsToAvoidRegexp(); 591 } 592 593 // Get the thread index ID. The index ID that is guaranteed to not be 594 // re-used by a process. They start at 1 and increase with each new thread. 595 // This allows easy command line access by a unique ID that is easier to 596 // type than the actual system thread ID. 597 uint32_t 598 GetIndexID () const; 599 600 //------------------------------------------------------------------ 601 // lldb::ExecutionContextScope pure virtual functions 602 //------------------------------------------------------------------ 603 virtual Target * 604 CalculateTarget (); 605 606 virtual Process * 607 CalculateProcess (); 608 609 virtual Thread * 610 CalculateThread (); 611 612 virtual StackFrame * 613 CalculateStackFrame (); 614 615 virtual void 616 Calculate (ExecutionContext &exe_ctx); 617 618 lldb::StackFrameSP 619 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr); 620 621protected: 622 623 friend class ThreadPlan; 624 friend class StackFrameList; 625 626 void 627 PushPlan (lldb::ThreadPlanSP &plan_sp); 628 629 void 630 PopPlan (); 631 632 void 633 DiscardPlan (); 634 635 ThreadPlan *GetPreviousPlan (ThreadPlan *plan); 636 637 virtual lldb::StopInfoSP 638 GetPrivateStopReason () = 0; 639 640 typedef std::vector<lldb::ThreadPlanSP> plan_stack; 641 642 virtual lldb_private::Unwind * 643 GetUnwinder () = 0; 644 645 StackFrameList & 646 GetStackFrameList (); 647 648 //------------------------------------------------------------------ 649 // Classes that inherit from Process can see and modify these 650 //------------------------------------------------------------------ 651 Process & m_process; ///< The process that owns this thread. 652 lldb::StopInfoSP m_public_stop_info_sp; ///< The public stop reason for this thread 653 lldb::StopInfoSP m_actual_stop_info_sp; ///< The private stop reason for this thread 654 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access. 655 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state. 656 lldb::StateType m_state; ///< The state of our process. 657 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state. 658 plan_stack m_plan_stack; ///< The stack of plans this thread is executing. 659 plan_stack m_immediate_plan_stack; ///< The plans that need to get executed before any other work gets done. 660 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes. 661 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes. 662 std::auto_ptr<StackFrameList> m_curr_frames_ap; ///< The stack frames that get lazily populated after a thread stops. 663 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. 664 int m_resume_signal; ///< The signal that should be used when continuing this thread. 665 lldb::StateType m_resume_state; ///< The state that indicates what this thread should do when the process is resumed. 666 std::auto_ptr<lldb_private::Unwind> m_unwinder_ap; 667private: 668 //------------------------------------------------------------------ 669 // For Thread only 670 //------------------------------------------------------------------ 671 DISALLOW_COPY_AND_ASSIGN (Thread); 672 673}; 674 675} // namespace lldb_private 676 677#endif // liblldb_Thread_h_ 678