Home | History | Annotate | Download | only in interface
      1 //===-- SWIG Interface for SBProcess ----------------------------*- 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 namespace lldb {
     11 
     12 %feature("docstring",
     13 "Represents the process associated with the target program.
     14 
     15 SBProcess supports thread iteration. For example (from test/lldbutil.py),
     16 
     17 # ==================================================
     18 # Utility functions related to Threads and Processes
     19 # ==================================================
     20 
     21 def get_stopped_threads(process, reason):
     22     '''Returns the thread(s) with the specified stop reason in a list.
     23 
     24     The list can be empty if no such thread exists.
     25     '''
     26     threads = []
     27     for t in process:
     28         if t.GetStopReason() == reason:
     29             threads.append(t)
     30     return threads
     31 
     32 ...
     33 "
     34 ) SBProcess;
     35 class SBProcess
     36 {
     37 public:
     38     //------------------------------------------------------------------
     39     /// Broadcaster event bits definitions.
     40     //------------------------------------------------------------------
     41     enum
     42     {
     43         eBroadcastBitStateChanged   = (1 << 0),
     44         eBroadcastBitInterrupt      = (1 << 1),
     45         eBroadcastBitSTDOUT         = (1 << 2),
     46         eBroadcastBitSTDERR         = (1 << 3),
     47         eBroadcastBitProfileData    = (1 << 4)
     48     };
     49 
     50     SBProcess ();
     51 
     52     SBProcess (const lldb::SBProcess& rhs);
     53 
     54     ~SBProcess();
     55 
     56     static const char *
     57     GetBroadcasterClassName ();
     58 
     59     const char *
     60     GetPluginName ();
     61 
     62     const char *
     63     GetShortPluginName ();
     64 
     65     void
     66     Clear ();
     67 
     68     bool
     69     IsValid() const;
     70 
     71     lldb::SBTarget
     72     GetTarget() const;
     73 
     74     lldb::ByteOrder
     75     GetByteOrder() const;
     76 
     77     %feature("autodoc", "
     78     Writes data into the current process's stdin. API client specifies a Python
     79     string as the only argument.
     80     ") PutSTDIN;
     81     size_t
     82     PutSTDIN (const char *src, size_t src_len);
     83 
     84     %feature("autodoc", "
     85     Reads data from the current process's stdout stream. API client specifies
     86     the size of the buffer to read data into. It returns the byte buffer in a
     87     Python string.
     88     ") GetSTDOUT;
     89     size_t
     90     GetSTDOUT (char *dst, size_t dst_len) const;
     91 
     92     %feature("autodoc", "
     93     Reads data from the current process's stderr stream. API client specifies
     94     the size of the buffer to read data into. It returns the byte buffer in a
     95     Python string.
     96     ") GetSTDERR;
     97     size_t
     98     GetSTDERR (char *dst, size_t dst_len) const;
     99 
    100     size_t
    101     GetAsyncProfileData(char *dst, size_t dst_len) const;
    102 
    103     void
    104     ReportEventState (const lldb::SBEvent &event, FILE *out) const;
    105 
    106     void
    107     AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
    108 
    109     %feature("docstring", "
    110     //------------------------------------------------------------------
    111     /// Remote connection related functions. These will fail if the
    112     /// process is not in eStateConnected. They are intended for use
    113     /// when connecting to an externally managed debugserver instance.
    114     //------------------------------------------------------------------
    115     ") RemoteAttachToProcessWithID;
    116     bool
    117     RemoteAttachToProcessWithID (lldb::pid_t pid,
    118                                  lldb::SBError& error);
    119 
    120     %feature("docstring",
    121     "See SBTarget.Launch for argument description and usage."
    122     ) RemoteLaunch;
    123     bool
    124     RemoteLaunch (char const **argv,
    125                   char const **envp,
    126                   const char *stdin_path,
    127                   const char *stdout_path,
    128                   const char *stderr_path,
    129                   const char *working_directory,
    130                   uint32_t launch_flags,
    131                   bool stop_at_entry,
    132                   lldb::SBError& error);
    133 
    134     //------------------------------------------------------------------
    135     // Thread related functions
    136     //------------------------------------------------------------------
    137     uint32_t
    138     GetNumThreads ();
    139 
    140     %feature("autodoc", "
    141     Returns the INDEX'th thread from the list of current threads.  The index
    142     of a thread is only valid for the current stop.  For a persistent thread
    143     identifier use either the thread ID or the IndexID.  See help on SBThread
    144     for more details.
    145     ") GetThreadAtIndex;
    146     lldb::SBThread
    147     GetThreadAtIndex (size_t index);
    148 
    149     %feature("autodoc", "
    150     Returns the thread with the given thread ID.
    151     ") GetThreadByID;
    152     lldb::SBThread
    153     GetThreadByID (lldb::tid_t sb_thread_id);
    154 
    155     %feature("autodoc", "
    156     Returns the thread with the given thread IndexID.
    157     ") GetThreadByIndexID;
    158     lldb::SBThread
    159     GetThreadByIndexID (uint32_t index_id);
    160 
    161     %feature("autodoc", "
    162     Returns the currently selected thread.
    163     ") GetSelectedThread;
    164     lldb::SBThread
    165     GetSelectedThread () const;
    166 
    167     %feature("autodoc", "
    168     Lazily create a thread on demand through the current OperatingSystem plug-in, if the current OperatingSystem plug-in supports it.
    169     ") CreateOSPluginThread;
    170     lldb::SBThread
    171     CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context);
    172 
    173     bool
    174     SetSelectedThread (const lldb::SBThread &thread);
    175 
    176     bool
    177     SetSelectedThreadByID (lldb::tid_t tid);
    178 
    179     bool
    180     SetSelectedThreadByIndexID (uint32_t index_id);
    181 
    182     //------------------------------------------------------------------
    183     // Stepping related functions
    184     //------------------------------------------------------------------
    185 
    186     lldb::StateType
    187     GetState ();
    188 
    189     int
    190     GetExitStatus ();
    191 
    192     const char *
    193     GetExitDescription ();
    194 
    195     %feature("autodoc", "
    196     Returns the process ID of the process.
    197     ") GetProcessID;
    198     lldb::pid_t
    199     GetProcessID ();
    200 
    201     %feature("autodoc", "
    202     Returns an integer ID that is guaranteed to be unique across all process instances. This is not the process ID, just a unique integer for comparison and caching purposes.
    203     ") GetUniqueID;
    204     uint32_t
    205     GetUniqueID();
    206 
    207     uint32_t
    208     GetAddressByteSize() const;
    209 
    210     %feature("docstring", "
    211     Kills the process and shuts down all threads that were spawned to
    212     track and monitor process.
    213     ") Destroy;
    214     lldb::SBError
    215     Destroy ();
    216 
    217     lldb::SBError
    218     Continue ();
    219 
    220     lldb::SBError
    221     Stop ();
    222 
    223     %feature("docstring", "Same as Destroy(self).") Destroy;
    224     lldb::SBError
    225     Kill ();
    226 
    227     lldb::SBError
    228     Detach ();
    229 
    230     %feature("docstring", "Sends the process a unix signal.") Signal;
    231     lldb::SBError
    232     Signal (int signal);
    233 
    234     %feature("docstring", "
    235     Returns a stop id that will increase every time the process executes.  If
    236     include_expression_stops is true, then stops caused by expression evaluation
    237     will cause the returned value to increase, otherwise the counter returned will
    238     only increase when execution is continued explicitly by the user.  Note, the value
    239     will always increase, but may increase by more than one per stop.
    240     ") GetStopID;
    241     uint32_t
    242     GetStopID(bool include_expression_stops = false);
    243 
    244     void
    245     SendAsyncInterrupt();
    246 
    247     %feature("autodoc", "
    248     Reads memory from the current process's address space and removes any
    249     traps that may have been inserted into the memory. It returns the byte
    250     buffer in a Python string. Example:
    251 
    252     # Read 4 bytes from address 'addr' and assume error.Success() is True.
    253     content = process.ReadMemory(addr, 4, error)
    254     # Use 'ascii' encoding as each byte of 'content' is within [0..255].
    255     new_bytes = bytearray(content, 'ascii')
    256     ") ReadMemory;
    257     size_t
    258     ReadMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
    259 
    260     %feature("autodoc", "
    261     Writes memory to the current process's address space and maintains any
    262     traps that might be present due to software breakpoints. Example:
    263 
    264     # Create a Python string from the byte array.
    265     new_value = str(bytes)
    266     result = process.WriteMemory(addr, new_value, error)
    267     if not error.Success() or result != len(bytes):
    268         print 'SBProcess.WriteMemory() failed!'
    269     ") WriteMemory;
    270     size_t
    271     WriteMemory (addr_t addr, const void *buf, size_t size, lldb::SBError &error);
    272 
    273     %feature("autodoc", "
    274     Reads a NULL terminated C string from the current process's address space.
    275     It returns a python string of the exact length, or truncates the string if
    276     the maximum character limit is reached. Example:
    277 
    278     # Read a C string of at most 256 bytes from address '0x1000'
    279     error = lldb.SBError()
    280     cstring = process.ReadCStringFromMemory(0x1000, 256, error)
    281     if error.Success():
    282         print 'cstring: ', cstring
    283     else
    284         print 'error: ', error
    285     ") ReadCStringFromMemory;
    286 
    287     size_t
    288     ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &error);
    289 
    290     %feature("autodoc", "
    291     Reads an unsigned integer from memory given a byte size and an address.
    292     Returns the unsigned integer that was read. Example:
    293 
    294     # Read a 4 byte unsigned integer from address 0x1000
    295     error = lldb.SBError()
    296     uint = ReadUnsignedFromMemory(0x1000, 4, error)
    297     if error.Success():
    298         print 'integer: %u' % uint
    299     else
    300         print 'error: ', error
    301 
    302     ") ReadUnsignedFromMemory;
    303 
    304     uint64_t
    305     ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &error);
    306 
    307     %feature("autodoc", "
    308     Reads a pointer from memory from an address and returns the value. Example:
    309 
    310     # Read a pointer from address 0x1000
    311     error = lldb.SBError()
    312     ptr = ReadPointerFromMemory(0x1000, error)
    313     if error.Success():
    314         print 'pointer: 0x%x' % ptr
    315     else
    316         print 'error: ', error
    317 
    318     ") ReadPointerFromMemory;
    319 
    320     lldb::addr_t
    321     ReadPointerFromMemory (addr_t addr, lldb::SBError &error);
    322 
    323 
    324     // Events
    325     static lldb::StateType
    326     GetStateFromEvent (const lldb::SBEvent &event);
    327 
    328     static bool
    329     GetRestartedFromEvent (const lldb::SBEvent &event);
    330 
    331     static size_t
    332     GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event);
    333 
    334     static const char *
    335     GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx);
    336 
    337     static lldb::SBProcess
    338     GetProcessFromEvent (const lldb::SBEvent &event);
    339 
    340     static bool
    341     EventIsProcessEvent (const lldb::SBEvent &event);
    342 
    343     lldb::SBBroadcaster
    344     GetBroadcaster () const;
    345 
    346     bool
    347     GetDescription (lldb::SBStream &description);
    348 
    349     uint32_t
    350     GetNumSupportedHardwareWatchpoints (lldb::SBError &error) const;
    351 
    352     uint32_t
    353     LoadImage (lldb::SBFileSpec &image_spec, lldb::SBError &error);
    354 
    355     lldb::SBError
    356     UnloadImage (uint32_t image_token);
    357 
    358     %pythoncode %{
    359         def __get_is_alive__(self):
    360             '''Returns "True" if the process is currently alive, "False" otherwise'''
    361             s = self.GetState()
    362             if (s == eStateAttaching or
    363                 s == eStateLaunching or
    364                 s == eStateStopped or
    365                 s == eStateRunning or
    366                 s == eStateStepping or
    367                 s == eStateCrashed or
    368                 s == eStateSuspended):
    369                 return True
    370             return False
    371 
    372         def __get_is_running__(self):
    373             '''Returns "True" if the process is currently running, "False" otherwise'''
    374             state = self.GetState()
    375             if state == eStateRunning or state == eStateStepping:
    376                 return True
    377             return False
    378 
    379         def __get_is_running__(self):
    380             '''Returns "True" if the process is currently stopped, "False" otherwise'''
    381             state = self.GetState()
    382             if state == eStateStopped or state == eStateCrashed or state == eStateSuspended:
    383                 return True
    384             return False
    385 
    386         class threads_access(object):
    387             '''A helper object that will lazily hand out thread for a process when supplied an index.'''
    388             def __init__(self, sbprocess):
    389                 self.sbprocess = sbprocess
    390 
    391             def __len__(self):
    392                 if self.sbprocess:
    393                     return int(self.sbprocess.GetNumThreads())
    394                 return 0
    395 
    396             def __getitem__(self, key):
    397                 if type(key) is int and key < len(self):
    398                     return self.sbprocess.GetThreadAtIndex(key)
    399                 return None
    400 
    401         def get_threads_access_object(self):
    402             '''An accessor function that returns a modules_access() object which allows lazy thread access from a lldb.SBProcess object.'''
    403             return self.threads_access (self)
    404 
    405         def get_process_thread_list(self):
    406             '''An accessor function that returns a list() that contains all threads in a lldb.SBProcess object.'''
    407             threads = []
    408             accessor = self.get_threads_access_object()
    409             for idx in range(len(accessor)):
    410                 threads.append(accessor[idx])
    411             return threads
    412 
    413         __swig_getmethods__["threads"] = get_process_thread_list
    414         if _newclass: threads = property(get_process_thread_list, None, doc='''A read only property that returns a list() of lldb.SBThread objects for this process.''')
    415 
    416         __swig_getmethods__["thread"] = get_threads_access_object
    417         if _newclass: thread = property(get_threads_access_object, None, doc='''A read only property that returns an object that can access threads by thread index (thread = lldb.process.thread[12]).''')
    418 
    419         __swig_getmethods__["is_alive"] = __get_is_alive__
    420         if _newclass: is_alive = property(__get_is_alive__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently alive.''')
    421 
    422         __swig_getmethods__["is_running"] = __get_is_running__
    423         if _newclass: is_running = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently running.''')
    424 
    425         __swig_getmethods__["is_stopped"] = __get_is_running__
    426         if _newclass: is_stopped = property(__get_is_running__, None, doc='''A read only property that returns a boolean value that indicates if this process is currently stopped.''')
    427 
    428         __swig_getmethods__["id"] = GetProcessID
    429         if _newclass: id = property(GetProcessID, None, doc='''A read only property that returns the process ID as an integer.''')
    430 
    431         __swig_getmethods__["target"] = GetTarget
    432         if _newclass: target = property(GetTarget, None, doc='''A read only property that an lldb object that represents the target (lldb.SBTarget) that owns this process.''')
    433 
    434         __swig_getmethods__["num_threads"] = GetNumThreads
    435         if _newclass: num_threads = property(GetNumThreads, None, doc='''A read only property that returns the number of threads in this process as an integer.''')
    436 
    437         __swig_getmethods__["selected_thread"] = GetSelectedThread
    438         __swig_setmethods__["selected_thread"] = SetSelectedThread
    439         if _newclass: selected_thread = property(GetSelectedThread, SetSelectedThread, doc='''A read/write property that gets/sets the currently selected thread in this process. The getter returns a lldb.SBThread object and the setter takes an lldb.SBThread object.''')
    440 
    441         __swig_getmethods__["state"] = GetState
    442         if _newclass: state = property(GetState, None, doc='''A read only property that returns an lldb enumeration value (see enumerations that start with "lldb.eState") that represents the current state of this process (running, stopped, exited, etc.).''')
    443 
    444         __swig_getmethods__["exit_state"] = GetExitStatus
    445         if _newclass: exit_state = property(GetExitStatus, None, doc='''A read only property that returns an exit status as an integer of this process when the process state is lldb.eStateExited.''')
    446 
    447         __swig_getmethods__["exit_description"] = GetExitDescription
    448         if _newclass: exit_description = property(GetExitDescription, None, doc='''A read only property that returns an exit description as a string of this process when the process state is lldb.eStateExited.''')
    449 
    450         __swig_getmethods__["broadcaster"] = GetBroadcaster
    451         if _newclass: broadcaster = property(GetBroadcaster, None, doc='''A read only property that an lldb object that represents the broadcaster (lldb.SBBroadcaster) for this process.''')
    452     %}
    453 
    454 };
    455 
    456 }  // namespace lldb
    457