Home | History | Annotate | Download | only in Target
      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 
     21 namespace lldb_private {
     22 
     23 class 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.
     28 public:
     29     ThreadPlanCallFunction (Thread &thread,
     30                             const 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                             const 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     ShouldStop (Event *event_ptr);
     63 
     64     virtual Vote
     65     ShouldReportStop(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     // If it hasn't been set for one or the other of these reasons, we'll return the PrivateStopReason.
    119     // This is needed because we want the CallFunction thread plans not to show up as the stop reason.
    120     // But if something bad goes wrong, it is nice to be able to tell the user what really happened.
    121 
    122     virtual lldb::StopInfoSP
    123     GetRealStopInfo()
    124     {
    125         if (m_real_stop_info_sp)
    126             return m_real_stop_info_sp;
    127         else
    128             return GetPrivateStopInfo ();
    129     }
    130 
    131     lldb::addr_t
    132     GetStopAddress ()
    133     {
    134         return m_stop_address;
    135     }
    136 
    137     virtual bool
    138     RestoreThreadState();
    139 
    140 protected:
    141     void ReportRegisterState (const char *message);
    142 
    143     virtual bool
    144     DoPlanExplainsStop (Event *event_ptr);
    145 
    146 private:
    147 
    148     bool
    149     ConstructorSetup (Thread &thread,
    150                       ABI *& abi,
    151                       lldb::addr_t &start_load_addr,
    152                       lldb::addr_t &function_load_addr);
    153 
    154     void
    155     DoTakedown (bool success);
    156 
    157     void
    158     SetBreakpoints ();
    159 
    160     void
    161     ClearBreakpoints ();
    162 
    163     bool
    164     BreakpointsExplainStop ();
    165 
    166     bool                                            m_valid;
    167     bool                                            m_stop_other_threads;
    168     Address                                         m_function_addr;
    169     Address                                         m_start_addr;
    170     lldb::addr_t                                    m_function_sp;
    171     Thread::RegisterCheckpoint                      m_register_backup;
    172     lldb::ThreadPlanSP                              m_subplan_sp;
    173     LanguageRuntime                                *m_cxx_language_runtime;
    174     LanguageRuntime                                *m_objc_language_runtime;
    175     Thread::ThreadStateCheckpoint                   m_stored_thread_state;
    176     lldb::StopInfoSP                                m_real_stop_info_sp; // In general we want to hide call function
    177                                                                          // thread plans, but for reporting purposes,
    178                                                                          // it's nice to know the real stop reason.
    179                                                                          // This gets set in DoTakedown.
    180     StreamString                                    m_constructor_errors;
    181     ClangASTType                                    m_return_type;
    182     lldb::ValueObjectSP                             m_return_valobj_sp;  // If this contains a valid pointer, use the ABI to extract values when complete
    183     bool                                            m_takedown_done;    // We want to ensure we only do the takedown once.  This ensures that.
    184     lldb::addr_t                                    m_stop_address;     // This is the address we stopped at.  Also set in DoTakedown;
    185     bool                                            m_unwind_on_error;
    186     bool                                            m_ignore_breakpoints;
    187 
    188     DISALLOW_COPY_AND_ASSIGN (ThreadPlanCallFunction);
    189 };
    190 
    191 } // namespace lldb_private
    192 
    193 #endif  // liblldb_ThreadPlanCallFunction_h_
    194