SBThread.h revision 2c354722318f0fcad087c76f2bc0dc8db9200b4b
1//===-- SBThread.h ----------------------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLDB_SBThread_h_
11#define LLDB_SBThread_h_
12
13#include "lldb/API/SBDefines.h"
14
15#include <stdio.h>
16
17namespace lldb {
18
19class SBFrame;
20
21class SBThread
22{
23public:
24    enum
25    {
26        eBroadcastBitStackChanged           = (1 << 0),
27        eBroadcastBitThreadSuspended        = (1 << 1),
28        eBroadcastBitThreadResumed          = (1 << 2),
29        eBroadcastBitSelectedFrameChanged   = (1 << 3),
30        eBroadcastBitThreadSelected         = (1 << 4)
31    };
32
33    static const char *
34    GetBroadcasterClassName ();
35
36    SBThread ();
37
38    SBThread (const lldb::SBThread &thread);
39
40   ~SBThread();
41
42    bool
43    IsValid() const;
44
45    void
46    Clear ();
47
48    lldb::StopReason
49    GetStopReason();
50
51    /// Get the number of words associated with the stop reason.
52    /// See also GetStopReasonDataAtIndex().
53    size_t
54    GetStopReasonDataCount();
55
56    //--------------------------------------------------------------------------
57    /// Get information associated with a stop reason.
58    ///
59    /// Breakpoint stop reasons will have data that consists of pairs of
60    /// breakpoint IDs followed by the breakpoint location IDs (they always come
61    /// in pairs).
62    ///
63    /// Stop Reason              Count Data Type
64    /// ======================== ===== =========================================
65    /// eStopReasonNone          0
66    /// eStopReasonTrace         0
67    /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
68    /// eStopReasonWatchpoint    1     watchpoint id
69    /// eStopReasonSignal        1     unix signal number
70    /// eStopReasonException     N     exception data
71    /// eStopReasonExec          0
72    /// eStopReasonPlanComplete  0
73    //--------------------------------------------------------------------------
74    uint64_t
75    GetStopReasonDataAtIndex(uint32_t idx);
76
77    size_t
78    GetStopDescription (char *dst, size_t dst_len);
79
80    SBValue
81    GetStopReturnValue ();
82
83    lldb::tid_t
84    GetThreadID () const;
85
86    uint32_t
87    GetIndexID () const;
88
89    const char *
90    GetName () const;
91
92    const char *
93    GetQueueName() const;
94
95    void
96    StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
97
98    void
99    StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
100
101    void
102    StepInto (const char *target_name, lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
103
104    void
105    StepOut ();
106
107    void
108    StepOutOfFrame (lldb::SBFrame &frame);
109
110    void
111    StepInstruction(bool step_over);
112
113    SBError
114    StepOverUntil (lldb::SBFrame &frame,
115                   lldb::SBFileSpec &file_spec,
116                   uint32_t line);
117
118    void
119    RunToAddress (lldb::addr_t addr);
120
121    SBError
122    ReturnFromFrame (SBFrame &frame, SBValue &return_value);
123
124    //--------------------------------------------------------------------------
125    /// LLDB currently supports process centric debugging which means when any
126    /// thread in a process stops, all other threads are stopped. The Suspend()
127    /// call here tells our process to suspend a thread and not let it run when
128    /// the other threads in a process are allowed to run. So when
129    /// SBProcess::Continue() is called, any threads that aren't suspended will
130    /// be allowed to run. If any of the SBThread functions for stepping are
131    /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
132    /// thread will now be allowed to run and these funtions will simply return.
133    ///
134    /// Eventually we plan to add support for thread centric debugging where
135    /// each thread is controlled individually and each thread would broadcast
136    /// its state, but we haven't implemented this yet.
137    ///
138    /// Likewise the SBThread::Resume() call will again allow the thread to run
139    /// when the process is continued.
140    ///
141    /// Suspend() and Resume() functions are not currently reference counted, if
142    /// anyone has the need for them to be reference counted, please let us
143    /// know.
144    //--------------------------------------------------------------------------
145    bool
146    Suspend();
147
148    bool
149    Resume ();
150
151    bool
152    IsSuspended();
153
154    bool
155    IsStopped();
156
157    uint32_t
158    GetNumFrames ();
159
160    lldb::SBFrame
161    GetFrameAtIndex (uint32_t idx);
162
163    lldb::SBFrame
164    GetSelectedFrame ();
165
166    lldb::SBFrame
167    SetSelectedFrame (uint32_t frame_idx);
168
169    static bool
170    EventIsThreadEvent (const SBEvent &event);
171
172    static SBFrame
173    GetStackFrameFromEvent (const SBEvent &event);
174
175    static SBThread
176    GetThreadFromEvent (const SBEvent &event);
177
178    lldb::SBProcess
179    GetProcess ();
180
181    const lldb::SBThread &
182    operator = (const lldb::SBThread &rhs);
183
184    bool
185    operator == (const lldb::SBThread &rhs) const;
186
187    bool
188    operator != (const lldb::SBThread &rhs) const;
189
190    bool
191    GetDescription (lldb::SBStream &description) const;
192
193    bool
194    GetStatus (lldb::SBStream &status) const;
195
196protected:
197    friend class SBBreakpoint;
198    friend class SBBreakpointLocation;
199    friend class SBFrame;
200    friend class SBProcess;
201    friend class SBDebugger;
202    friend class SBValue;
203
204    SBThread (const lldb::ThreadSP& lldb_object_sp);
205
206    void
207    SetThread (const lldb::ThreadSP& lldb_object_sp);
208
209#ifndef SWIG
210    SBError
211    ResumeNewPlan (lldb_private::ExecutionContext &exe_ctx, lldb_private::ThreadPlan *new_plan);
212#endif
213
214private:
215    lldb::ExecutionContextRefSP m_opaque_sp;
216};
217
218} // namespace lldb
219
220#endif  // LLDB_SBThread_h_
221