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