ThreadPlanCallFunction.h revision ba560cc7d03c9f7d9df81e60201c5ec75cff5232
1//===-- ThreadPlanCallFunction.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 liblldb_ThreadPlanCallFunction_h_
11#define liblldb_ThreadPlanCallFunction_h_
12
13// C Includes
14// C++ Includes
15// Other libraries and framework includes
16// Project includes
17#include "lldb/lldb-private.h"
18#include "lldb/Target/Thread.h"
19#include "lldb/Target/ThreadPlan.h"
20
21namespace lldb_private {
22
23class ThreadPlanCallFunction : public ThreadPlan
24{
25public:
26    ThreadPlanCallFunction (Thread &thread,
27                            Address &function,
28                            lldb::addr_t arg,
29                            bool stop_other_threads,
30                            bool discard_on_error = true,
31                            lldb::addr_t *this_arg = 0,
32                            lldb::addr_t *cmd_arg = 0);
33
34    ThreadPlanCallFunction (Thread &thread,
35                            Address &function,
36                            bool stop_other_threads,
37                            bool discard_on_error,
38                            lldb::addr_t *arg1_ptr = NULL,
39                            lldb::addr_t *arg2_ptr = NULL,
40                            lldb::addr_t *arg3_ptr = NULL,
41                            lldb::addr_t *arg4_ptr = NULL,
42                            lldb::addr_t *arg5_ptr = NULL,
43                            lldb::addr_t *arg6_ptr = NULL);
44
45    virtual
46    ~ThreadPlanCallFunction ();
47
48    virtual void
49    GetDescription (Stream *s, lldb::DescriptionLevel level);
50
51    virtual bool
52    ValidatePlan (Stream *error);
53
54    virtual bool
55    PlanExplainsStop ();
56
57    virtual bool
58    ShouldStop (Event *event_ptr);
59
60    virtual bool
61    StopOthers ();
62
63    virtual void
64    SetStopOthers (bool new_value);
65
66    virtual lldb::StateType
67    GetPlanRunState ();
68
69    virtual void
70    DidPush ();
71
72    virtual bool
73    WillStop ();
74
75    virtual bool
76    MischiefManaged ();
77
78    virtual bool
79    IsMasterPlan()
80    {
81        return true;
82    }
83
84    // To get the return value from a function call you must create a
85    // lldb::ValueSP that contains a valid clang type in its context and call
86    // RequestReturnValue. The ValueSP will be stored and when the function is
87    // done executing, the object will check if there is a requested return
88    // value. If there is, the return value will be retrieved using the
89    // ABI::GetReturnValue() for the ABI in the process. Then after the thread
90    // plan is complete, you can call "GetReturnValue()" to retrieve the value
91    // that was extracted.
92
93    const lldb::ValueSP &
94    GetReturnValue ()
95    {
96        return m_return_value_sp;
97    }
98
99    void
100    RequestReturnValue (lldb::ValueSP &return_value_sp)
101    {
102        m_return_value_sp = return_value_sp;
103    }
104
105    // Return the stack pointer that the function received
106    // on entry.  Any stack address below this should be
107    // considered invalid after the function has been
108    // cleaned up.
109    lldb::addr_t
110    GetFunctionStackPointer()
111    {
112        return m_function_sp;
113    }
114
115    // Classes that derive from ClangFunction, and implement
116    // their own WillPop methods should call this so that the
117    // thread state gets restored if the plan gets discarded.
118    virtual void
119    WillPop ();
120
121    // If the thread plan stops mid-course, this will be the stop reason that interrupted us.
122    // Once DoTakedown is called, this will be the real stop reason at the end of the function call.
123    // This is needed because we want the CallFunction thread plans not to show up as the stop reason.
124    // But if something bad goes wrong, it is nice to be able to tell the user what really happened.
125    virtual lldb::StopInfoSP
126    GetRealStopInfo()
127    {
128        return m_real_stop_info_sp;
129    }
130
131    lldb::addr_t
132    GetStopAddress ()
133    {
134        return m_stop_address;
135    }
136
137protected:
138    void ReportRegisterState (const char *message);
139private:
140    void
141    DoTakedown ();
142
143    void
144    SetBreakpoints ();
145
146    void
147    ClearBreakpoints ();
148
149    bool
150    BreakpointsExplainStop ();
151
152    bool                                            m_valid;
153    bool                                            m_stop_other_threads;
154    Address                                         m_function_addr;
155    Address                                         m_start_addr;
156    lldb::addr_t                                    m_function_sp;
157//    Process                                        &m_process;
158//    Thread                                         &m_thread;
159    Thread::RegisterCheckpoint                      m_register_backup;
160    lldb::ThreadPlanSP                              m_subplan_sp;
161    LanguageRuntime                                *m_cxx_language_runtime;
162    LanguageRuntime                                *m_objc_language_runtime;
163    Thread::ThreadStateCheckpoint                   m_stored_thread_state;
164    lldb::StopInfoSP                                m_real_stop_info_sp; // In general we want to hide call function
165                                                                         // thread plans, but for reporting purposes,
166                                                                         // it's nice to know the real stop reason.
167                                                                         // This gets set in DoTakedown.
168    lldb::ValueSP                                   m_return_value_sp;  // If this contains a valid pointer, use the ABI to extract values when complete
169    bool                                            m_takedown_done;    // We want to ensure we only do the takedown once.  This ensures that.
170    lldb::addr_t                                    m_stop_address;     // This is the address we stopped at.  Also set in DoTakedown;
171
172    DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction);
173};
174
175} // namespace lldb_private
176
177#endif  // liblldb_ThreadPlanCallFunction_h_
178