SBThread.i revision 394da8e3d59e49ce3a02e6b287ccfc6f568c19a9
1c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//===-- SWIG Interface for SBThread -----------------------------*- C++ -*-===//
2c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//
3c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//                     The LLVM Compiler Infrastructure
4c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//
5c3fba812b636dcdede81be622d557efbdc834240Johnny Chen// This file is distributed under the University of Illinois Open Source
6c3fba812b636dcdede81be622d557efbdc834240Johnny Chen// License. See LICENSE.TXT for details.
7c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//
8c3fba812b636dcdede81be622d557efbdc834240Johnny Chen//===----------------------------------------------------------------------===//
9c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
10c3fba812b636dcdede81be622d557efbdc834240Johnny Chennamespace lldb {
11c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
12c3fba812b636dcdede81be622d557efbdc834240Johnny Chen%feature("docstring",
13c3fba812b636dcdede81be622d557efbdc834240Johnny Chen"Represents a thread of execution. SBProcess contains SBThread(s).
14c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
15c3fba812b636dcdede81be622d557efbdc834240Johnny ChenSBThread supports frame iteration. For example (from test/python_api/
16c3fba812b636dcdede81be622d557efbdc834240Johnny Chenlldbutil/iter/TestLLDBIterator.py),
17c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
18c3fba812b636dcdede81be622d557efbdc834240Johnny Chen        from lldbutil import print_stacktrace
19c3fba812b636dcdede81be622d557efbdc834240Johnny Chen        stopped_due_to_breakpoint = False
20c3fba812b636dcdede81be622d557efbdc834240Johnny Chen        for thread in process:
21c3fba812b636dcdede81be622d557efbdc834240Johnny Chen            if self.TraceOn():
22c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                print_stacktrace(thread)
23c3fba812b636dcdede81be622d557efbdc834240Johnny Chen            ID = thread.GetThreadID()
24c3fba812b636dcdede81be622d557efbdc834240Johnny Chen            if thread.GetStopReason() == lldb.eStopReasonBreakpoint:
25c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                stopped_due_to_breakpoint = True
26c3fba812b636dcdede81be622d557efbdc834240Johnny Chen            for frame in thread:
27c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                self.assertTrue(frame.GetThread().GetThreadID() == ID)
28c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                if self.TraceOn():
29c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                    print frame
30c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
31c3fba812b636dcdede81be622d557efbdc834240Johnny Chen        self.assertTrue(stopped_due_to_breakpoint)
32c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
33c3fba812b636dcdede81be622d557efbdc834240Johnny ChenSee also SBProcess and SBFrame."
34c3fba812b636dcdede81be622d557efbdc834240Johnny Chen) SBThread;
35c3fba812b636dcdede81be622d557efbdc834240Johnny Chenclass SBThread
36c3fba812b636dcdede81be622d557efbdc834240Johnny Chen{
37c3fba812b636dcdede81be622d557efbdc834240Johnny Chenpublic:
38c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    SBThread ();
39c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
40c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    SBThread (const lldb::SBThread &thread);
41c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
42c3fba812b636dcdede81be622d557efbdc834240Johnny Chen   ~SBThread();
43c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
44c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    bool
45c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    IsValid() const;
46c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
47c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
48c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    Clear ();
49c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
50c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::StopReason
51c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetStopReason();
52c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
53c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    %feature("docstring", "
54c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Get the number of words associated with the stop reason.
55c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// See also GetStopReasonDataAtIndex().
56c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ") GetStopReasonDataCount;
57c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    size_t
58c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetStopReasonDataCount();
59c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
60c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    %feature("docstring", "
61c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    //--------------------------------------------------------------------------
62c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Get information associated with a stop reason.
63c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ///
64c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Breakpoint stop reasons will have data that consists of pairs of
65c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// breakpoint IDs followed by the breakpoint location IDs (they always come
66c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// in pairs).
67c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ///
68c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Stop Reason              Count Data Type
69c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// ======================== ===== =========================================
70c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonNone          0
71c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonTrace         0
72c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonBreakpoint    N     duple: {breakpoint id, location id}
73bcbefa8de7877c5d0674d5816cf96db48b103e6fJohnny Chen    /// eStopReasonWatchpoint    1     watchpoint id
74c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonSignal        1     unix signal number
75c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonException     N     exception data
76c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// eStopReasonPlanComplete  0
77c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    //--------------------------------------------------------------------------
78c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ") GetStopReasonDataAtIndex;
79c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    uint64_t
80c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetStopReasonDataAtIndex(uint32_t idx);
81c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
8265f4fb01ed41075a3efe9d2b5a337e5a8fe7f006Johnny Chen    %feature("autodoc", "
8365f4fb01ed41075a3efe9d2b5a337e5a8fe7f006Johnny Chen    Pass only an (int)length and expect to get a Python string describing the
8465f4fb01ed41075a3efe9d2b5a337e5a8fe7f006Johnny Chen    stop reason.
8565f4fb01ed41075a3efe9d2b5a337e5a8fe7f006Johnny Chen    ") GetStopDescription;
86c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    size_t
87c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetStopDescription (char *dst, size_t dst_len);
88c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
891586d9720002e407a3a097baf302de5fa4ca9c1bJim Ingham    SBValue
901586d9720002e407a3a097baf302de5fa4ca9c1bJim Ingham    GetStopReturnValue ();
911586d9720002e407a3a097baf302de5fa4ca9c1bJim Ingham
92c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::tid_t
93c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetThreadID () const;
94c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
95c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    uint32_t
96c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetIndexID () const;
97c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
98c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    const char *
99c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetName () const;
100c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
101c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    const char *
102c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetQueueName() const;
103c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
104c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
105c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepOver (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
106c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
107c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
108c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepInto (lldb::RunMode stop_other_threads = lldb::eOnlyDuringStepping);
109c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
110c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
111c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepOut ();
112c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
113c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
114c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepOutOfFrame (lldb::SBFrame &frame);
115c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
116c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
117c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepInstruction(bool step_over);
118c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
119c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    SBError
120c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    StepOverUntil (lldb::SBFrame &frame,
121c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                   lldb::SBFileSpec &file_spec,
122c3fba812b636dcdede81be622d557efbdc834240Johnny Chen                   uint32_t line);
123c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
124c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    void
125c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    RunToAddress (lldb::addr_t addr);
126c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
127c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    %feature("docstring", "
128c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    //--------------------------------------------------------------------------
129c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// LLDB currently supports process centric debugging which means when any
130c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// thread in a process stops, all other threads are stopped. The Suspend()
131c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// call here tells our process to suspend a thread and not let it run when
132c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// the other threads in a process are allowed to run. So when
133c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// SBProcess::Continue() is called, any threads that aren't suspended will
134c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// be allowed to run. If any of the SBThread functions for stepping are
135c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// called (StepOver, StepInto, StepOut, StepInstruction, RunToAddres), the
136c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// thread will now be allowed to run and these funtions will simply return.
137c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ///
138c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Eventually we plan to add support for thread centric debugging where
139c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// each thread is controlled individually and each thread would broadcast
140c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// its state, but we haven't implemented this yet.
141c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ///
142c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Likewise the SBThread::Resume() call will again allow the thread to run
143c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// when the process is continued.
144c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ///
145c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// Suspend() and Resume() functions are not currently reference counted, if
146c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// anyone has the need for them to be reference counted, please let us
147c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    /// know.
148c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    //--------------------------------------------------------------------------
149c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    ") Suspend;
150c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    bool
151c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    Suspend();
152c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
153c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    bool
154c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    Resume ();
155c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
156c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    bool
157c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    IsSuspended();
158c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
159c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    uint32_t
160c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetNumFrames ();
161c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
162c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::SBFrame
163c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetFrameAtIndex (uint32_t idx);
164c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
165c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::SBFrame
166c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetSelectedFrame ();
167c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
168c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::SBFrame
169c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    SetSelectedFrame (uint32_t frame_idx);
170c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
171c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    lldb::SBProcess
172c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetProcess ();
173c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
174c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    bool
175c3fba812b636dcdede81be622d557efbdc834240Johnny Chen    GetDescription (lldb::SBStream &description) const;
1761b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
1771b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton    %pythoncode %{
178394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton        def get_thread_frames(self):
179394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton            frames = []
180394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton            for frame in self:
181394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton                frames.append(frame)
182394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton            return frames
183394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton
184394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton
1851b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["id"] = GetThreadID
1861b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetThreadID, None)
1871b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
1881b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["idx"] = GetIndexID
1891b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetIndexID, None)
1901b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
1911b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["return_value"] = GetStopReturnValue
1921b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetStopReturnValue, None)
1931b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
1941b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["process"] = GetProcess
1951b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetProcess, None)
1961b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
1971b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["num_frames"] = GetNumFrames
1981b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetNumFrames, None)
1991b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
200394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton        __swig_getmethods__["frames"] = get_thread_frames
201394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton        if _newclass: x = property(get_thread_frames, None)
202394da8e3d59e49ce3a02e6b287ccfc6f568c19a9Greg Clayton
2031b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["name"] = GetName
2041b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetName, None)
2051b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
2061b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["queue"] = GetQueueName
2071b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetQueueName, None)
2081b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
2091b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["stop_reason"] = GetStopReason
2101b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(GetStopReason, None)
2111b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
2121b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        __swig_getmethods__["is_suspended"] = IsSuspended
2131b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton        if _newclass: x = property(IsSuspended, None)
2141b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton    %}
2151b925206e3c4867fea9eb55a4c6460962cf32564Greg Clayton
216c3fba812b636dcdede81be622d557efbdc834240Johnny Chen};
217c3fba812b636dcdede81be622d557efbdc834240Johnny Chen
218c3fba812b636dcdede81be622d557efbdc834240Johnny Chen} // namespace lldb
219