Andrew Walbran | 3d2c197 | 2020-04-07 12:24:26 +0100 | [diff] [blame^] | 1 | //===-- Thread.h ------------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #ifndef liblldb_Thread_h_ |
| 10 | #define liblldb_Thread_h_ |
| 11 | |
| 12 | #include <memory> |
| 13 | #include <mutex> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | #include "lldb/Core/UserSettingsController.h" |
| 18 | #include "lldb/Target/ExecutionContextScope.h" |
| 19 | #include "lldb/Target/RegisterCheckpoint.h" |
| 20 | #include "lldb/Target/StackFrameList.h" |
| 21 | #include "lldb/Utility/Broadcaster.h" |
| 22 | #include "lldb/Utility/Event.h" |
| 23 | #include "lldb/Utility/StructuredData.h" |
| 24 | #include "lldb/Utility/UserID.h" |
| 25 | #include "lldb/lldb-private.h" |
| 26 | |
| 27 | #define LLDB_THREAD_MAX_STOP_EXC_DATA 8 |
| 28 | |
| 29 | namespace lldb_private { |
| 30 | |
| 31 | class ThreadProperties : public Properties { |
| 32 | public: |
| 33 | ThreadProperties(bool is_global); |
| 34 | |
| 35 | ~ThreadProperties() override; |
| 36 | |
| 37 | /// The regular expression returned determines symbols that this |
| 38 | /// thread won't stop in during "step-in" operations. |
| 39 | /// |
| 40 | /// \return |
| 41 | /// A pointer to a regular expression to compare against symbols, |
| 42 | /// or nullptr if all symbols are allowed. |
| 43 | /// |
| 44 | const RegularExpression *GetSymbolsToAvoidRegexp(); |
| 45 | |
| 46 | FileSpecList GetLibrariesToAvoid() const; |
| 47 | |
| 48 | bool GetTraceEnabledState() const; |
| 49 | |
| 50 | bool GetStepInAvoidsNoDebug() const; |
| 51 | |
| 52 | bool GetStepOutAvoidsNoDebug() const; |
| 53 | |
| 54 | uint64_t GetMaxBacktraceDepth() const; |
| 55 | }; |
| 56 | |
| 57 | typedef std::shared_ptr<ThreadProperties> ThreadPropertiesSP; |
| 58 | |
| 59 | class Thread : public std::enable_shared_from_this<Thread>, |
| 60 | public ThreadProperties, |
| 61 | public UserID, |
| 62 | public ExecutionContextScope, |
| 63 | public Broadcaster { |
| 64 | public: |
| 65 | /// Broadcaster event bits definitions. |
| 66 | enum { |
| 67 | eBroadcastBitStackChanged = (1 << 0), |
| 68 | eBroadcastBitThreadSuspended = (1 << 1), |
| 69 | eBroadcastBitThreadResumed = (1 << 2), |
| 70 | eBroadcastBitSelectedFrameChanged = (1 << 3), |
| 71 | eBroadcastBitThreadSelected = (1 << 4) |
| 72 | }; |
| 73 | |
| 74 | static ConstString &GetStaticBroadcasterClass(); |
| 75 | |
| 76 | ConstString &GetBroadcasterClass() const override { |
| 77 | return GetStaticBroadcasterClass(); |
| 78 | } |
| 79 | |
| 80 | class ThreadEventData : public EventData { |
| 81 | public: |
| 82 | ThreadEventData(const lldb::ThreadSP thread_sp); |
| 83 | |
| 84 | ThreadEventData(const lldb::ThreadSP thread_sp, const StackID &stack_id); |
| 85 | |
| 86 | ThreadEventData(); |
| 87 | |
| 88 | ~ThreadEventData() override; |
| 89 | |
| 90 | static ConstString GetFlavorString(); |
| 91 | |
| 92 | ConstString GetFlavor() const override { |
| 93 | return ThreadEventData::GetFlavorString(); |
| 94 | } |
| 95 | |
| 96 | void Dump(Stream *s) const override; |
| 97 | |
| 98 | static const ThreadEventData *GetEventDataFromEvent(const Event *event_ptr); |
| 99 | |
| 100 | static lldb::ThreadSP GetThreadFromEvent(const Event *event_ptr); |
| 101 | |
| 102 | static StackID GetStackIDFromEvent(const Event *event_ptr); |
| 103 | |
| 104 | static lldb::StackFrameSP GetStackFrameFromEvent(const Event *event_ptr); |
| 105 | |
| 106 | lldb::ThreadSP GetThread() const { return m_thread_sp; } |
| 107 | |
| 108 | StackID GetStackID() const { return m_stack_id; } |
| 109 | |
| 110 | private: |
| 111 | lldb::ThreadSP m_thread_sp; |
| 112 | StackID m_stack_id; |
| 113 | |
| 114 | DISALLOW_COPY_AND_ASSIGN(ThreadEventData); |
| 115 | }; |
| 116 | |
| 117 | struct ThreadStateCheckpoint { |
| 118 | uint32_t orig_stop_id; // Dunno if I need this yet but it is an interesting |
| 119 | // bit of data. |
| 120 | lldb::StopInfoSP stop_info_sp; // You have to restore the stop info or you |
| 121 | // might continue with the wrong signals. |
| 122 | std::vector<lldb::ThreadPlanSP> m_completed_plan_stack; |
| 123 | lldb::RegisterCheckpointSP |
| 124 | register_backup_sp; // You need to restore the registers, of course... |
| 125 | uint32_t current_inlined_depth; |
| 126 | lldb::addr_t current_inlined_pc; |
| 127 | }; |
| 128 | |
| 129 | /// Constructor |
| 130 | /// |
| 131 | /// \param [in] process |
| 132 | /// |
| 133 | /// \param [in] tid |
| 134 | /// |
| 135 | /// \param [in] use_invalid_index_id |
| 136 | /// Optional parameter, defaults to false. The only subclass that |
| 137 | /// is likely to set use_invalid_index_id == true is the HistoryThread |
| 138 | /// class. In that case, the Thread we are constructing represents |
| 139 | /// a thread from earlier in the program execution. We may have the |
| 140 | /// tid of the original thread that they represent but we don't want |
| 141 | /// to reuse the IndexID of that thread, or create a new one. If a |
| 142 | /// client wants to know the original thread's IndexID, they should use |
| 143 | /// Thread::GetExtendedBacktraceOriginatingIndexID(). |
| 144 | Thread(Process &process, lldb::tid_t tid, bool use_invalid_index_id = false); |
| 145 | |
| 146 | ~Thread() override; |
| 147 | |
| 148 | static void SettingsInitialize(); |
| 149 | |
| 150 | static void SettingsTerminate(); |
| 151 | |
| 152 | static const ThreadPropertiesSP &GetGlobalProperties(); |
| 153 | |
| 154 | lldb::ProcessSP GetProcess() const { return m_process_wp.lock(); } |
| 155 | |
| 156 | int GetResumeSignal() const { return m_resume_signal; } |
| 157 | |
| 158 | void SetResumeSignal(int signal) { m_resume_signal = signal; } |
| 159 | |
| 160 | lldb::StateType GetState() const; |
| 161 | |
| 162 | void SetState(lldb::StateType state); |
| 163 | |
| 164 | /// Sets the USER resume state for this thread. If you set a thread to |
| 165 | /// suspended with |
| 166 | /// this API, it won't take part in any of the arbitration for ShouldResume, |
| 167 | /// and will stay |
| 168 | /// suspended even when other threads do get to run. |
| 169 | /// |
| 170 | /// N.B. This is not the state that is used internally by thread plans to |
| 171 | /// implement |
| 172 | /// staying on one thread while stepping over a breakpoint, etc. The is the |
| 173 | /// TemporaryResume state, and if you are implementing some bit of strategy in |
| 174 | /// the stepping |
| 175 | /// machinery you should be using that state and not the user resume state. |
| 176 | /// |
| 177 | /// If you are just preparing all threads to run, you should not override the |
| 178 | /// threads that are |
| 179 | /// marked as suspended by the debugger. In that case, pass override_suspend |
| 180 | /// = false. If you want |
| 181 | /// to force the thread to run (e.g. the "thread continue" command, or are |
| 182 | /// resetting the state |
| 183 | /// (e.g. in SBThread::Resume()), then pass true to override_suspend. |
| 184 | /// \return |
| 185 | /// The User resume state for this thread. |
| 186 | void SetResumeState(lldb::StateType state, bool override_suspend = false) { |
| 187 | if (m_resume_state == lldb::eStateSuspended && !override_suspend) |
| 188 | return; |
| 189 | m_resume_state = state; |
| 190 | } |
| 191 | |
| 192 | /// Gets the USER resume state for this thread. This is not the same as what |
| 193 | /// this thread is going to do for any particular step, however if this thread |
| 194 | /// returns eStateSuspended, then the process control logic will never allow |
| 195 | /// this |
| 196 | /// thread to run. |
| 197 | /// |
| 198 | /// \return |
| 199 | /// The User resume state for this thread. |
| 200 | lldb::StateType GetResumeState() const { return m_resume_state; } |
| 201 | |
| 202 | // This function is called on all the threads before "ShouldResume" and |
| 203 | // "WillResume" in case a thread needs to change its state before the |
| 204 | // ThreadList polls all the threads to figure out which ones actually will |
| 205 | // get to run and how. |
| 206 | void SetupForResume(); |
| 207 | |
| 208 | // Do not override this function, it is for thread plan logic only |
| 209 | bool ShouldResume(lldb::StateType resume_state); |
| 210 | |
| 211 | // Override this to do platform specific tasks before resume. |
| 212 | virtual void WillResume(lldb::StateType resume_state) {} |
| 213 | |
| 214 | // This clears generic thread state after a resume. If you subclass this, be |
| 215 | // sure to call it. |
| 216 | virtual void DidResume(); |
| 217 | |
| 218 | // This notifies the thread when a private stop occurs. |
| 219 | virtual void DidStop(); |
| 220 | |
| 221 | virtual void RefreshStateAfterStop() = 0; |
| 222 | |
| 223 | void WillStop(); |
| 224 | |
| 225 | bool ShouldStop(Event *event_ptr); |
| 226 | |
| 227 | Vote ShouldReportStop(Event *event_ptr); |
| 228 | |
| 229 | Vote ShouldReportRun(Event *event_ptr); |
| 230 | |
| 231 | void Flush(); |
| 232 | |
| 233 | // Return whether this thread matches the specification in ThreadSpec. This |
| 234 | // is a virtual method because at some point we may extend the thread spec |
| 235 | // with a platform specific dictionary of attributes, which then only the |
| 236 | // platform specific Thread implementation would know how to match. For now, |
| 237 | // this just calls through to the ThreadSpec's ThreadPassesBasicTests method. |
| 238 | virtual bool MatchesSpec(const ThreadSpec *spec); |
| 239 | |
| 240 | lldb::StopInfoSP GetStopInfo(); |
| 241 | |
| 242 | lldb::StopReason GetStopReason(); |
| 243 | |
| 244 | bool StopInfoIsUpToDate() const; |
| 245 | |
| 246 | // This sets the stop reason to a "blank" stop reason, so you can call |
| 247 | // functions on the thread without having the called function run with |
| 248 | // whatever stop reason you stopped with. |
| 249 | void SetStopInfoToNothing(); |
| 250 | |
| 251 | bool ThreadStoppedForAReason(); |
| 252 | |
| 253 | static const char *RunModeAsCString(lldb::RunMode mode); |
| 254 | |
| 255 | static const char *StopReasonAsCString(lldb::StopReason reason); |
| 256 | |
| 257 | virtual const char *GetInfo() { return nullptr; } |
| 258 | |
| 259 | /// Retrieve a dictionary of information about this thread |
| 260 | /// |
| 261 | /// On Mac OS X systems there may be voucher information. |
| 262 | /// The top level dictionary returned will have an "activity" key and the |
| 263 | /// value of the activity is a dictionary. Keys in that dictionary will |
| 264 | /// be "name" and "id", among others. |
| 265 | /// There may also be "trace_messages" (an array) with each entry in that |
| 266 | /// array |
| 267 | /// being a dictionary (keys include "message" with the text of the trace |
| 268 | /// message). |
| 269 | StructuredData::ObjectSP GetExtendedInfo() { |
| 270 | if (!m_extended_info_fetched) { |
| 271 | m_extended_info = FetchThreadExtendedInfo(); |
| 272 | m_extended_info_fetched = true; |
| 273 | } |
| 274 | return m_extended_info; |
| 275 | } |
| 276 | |
| 277 | virtual const char *GetName() { return nullptr; } |
| 278 | |
| 279 | virtual void SetName(const char *name) {} |
| 280 | |
| 281 | /// Whether this thread can be associated with a libdispatch queue |
| 282 | /// |
| 283 | /// The Thread may know if it is associated with a libdispatch queue, |
| 284 | /// it may know definitively that it is NOT associated with a libdispatch |
| 285 | /// queue, or it may be unknown whether it is associated with a libdispatch |
| 286 | /// queue. |
| 287 | /// |
| 288 | /// \return |
| 289 | /// eLazyBoolNo if this thread is definitely not associated with a |
| 290 | /// libdispatch queue (e.g. on a non-Darwin system where GCD aka |
| 291 | /// libdispatch is not available). |
| 292 | /// |
| 293 | /// eLazyBoolYes this thread is associated with a libdispatch queue. |
| 294 | /// |
| 295 | /// eLazyBoolCalculate this thread may be associated with a libdispatch |
| 296 | /// queue but the thread doesn't know one way or the other. |
| 297 | virtual lldb_private::LazyBool GetAssociatedWithLibdispatchQueue() { |
| 298 | return eLazyBoolNo; |
| 299 | } |
| 300 | |
| 301 | virtual void SetAssociatedWithLibdispatchQueue( |
| 302 | lldb_private::LazyBool associated_with_libdispatch_queue) {} |
| 303 | |
| 304 | /// Retrieve the Queue ID for the queue currently using this Thread |
| 305 | /// |
| 306 | /// If this Thread is doing work on behalf of a libdispatch/GCD queue, |
| 307 | /// retrieve the QueueID. |
| 308 | /// |
| 309 | /// This is a unique identifier for the libdispatch/GCD queue in a |
| 310 | /// process. Often starting at 1 for the initial system-created |
| 311 | /// queues and incrementing, a QueueID will not be reused for a |
| 312 | /// different queue during the lifetime of a process. |
| 313 | /// |
| 314 | /// \return |
| 315 | /// A QueueID if the Thread subclass implements this, else |
| 316 | /// LLDB_INVALID_QUEUE_ID. |
| 317 | virtual lldb::queue_id_t GetQueueID() { return LLDB_INVALID_QUEUE_ID; } |
| 318 | |
| 319 | virtual void SetQueueID(lldb::queue_id_t new_val) {} |
| 320 | |
| 321 | /// Retrieve the Queue name for the queue currently using this Thread |
| 322 | /// |
| 323 | /// If this Thread is doing work on behalf of a libdispatch/GCD queue, |
| 324 | /// retrieve the Queue name. |
| 325 | /// |
| 326 | /// \return |
| 327 | /// The Queue name, if the Thread subclass implements this, else |
| 328 | /// nullptr. |
| 329 | virtual const char *GetQueueName() { return nullptr; } |
| 330 | |
| 331 | virtual void SetQueueName(const char *name) {} |
| 332 | |
| 333 | /// Retrieve the Queue kind for the queue currently using this Thread |
| 334 | /// |
| 335 | /// If this Thread is doing work on behalf of a libdispatch/GCD queue, |
| 336 | /// retrieve the Queue kind - either eQueueKindSerial or |
| 337 | /// eQueueKindConcurrent, indicating that this queue processes work |
| 338 | /// items serially or concurrently. |
| 339 | /// |
| 340 | /// \return |
| 341 | /// The Queue kind, if the Thread subclass implements this, else |
| 342 | /// eQueueKindUnknown. |
| 343 | virtual lldb::QueueKind GetQueueKind() { return lldb::eQueueKindUnknown; } |
| 344 | |
| 345 | virtual void SetQueueKind(lldb::QueueKind kind) {} |
| 346 | |
| 347 | /// Retrieve the Queue for this thread, if any. |
| 348 | /// |
| 349 | /// \return |
| 350 | /// A QueueSP for the queue that is currently associated with this |
| 351 | /// thread. |
| 352 | /// An empty shared pointer indicates that this thread is not |
| 353 | /// associated with a queue, or libdispatch queues are not |
| 354 | /// supported on this target. |
| 355 | virtual lldb::QueueSP GetQueue() { return lldb::QueueSP(); } |
| 356 | |
| 357 | /// Retrieve the address of the libdispatch_queue_t struct for queue |
| 358 | /// currently using this Thread |
| 359 | /// |
| 360 | /// If this Thread is doing work on behalf of a libdispatch/GCD queue, |
| 361 | /// retrieve the address of the libdispatch_queue_t structure describing |
| 362 | /// the queue. |
| 363 | /// |
| 364 | /// This address may be reused for different queues later in the Process |
| 365 | /// lifetime and should not be used to identify a queue uniquely. Use |
| 366 | /// the GetQueueID() call for that. |
| 367 | /// |
| 368 | /// \return |
| 369 | /// The Queue's libdispatch_queue_t address if the Thread subclass |
| 370 | /// implements this, else LLDB_INVALID_ADDRESS. |
| 371 | virtual lldb::addr_t GetQueueLibdispatchQueueAddress() { |
| 372 | return LLDB_INVALID_ADDRESS; |
| 373 | } |
| 374 | |
| 375 | virtual void SetQueueLibdispatchQueueAddress(lldb::addr_t dispatch_queue_t) {} |
| 376 | |
| 377 | /// Whether this Thread already has all the Queue information cached or not |
| 378 | /// |
| 379 | /// A Thread may be associated with a libdispatch work Queue at a given |
| 380 | /// public stop event. If so, the thread can satisify requests like |
| 381 | /// GetQueueLibdispatchQueueAddress, GetQueueKind, GetQueueName, and |
| 382 | /// GetQueueID |
| 383 | /// either from information from the remote debug stub when it is initially |
| 384 | /// created, or it can query the SystemRuntime for that information. |
| 385 | /// |
| 386 | /// This method allows the SystemRuntime to discover if a thread has this |
| 387 | /// information already, instead of calling the thread to get the information |
| 388 | /// and having the thread call the SystemRuntime again. |
| 389 | virtual bool ThreadHasQueueInformation() const { return false; } |
| 390 | |
| 391 | virtual uint32_t GetStackFrameCount() { |
| 392 | return GetStackFrameList()->GetNumFrames(); |
| 393 | } |
| 394 | |
| 395 | virtual lldb::StackFrameSP GetStackFrameAtIndex(uint32_t idx) { |
| 396 | return GetStackFrameList()->GetFrameAtIndex(idx); |
| 397 | } |
| 398 | |
| 399 | virtual lldb::StackFrameSP |
| 400 | GetFrameWithConcreteFrameIndex(uint32_t unwind_idx); |
| 401 | |
| 402 | bool DecrementCurrentInlinedDepth() { |
| 403 | return GetStackFrameList()->DecrementCurrentInlinedDepth(); |
| 404 | } |
| 405 | |
| 406 | uint32_t GetCurrentInlinedDepth() { |
| 407 | return GetStackFrameList()->GetCurrentInlinedDepth(); |
| 408 | } |
| 409 | |
| 410 | Status ReturnFromFrameWithIndex(uint32_t frame_idx, |
| 411 | lldb::ValueObjectSP return_value_sp, |
| 412 | bool broadcast = false); |
| 413 | |
| 414 | Status ReturnFromFrame(lldb::StackFrameSP frame_sp, |
| 415 | lldb::ValueObjectSP return_value_sp, |
| 416 | bool broadcast = false); |
| 417 | |
| 418 | Status JumpToLine(const FileSpec &file, uint32_t line, |
| 419 | bool can_leave_function, std::string *warnings = nullptr); |
| 420 | |
| 421 | virtual lldb::StackFrameSP GetFrameWithStackID(const StackID &stack_id) { |
| 422 | if (stack_id.IsValid()) |
| 423 | return GetStackFrameList()->GetFrameWithStackID(stack_id); |
| 424 | return lldb::StackFrameSP(); |
| 425 | } |
| 426 | |
| 427 | uint32_t GetSelectedFrameIndex() { |
| 428 | return GetStackFrameList()->GetSelectedFrameIndex(); |
| 429 | } |
| 430 | |
| 431 | lldb::StackFrameSP GetSelectedFrame(); |
| 432 | |
| 433 | uint32_t SetSelectedFrame(lldb_private::StackFrame *frame, |
| 434 | bool broadcast = false); |
| 435 | |
| 436 | bool SetSelectedFrameByIndex(uint32_t frame_idx, bool broadcast = false); |
| 437 | |
| 438 | bool SetSelectedFrameByIndexNoisily(uint32_t frame_idx, |
| 439 | Stream &output_stream); |
| 440 | |
| 441 | void SetDefaultFileAndLineToSelectedFrame() { |
| 442 | GetStackFrameList()->SetDefaultFileAndLineToSelectedFrame(); |
| 443 | } |
| 444 | |
| 445 | virtual lldb::RegisterContextSP GetRegisterContext() = 0; |
| 446 | |
| 447 | virtual lldb::RegisterContextSP |
| 448 | CreateRegisterContextForFrame(StackFrame *frame) = 0; |
| 449 | |
| 450 | virtual void ClearStackFrames(); |
| 451 | |
| 452 | virtual bool SetBackingThread(const lldb::ThreadSP &thread_sp) { |
| 453 | return false; |
| 454 | } |
| 455 | |
| 456 | virtual lldb::ThreadSP GetBackingThread() const { return lldb::ThreadSP(); } |
| 457 | |
| 458 | virtual void ClearBackingThread() { |
| 459 | // Subclasses can use this function if a thread is actually backed by |
| 460 | // another thread. This is currently used for the OperatingSystem plug-ins |
| 461 | // where they might have a thread that is in memory, yet its registers are |
| 462 | // available through the lldb_private::Thread subclass for the current |
| 463 | // lldb_private::Process class. Since each time the process stops the |
| 464 | // backing threads for memory threads can change, we need a way to clear |
| 465 | // the backing thread for all memory threads each time we stop. |
| 466 | } |
| 467 | |
| 468 | // If stop_format is true, this will be the form used when we print stop |
| 469 | // info. If false, it will be the form we use for thread list and co. |
| 470 | void DumpUsingSettingsFormat(Stream &strm, uint32_t frame_idx, |
| 471 | bool stop_format); |
| 472 | |
| 473 | bool GetDescription(Stream &s, lldb::DescriptionLevel level, |
| 474 | bool print_json_thread, bool print_json_stopinfo); |
| 475 | |
| 476 | /// Default implementation for stepping into. |
| 477 | /// |
| 478 | /// This function is designed to be used by commands where the |
| 479 | /// process is publicly stopped. |
| 480 | /// |
| 481 | /// \param[in] source_step |
| 482 | /// If true and the frame has debug info, then do a source level |
| 483 | /// step in, else do a single instruction step in. |
| 484 | /// |
| 485 | /// \param[in] step_in_avoids_code_without_debug_info |
| 486 | /// If \a true, then avoid stepping into code that doesn't have |
| 487 | /// debug info, else step into any code regardless of whether it |
| 488 | /// has debug info. |
| 489 | /// |
| 490 | /// \param[in] step_out_avoids_code_without_debug_info |
| 491 | /// If \a true, then if you step out to code with no debug info, keep |
| 492 | /// stepping out till you get to code with debug info. |
| 493 | /// |
| 494 | /// \return |
| 495 | /// An error that describes anything that went wrong |
| 496 | virtual Status |
| 497 | StepIn(bool source_step, |
| 498 | LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, |
| 499 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 500 | |
| 501 | /// Default implementation for stepping over. |
| 502 | /// |
| 503 | /// This function is designed to be used by commands where the |
| 504 | /// process is publicly stopped. |
| 505 | /// |
| 506 | /// \param[in] source_step |
| 507 | /// If true and the frame has debug info, then do a source level |
| 508 | /// step over, else do a single instruction step over. |
| 509 | /// |
| 510 | /// \return |
| 511 | /// An error that describes anything that went wrong |
| 512 | virtual Status StepOver( |
| 513 | bool source_step, |
| 514 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 515 | |
| 516 | /// Default implementation for stepping out. |
| 517 | /// |
| 518 | /// This function is designed to be used by commands where the |
| 519 | /// process is publicly stopped. |
| 520 | /// |
| 521 | /// \return |
| 522 | /// An error that describes anything that went wrong |
| 523 | virtual Status StepOut(); |
| 524 | |
| 525 | /// Retrieves the per-thread data area. |
| 526 | /// Most OSs maintain a per-thread pointer (e.g. the FS register on |
| 527 | /// x64), which we return the value of here. |
| 528 | /// |
| 529 | /// \return |
| 530 | /// LLDB_INVALID_ADDRESS if not supported, otherwise the thread |
| 531 | /// pointer value. |
| 532 | virtual lldb::addr_t GetThreadPointer(); |
| 533 | |
| 534 | /// Retrieves the per-module TLS block for a thread. |
| 535 | /// |
| 536 | /// \param[in] module |
| 537 | /// The module to query TLS data for. |
| 538 | /// |
| 539 | /// \param[in] tls_file_addr |
| 540 | /// The thread local address in module |
| 541 | /// \return |
| 542 | /// If the thread has TLS data allocated for the |
| 543 | /// module, the address of the TLS block. Otherwise |
| 544 | /// LLDB_INVALID_ADDRESS is returned. |
| 545 | virtual lldb::addr_t GetThreadLocalData(const lldb::ModuleSP module, |
| 546 | lldb::addr_t tls_file_addr); |
| 547 | |
| 548 | /// Check whether this thread is safe to run functions |
| 549 | /// |
| 550 | /// The SystemRuntime may know of certain thread states (functions in |
| 551 | /// process of execution, for instance) which can make it unsafe for |
| 552 | /// functions to be called. |
| 553 | /// |
| 554 | /// \return |
| 555 | /// True if it is safe to call functions on this thread. |
| 556 | /// False if function calls should be avoided on this thread. |
| 557 | virtual bool SafeToCallFunctions(); |
| 558 | |
| 559 | // Thread Plan Providers: |
| 560 | // This section provides the basic thread plans that the Process control |
| 561 | // machinery uses to run the target. ThreadPlan.h provides more details on |
| 562 | // how this mechanism works. The thread provides accessors to a set of plans |
| 563 | // that perform basic operations. The idea is that particular Platform |
| 564 | // plugins can override these methods to provide the implementation of these |
| 565 | // basic operations appropriate to their environment. |
| 566 | // |
| 567 | // NB: All the QueueThreadPlanXXX providers return Shared Pointers to |
| 568 | // Thread plans. This is useful so that you can modify the plans after |
| 569 | // creation in ways specific to that plan type. Also, it is often necessary |
| 570 | // for ThreadPlans that utilize other ThreadPlans to implement their task to |
| 571 | // keep a shared pointer to the sub-plan. But besides that, the shared |
| 572 | // pointers should only be held onto by entities who live no longer than the |
| 573 | // thread containing the ThreadPlan. |
| 574 | // FIXME: If this becomes a problem, we can make a version that just returns a |
| 575 | // pointer, |
| 576 | // which it is clearly unsafe to hold onto, and a shared pointer version, and |
| 577 | // only allow ThreadPlan and Co. to use the latter. That is made more |
| 578 | // annoying to do because there's no elegant way to friend a method to all |
| 579 | // sub-classes of a given class. |
| 580 | // |
| 581 | |
| 582 | /// Queues the base plan for a thread. |
| 583 | /// The version returned by Process does some things that are useful, |
| 584 | /// like handle breakpoints and signals, so if you return a plugin specific |
| 585 | /// one you probably want to call through to the Process one for anything |
| 586 | /// your plugin doesn't explicitly handle. |
| 587 | /// |
| 588 | /// \param[in] abort_other_plans |
| 589 | /// \b true if we discard the currently queued plans and replace them with |
| 590 | /// this one. |
| 591 | /// Otherwise this plan will go on the end of the plan stack. |
| 592 | /// |
| 593 | /// \return |
| 594 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 595 | /// plan could not be queued. |
| 596 | virtual lldb::ThreadPlanSP QueueFundamentalPlan(bool abort_other_plans); |
| 597 | |
| 598 | /// Queues the plan used to step one instruction from the current PC of \a |
| 599 | /// thread. |
| 600 | /// |
| 601 | /// \param[in] step_over |
| 602 | /// \b true if we step over calls to functions, false if we step in. |
| 603 | /// |
| 604 | /// \param[in] abort_other_plans |
| 605 | /// \b true if we discard the currently queued plans and replace them with |
| 606 | /// this one. |
| 607 | /// Otherwise this plan will go on the end of the plan stack. |
| 608 | /// |
| 609 | /// \param[in] stop_other_threads |
| 610 | /// \b true if we will stop other threads while we single step this one. |
| 611 | /// |
| 612 | /// \param[out] status |
| 613 | /// A status with an error if queuing failed. |
| 614 | /// |
| 615 | /// \return |
| 616 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 617 | /// plan could not be queued. |
| 618 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepSingleInstruction( |
| 619 | bool step_over, bool abort_other_plans, bool stop_other_threads, |
| 620 | Status &status); |
| 621 | |
| 622 | /// Queues the plan used to step through an address range, stepping over |
| 623 | /// function calls. |
| 624 | /// |
| 625 | /// \param[in] abort_other_plans |
| 626 | /// \b true if we discard the currently queued plans and replace them with |
| 627 | /// this one. |
| 628 | /// Otherwise this plan will go on the end of the plan stack. |
| 629 | /// |
| 630 | /// \param[in] type |
| 631 | /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported |
| 632 | /// by this plan. |
| 633 | /// |
| 634 | /// \param[in] range |
| 635 | /// The address range to step through. |
| 636 | /// |
| 637 | /// \param[in] addr_context |
| 638 | /// When dealing with stepping through inlined functions the current PC is |
| 639 | /// not enough information to know |
| 640 | /// what "step" means. For instance a series of nested inline functions |
| 641 | /// might start at the same address. |
| 642 | // The \a addr_context provides the current symbol context the step |
| 643 | /// is supposed to be out of. |
| 644 | // FIXME: Currently unused. |
| 645 | /// |
| 646 | /// \param[in] stop_other_threads |
| 647 | /// \b true if we will stop other threads while we single step this one. |
| 648 | /// |
| 649 | /// \param[out] status |
| 650 | /// A status with an error if queuing failed. |
| 651 | /// |
| 652 | /// \param[in] step_out_avoids_code_without_debug_info |
| 653 | /// If eLazyBoolYes, if the step over steps out it will continue to step |
| 654 | /// out till it comes to a frame with debug info. |
| 655 | /// If eLazyBoolCalculate, we will consult the default set in the thread. |
| 656 | /// |
| 657 | /// \return |
| 658 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 659 | /// plan could not be queued. |
| 660 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( |
| 661 | bool abort_other_plans, const AddressRange &range, |
| 662 | const SymbolContext &addr_context, lldb::RunMode stop_other_threads, |
| 663 | Status &status, |
| 664 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 665 | |
| 666 | // Helper function that takes a LineEntry to step, insted of an AddressRange. |
| 667 | // This may combine multiple LineEntries of the same source line number to |
| 668 | // step over a longer address range in a single operation. |
| 669 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepOverRange( |
| 670 | bool abort_other_plans, const LineEntry &line_entry, |
| 671 | const SymbolContext &addr_context, lldb::RunMode stop_other_threads, |
| 672 | Status &status, |
| 673 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 674 | |
| 675 | /// Queues the plan used to step through an address range, stepping into |
| 676 | /// functions. |
| 677 | /// |
| 678 | /// \param[in] abort_other_plans |
| 679 | /// \b true if we discard the currently queued plans and replace them with |
| 680 | /// this one. |
| 681 | /// Otherwise this plan will go on the end of the plan stack. |
| 682 | /// |
| 683 | /// \param[in] type |
| 684 | /// Type of step to do, only eStepTypeInto and eStepTypeOver are supported |
| 685 | /// by this plan. |
| 686 | /// |
| 687 | /// \param[in] range |
| 688 | /// The address range to step through. |
| 689 | /// |
| 690 | /// \param[in] addr_context |
| 691 | /// When dealing with stepping through inlined functions the current PC is |
| 692 | /// not enough information to know |
| 693 | /// what "step" means. For instance a series of nested inline functions |
| 694 | /// might start at the same address. |
| 695 | // The \a addr_context provides the current symbol context the step |
| 696 | /// is supposed to be out of. |
| 697 | // FIXME: Currently unused. |
| 698 | /// |
| 699 | /// \param[in] step_in_target |
| 700 | /// Name if function we are trying to step into. We will step out if we |
| 701 | /// don't land in that function. |
| 702 | /// |
| 703 | /// \param[in] stop_other_threads |
| 704 | /// \b true if we will stop other threads while we single step this one. |
| 705 | /// |
| 706 | /// \param[out] status |
| 707 | /// A status with an error if queuing failed. |
| 708 | /// |
| 709 | /// \param[in] step_in_avoids_code_without_debug_info |
| 710 | /// If eLazyBoolYes we will step out if we step into code with no debug |
| 711 | /// info. |
| 712 | /// If eLazyBoolCalculate we will consult the default set in the thread. |
| 713 | /// |
| 714 | /// \param[in] step_out_avoids_code_without_debug_info |
| 715 | /// If eLazyBoolYes, if the step over steps out it will continue to step |
| 716 | /// out till it comes to a frame with debug info. |
| 717 | /// If eLazyBoolCalculate, it will consult the default set in the thread. |
| 718 | /// |
| 719 | /// \return |
| 720 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 721 | /// plan could not be queued. |
| 722 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( |
| 723 | bool abort_other_plans, const AddressRange &range, |
| 724 | const SymbolContext &addr_context, const char *step_in_target, |
| 725 | lldb::RunMode stop_other_threads, Status &status, |
| 726 | LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, |
| 727 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 728 | |
| 729 | // Helper function that takes a LineEntry to step, insted of an AddressRange. |
| 730 | // This may combine multiple LineEntries of the same source line number to |
| 731 | // step over a longer address range in a single operation. |
| 732 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepInRange( |
| 733 | bool abort_other_plans, const LineEntry &line_entry, |
| 734 | const SymbolContext &addr_context, const char *step_in_target, |
| 735 | lldb::RunMode stop_other_threads, Status &status, |
| 736 | LazyBool step_in_avoids_code_without_debug_info = eLazyBoolCalculate, |
| 737 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 738 | |
| 739 | /// Queue the plan used to step out of the function at the current PC of |
| 740 | /// \a thread. |
| 741 | /// |
| 742 | /// \param[in] abort_other_plans |
| 743 | /// \b true if we discard the currently queued plans and replace them with |
| 744 | /// this one. |
| 745 | /// Otherwise this plan will go on the end of the plan stack. |
| 746 | /// |
| 747 | /// \param[in] addr_context |
| 748 | /// When dealing with stepping through inlined functions the current PC is |
| 749 | /// not enough information to know |
| 750 | /// what "step" means. For instance a series of nested inline functions |
| 751 | /// might start at the same address. |
| 752 | // The \a addr_context provides the current symbol context the step |
| 753 | /// is supposed to be out of. |
| 754 | // FIXME: Currently unused. |
| 755 | /// |
| 756 | /// \param[in] first_insn |
| 757 | /// \b true if this is the first instruction of a function. |
| 758 | /// |
| 759 | /// \param[in] stop_other_threads |
| 760 | /// \b true if we will stop other threads while we single step this one. |
| 761 | /// |
| 762 | /// \param[in] stop_vote |
| 763 | /// \param[in] run_vote |
| 764 | /// See standard meanings for the stop & run votes in ThreadPlan.h. |
| 765 | /// |
| 766 | /// \param[out] status |
| 767 | /// A status with an error if queuing failed. |
| 768 | /// |
| 769 | /// \param[in] step_out_avoids_code_without_debug_info |
| 770 | /// If eLazyBoolYes, if the step over steps out it will continue to step |
| 771 | /// out till it comes to a frame with debug info. |
| 772 | /// If eLazyBoolCalculate, it will consult the default set in the thread. |
| 773 | /// |
| 774 | /// \return |
| 775 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 776 | /// plan could not be queued. |
| 777 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepOut( |
| 778 | bool abort_other_plans, SymbolContext *addr_context, bool first_insn, |
| 779 | bool stop_other_threads, Vote stop_vote, Vote run_vote, |
| 780 | uint32_t frame_idx, Status &status, |
| 781 | LazyBool step_out_avoids_code_without_debug_info = eLazyBoolCalculate); |
| 782 | |
| 783 | /// Queue the plan used to step out of the function at the current PC of |
| 784 | /// a thread. This version does not consult the should stop here callback, |
| 785 | /// and should only |
| 786 | /// be used by other thread plans when they need to retain control of the step |
| 787 | /// out. |
| 788 | /// |
| 789 | /// \param[in] abort_other_plans |
| 790 | /// \b true if we discard the currently queued plans and replace them with |
| 791 | /// this one. |
| 792 | /// Otherwise this plan will go on the end of the plan stack. |
| 793 | /// |
| 794 | /// \param[in] addr_context |
| 795 | /// When dealing with stepping through inlined functions the current PC is |
| 796 | /// not enough information to know |
| 797 | /// what "step" means. For instance a series of nested inline functions |
| 798 | /// might start at the same address. |
| 799 | // The \a addr_context provides the current symbol context the step |
| 800 | /// is supposed to be out of. |
| 801 | // FIXME: Currently unused. |
| 802 | /// |
| 803 | /// \param[in] first_insn |
| 804 | /// \b true if this is the first instruction of a function. |
| 805 | /// |
| 806 | /// \param[in] stop_other_threads |
| 807 | /// \b true if we will stop other threads while we single step this one. |
| 808 | /// |
| 809 | /// \param[in] stop_vote |
| 810 | /// |
| 811 | /// \param[in] run_vote |
| 812 | /// See standard meanings for the stop & run votes in ThreadPlan.h. |
| 813 | /// |
| 814 | /// \param[in] frame_idx |
| 815 | /// |
| 816 | /// \param[out] status |
| 817 | /// A status with an error if queuing failed. |
| 818 | /// |
| 819 | /// \param[in] continue_to_next_branch |
| 820 | /// Normally this will enqueue a plan that will put a breakpoint on the |
| 821 | /// return address and continue |
| 822 | /// to there. If continue_to_next_branch is true, this is an operation not |
| 823 | /// involving the user -- |
| 824 | /// e.g. stepping "next" in a source line and we instruction stepped into |
| 825 | /// another function -- |
| 826 | /// so instead of putting a breakpoint on the return address, advance the |
| 827 | /// breakpoint to the |
| 828 | /// end of the source line that is doing the call, or until the next flow |
| 829 | /// control instruction. |
| 830 | /// If the return value from the function call is to be retrieved / |
| 831 | /// displayed to the user, you must stop |
| 832 | /// on the return address. The return value may be stored in volatile |
| 833 | /// registers which are overwritten |
| 834 | /// before the next branch instruction. |
| 835 | /// |
| 836 | /// \return |
| 837 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 838 | /// plan could not be queued. |
| 839 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepOutNoShouldStop( |
| 840 | bool abort_other_plans, SymbolContext *addr_context, bool first_insn, |
| 841 | bool stop_other_threads, Vote stop_vote, Vote run_vote, |
| 842 | uint32_t frame_idx, Status &status, bool continue_to_next_branch = false); |
| 843 | |
| 844 | /// Gets the plan used to step through the code that steps from a function |
| 845 | /// call site at the current PC into the actual function call. |
| 846 | /// |
| 847 | /// \param[in] return_stack_id |
| 848 | /// The stack id that we will return to (by setting backstop breakpoints on |
| 849 | /// the return |
| 850 | /// address to that frame) if we fail to step through. |
| 851 | /// |
| 852 | /// \param[in] abort_other_plans |
| 853 | /// \b true if we discard the currently queued plans and replace them with |
| 854 | /// this one. |
| 855 | /// Otherwise this plan will go on the end of the plan stack. |
| 856 | /// |
| 857 | /// \param[in] stop_other_threads |
| 858 | /// \b true if we will stop other threads while we single step this one. |
| 859 | /// |
| 860 | /// \param[out] status |
| 861 | /// A status with an error if queuing failed. |
| 862 | /// |
| 863 | /// \return |
| 864 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 865 | /// plan could not be queued. |
| 866 | virtual lldb::ThreadPlanSP |
| 867 | QueueThreadPlanForStepThrough(StackID &return_stack_id, |
| 868 | bool abort_other_plans, bool stop_other_threads, |
| 869 | Status &status); |
| 870 | |
| 871 | /// Gets the plan used to continue from the current PC. |
| 872 | /// This is a simple plan, mostly useful as a backstop when you are continuing |
| 873 | /// for some particular purpose. |
| 874 | /// |
| 875 | /// \param[in] abort_other_plans |
| 876 | /// \b true if we discard the currently queued plans and replace them with |
| 877 | /// this one. |
| 878 | /// Otherwise this plan will go on the end of the plan stack. |
| 879 | /// |
| 880 | /// \param[in] target_addr |
| 881 | /// The address to which we're running. |
| 882 | /// |
| 883 | /// \param[in] stop_other_threads |
| 884 | /// \b true if we will stop other threads while we single step this one. |
| 885 | /// |
| 886 | /// \param[out] status |
| 887 | /// A status with an error if queuing failed. |
| 888 | /// |
| 889 | /// \return |
| 890 | /// A shared pointer to the newly queued thread plan, or nullptr if the |
| 891 | /// plan could not be queued. |
| 892 | virtual lldb::ThreadPlanSP |
| 893 | QueueThreadPlanForRunToAddress(bool abort_other_plans, Address &target_addr, |
| 894 | bool stop_other_threads, Status &status); |
| 895 | |
| 896 | virtual lldb::ThreadPlanSP QueueThreadPlanForStepUntil( |
| 897 | bool abort_other_plans, lldb::addr_t *address_list, size_t num_addresses, |
| 898 | bool stop_others, uint32_t frame_idx, Status &status); |
| 899 | |
| 900 | virtual lldb::ThreadPlanSP |
| 901 | QueueThreadPlanForStepScripted(bool abort_other_plans, const char *class_name, |
| 902 | bool stop_other_threads, Status &status); |
| 903 | |
| 904 | // Thread Plan accessors: |
| 905 | |
| 906 | /// Gets the plan which will execute next on the plan stack. |
| 907 | /// |
| 908 | /// \return |
| 909 | /// A pointer to the next executed plan. |
| 910 | ThreadPlan *GetCurrentPlan(); |
| 911 | |
| 912 | /// Unwinds the thread stack for the innermost expression plan currently |
| 913 | /// on the thread plan stack. |
| 914 | /// |
| 915 | /// \return |
| 916 | /// An error if the thread plan could not be unwound. |
| 917 | |
| 918 | Status UnwindInnermostExpression(); |
| 919 | |
| 920 | /// Gets the outer-most plan that was popped off the plan stack in the |
| 921 | /// most recent stop. Useful for printing the stop reason accurately. |
| 922 | /// |
| 923 | /// \return |
| 924 | /// A pointer to the last completed plan. |
| 925 | lldb::ThreadPlanSP GetCompletedPlan(); |
| 926 | |
| 927 | /// Gets the outer-most return value from the completed plans |
| 928 | /// |
| 929 | /// \return |
| 930 | /// A ValueObjectSP, either empty if there is no return value, |
| 931 | /// or containing the return value. |
| 932 | lldb::ValueObjectSP GetReturnValueObject(); |
| 933 | |
| 934 | /// Gets the outer-most expression variable from the completed plans |
| 935 | /// |
| 936 | /// \return |
| 937 | /// A ExpressionVariableSP, either empty if there is no |
| 938 | /// plan completed an expression during the current stop |
| 939 | /// or the expression variable that was made for the completed expression. |
| 940 | lldb::ExpressionVariableSP GetExpressionVariable(); |
| 941 | |
| 942 | /// Checks whether the given plan is in the completed plans for this |
| 943 | /// stop. |
| 944 | /// |
| 945 | /// \param[in] plan |
| 946 | /// Pointer to the plan you're checking. |
| 947 | /// |
| 948 | /// \return |
| 949 | /// Returns true if the input plan is in the completed plan stack, |
| 950 | /// false otherwise. |
| 951 | bool IsThreadPlanDone(ThreadPlan *plan); |
| 952 | |
| 953 | /// Checks whether the given plan is in the discarded plans for this |
| 954 | /// stop. |
| 955 | /// |
| 956 | /// \param[in] plan |
| 957 | /// Pointer to the plan you're checking. |
| 958 | /// |
| 959 | /// \return |
| 960 | /// Returns true if the input plan is in the discarded plan stack, |
| 961 | /// false otherwise. |
| 962 | bool WasThreadPlanDiscarded(ThreadPlan *plan); |
| 963 | |
| 964 | /// Check if we have completed plan to override breakpoint stop reason |
| 965 | /// |
| 966 | /// \return |
| 967 | /// Returns true if completed plan stack is not empty |
| 968 | /// false otherwise. |
| 969 | bool CompletedPlanOverridesBreakpoint(); |
| 970 | |
| 971 | /// Queues a generic thread plan. |
| 972 | /// |
| 973 | /// \param[in] plan_sp |
| 974 | /// The plan to queue. |
| 975 | /// |
| 976 | /// \param[in] abort_other_plans |
| 977 | /// \b true if we discard the currently queued plans and replace them with |
| 978 | /// this one. |
| 979 | /// Otherwise this plan will go on the end of the plan stack. |
| 980 | /// |
| 981 | /// \return |
| 982 | /// A pointer to the last completed plan. |
| 983 | Status QueueThreadPlan(lldb::ThreadPlanSP &plan_sp, bool abort_other_plans); |
| 984 | |
| 985 | /// Discards the plans queued on the plan stack of the current thread. This |
| 986 | /// is |
| 987 | /// arbitrated by the "Master" ThreadPlans, using the "OkayToDiscard" call. |
| 988 | // But if \a force is true, all thread plans are discarded. |
| 989 | void DiscardThreadPlans(bool force); |
| 990 | |
| 991 | /// Discards the plans queued on the plan stack of the current thread up to |
| 992 | /// and |
| 993 | /// including up_to_plan_sp. |
| 994 | // |
| 995 | // \param[in] up_to_plan_sp |
| 996 | // Discard all plans up to and including this one. |
| 997 | void DiscardThreadPlansUpToPlan(lldb::ThreadPlanSP &up_to_plan_sp); |
| 998 | |
| 999 | void DiscardThreadPlansUpToPlan(ThreadPlan *up_to_plan_ptr); |
| 1000 | |
| 1001 | /// Discards the plans queued on the plan stack of the current thread up to |
| 1002 | /// and |
| 1003 | /// including the plan in that matches \a thread_index counting only |
| 1004 | /// the non-Private plans. |
| 1005 | /// |
| 1006 | /// \param[in] up_to_plan_sp |
| 1007 | /// Discard all plans up to and including this user plan given by this |
| 1008 | /// index. |
| 1009 | /// |
| 1010 | /// \return |
| 1011 | /// \b true if there was a thread plan with that user index, \b false |
| 1012 | /// otherwise. |
| 1013 | bool DiscardUserThreadPlansUpToIndex(uint32_t thread_index); |
| 1014 | |
| 1015 | /// Prints the current plan stack. |
| 1016 | /// |
| 1017 | /// \param[in] s |
| 1018 | /// The stream to which to dump the plan stack info. |
| 1019 | /// |
| 1020 | void DumpThreadPlans( |
| 1021 | Stream *s, |
| 1022 | lldb::DescriptionLevel desc_level = lldb::eDescriptionLevelVerbose, |
| 1023 | bool include_internal = true, bool ignore_boring = false) const; |
| 1024 | |
| 1025 | virtual bool CheckpointThreadState(ThreadStateCheckpoint &saved_state); |
| 1026 | |
| 1027 | virtual bool |
| 1028 | RestoreRegisterStateFromCheckpoint(ThreadStateCheckpoint &saved_state); |
| 1029 | |
| 1030 | virtual bool |
| 1031 | RestoreThreadStateFromCheckpoint(ThreadStateCheckpoint &saved_state); |
| 1032 | |
| 1033 | void EnableTracer(bool value, bool single_step); |
| 1034 | |
| 1035 | void SetTracer(lldb::ThreadPlanTracerSP &tracer_sp); |
| 1036 | |
| 1037 | // Get the thread index ID. The index ID that is guaranteed to not be re-used |
| 1038 | // by a process. They start at 1 and increase with each new thread. This |
| 1039 | // allows easy command line access by a unique ID that is easier to type than |
| 1040 | // the actual system thread ID. |
| 1041 | uint32_t GetIndexID() const; |
| 1042 | |
| 1043 | // Get the originating thread's index ID. |
| 1044 | // In the case of an "extended" thread -- a thread which represents the stack |
| 1045 | // that enqueued/spawned work that is currently executing -- we need to |
| 1046 | // provide the IndexID of the thread that actually did this work. We don't |
| 1047 | // want to just masquerade as that thread's IndexID by using it in our own |
| 1048 | // IndexID because that way leads to madness - but the driver program which |
| 1049 | // is iterating over extended threads may ask for the OriginatingThreadID to |
| 1050 | // display that information to the user. |
| 1051 | // Normal threads will return the same thing as GetIndexID(); |
| 1052 | virtual uint32_t GetExtendedBacktraceOriginatingIndexID() { |
| 1053 | return GetIndexID(); |
| 1054 | } |
| 1055 | |
| 1056 | // The API ID is often the same as the Thread::GetID(), but not in all cases. |
| 1057 | // Thread::GetID() is the user visible thread ID that clients would want to |
| 1058 | // see. The API thread ID is the thread ID that is used when sending data |
| 1059 | // to/from the debugging protocol. |
| 1060 | virtual lldb::user_id_t GetProtocolID() const { return GetID(); } |
| 1061 | |
| 1062 | // lldb::ExecutionContextScope pure virtual functions |
| 1063 | lldb::TargetSP CalculateTarget() override; |
| 1064 | |
| 1065 | lldb::ProcessSP CalculateProcess() override; |
| 1066 | |
| 1067 | lldb::ThreadSP CalculateThread() override; |
| 1068 | |
| 1069 | lldb::StackFrameSP CalculateStackFrame() override; |
| 1070 | |
| 1071 | void CalculateExecutionContext(ExecutionContext &exe_ctx) override; |
| 1072 | |
| 1073 | lldb::StackFrameSP |
| 1074 | GetStackFrameSPForStackFramePtr(StackFrame *stack_frame_ptr); |
| 1075 | |
| 1076 | size_t GetStatus(Stream &strm, uint32_t start_frame, uint32_t num_frames, |
| 1077 | uint32_t num_frames_with_source, bool stop_format, |
| 1078 | bool only_stacks = false); |
| 1079 | |
| 1080 | size_t GetStackFrameStatus(Stream &strm, uint32_t first_frame, |
| 1081 | uint32_t num_frames, bool show_frame_info, |
| 1082 | uint32_t num_frames_with_source); |
| 1083 | |
| 1084 | // We need a way to verify that even though we have a thread in a shared |
| 1085 | // pointer that the object itself is still valid. Currently this won't be the |
| 1086 | // case if DestroyThread() was called. DestroyThread is called when a thread |
| 1087 | // has been removed from the Process' thread list. |
| 1088 | bool IsValid() const { return !m_destroy_called; } |
| 1089 | |
| 1090 | // Sets and returns a valid stop info based on the process stop ID and the |
| 1091 | // current thread plan. If the thread stop ID does not match the process' |
| 1092 | // stop ID, the private stop reason is not set and an invalid StopInfoSP may |
| 1093 | // be returned. |
| 1094 | // |
| 1095 | // NOTE: This function must be called before the current thread plan is |
| 1096 | // moved to the completed plan stack (in Thread::ShouldStop()). |
| 1097 | // |
| 1098 | // NOTE: If subclasses override this function, ensure they do not overwrite |
| 1099 | // the m_actual_stop_info if it is valid. The stop info may be a |
| 1100 | // "checkpointed and restored" stop info, so if it is still around it is |
| 1101 | // right even if you have not calculated this yourself, or if it disagrees |
| 1102 | // with what you might have calculated. |
| 1103 | virtual lldb::StopInfoSP GetPrivateStopInfo(); |
| 1104 | |
| 1105 | // Ask the thread subclass to set its stop info. |
| 1106 | // |
| 1107 | // Thread subclasses should call Thread::SetStopInfo(...) with the reason the |
| 1108 | // thread stopped. |
| 1109 | // |
| 1110 | // \return |
| 1111 | // True if Thread::SetStopInfo(...) was called, false otherwise. |
| 1112 | virtual bool CalculateStopInfo() = 0; |
| 1113 | |
| 1114 | // Gets the temporary resume state for a thread. |
| 1115 | // |
| 1116 | // This value gets set in each thread by complex debugger logic in |
| 1117 | // Thread::ShouldResume() and an appropriate thread resume state will get set |
| 1118 | // in each thread every time the process is resumed prior to calling |
| 1119 | // Process::DoResume(). The lldb_private::Process subclass should adhere to |
| 1120 | // the thread resume state request which will be one of: |
| 1121 | // |
| 1122 | // eStateRunning - thread will resume when process is resumed |
| 1123 | // eStateStepping - thread should step 1 instruction and stop when process |
| 1124 | // is resumed |
| 1125 | // eStateSuspended - thread should not execute any instructions when |
| 1126 | // process is resumed |
| 1127 | lldb::StateType GetTemporaryResumeState() const { |
| 1128 | return m_temporary_resume_state; |
| 1129 | } |
| 1130 | |
| 1131 | void SetStopInfo(const lldb::StopInfoSP &stop_info_sp); |
| 1132 | |
| 1133 | void ResetStopInfo(); |
| 1134 | |
| 1135 | void SetShouldReportStop(Vote vote); |
| 1136 | |
| 1137 | /// Sets the extended backtrace token for this thread |
| 1138 | /// |
| 1139 | /// Some Thread subclasses may maintain a token to help with providing |
| 1140 | /// an extended backtrace. The SystemRuntime plugin will set/request this. |
| 1141 | /// |
| 1142 | /// \param [in] token |
| 1143 | virtual void SetExtendedBacktraceToken(uint64_t token) {} |
| 1144 | |
| 1145 | /// Gets the extended backtrace token for this thread |
| 1146 | /// |
| 1147 | /// Some Thread subclasses may maintain a token to help with providing |
| 1148 | /// an extended backtrace. The SystemRuntime plugin will set/request this. |
| 1149 | /// |
| 1150 | /// \return |
| 1151 | /// The token needed by the SystemRuntime to create an extended backtrace. |
| 1152 | /// LLDB_INVALID_ADDRESS is returned if no token is available. |
| 1153 | virtual uint64_t GetExtendedBacktraceToken() { return LLDB_INVALID_ADDRESS; } |
| 1154 | |
| 1155 | lldb::ValueObjectSP GetCurrentException(); |
| 1156 | |
| 1157 | lldb::ThreadSP GetCurrentExceptionBacktrace(); |
| 1158 | |
| 1159 | protected: |
| 1160 | friend class ThreadPlan; |
| 1161 | friend class ThreadList; |
| 1162 | friend class ThreadEventData; |
| 1163 | friend class StackFrameList; |
| 1164 | friend class StackFrame; |
| 1165 | friend class OperatingSystem; |
| 1166 | |
| 1167 | // This is necessary to make sure thread assets get destroyed while the |
| 1168 | // thread is still in good shape to call virtual thread methods. This must |
| 1169 | // be called by classes that derive from Thread in their destructor. |
| 1170 | virtual void DestroyThread(); |
| 1171 | |
| 1172 | void PushPlan(lldb::ThreadPlanSP &plan_sp); |
| 1173 | |
| 1174 | void PopPlan(); |
| 1175 | |
| 1176 | void DiscardPlan(); |
| 1177 | |
| 1178 | ThreadPlan *GetPreviousPlan(ThreadPlan *plan); |
| 1179 | |
| 1180 | typedef std::vector<lldb::ThreadPlanSP> plan_stack; |
| 1181 | |
| 1182 | virtual lldb_private::Unwind *GetUnwinder(); |
| 1183 | |
| 1184 | // Check to see whether the thread is still at the last breakpoint hit that |
| 1185 | // stopped it. |
| 1186 | virtual bool IsStillAtLastBreakpointHit(); |
| 1187 | |
| 1188 | // Some threads are threads that are made up by OperatingSystem plugins that |
| 1189 | // are threads that exist and are context switched out into memory. The |
| 1190 | // OperatingSystem plug-in need a ways to know if a thread is "real" or made |
| 1191 | // up. |
| 1192 | virtual bool IsOperatingSystemPluginThread() const { return false; } |
| 1193 | |
| 1194 | // Subclasses that have a way to get an extended info dictionary for this |
| 1195 | // thread should fill |
| 1196 | virtual lldb_private::StructuredData::ObjectSP FetchThreadExtendedInfo() { |
| 1197 | return StructuredData::ObjectSP(); |
| 1198 | } |
| 1199 | |
| 1200 | lldb::StackFrameListSP GetStackFrameList(); |
| 1201 | |
| 1202 | void SetTemporaryResumeState(lldb::StateType new_state) { |
| 1203 | m_temporary_resume_state = new_state; |
| 1204 | } |
| 1205 | |
| 1206 | void FunctionOptimizationWarning(lldb_private::StackFrame *frame); |
| 1207 | |
| 1208 | // Classes that inherit from Process can see and modify these |
| 1209 | lldb::ProcessWP m_process_wp; ///< The process that owns this thread. |
| 1210 | lldb::StopInfoSP m_stop_info_sp; ///< The private stop reason for this thread |
| 1211 | uint32_t m_stop_info_stop_id; // This is the stop id for which the StopInfo is |
| 1212 | // valid. Can use this so you know that |
| 1213 | // the thread's m_stop_info_sp is current and you don't have to fetch it |
| 1214 | // again |
| 1215 | uint32_t m_stop_info_override_stop_id; // The stop ID containing the last time |
| 1216 | // the stop info was checked against |
| 1217 | // the stop info override |
| 1218 | const uint32_t m_index_id; ///< A unique 1 based index assigned to each thread |
| 1219 | ///for easy UI/command line access. |
| 1220 | lldb::RegisterContextSP m_reg_context_sp; ///< The register context for this |
| 1221 | ///thread's current register state. |
| 1222 | lldb::StateType m_state; ///< The state of our process. |
| 1223 | mutable std::recursive_mutex |
| 1224 | m_state_mutex; ///< Multithreaded protection for m_state. |
| 1225 | plan_stack m_plan_stack; ///< The stack of plans this thread is executing. |
| 1226 | plan_stack m_completed_plan_stack; ///< Plans that have been completed by this |
| 1227 | ///stop. They get deleted when the thread |
| 1228 | ///resumes. |
| 1229 | plan_stack m_discarded_plan_stack; ///< Plans that have been discarded by this |
| 1230 | ///stop. They get deleted when the thread |
| 1231 | ///resumes. |
| 1232 | mutable std::recursive_mutex |
| 1233 | m_frame_mutex; ///< Multithreaded protection for m_state. |
| 1234 | lldb::StackFrameListSP m_curr_frames_sp; ///< The stack frames that get lazily |
| 1235 | ///populated after a thread stops. |
| 1236 | lldb::StackFrameListSP m_prev_frames_sp; ///< The previous stack frames from |
| 1237 | ///the last time this thread stopped. |
| 1238 | int m_resume_signal; ///< The signal that should be used when continuing this |
| 1239 | ///thread. |
| 1240 | lldb::StateType m_resume_state; ///< This state is used to force a thread to |
| 1241 | ///be suspended from outside the ThreadPlan |
| 1242 | ///logic. |
| 1243 | lldb::StateType m_temporary_resume_state; ///< This state records what the |
| 1244 | ///thread was told to do by the |
| 1245 | ///thread plan logic for the current |
| 1246 | ///resume. |
| 1247 | /// It gets set in Thread::ShouldResume. |
| 1248 | std::unique_ptr<lldb_private::Unwind> m_unwinder_up; |
| 1249 | bool m_destroy_called; // This is used internally to make sure derived Thread |
| 1250 | // classes call DestroyThread. |
| 1251 | LazyBool m_override_should_notify; |
| 1252 | |
| 1253 | private: |
| 1254 | bool m_extended_info_fetched; // Have we tried to retrieve the m_extended_info |
| 1255 | // for this thread? |
| 1256 | StructuredData::ObjectSP m_extended_info; // The extended info for this thread |
| 1257 | |
| 1258 | private: |
| 1259 | bool PlanIsBasePlan(ThreadPlan *plan_ptr); |
| 1260 | |
| 1261 | void BroadcastSelectedFrameChange(StackID &new_frame_id); |
| 1262 | |
| 1263 | DISALLOW_COPY_AND_ASSIGN(Thread); |
| 1264 | }; |
| 1265 | |
| 1266 | } // namespace lldb_private |
| 1267 | |
| 1268 | #endif // liblldb_Thread_h_ |