10b57cec5SDimitry Andric //===-- SBThread.h ----------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 95ffd83dbSDimitry Andric #ifndef LLDB_API_SBTHREAD_H 105ffd83dbSDimitry Andric #define LLDB_API_SBTHREAD_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "lldb/API/SBDefines.h" 130b57cec5SDimitry Andric 14fe6060f1SDimitry Andric #include <cstdio> 150b57cec5SDimitry Andric 1606c3fb27SDimitry Andric namespace lldb_private { 1706c3fb27SDimitry Andric namespace python { 1806c3fb27SDimitry Andric class SWIGBridge; 1906c3fb27SDimitry Andric } 2006c3fb27SDimitry Andric } // namespace lldb_private 2106c3fb27SDimitry Andric 220b57cec5SDimitry Andric namespace lldb { 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric class SBFrame; 250b57cec5SDimitry Andric 260b57cec5SDimitry Andric class LLDB_API SBThread { 270b57cec5SDimitry Andric public: 280b57cec5SDimitry Andric enum { 290b57cec5SDimitry Andric eBroadcastBitStackChanged = (1 << 0), 300b57cec5SDimitry Andric eBroadcastBitThreadSuspended = (1 << 1), 310b57cec5SDimitry Andric eBroadcastBitThreadResumed = (1 << 2), 320b57cec5SDimitry Andric eBroadcastBitSelectedFrameChanged = (1 << 3), 330b57cec5SDimitry Andric eBroadcastBitThreadSelected = (1 << 4) 340b57cec5SDimitry Andric }; 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric static const char *GetBroadcasterClassName(); 370b57cec5SDimitry Andric 380b57cec5SDimitry Andric SBThread(); 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric SBThread(const lldb::SBThread &thread); 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric ~SBThread(); 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric lldb::SBQueue GetQueue() const; 450b57cec5SDimitry Andric 460b57cec5SDimitry Andric explicit operator bool() const; 470b57cec5SDimitry Andric 480b57cec5SDimitry Andric bool IsValid() const; 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric void Clear(); 510b57cec5SDimitry Andric 520b57cec5SDimitry Andric lldb::StopReason GetStopReason(); 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric /// Get the number of words associated with the stop reason. 550b57cec5SDimitry Andric /// See also GetStopReasonDataAtIndex(). 560b57cec5SDimitry Andric size_t GetStopReasonDataCount(); 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric /// Get information associated with a stop reason. 590b57cec5SDimitry Andric /// 600b57cec5SDimitry Andric /// Breakpoint stop reasons will have data that consists of pairs of 610b57cec5SDimitry Andric /// breakpoint IDs followed by the breakpoint location IDs (they always come 620b57cec5SDimitry Andric /// in pairs). 630b57cec5SDimitry Andric /// 640b57cec5SDimitry Andric /// Stop Reason Count Data Type 650b57cec5SDimitry Andric /// ======================== ===== ========================================= 660b57cec5SDimitry Andric /// eStopReasonNone 0 670b57cec5SDimitry Andric /// eStopReasonTrace 0 680b57cec5SDimitry Andric /// eStopReasonBreakpoint N duple: {breakpoint id, location id} 690b57cec5SDimitry Andric /// eStopReasonWatchpoint 1 watchpoint id 700b57cec5SDimitry Andric /// eStopReasonSignal 1 unix signal number 710b57cec5SDimitry Andric /// eStopReasonException N exception data 720b57cec5SDimitry Andric /// eStopReasonExec 0 73fe6060f1SDimitry Andric /// eStopReasonFork 1 pid of the child process 74fe6060f1SDimitry Andric /// eStopReasonVFork 1 pid of the child process 75fe6060f1SDimitry Andric /// eStopReasonVForkDone 0 760b57cec5SDimitry Andric /// eStopReasonPlanComplete 0 770b57cec5SDimitry Andric uint64_t GetStopReasonDataAtIndex(uint32_t idx); 780b57cec5SDimitry Andric 790b57cec5SDimitry Andric bool GetStopReasonExtendedInfoAsJSON(lldb::SBStream &stream); 800b57cec5SDimitry Andric 810b57cec5SDimitry Andric SBThreadCollection 820b57cec5SDimitry Andric GetStopReasonExtendedBacktraces(InstrumentationRuntimeType type); 830b57cec5SDimitry Andric 8406c3fb27SDimitry Andric size_t GetStopDescription(char *dst_or_null, size_t dst_len); 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric SBValue GetStopReturnValue(); 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric lldb::tid_t GetThreadID() const; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric uint32_t GetIndexID() const; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric const char *GetName() const; 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric const char *GetQueueName() const; 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric lldb::queue_id_t GetQueueID() const; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric bool GetInfoItemByPathAsString(const char *path, SBStream &strm); 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric void StepOver(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric void StepOver(lldb::RunMode stop_other_threads, SBError &error); 1030b57cec5SDimitry Andric 1040b57cec5SDimitry Andric void StepInto(lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 1050b57cec5SDimitry Andric 1060b57cec5SDimitry Andric void StepInto(const char *target_name, 1070b57cec5SDimitry Andric lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric void StepInto(const char *target_name, uint32_t end_line, SBError &error, 1100b57cec5SDimitry Andric lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric void StepOut(); 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric void StepOut(SBError &error); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric void StepOutOfFrame(SBFrame &frame); 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric void StepOutOfFrame(SBFrame &frame, SBError &error); 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric void StepInstruction(bool step_over); 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric void StepInstruction(bool step_over, SBError &error); 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric SBError StepOverUntil(lldb::SBFrame &frame, lldb::SBFileSpec &file_spec, 1250b57cec5SDimitry Andric uint32_t line); 1260b57cec5SDimitry Andric 1270b57cec5SDimitry Andric SBError StepUsingScriptedThreadPlan(const char *script_class_name); 1280b57cec5SDimitry Andric 1290b57cec5SDimitry Andric SBError StepUsingScriptedThreadPlan(const char *script_class_name, 1300b57cec5SDimitry Andric bool resume_immediately); 1310b57cec5SDimitry Andric 1329dba64beSDimitry Andric SBError StepUsingScriptedThreadPlan(const char *script_class_name, 1339dba64beSDimitry Andric lldb::SBStructuredData &args_data, 1349dba64beSDimitry Andric bool resume_immediately); 1359dba64beSDimitry Andric 1360b57cec5SDimitry Andric SBError JumpToLine(lldb::SBFileSpec &file_spec, uint32_t line); 1370b57cec5SDimitry Andric 1380b57cec5SDimitry Andric void RunToAddress(lldb::addr_t addr); 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric void RunToAddress(lldb::addr_t addr, SBError &error); 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric SBError ReturnFromFrame(SBFrame &frame, SBValue &return_value); 1430b57cec5SDimitry Andric 1440b57cec5SDimitry Andric SBError UnwindInnermostExpression(); 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric /// LLDB currently supports process centric debugging which means when any 1470b57cec5SDimitry Andric /// thread in a process stops, all other threads are stopped. The Suspend() 1480b57cec5SDimitry Andric /// call here tells our process to suspend a thread and not let it run when 1490b57cec5SDimitry Andric /// the other threads in a process are allowed to run. So when 1500b57cec5SDimitry Andric /// SBProcess::Continue() is called, any threads that aren't suspended will 1510b57cec5SDimitry Andric /// be allowed to run. If any of the SBThread functions for stepping are 1520b57cec5SDimitry Andric /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddress), the 1530b57cec5SDimitry Andric /// thread will not be allowed to run and these functions will simply return. 1540b57cec5SDimitry Andric /// 1550b57cec5SDimitry Andric /// Eventually we plan to add support for thread centric debugging where 1560b57cec5SDimitry Andric /// each thread is controlled individually and each thread would broadcast 1570b57cec5SDimitry Andric /// its state, but we haven't implemented this yet. 1580b57cec5SDimitry Andric /// 1590b57cec5SDimitry Andric /// Likewise the SBThread::Resume() call will again allow the thread to run 1600b57cec5SDimitry Andric /// when the process is continued. 1610b57cec5SDimitry Andric /// 1620b57cec5SDimitry Andric /// Suspend() and Resume() functions are not currently reference counted, if 1630b57cec5SDimitry Andric /// anyone has the need for them to be reference counted, please let us 1640b57cec5SDimitry Andric /// know. 1650b57cec5SDimitry Andric bool Suspend(); 1660b57cec5SDimitry Andric 1670b57cec5SDimitry Andric bool Suspend(SBError &error); 1680b57cec5SDimitry Andric 1690b57cec5SDimitry Andric bool Resume(); 1700b57cec5SDimitry Andric 1710b57cec5SDimitry Andric bool Resume(SBError &error); 1720b57cec5SDimitry Andric 1730b57cec5SDimitry Andric bool IsSuspended(); 1740b57cec5SDimitry Andric 1750b57cec5SDimitry Andric bool IsStopped(); 1760b57cec5SDimitry Andric 1770b57cec5SDimitry Andric uint32_t GetNumFrames(); 1780b57cec5SDimitry Andric 1790b57cec5SDimitry Andric lldb::SBFrame GetFrameAtIndex(uint32_t idx); 1800b57cec5SDimitry Andric 1810b57cec5SDimitry Andric lldb::SBFrame GetSelectedFrame(); 1820b57cec5SDimitry Andric 1830b57cec5SDimitry Andric lldb::SBFrame SetSelectedFrame(uint32_t frame_idx); 1840b57cec5SDimitry Andric 1850b57cec5SDimitry Andric static bool EventIsThreadEvent(const SBEvent &event); 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric static SBFrame GetStackFrameFromEvent(const SBEvent &event); 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric static SBThread GetThreadFromEvent(const SBEvent &event); 1900b57cec5SDimitry Andric 1910b57cec5SDimitry Andric lldb::SBProcess GetProcess(); 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric const lldb::SBThread &operator=(const lldb::SBThread &rhs); 1940b57cec5SDimitry Andric 1950b57cec5SDimitry Andric bool operator==(const lldb::SBThread &rhs) const; 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric bool operator!=(const lldb::SBThread &rhs) const; 1980b57cec5SDimitry Andric 1990b57cec5SDimitry Andric bool GetDescription(lldb::SBStream &description) const; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric bool GetDescription(lldb::SBStream &description, bool stop_format) const; 2020b57cec5SDimitry Andric 2035f757f3fSDimitry Andric /// Similar to \a GetDescription() but the format of the description can be 2045f757f3fSDimitry Andric /// configured via the \p format parameter. See 2055f757f3fSDimitry Andric /// https://lldb.llvm.org/use/formatting.html for more information on format 2065f757f3fSDimitry Andric /// strings. 2075f757f3fSDimitry Andric /// 2085f757f3fSDimitry Andric /// \param[in] format 2095f757f3fSDimitry Andric /// The format to use for generating the description. 2105f757f3fSDimitry Andric /// 2115f757f3fSDimitry Andric /// \param[out] output 2125f757f3fSDimitry Andric /// The stream where the description will be written to. 2135f757f3fSDimitry Andric /// 2145f757f3fSDimitry Andric /// \return 2155f757f3fSDimitry Andric /// An error object with an error message in case of failures. 2165f757f3fSDimitry Andric SBError GetDescriptionWithFormat(const SBFormat &format, SBStream &output); 2175f757f3fSDimitry Andric 2180b57cec5SDimitry Andric bool GetStatus(lldb::SBStream &status) const; 2190b57cec5SDimitry Andric 2200b57cec5SDimitry Andric SBThread GetExtendedBacktraceThread(const char *type); 2210b57cec5SDimitry Andric 2220b57cec5SDimitry Andric uint32_t GetExtendedBacktraceOriginatingIndexID(); 2230b57cec5SDimitry Andric 2240b57cec5SDimitry Andric SBValue GetCurrentException(); 2250b57cec5SDimitry Andric 2260b57cec5SDimitry Andric SBThread GetCurrentExceptionBacktrace(); 2270b57cec5SDimitry Andric 2280b57cec5SDimitry Andric bool SafeToCallFunctions(); 2290b57cec5SDimitry Andric 2301fd87a68SDimitry Andric SBValue GetSiginfo(); 23104eeddc0SDimitry Andric 2320b57cec5SDimitry Andric private: 2330b57cec5SDimitry Andric friend class SBBreakpoint; 2340b57cec5SDimitry Andric friend class SBBreakpointLocation; 2350b57cec5SDimitry Andric friend class SBBreakpointCallbackBaton; 2360b57cec5SDimitry Andric friend class SBExecutionContext; 2370b57cec5SDimitry Andric friend class SBFrame; 2380b57cec5SDimitry Andric friend class SBProcess; 2390b57cec5SDimitry Andric friend class SBDebugger; 2400b57cec5SDimitry Andric friend class SBValue; 2410b57cec5SDimitry Andric friend class lldb_private::QueueImpl; 2420b57cec5SDimitry Andric friend class SBQueueItem; 24306c3fb27SDimitry Andric friend class SBThreadCollection; 2440b57cec5SDimitry Andric friend class SBThreadPlan; 245fe6060f1SDimitry Andric friend class SBTrace; 2460b57cec5SDimitry Andric 24706c3fb27SDimitry Andric friend class lldb_private::python::SWIGBridge; 24806c3fb27SDimitry Andric 24906c3fb27SDimitry Andric SBThread(const lldb::ThreadSP &lldb_object_sp); 25006c3fb27SDimitry Andric 2510b57cec5SDimitry Andric void SetThread(const lldb::ThreadSP &lldb_object_sp); 2520b57cec5SDimitry Andric 2530b57cec5SDimitry Andric SBError ResumeNewPlan(lldb_private::ExecutionContext &exe_ctx, 2540b57cec5SDimitry Andric lldb_private::ThreadPlan *new_plan); 2550b57cec5SDimitry Andric 2560b57cec5SDimitry Andric lldb::ExecutionContextRefSP m_opaque_sp; 2570b57cec5SDimitry Andric 2580b57cec5SDimitry Andric lldb_private::Thread *operator->(); 2590b57cec5SDimitry Andric 2600b57cec5SDimitry Andric lldb_private::Thread *get(); 2610b57cec5SDimitry Andric }; 2620b57cec5SDimitry Andric 2630b57cec5SDimitry Andric } // namespace lldb 2640b57cec5SDimitry Andric 2655ffd83dbSDimitry Andric #endif // LLDB_API_SBTHREAD_H 266