SBThread.h revision 94a5d0de4433dce556db59758f3d6124eb0e1a2a
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    /// eStopReasonPlanComplete  0
71    //--------------------------------------------------------------------------
72    uint64_t
73    GetStopReasonDataAtIndex(uint32_t idx);
74
75    size_t
76    GetStopDescription (char *dst, size_t dst_len);
77
78    SBValue
79    GetStopReturnValue ();
80
81    lldb::tid_t
82    GetThreadID () const;
83
84    uint32_t
85    GetIndexID () const;
86
87    const char *
88    GetName () const;
89
90    const char *
91    GetQueueName() const;
92
93    void
94    StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
95
96    void
97    StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
98
99    void
100    StepOut ();
101
102    void
103    StepOutOfFrame (lldb::SBFrame &frame);
104
105    void
106    StepInstruction(bool step_over);
107
108    SBError
109    StepOverUntil (lldb::SBFrame &frame,
110                   lldb::SBFileSpec &file_spec,
111                   uint32_t line);
112
113    void
114    RunToAddress (lldb::addr_t addr);
115
116    SBError
117    ReturnFromFrame (SBFrame &frame, SBValue &return_value);
118
119    //--------------------------------------------------------------------------
120    /// LLDB currently supports process centric debugging which means when any
121    /// thread in a process stops, all other threads are stopped. The Suspend()
122    /// call here tells our process to suspend a thread and not let it run when
123    /// the other threads in a process are allowed to run. So when
124    /// SBProcess::Continue() is called, any threads that aren't suspended will
125    /// be allowed to run. If any of the SBThread functions for stepping are
126    /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
127    /// thread will now be allowed to run and these funtions will simply return.
128    ///
129    /// Eventually we plan to add support for thread centric debugging where
130    /// each thread is controlled individually and each thread would broadcast
131    /// its state, but we haven't implemented this yet.
132    ///
133    /// Likewise the SBThread::Resume() call will again allow the thread to run
134    /// when the process is continued.
135    ///
136    /// Suspend() and Resume() functions are not currently reference counted, if
137    /// anyone has the need for them to be reference counted, please let us
138    /// know.
139    //--------------------------------------------------------------------------
140    bool
141    Suspend();
142
143    bool
144    Resume ();
145
146    bool
147    IsSuspended();
148
149    uint32_t
150    GetNumFrames ();
151
152    lldb::SBFrame
153    GetFrameAtIndex (uint32_t idx);
154
155    lldb::SBFrame
156    GetSelectedFrame ();
157
158    lldb::SBFrame
159    SetSelectedFrame (uint32_t frame_idx);
160
161    static bool
162    EventIsThreadEvent (const SBEvent &event);
163
164    static SBFrame
165    GetStackFrameFromEvent (const SBEvent &event);
166
167    static SBThread
168    GetThreadFromEvent (const SBEvent &event);
169
170    lldb::SBProcess
171    GetProcess ();
172
173    const lldb::SBThread &
174    operator = (const lldb::SBThread &rhs);
175
176    bool
177    operator == (const lldb::SBThread &rhs) const;
178
179    bool
180    operator != (const lldb::SBThread &rhs) const;
181
182    bool
183    GetDescription (lldb::SBStream &description) const;
184
185    bool
186    GetStatus (lldb::SBStream &status) const;
187
188protected:
189    friend class SBBreakpoint;
190    friend class SBBreakpointLocation;
191    friend class SBFrame;
192    friend class SBProcess;
193    friend class SBDebugger;
194    friend class SBValue;
195
196    SBThread (const lldb::ThreadSP& lldb_object_sp);
197
198    void
199    SetThread (const lldb::ThreadSP& lldb_object_sp);
200
201#ifndef SWIG
202    SBError
203    ResumeNewPlan (lldb_private::ExecutionContext &exe_ctx, lldb_private::ThreadPlan *new_plan);
204#endif
205
206private:
207    lldb::ExecutionContextRefSP m_opaque_sp;
208};
209
210} // namespace lldb
211
212#endif  // LLDB_SBThread_h_
213