1061da546Spatrick //===-- SBThread.h ----------------------------------------------*- C++ -*-===// 2061da546Spatrick // 3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information. 5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6061da546Spatrick // 7061da546Spatrick //===----------------------------------------------------------------------===// 8061da546Spatrick 9dda28197Spatrick #ifndef LLDB_API_SBTHREAD_H 10dda28197Spatrick #define LLDB_API_SBTHREAD_H 11061da546Spatrick 12061da546Spatrick #include "lldb/API/SBDefines.h" 13061da546Spatrick 14be691f3bSpatrick #include <cstdio> 15061da546Spatrick 16061da546Spatrick namespace lldb { 17061da546Spatrick 18061da546Spatrick class SBFrame; 19061da546Spatrick 20061da546Spatrick class LLDB_API SBThread { 21061da546Spatrick public: 22061da546Spatrick enum { 23061da546Spatrick eBroadcastBitStackChanged = (1 << 0), 24061da546Spatrick eBroadcastBitThreadSuspended = (1 << 1), 25061da546Spatrick eBroadcastBitThreadResumed = (1 << 2), 26061da546Spatrick eBroadcastBitSelectedFrameChanged = (1 << 3), 27061da546Spatrick eBroadcastBitThreadSelected = (1 << 4) 28061da546Spatrick }; 29061da546Spatrick 30061da546Spatrick static const char *GetBroadcasterClassName(); 31061da546Spatrick 32061da546Spatrick SBThread(); 33061da546Spatrick 34061da546Spatrick SBThread(const lldb::SBThread &thread); 35061da546Spatrick 36061da546Spatrick SBThread(const lldb::ThreadSP &lldb_object_sp); 37061da546Spatrick 38061da546Spatrick ~SBThread(); 39061da546Spatrick 40061da546Spatrick lldb::SBQueue GetQueue() const; 41061da546Spatrick 42061da546Spatrick explicit operator bool() const; 43061da546Spatrick 44061da546Spatrick bool IsValid() const; 45061da546Spatrick 46061da546Spatrick void Clear(); 47061da546Spatrick 48061da546Spatrick lldb::StopReason GetStopReason(); 49061da546Spatrick 50061da546Spatrick /// Get the number of words associated with the stop reason. 51061da546Spatrick /// See also GetStopReasonDataAtIndex(). 52061da546Spatrick size_t GetStopReasonDataCount(); 53061da546Spatrick 54061da546Spatrick /// Get information associated with a stop reason. 55061da546Spatrick /// 56061da546Spatrick /// Breakpoint stop reasons will have data that consists of pairs of 57061da546Spatrick /// breakpoint IDs followed by the breakpoint location IDs (they always come 58061da546Spatrick /// in pairs). 59061da546Spatrick /// 60061da546Spatrick /// Stop Reason Count Data Type 61061da546Spatrick /// ======================== ===== ========================================= 62061da546Spatrick /// eStopReasonNone 0 63061da546Spatrick /// eStopReasonTrace 0 64061da546Spatrick /// eStopReasonBreakpoint N duple: {breakpoint id, location id} 65061da546Spatrick /// eStopReasonWatchpoint 1 watchpoint id 66061da546Spatrick /// eStopReasonSignal 1 unix signal number 67061da546Spatrick /// eStopReasonException N exception data 68061da546Spatrick /// eStopReasonExec 0 69be691f3bSpatrick /// eStopReasonFork 1 pid of the child process 70be691f3bSpatrick /// eStopReasonVFork 1 pid of the child process 71be691f3bSpatrick /// eStopReasonVForkDone 0 72061da546Spatrick /// eStopReasonPlanComplete 0 73061da546Spatrick uint64_t GetStopReasonDataAtIndex(uint32_t idx); 74061da546Spatrick 75061da546Spatrick bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream); 76061da546Spatrick 77061da546Spatrick SBThreadCollection 78061da546Spatrick GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type); 79061da546Spatrick 80061da546Spatrick size_t GetStopDescription(char *dst, size_t dst_len); 81061da546Spatrick 82061da546Spatrick SBValue GetStopReturnValue(); 83061da546Spatrick 84061da546Spatrick lldb::tid_t GetThreadID() const; 85061da546Spatrick 86061da546Spatrick uint32_t GetIndexID() const; 87061da546Spatrick 88061da546Spatrick const char *GetName() const; 89061da546Spatrick 90061da546Spatrick const char *GetQueueName() const; 91061da546Spatrick 92061da546Spatrick lldb::queue_id_t GetQueueID() const; 93061da546Spatrick 94061da546Spatrick bool GetInfoItemByPathAsString(const char *path, SBStream &strm); 95061da546Spatrick 96061da546Spatrick void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 97061da546Spatrick 98061da546Spatrick void StepOver(lldb::RunMode stop_other_threads, SBError &error); 99061da546Spatrick 100061da546Spatrick void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 101061da546Spatrick 102061da546Spatrick void StepInto(const char *target_name, 103061da546Spatrick lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 104061da546Spatrick 105061da546Spatrick void StepInto(const char *target_name, uint32_t end_line, SBError &error, 106061da546Spatrick lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 107061da546Spatrick 108061da546Spatrick void StepOut(); 109061da546Spatrick 110061da546Spatrick void StepOut(SBError &error); 111061da546Spatrick 112061da546Spatrick void StepOutOfFrame(SBFrame &frame); 113061da546Spatrick 114061da546Spatrick void StepOutOfFrame(SBFrame &frame, SBError &error); 115061da546Spatrick 116061da546Spatrick void StepInstruction(bool step_over); 117061da546Spatrick 118061da546Spatrick void StepInstruction(bool step_over, SBError &error); 119061da546Spatrick 120061da546Spatrick SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec, 121061da546Spatrick uint32_t line); 122061da546Spatrick 123061da546Spatrick SBError StepUsingScriptedThreadPlan(const char *script_class_name); 124061da546Spatrick 125061da546Spatrick SBError StepUsingScriptedThreadPlan(const char *script_class_name, 126061da546Spatrick bool resume_immediately); 127061da546Spatrick 128061da546Spatrick SBError StepUsingScriptedThreadPlan(const char *script_class_name, 129061da546Spatrick lldb::SBStructuredData &args_data, 130061da546Spatrick bool resume_immediately); 131061da546Spatrick 132061da546Spatrick SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line); 133061da546Spatrick 134061da546Spatrick void RunToAddress(lldb::addr_t addr); 135061da546Spatrick 136061da546Spatrick void RunToAddress(lldb::addr_t addr, SBError &error); 137061da546Spatrick 138061da546Spatrick SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value); 139061da546Spatrick 140061da546Spatrick SBError UnwindInnermostExpression(); 141061da546Spatrick 142061da546Spatrick /// LLDB currently supports process centric debugging which means when any 143061da546Spatrick /// thread in a process stops, all other threads are stopped. The Suspend() 144061da546Spatrick /// call here tells our process to suspend a thread and not let it run when 145061da546Spatrick /// the other threads in a process are allowed to run. So when 146061da546Spatrick /// SBProcess::Continue() is called, any threads that aren't suspended will 147061da546Spatrick /// be allowed to run. If any of the SBThread functions for stepping are 148061da546Spatrick /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the 149061da546Spatrick /// thread will not be allowed to run and these functions will simply return. 150061da546Spatrick /// 151061da546Spatrick /// Eventually we plan to add support for thread centric debugging where 152061da546Spatrick /// each thread is controlled individually and each thread would broadcast 153061da546Spatrick /// its state, but we haven't implemented this yet. 154061da546Spatrick /// 155061da546Spatrick /// Likewise the SBThread::Resume() call will again allow the thread to run 156061da546Spatrick /// when the process is continued. 157061da546Spatrick /// 158061da546Spatrick /// Suspend() and Resume() functions are not currently reference counted, if 159061da546Spatrick /// anyone has the need for them to be reference counted, please let us 160061da546Spatrick /// know. 161061da546Spatrick bool Suspend(); 162061da546Spatrick 163061da546Spatrick bool Suspend(SBError &error); 164061da546Spatrick 165061da546Spatrick bool Resume(); 166061da546Spatrick 167061da546Spatrick bool Resume(SBError &error); 168061da546Spatrick 169061da546Spatrick bool IsSuspended(); 170061da546Spatrick 171061da546Spatrick bool IsStopped(); 172061da546Spatrick 173061da546Spatrick uint32_t GetNumFrames(); 174061da546Spatrick 175061da546Spatrick lldb::SBFrame GetFrameAtIndex(uint32_t idx); 176061da546Spatrick 177061da546Spatrick lldb::SBFrame GetSelectedFrame(); 178061da546Spatrick 179061da546Spatrick lldb::SBFrame SetSelectedFrame(uint32_t frame_idx); 180061da546Spatrick 181061da546Spatrick static bool EventIsThreadEvent(const SBEvent &event); 182061da546Spatrick 183061da546Spatrick static SBFrame GetStackFrameFromEvent(const SBEvent &event); 184061da546Spatrick 185061da546Spatrick static SBThread GetThreadFromEvent(const SBEvent &event); 186061da546Spatrick 187061da546Spatrick lldb::SBProcess GetProcess(); 188061da546Spatrick 189061da546Spatrick const lldb::SBThread &operator=(const lldb::SBThread &rhs); 190061da546Spatrick 191061da546Spatrick bool operator==(const lldb::SBThread &rhs) const; 192061da546Spatrick 193061da546Spatrick bool operator!=(const lldb::SBThread &rhs) const; 194061da546Spatrick 195061da546Spatrick bool GetDescription(lldb::SBStream &description) const; 196061da546Spatrick 197061da546Spatrick bool GetDescription(lldb::SBStream &description, bool stop_format) const; 198061da546Spatrick 199061da546Spatrick bool GetStatus(lldb::SBStream &status) const; 200061da546Spatrick 201061da546Spatrick SBThread GetExtendedBacktraceThread(const char *type); 202061da546Spatrick 203061da546Spatrick uint32_t GetExtendedBacktraceOriginatingIndexID(); 204061da546Spatrick 205061da546Spatrick SBValue GetCurrentException(); 206061da546Spatrick 207061da546Spatrick SBThread GetCurrentExceptionBacktrace(); 208061da546Spatrick 209061da546Spatrick bool SafeToCallFunctions(); 210061da546Spatrick 211*f6aab3d8Srobert SBValue GetSiginfo(); 212*f6aab3d8Srobert 213061da546Spatrick private: 214061da546Spatrick friend class SBBreakpoint; 215061da546Spatrick friend class SBBreakpointLocation; 216061da546Spatrick friend class SBBreakpointCallbackBaton; 217061da546Spatrick friend class SBExecutionContext; 218061da546Spatrick friend class SBFrame; 219061da546Spatrick friend class SBProcess; 220061da546Spatrick friend class SBDebugger; 221061da546Spatrick friend class SBValue; 222061da546Spatrick friend class lldb_private::QueueImpl; 223061da546Spatrick friend class SBQueueItem; 224061da546Spatrick friend class SBThreadPlan; 225be691f3bSpatrick friend class SBTrace; 226061da546Spatrick 227061da546Spatrick void SetThread(const lldb::ThreadSP &lldb_object_sp); 228061da546Spatrick 229061da546Spatrick SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx, 230061da546Spatrick lldb_private::ThreadPlan *new_plan); 231061da546Spatrick 232061da546Spatrick lldb::ExecutionContextRefSP m_opaque_sp; 233061da546Spatrick 234061da546Spatrick lldb_private::Thread *operator->(); 235061da546Spatrick 236061da546Spatrick lldb_private::Thread *get(); 237061da546Spatrick }; 238061da546Spatrick 239061da546Spatrick } // namespace lldb 240061da546Spatrick 241dda28197Spatrick #endif // LLDB_API_SBTHREAD_H 242