Thread.h revision 038fa8e30621e0e55faed3479387d811986f28b7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===-- Thread.h ------------------------------------------------*- C++ -*-===// 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The LLVM Compiler Infrastructure 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This file is distributed under the University of Illinois Open Source 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// License. See LICENSE.TXT for details. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//===----------------------------------------------------------------------===// 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef liblldb_Thread_h_ 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define liblldb_Thread_h_ 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/lldb-private.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Host/Mutex.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Core/UserID.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Core/UserSettingsController.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Target/ExecutionContextScope.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "lldb/Target/StackFrameList.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define LLDB_THREAD_MAX_STOP_EXC_DATA 8 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace lldb_private { 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ThreadInstanceSettings : public InstanceSettings 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles){ 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)public: 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ThreadInstanceSettings (const lldb::UserSettingsControllerSP &owner_sp, bool live_instance = true, const char *name = NULL); 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ThreadInstanceSettings (const ThreadInstanceSettings &rhs); 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) virtual 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ~ThreadInstanceSettings (); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ThreadInstanceSettings& 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) operator= (const ThreadInstanceSettings &rhs); 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UpdateInstanceSettingsVariable (const ConstString &var_name, 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *index_value, 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const char *value, 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ConstString &instance_name, 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const SettingEntry &entry, 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) VarSetOperationType op, 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Error &err, 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool pending); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetInstanceSettingsValue (const SettingEntry &entry, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ConstString &var_name, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StringList &value, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Error *err); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) RegularExpression * 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GetSymbolsToAvoidRegexp() 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) { 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return m_avoid_regexp_ap.get(); 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const ConstString & 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) StepAvoidRegexpVarName (); 630f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) 640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) bool 650f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) GetTraceEnabledState() 660f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) { 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return m_trace_enabled; 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const ConstString & 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) GetTraceThreadVarName (); 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)protected: 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) CopyInstanceSettings (const lldb::InstanceSettingsSP &new_settings, 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool pending); 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const ConstString 792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CreateInstanceName (); 802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)private: 822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::auto_ptr<RegularExpression> m_avoid_regexp_ap; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool m_trace_enabled; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 86 87class Thread : 88 public STD_ENABLE_SHARED_FROM_THIS(Thread), 89 public UserID, 90 public ExecutionContextScope, 91 public ThreadInstanceSettings 92{ 93public: 94 95 class SettingsController : public UserSettingsController 96 { 97 public: 98 99 SettingsController (); 100 101 virtual 102 ~SettingsController (); 103 104 static SettingEntry global_settings_table[]; 105 static SettingEntry instance_settings_table[]; 106 107 protected: 108 109 lldb::InstanceSettingsSP 110 CreateInstanceSettings (const char *instance_name); 111 112 private: 113 114 // Class-wide settings. 115 116 DISALLOW_COPY_AND_ASSIGN (SettingsController); 117 }; 118 119 // TODO: You shouldn't just checkpoint the register state alone, so this should get 120 // moved to protected. To do that ThreadStateCheckpoint needs to be returned as a token... 121 class RegisterCheckpoint 122 { 123 public: 124 125 RegisterCheckpoint() : 126 m_stack_id (), 127 m_data_sp () 128 { 129 } 130 131 RegisterCheckpoint (const StackID &stack_id) : 132 m_stack_id (stack_id), 133 m_data_sp () 134 { 135 } 136 137 ~RegisterCheckpoint() 138 { 139 } 140 141 const RegisterCheckpoint& 142 operator= (const RegisterCheckpoint &rhs) 143 { 144 if (this != &rhs) 145 { 146 this->m_stack_id = rhs.m_stack_id; 147 this->m_data_sp = rhs.m_data_sp; 148 } 149 return *this; 150 } 151 152 RegisterCheckpoint (const RegisterCheckpoint &rhs) : 153 m_stack_id (rhs.m_stack_id), 154 m_data_sp (rhs.m_data_sp) 155 { 156 } 157 158 const StackID & 159 GetStackID() 160 { 161 return m_stack_id; 162 } 163 164 void 165 SetStackID (const StackID &stack_id) 166 { 167 m_stack_id = stack_id; 168 } 169 170 lldb::DataBufferSP & 171 GetData() 172 { 173 return m_data_sp; 174 } 175 176 const lldb::DataBufferSP & 177 GetData() const 178 { 179 return m_data_sp; 180 } 181 182 protected: 183 StackID m_stack_id; 184 lldb::DataBufferSP m_data_sp; 185 }; 186 187 struct ThreadStateCheckpoint 188 { 189 uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting bit of data. 190 lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you might continue with the wrong signals. 191 RegisterCheckpoint register_backup; // You need to restore the registers, of course... 192 }; 193 194 void 195 UpdateInstanceName (); 196 197 static void 198 SettingsInitialize (); 199 200 static void 201 SettingsTerminate (); 202 203 static lldb::UserSettingsControllerSP & 204 GetSettingsController (); 205 206 Thread (const lldb::ProcessSP &process_sp, lldb::tid_t tid); 207 virtual ~Thread(); 208 209 lldb::ProcessSP 210 GetProcess() const 211 { 212 return m_process_wp.lock(); 213 } 214 215 int 216 GetResumeSignal () const 217 { 218 return m_resume_signal; 219 } 220 221 void 222 SetResumeSignal (int signal) 223 { 224 m_resume_signal = signal; 225 } 226 227 lldb::StateType 228 GetState() const; 229 230 void 231 SetState (lldb::StateType state); 232 233 lldb::StateType 234 GetResumeState () const 235 { 236 return m_resume_state; 237 } 238 239 void 240 SetResumeState (lldb::StateType state) 241 { 242 m_resume_state = state; 243 } 244 245 // This function is called on all the threads before "WillResume" in case 246 // a thread needs to change its state before the ThreadList polls all the 247 // threads to figure out which ones actually will get to run and how. 248 void 249 SetupForResume (); 250 251 // Override this to do platform specific tasks before resume, but always 252 // call the Thread::WillResume at the end of your work. 253 254 virtual bool 255 WillResume (lldb::StateType resume_state); 256 257 // This clears generic thread state after a resume. If you subclass this, 258 // be sure to call it. 259 virtual void 260 DidResume (); 261 262 virtual void 263 RefreshStateAfterStop() = 0; 264 265 void 266 WillStop (); 267 268 bool 269 ShouldStop (Event *event_ptr); 270 271 Vote 272 ShouldReportStop (Event *event_ptr); 273 274 Vote 275 ShouldReportRun (Event *event_ptr); 276 277 // Return whether this thread matches the specification in ThreadSpec. This is a virtual 278 // method because at some point we may extend the thread spec with a platform specific 279 // dictionary of attributes, which then only the platform specific Thread implementation 280 // would know how to match. For now, this just calls through to the ThreadSpec's 281 // ThreadPassesBasicTests method. 282 virtual bool 283 MatchesSpec (const ThreadSpec *spec); 284 285 lldb::StopInfoSP 286 GetStopInfo (); 287 288 // This sets the stop reason to a "blank" stop reason, so you can call functions on the thread 289 // without having the called function run with whatever stop reason you stopped with. 290 void 291 SetStopInfoToNothing(); 292 293 bool 294 ThreadStoppedForAReason (); 295 296 static const char * 297 RunModeAsCString (lldb::RunMode mode); 298 299 static const char * 300 StopReasonAsCString (lldb::StopReason reason); 301 302 virtual const char * 303 GetInfo () 304 { 305 return NULL; 306 } 307 308 virtual const char * 309 GetName () 310 { 311 return NULL; 312 } 313 314 virtual const char * 315 GetQueueName () 316 { 317 return NULL; 318 } 319 320 virtual uint32_t 321 GetStackFrameCount() 322 { 323 return GetStackFrameList()->GetNumFrames(); 324 } 325 326 virtual lldb::StackFrameSP 327 GetStackFrameAtIndex (uint32_t idx) 328 { 329 return GetStackFrameList()->GetFrameAtIndex(idx); 330 } 331 332 virtual lldb::StackFrameSP 333 GetFrameWithConcreteFrameIndex (uint32_t unwind_idx); 334 335 virtual lldb::StackFrameSP 336 GetFrameWithStackID (const StackID &stack_id) 337 { 338 return GetStackFrameList()->GetFrameWithStackID (stack_id); 339 } 340 341 uint32_t 342 GetSelectedFrameIndex () 343 { 344 return GetStackFrameList()->GetSelectedFrameIndex(); 345 } 346 347 lldb::StackFrameSP 348 GetSelectedFrame () 349 { 350 lldb::StackFrameListSP stack_frame_list_sp(GetStackFrameList()); 351 return stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex()); 352 } 353 354 uint32_t 355 SetSelectedFrame (lldb_private::StackFrame *frame) 356 { 357 return GetStackFrameList()->SetSelectedFrame(frame); 358 } 359 360 bool 361 SetSelectedFrameByIndex (uint32_t frame_idx) 362 { 363 return GetStackFrameList()->SetSelectedFrameByIndex(frame_idx); 364 } 365 366 void 367 SetDefaultFileAndLineToSelectedFrame() 368 { 369 GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); 370 } 371 372 virtual lldb::RegisterContextSP 373 GetRegisterContext () = 0; 374 375 virtual lldb::RegisterContextSP 376 CreateRegisterContextForFrame (StackFrame *frame) = 0; 377 378 virtual void 379 ClearStackFrames (); 380 381 void 382 DumpUsingSettingsFormat (Stream &strm, uint32_t frame_idx); 383 384 //------------------------------------------------------------------ 385 // Thread Plan Providers: 386 // This section provides the basic thread plans that the Process control 387 // machinery uses to run the target. ThreadPlan.h provides more details on 388 // how this mechanism works. 389 // The thread provides accessors to a set of plans that perform basic operations. 390 // The idea is that particular Platform plugins can override these methods to 391 // provide the implementation of these basic operations appropriate to their 392 // environment. 393 //------------------------------------------------------------------ 394 395 //------------------------------------------------------------------ 396 /// Queues the base plan for a thread. 397 /// The version returned by Process does some things that are useful, 398 /// like handle breakpoints and signals, so if you return a plugin specific 399 /// one you probably want to call through to the Process one for anything 400 /// your plugin doesn't explicitly handle. 401 /// 402 /// @param[in] abort_other_plans 403 /// \b true if we discard the currently queued plans and replace them with this one. 404 /// Otherwise this plan will go on the end of the plan stack. 405 /// 406 /// @return 407 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 408 //------------------------------------------------------------------ 409 virtual ThreadPlan * 410 QueueFundamentalPlan (bool abort_other_plans); 411 412 //------------------------------------------------------------------ 413 /// Queues the plan used to step over a breakpoint at the current PC of \a thread. 414 /// The default version returned by Process handles trap based breakpoints, and 415 /// will disable the breakpoint, single step over it, then re-enable it. 416 /// 417 /// @param[in] abort_other_plans 418 /// \b true if we discard the currently queued plans and replace them with this one. 419 /// Otherwise this plan will go on the end of the plan stack. 420 /// 421 /// @return 422 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 423 //------------------------------------------------------------------ 424 virtual ThreadPlan * 425 QueueThreadPlanForStepOverBreakpointPlan (bool abort_other_plans); 426 427 //------------------------------------------------------------------ 428 /// Queues the plan used to step one instruction from the current PC of \a thread. 429 /// 430 /// @param[in] step_over 431 /// \b true if we step over calls to functions, false if we step in. 432 /// 433 /// @param[in] abort_other_plans 434 /// \b true if we discard the currently queued plans and replace them with this one. 435 /// Otherwise this plan will go on the end of the plan stack. 436 /// 437 /// @param[in] stop_other_threads 438 /// \b true if we will stop other threads while we single step this one. 439 /// 440 /// @return 441 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 442 //------------------------------------------------------------------ 443 virtual ThreadPlan * 444 QueueThreadPlanForStepSingleInstruction (bool step_over, 445 bool abort_other_plans, 446 bool stop_other_threads); 447 448 //------------------------------------------------------------------ 449 /// Queues the plan used to step through an address range, stepping into or over 450 /// function calls depending on the value of StepType. 451 /// 452 /// @param[in] abort_other_plans 453 /// \b true if we discard the currently queued plans and replace them with this one. 454 /// Otherwise this plan will go on the end of the plan stack. 455 /// 456 /// @param[in] type 457 /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported by this plan. 458 /// 459 /// @param[in] range 460 /// The address range to step through. 461 /// 462 /// @param[in] addr_context 463 /// When dealing with stepping through inlined functions the current PC is not enough information to know 464 /// what "step" means. For instance a series of nested inline functions might start at the same address. 465 // The \a addr_context provides the current symbol context the step 466 /// is supposed to be out of. 467 // FIXME: Currently unused. 468 /// 469 /// @param[in] stop_other_threads 470 /// \b true if we will stop other threads while we single step this one. 471 /// 472 /// @return 473 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 474 //------------------------------------------------------------------ 475 virtual ThreadPlan * 476 QueueThreadPlanForStepRange (bool abort_other_plans, 477 StepType type, 478 const AddressRange &range, 479 const SymbolContext &addr_context, 480 lldb::RunMode stop_other_threads, 481 bool avoid_code_without_debug_info); 482 483 //------------------------------------------------------------------ 484 /// Queue the plan used to step out of the function at the current PC of 485 /// \a thread. 486 /// 487 /// @param[in] abort_other_plans 488 /// \b true if we discard the currently queued plans and replace them with this one. 489 /// Otherwise this plan will go on the end of the plan stack. 490 /// 491 /// @param[in] addr_context 492 /// When dealing with stepping through inlined functions the current PC is not enough information to know 493 /// what "step" means. For instance a series of nested inline functions might start at the same address. 494 // The \a addr_context provides the current symbol context the step 495 /// is supposed to be out of. 496 // FIXME: Currently unused. 497 /// 498 /// @param[in] first_insn 499 /// \b true if this is the first instruction of a function. 500 /// 501 /// @param[in] stop_other_threads 502 /// \b true if we will stop other threads while we single step this one. 503 /// 504 /// @param[in] stop_vote 505 /// @param[in] run_vote 506 /// See standard meanings for the stop & run votes in ThreadPlan.h. 507 /// 508 /// @return 509 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 510 //------------------------------------------------------------------ 511 virtual ThreadPlan * 512 QueueThreadPlanForStepOut (bool abort_other_plans, 513 SymbolContext *addr_context, 514 bool first_insn, 515 bool stop_other_threads, 516 Vote stop_vote, // = eVoteYes, 517 Vote run_vote, // = eVoteNoOpinion); 518 uint32_t frame_idx); 519 520 //------------------------------------------------------------------ 521 /// Gets the plan used to step through the code that steps from a function 522 /// call site at the current PC into the actual function call. 523 /// 524 /// 525 /// @param[in] return_stack_id 526 /// The stack id that we will return to (by setting backstop breakpoints on the return 527 /// address to that frame) if we fail to step through. 528 /// 529 /// @param[in] abort_other_plans 530 /// \b true if we discard the currently queued plans and replace them with this one. 531 /// Otherwise this plan will go on the end of the plan stack. 532 /// 533 /// @param[in] stop_other_threads 534 /// \b true if we will stop other threads while we single step this one. 535 /// 536 /// @return 537 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 538 //------------------------------------------------------------------ 539 virtual ThreadPlan * 540 QueueThreadPlanForStepThrough (StackID &return_stack_id, 541 bool abort_other_plans, 542 bool stop_other_threads); 543 544 //------------------------------------------------------------------ 545 /// Gets the plan used to continue from the current PC. 546 /// This is a simple plan, mostly useful as a backstop when you are continuing 547 /// for some particular purpose. 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 /// @param[in] target_addr 554 /// The address to which we're running. 555 /// 556 /// @param[in] stop_other_threads 557 /// \b true if we will stop other threads while we single step this one. 558 /// 559 /// @return 560 /// A pointer to the newly queued thread plan, or NULL if the plan could not be queued. 561 //------------------------------------------------------------------ 562 virtual ThreadPlan * 563 QueueThreadPlanForRunToAddress (bool abort_other_plans, 564 Address &target_addr, 565 bool stop_other_threads); 566 567 virtual ThreadPlan * 568 QueueThreadPlanForStepUntil (bool abort_other_plans, 569 lldb::addr_t *address_list, 570 size_t num_addresses, 571 bool stop_others, 572 uint32_t frame_idx); 573 574 virtual ThreadPlan * 575 QueueThreadPlanForCallFunction (bool abort_other_plans, 576 Address& function, 577 lldb::addr_t arg, 578 bool stop_other_threads, 579 bool discard_on_error = false); 580 581 //------------------------------------------------------------------ 582 // Thread Plan accessors: 583 //------------------------------------------------------------------ 584 585 //------------------------------------------------------------------ 586 /// Gets the plan which will execute next on the plan stack. 587 /// 588 /// @return 589 /// A pointer to the next executed plan. 590 //------------------------------------------------------------------ 591 ThreadPlan * 592 GetCurrentPlan (); 593 594private: 595 bool 596 PlanIsBasePlan (ThreadPlan *plan_ptr); 597 598public: 599 600 //------------------------------------------------------------------ 601 /// Gets the outer-most plan that was popped off the plan stack in the 602 /// most recent stop. Useful for printing the stop reason accurately. 603 /// 604 /// @return 605 /// A pointer to the last completed plan. 606 //------------------------------------------------------------------ 607 lldb::ThreadPlanSP 608 GetCompletedPlan (); 609 610 //------------------------------------------------------------------ 611 /// Gets the outer-most return value from the completed plans 612 /// 613 /// @return 614 /// A ValueObjectSP, either empty if there is no return value, 615 /// or containing the return value. 616 //------------------------------------------------------------------ 617 lldb::ValueObjectSP 618 GetReturnValueObject (); 619 620 //------------------------------------------------------------------ 621 /// Checks whether the given plan is in the completed plans for this 622 /// stop. 623 /// 624 /// @param[in] plan 625 /// Pointer to the plan you're checking. 626 /// 627 /// @return 628 /// Returns true if the input plan is in the completed plan stack, 629 /// false otherwise. 630 //------------------------------------------------------------------ 631 bool 632 IsThreadPlanDone (ThreadPlan *plan); 633 634 //------------------------------------------------------------------ 635 /// Checks whether the given plan is in the discarded plans for this 636 /// stop. 637 /// 638 /// @param[in] plan 639 /// Pointer to the plan you're checking. 640 /// 641 /// @return 642 /// Returns true if the input plan is in the discarded plan stack, 643 /// false otherwise. 644 //------------------------------------------------------------------ 645 bool 646 WasThreadPlanDiscarded (ThreadPlan *plan); 647 648 //------------------------------------------------------------------ 649 /// Queues a generic thread plan. 650 /// 651 /// @param[in] plan_sp 652 /// The plan to queue. 653 /// 654 /// @param[in] abort_other_plans 655 /// \b true if we discard the currently queued plans and replace them with this one. 656 /// Otherwise this plan will go on the end of the plan stack. 657 /// 658 /// @return 659 /// A pointer to the last completed plan. 660 //------------------------------------------------------------------ 661 void 662 QueueThreadPlan (lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); 663 664 665 //------------------------------------------------------------------ 666 /// Discards the plans queued on the plan stack of the current thread. This is 667 /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call. 668 // But if \a force is true, all thread plans are discarded. 669 //------------------------------------------------------------------ 670 void 671 DiscardThreadPlans (bool force); 672 673 //------------------------------------------------------------------ 674 /// Discards the plans queued on the plan stack of the current thread up to and 675 /// including up_to_plan_sp. 676 // 677 // @param[in] up_to_plan_sp 678 // Discard all plans up to and including this one. 679 //------------------------------------------------------------------ 680 void 681 DiscardThreadPlansUpToPlan (lldb::ThreadPlanSP &up_to_plan_sp); 682 683 void 684 DiscardThreadPlansUpToPlan (ThreadPlan *up_to_plan_ptr); 685 686 //------------------------------------------------------------------ 687 /// Prints the current plan stack. 688 /// 689 /// @param[in] s 690 /// The stream to which to dump the plan stack info. 691 /// 692 //------------------------------------------------------------------ 693 void 694 DumpThreadPlans (Stream *s) const; 695 696 virtual bool 697 CheckpointThreadState (ThreadStateCheckpoint &saved_state); 698 699 virtual bool 700 RestoreThreadStateFromCheckpoint (ThreadStateCheckpoint &saved_state); 701 702 void 703 EnableTracer (bool value, bool single_step); 704 705 void 706 SetTracer (lldb::ThreadPlanTracerSP &tracer_sp); 707 708 //------------------------------------------------------------------ 709 /// The regular expression returned determines symbols that this 710 /// thread won't stop in during "step-in" operations. 711 /// 712 /// @return 713 /// A pointer to a regular expression to compare against symbols, 714 /// or NULL if all symbols are allowed. 715 /// 716 //------------------------------------------------------------------ 717 RegularExpression * 718 GetSymbolsToAvoidRegexp() 719 { 720 return ThreadInstanceSettings::GetSymbolsToAvoidRegexp(); 721 } 722 723 // Get the thread index ID. The index ID that is guaranteed to not be 724 // re-used by a process. They start at 1 and increase with each new thread. 725 // This allows easy command line access by a unique ID that is easier to 726 // type than the actual system thread ID. 727 uint32_t 728 GetIndexID () const; 729 730 //------------------------------------------------------------------ 731 // lldb::ExecutionContextScope pure virtual functions 732 //------------------------------------------------------------------ 733 virtual lldb::TargetSP 734 CalculateTarget (); 735 736 virtual lldb::ProcessSP 737 CalculateProcess (); 738 739 virtual lldb::ThreadSP 740 CalculateThread (); 741 742 virtual lldb::StackFrameSP 743 CalculateStackFrame (); 744 745 virtual void 746 CalculateExecutionContext (ExecutionContext &exe_ctx); 747 748 lldb::StackFrameSP 749 GetStackFrameSPForStackFramePtr (StackFrame *stack_frame_ptr); 750 751 size_t 752 GetStatus (Stream &strm, 753 uint32_t start_frame, 754 uint32_t num_frames, 755 uint32_t num_frames_with_source); 756 757 size_t 758 GetStackFrameStatus (Stream& strm, 759 uint32_t first_frame, 760 uint32_t num_frames, 761 bool show_frame_info, 762 uint32_t num_frames_with_source, 763 uint32_t source_lines_before, 764 uint32_t source_lines_after); 765 766 // We need a way to verify that even though we have a thread in a shared 767 // pointer that the object itself is still valid. Currently this won't be 768 // the case if DestroyThread() was called. DestroyThread is called when 769 // a thread has been removed from the Process' thread list. 770 bool 771 IsValid () const 772 { 773 return m_destroy_called; 774 } 775protected: 776 777 friend class ThreadPlan; 778 friend class ThreadList; 779 friend class StackFrameList; 780 781 // This is necessary to make sure thread assets get destroyed while the thread is still in good shape 782 // to call virtual thread methods. This must be called by classes that derive from Thread in their destructor. 783 virtual void DestroyThread (); 784 785 void 786 PushPlan (lldb::ThreadPlanSP &plan_sp); 787 788 void 789 PopPlan (); 790 791 void 792 DiscardPlan (); 793 794 ThreadPlan *GetPreviousPlan (ThreadPlan *plan); 795 796 // When you implement this method, make sure you don't overwrite the m_actual_stop_info if it claims to be 797 // valid. The stop info may be a "checkpointed and restored" stop info, so if it is still around it is right 798 // even if you have not calculated this yourself, or if it disagrees with what you might have calculated. 799 virtual lldb::StopInfoSP 800 GetPrivateStopReason () = 0; 801 802 typedef std::vector<lldb::ThreadPlanSP> plan_stack; 803 804 void 805 SetStopInfo (const lldb::StopInfoSP &stop_info_sp); 806 807 virtual bool 808 SaveFrameZeroState (RegisterCheckpoint &checkpoint); 809 810 virtual bool 811 RestoreSaveFrameZero (const RegisterCheckpoint &checkpoint); 812 813 virtual lldb_private::Unwind * 814 GetUnwinder (); 815 816 lldb::StackFrameListSP 817 GetStackFrameList (); 818 819 lldb::StateType GetTemporaryResumeState() 820 { 821 return m_temporary_resume_state; 822 } 823 824 lldb::StateType SetTemporaryResumeState(lldb::StateType resume_state) 825 { 826 lldb::StateType old_temp_resume_state = m_temporary_resume_state; 827 m_temporary_resume_state = resume_state; 828 return old_temp_resume_state; 829 } 830 831 struct ThreadState 832 { 833 uint32_t orig_stop_id; 834 lldb::StopInfoSP stop_info_sp; 835 RegisterCheckpoint register_backup; 836 }; 837 838 //------------------------------------------------------------------ 839 // Classes that inherit from Process can see and modify these 840 //------------------------------------------------------------------ 841 lldb::ProcessWP m_process_wp; ///< The process that owns this thread. 842 lldb::StopInfoSP m_actual_stop_info_sp; ///< The private stop reason for this thread 843 const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread for easy UI/command line access. 844 lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this thread's current register state. 845 lldb::StateType m_state; ///< The state of our process. 846 mutable Mutex m_state_mutex; ///< Multithreaded protection for m_state. 847 plan_stack m_plan_stack; ///< The stack of plans this thread is executing. 848 plan_stack m_completed_plan_stack; ///< Plans that have been completed by this stop. They get deleted when the thread resumes. 849 plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this stop. They get deleted when the thread resumes. 850 mutable Mutex m_frame_mutex; ///< Multithreaded protection for m_state. 851 lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily populated after a thread stops. 852 lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from the last time this thread stopped. 853 int m_resume_signal; ///< The signal that should be used when continuing this thread. 854 lldb::StateType m_resume_state; ///< This state is used to force a thread to be suspended from outside the ThreadPlan logic. 855 lldb::StateType m_temporary_resume_state; ///< This state records what the thread was told to do by the thread plan logic for the current resume. 856 /// It gets set in Thread::WillResume. 857 std::auto_ptr<lldb_private::Unwind> m_unwinder_ap; 858 bool m_destroy_called; // This is used internally to make sure derived Thread classes call DestroyThread. 859 uint32_t m_thread_stop_reason_stop_id; // This is the stop id for which the StopInfo is valid. Can use this so you know that 860 // the thread's m_actual_stop_info_sp is current and you don't have to fetch it again 861 862private: 863 //------------------------------------------------------------------ 864 // For Thread only 865 //------------------------------------------------------------------ 866 867 DISALLOW_COPY_AND_ASSIGN (Thread); 868 869}; 870 871} // namespace lldb_private 872 873#endif // liblldb_Thread_h_ 874