Coverage Report

Created: 2022-01-25 06:29

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