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