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