SBThread.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //===-- SBThread.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. #ifndef LLDB_API_SBTHREAD_H
  9. #define LLDB_API_SBTHREAD_H
  10. #include "lldb/API/SBDefines.h"
  11. #include <cstdio>
  12. namespace lldb {
  13. class SBFrame;
  14. class LLDB_API SBThread {
  15. public:
  16. enum {
  17. eBroadcastBitStackChanged = (1 << 0),
  18. eBroadcastBitThreadSuspended = (1 << 1),
  19. eBroadcastBitThreadResumed = (1 << 2),
  20. eBroadcastBitSelectedFrameChanged = (1 << 3),
  21. eBroadcastBitThreadSelected = (1 << 4)
  22. };
  23. static const char *GetBroadcasterClassName();
  24. SBThread();
  25. SBThread(const lldb::SBThread &thread);
  26. SBThread(const lldb::ThreadSP &lldb_object_sp);
  27. ~SBThread();
  28. lldb::SBQueue GetQueue() const;
  29. explicit operator bool() const;
  30. bool IsValid() const;
  31. void Clear();
  32. lldb::StopReason GetStopReason();
  33. /// Get the number of words associated with the stop reason.
  34. /// See also GetStopReasonDataAtIndex().
  35. size_t GetStopReasonDataCount();
  36. /// Get information associated with a stop reason.
  37. ///
  38. /// Breakpoint stop reasons will have data that consists of pairs of
  39. /// breakpoint IDs followed by the breakpoint location IDs (they always come
  40. /// in pairs).
  41. ///
  42. /// Stop Reason Count Data Type
  43. /// ======================== ===== =========================================
  44. /// eStopReasonNone 0
  45. /// eStopReasonTrace 0
  46. /// eStopReasonBreakpoint N duple: {breakpoint id, location id}
  47. /// eStopReasonWatchpoint 1 watchpoint id
  48. /// eStopReasonSignal 1 unix signal number
  49. /// eStopReasonException N exception data
  50. /// eStopReasonExec 0
  51. /// eStopReasonFork 1 pid of the child process
  52. /// eStopReasonVFork 1 pid of the child process
  53. /// eStopReasonVForkDone 0
  54. /// eStopReasonPlanComplete 0
  55. uint64_t GetStopReasonDataAtIndex(uint32_t idx);
  56. bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream);
  57. SBThreadCollection
  58. GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type);
  59. size_t GetStopDescription(char *dst, size_t dst_len);
  60. SBValue GetStopReturnValue();
  61. lldb::tid_t GetThreadID() const;
  62. uint32_t GetIndexID() const;
  63. const char *GetName() const;
  64. const char *GetQueueName() const;
  65. lldb::queue_id_t GetQueueID() const;
  66. bool GetInfoItemByPathAsString(const char *path, SBStream &strm);
  67. void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
  68. void StepOver(lldb::RunMode stop_other_threads, SBError &error);
  69. void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
  70. void StepInto(const char *target_name,
  71. lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
  72. void StepInto(const char *target_name, uint32_t end_line, SBError &error,
  73. lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
  74. void StepOut();
  75. void StepOut(SBError &error);
  76. void StepOutOfFrame(SBFrame &frame);
  77. void StepOutOfFrame(SBFrame &frame, SBError &error);
  78. void StepInstruction(bool step_over);
  79. void StepInstruction(bool step_over, SBError &error);
  80. SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec,
  81. uint32_t line);
  82. SBError StepUsingScriptedThreadPlan(const char *script_class_name);
  83. SBError StepUsingScriptedThreadPlan(const char *script_class_name,
  84. bool resume_immediately);
  85. SBError StepUsingScriptedThreadPlan(const char *script_class_name,
  86. lldb::SBStructuredData &args_data,
  87. bool resume_immediately);
  88. SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line);
  89. void RunToAddress(lldb::addr_t addr);
  90. void RunToAddress(lldb::addr_t addr, SBError &error);
  91. SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value);
  92. SBError UnwindInnermostExpression();
  93. /// LLDB currently supports process centric debugging which means when any
  94. /// thread in a process stops, all other threads are stopped. The Suspend()
  95. /// call here tells our process to suspend a thread and not let it run when
  96. /// the other threads in a process are allowed to run. So when
  97. /// SBProcess::Continue() is called, any threads that aren't suspended will
  98. /// be allowed to run. If any of the SBThread functions for stepping are
  99. /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the
  100. /// thread will not be allowed to run and these functions will simply return.
  101. ///
  102. /// Eventually we plan to add support for thread centric debugging where
  103. /// each thread is controlled individually and each thread would broadcast
  104. /// its state, but we haven't implemented this yet.
  105. ///
  106. /// Likewise the SBThread::Resume() call will again allow the thread to run
  107. /// when the process is continued.
  108. ///
  109. /// Suspend() and Resume() functions are not currently reference counted, if
  110. /// anyone has the need for them to be reference counted, please let us
  111. /// know.
  112. bool Suspend();
  113. bool Suspend(SBError &error);
  114. bool Resume();
  115. bool Resume(SBError &error);
  116. bool IsSuspended();
  117. bool IsStopped();
  118. uint32_t GetNumFrames();
  119. lldb::SBFrame GetFrameAtIndex(uint32_t idx);
  120. lldb::SBFrame GetSelectedFrame();
  121. lldb::SBFrame SetSelectedFrame(uint32_t frame_idx);
  122. static bool EventIsThreadEvent(const SBEvent &event);
  123. static SBFrame GetStackFrameFromEvent(const SBEvent &event);
  124. static SBThread GetThreadFromEvent(const SBEvent &event);
  125. lldb::SBProcess GetProcess();
  126. const lldb::SBThread &operator=(const lldb::SBThread &rhs);
  127. bool operator==(const lldb::SBThread &rhs) const;
  128. bool operator!=(const lldb::SBThread &rhs) const;
  129. bool GetDescription(lldb::SBStream &description) const;
  130. bool GetDescription(lldb::SBStream &description, bool stop_format) const;
  131. bool GetStatus(lldb::SBStream &status) const;
  132. SBThread GetExtendedBacktraceThread(const char *type);
  133. uint32_t GetExtendedBacktraceOriginatingIndexID();
  134. SBValue GetCurrentException();
  135. SBThread GetCurrentExceptionBacktrace();
  136. bool SafeToCallFunctions();
  137. private:
  138. friend class SBBreakpoint;
  139. friend class SBBreakpointLocation;
  140. friend class SBBreakpointCallbackBaton;
  141. friend class SBExecutionContext;
  142. friend class SBFrame;
  143. friend class SBProcess;
  144. friend class SBDebugger;
  145. friend class SBValue;
  146. friend class lldb_private::QueueImpl;
  147. friend class SBQueueItem;
  148. friend class SBThreadPlan;
  149. void SetThread(const lldb::ThreadSP &lldb_object_sp);
  150. SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx,
  151. lldb_private::ThreadPlan *new_plan);
  152. lldb::ExecutionContextRefSP m_opaque_sp;
  153. lldb_private::Thread *operator->();
  154. lldb_private::Thread *get();
  155. };
  156. } // namespace lldb
  157. #endif // LLDB_API_SBTHREAD_H