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