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