ProcessPOSIX.h revision ff3536bf16cf4abda02a69353db94137ee31819f
1//===-- ProcessPOSIX.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_ProcessPOSIX_H_
11#define liblldb_ProcessPOSIX_H_
12
13// C Includes
14
15// C++ Includes
16#include <queue>
17#include <set>
18
19// Other libraries and framework includes
20#include "lldb/Target/Process.h"
21#include "lldb/Target/UnixSignals.h"
22#include "ProcessMessage.h"
23
24class ProcessMonitor;
25
26class ProcessPOSIX :
27    public lldb_private::Process
28{
29public:
30
31    //------------------------------------------------------------------
32    // Constructors and destructors
33    //------------------------------------------------------------------
34    ProcessPOSIX(lldb_private::Target& target,
35                 lldb_private::Listener &listener);
36
37    virtual
38    ~ProcessPOSIX();
39
40    //------------------------------------------------------------------
41    // Process protocol.
42    //------------------------------------------------------------------
43    virtual bool
44    CanDebug(lldb_private::Target &target, bool plugin_specified_by_name);
45
46    virtual lldb_private::Error
47    WillLaunch(lldb_private::Module *module);
48
49    virtual lldb_private::Error
50    DoAttachToProcessWithID(lldb::pid_t pid);
51
52    virtual lldb_private::Error
53    DoAttachToProcessWithID (lldb::pid_t pid, const lldb_private::ProcessAttachInfo &attach_info);
54
55    virtual lldb_private::Error
56    DoLaunch (lldb_private::Module *exe_module,
57              const lldb_private::ProcessLaunchInfo &launch_info);
58
59    virtual void
60    DidLaunch();
61
62    virtual lldb_private::Error
63    DoResume();
64
65    virtual lldb_private::Error
66    DoHalt(bool &caused_stop);
67
68    virtual lldb_private::Error
69    DoDetach(bool keep_stopped);
70
71    virtual lldb_private::Error
72    DoSignal(int signal);
73
74    virtual lldb_private::Error
75    DoDestroy();
76
77    virtual void
78    RefreshStateAfterStop();
79
80    virtual bool
81    IsAlive();
82
83    virtual size_t
84    DoReadMemory(lldb::addr_t vm_addr,
85                 void *buf,
86                 size_t size,
87                 lldb_private::Error &error);
88
89    virtual size_t
90    DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
91                  lldb_private::Error &error);
92
93    virtual lldb::addr_t
94    DoAllocateMemory(size_t size, uint32_t permissions,
95                     lldb_private::Error &error);
96
97    virtual lldb_private::Error
98    DoDeallocateMemory(lldb::addr_t ptr);
99
100    virtual lldb::addr_t
101    ResolveIndirectFunction(const lldb_private::Address *address, lldb_private::Error &error);
102
103    virtual size_t
104    GetSoftwareBreakpointTrapOpcode(lldb_private::BreakpointSite* bp_site);
105
106    virtual lldb_private::Error
107    EnableBreakpointSite(lldb_private::BreakpointSite *bp_site);
108
109    virtual lldb_private::Error
110    DisableBreakpointSite(lldb_private::BreakpointSite *bp_site);
111
112    virtual lldb_private::Error
113    EnableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
114
115    virtual lldb_private::Error
116    DisableWatchpoint(lldb_private::Watchpoint *wp, bool notify = true);
117
118    virtual lldb_private::Error
119    GetWatchpointSupportInfo(uint32_t &num);
120
121    virtual lldb_private::Error
122    GetWatchpointSupportInfo(uint32_t &num, bool &after);
123
124    virtual uint32_t
125    UpdateThreadListIfNeeded();
126
127    virtual bool
128    UpdateThreadList(lldb_private::ThreadList &old_thread_list,
129                     lldb_private::ThreadList &new_thread_list) = 0;
130
131    virtual lldb::ByteOrder
132    GetByteOrder() const;
133
134    virtual lldb::addr_t
135    GetImageInfoAddress();
136
137    virtual size_t
138    PutSTDIN(const char *buf, size_t len, lldb_private::Error &error);
139
140    //--------------------------------------------------------------------------
141    // ProcessPOSIX internal API.
142
143    /// Registers the given message with this process.
144    void SendMessage(const ProcessMessage &message);
145
146    ProcessMonitor &
147    GetMonitor() { assert(m_monitor); return *m_monitor; }
148
149    lldb_private::UnixSignals &
150    GetUnixSignals();
151
152    const char *
153    GetFilePath(const lldb_private::ProcessLaunchInfo::FileAction *file_action,
154                const char *default_path);
155
156    /// Stops all threads in the process.
157    /// The \p stop_tid parameter indicates the thread which initiated the stop.
158    virtual void
159    StopAllThreads(lldb::tid_t stop_tid);
160
161    /// Adds the thread to the list of threads for which we have received the initial stopping signal.
162    /// The \p stop_tid paramter indicates the thread which the stop happened for.
163    bool
164    AddThreadForInitialStopIfNeeded(lldb::tid_t stop_tid);
165
166protected:
167    /// Target byte order.
168    lldb::ByteOrder m_byte_order;
169
170    /// Process monitor;
171    ProcessMonitor *m_monitor;
172
173    /// The module we are executing.
174    lldb_private::Module *m_module;
175
176    /// Message queue notifying this instance of inferior process state changes.
177    lldb_private::Mutex m_message_mutex;
178    std::queue<ProcessMessage> m_message_queue;
179
180    /// Drive any exit events to completion.
181    bool m_exit_now;
182
183    /// OS-specific signal set.
184    lldb_private::UnixSignals m_signals;
185
186    /// Returns true if the process has exited.
187    bool HasExited();
188
189    /// Returns true if the process is stopped.
190    bool IsStopped();
191
192    /// Returns true if at least one running is currently running
193    bool IsAThreadRunning();
194
195    typedef std::map<lldb::addr_t, lldb::addr_t> MMapMap;
196    MMapMap m_addr_to_mmap_size;
197
198    typedef std::set<lldb::tid_t> ThreadStopSet;
199    /// Every thread begins with a stop signal. This keeps track
200    /// of the threads for which we have received the stop signal.
201    ThreadStopSet m_seen_initial_stop;
202};
203
204#endif  // liblldb_MacOSXProcess_H_
205